cobalt

How to change url after start cobalt in preloading state


From the source code of rc_11(11.80927), it does has a interface Application::SetStartLink to set the start URL, but the param has not been used at all, there is no way to change the url when switching from preloading state to kStateStarted for some special cases(eg. add url pairing parameters for dial):

    //there doesn't use the link param(url) in StartApplication in cobalt/browser/main.cc
    void StartApplication(int /*argc*/, char** /*argv*/, const char* /*link*/,
                          const base::Closure& quit_closure) {
      if (!g_application) {
        g_application = new cobalt::browser::Application(quit_closure,
                                                         false /*should_preload*/);
        DCHECK(g_application);
      } else {
        g_application->Start(); -->does NOT use the url param
      }
    }

Solution

  • The URL and initial deep link can only be set at preload time. This is because Preloading is essentially like normal loading, so changing the URL would invalidate the loading that has been done, and would require loading the new URL. Changing the initial deep link also would invalidate the assumption that the initial deep link won't change.

    Once loaded, you can dispatch a kSbEventTypeLink at any time. This will not change the URL but will send a message to the running HTML application without causing a reload.