X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fxwalk%2Fapplication%2Fbrowser%2Fapplication.cc;h=fe87c276926c54ba67df29b06572a6e60fa46eb5;hb=949d079b90dcfa5fa918e1f366a6efb689615d20;hp=e43785ef3a6ed1b624f6b4ec85cfbc400694506a;hpb=d41e52f18cc3fee3627acf2db026b2a86c2a9d18;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/xwalk/application/browser/application.cc b/src/xwalk/application/browser/application.cc index e43785e..fe87c27 100644 --- a/src/xwalk/application/browser/application.cc +++ b/src/xwalk/application/browser/application.cc @@ -22,7 +22,8 @@ #include "xwalk/application/common/constants.h" #include "xwalk/application/common/manifest_handlers/warp_handler.h" #include "xwalk/runtime/browser/runtime.h" -#include "xwalk/runtime/browser/runtime_context.h" +#include "xwalk/runtime/browser/runtime_ui_delegate.h" +#include "xwalk/runtime/browser/xwalk_browser_context.h" #include "xwalk/runtime/browser/xwalk_runner.h" #if defined(OS_TIZEN) @@ -73,7 +74,7 @@ namespace application { scoped_ptr Application::Create( scoped_refptr data, - RuntimeContext* context) { + XWalkBrowserContext* context) { #if defined(OS_TIZEN) return make_scoped_ptr(new ApplicationTizen(data, context)); #else @@ -83,17 +84,17 @@ scoped_ptr Application::Create( Application::Application( scoped_refptr data, - RuntimeContext* runtime_context) + XWalkBrowserContext* browser_context) : data_(data), render_process_host_(NULL), web_contents_(NULL), security_mode_enabled_(false), - runtime_context_(runtime_context), + browser_context_(browser_context), observer_(NULL), remote_debugging_enabled_(false), weak_factory_(this) { - DCHECK(runtime_context_); - DCHECK(data_); + DCHECK(browser_context_); + DCHECK(data_.get()); } Application::~Application() { @@ -107,8 +108,11 @@ GURL Application::GetStartURL() { #if defined(OS_TIZEN) if (data_->IsHostedApp()) { std::string source; - data_->GetManifest()->GetString(widget_keys::kLaunchLocalPathKey, &source); - GURL url = GURL(source); + GURL url; + if (data_->GetManifest()->GetString( + widget_keys::kLaunchLocalPathKey, &source)) { + url = GURL(source); + } if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) return url; @@ -133,9 +137,10 @@ template<> GURL Application::GetStartURL() { if (data_->IsHostedApp()) { std::string source; - data_->GetManifest()->GetString(keys::kStartURLKey, &source); // Not trying to get a relative path for the "fake" application. - return GURL(source); + if (data_->GetManifest()->GetString(keys::kStartURLKey, &source)) + return GURL(source); + return GURL(); } GURL url = GetAbsoluteURLFromKey(keys::kStartURLKey); @@ -214,10 +219,11 @@ bool Application::Launch(const LaunchParams& launch_params) { return false; remote_debugging_enabled_ = launch_params.remote_debugging; - - Runtime* runtime = Runtime::Create( - runtime_context_, - this, content::SiteInstance::CreateForURL(runtime_context_, url)); + auto site = content::SiteInstance::CreateForURL(browser_context_, url); + Runtime* runtime = Runtime::Create(browser_context_, site); + runtime->set_observer(this); + runtime->set_remote_debugging_enabled(remote_debugging_enabled_); + runtimes_.push_back(runtime); render_process_host_ = runtime->GetRenderProcessHost(); render_process_host_->AddObserver(this); web_contents_ = runtime->web_contents(); @@ -227,12 +233,15 @@ bool Application::Launch(const LaunchParams& launch_params) { NativeAppWindow::CreateParams params; params.net_wm_pid = launch_params.launcher_pid; params.state = is_wgt ? - GetWindowShowState(launch_params): + GetWindowShowState(launch_params) : GetWindowShowState(launch_params); + window_show_params_ = params; + // Only the first runtime can have a launch screen. params.splash_screen_path = GetSplashScreenPath(); - - runtime->AttachWindow(params); + runtime->set_ui_delegate(DefaultRuntimeUIDelegate::Create(runtime, params)); + // We call "Show" after RP is initialized to reduce + // the application start up time. return true; } @@ -248,9 +257,9 @@ GURL Application::GetAbsoluteURLFromKey(const std::string& key) { } void Application::Terminate() { - std::set to_be_closed(runtimes_); - std::for_each(to_be_closed.begin(), to_be_closed.end(), - std::mem_fun(&Runtime::Close)); + std::vector to_be_closed(runtimes_.get()); + for (Runtime* runtime : to_be_closed) + runtime->Close(); } int Application::GetRenderProcessHostID() const { @@ -258,24 +267,25 @@ int Application::GetRenderProcessHostID() const { return render_process_host_->GetID(); } -void Application::OnRuntimeAdded(Runtime* runtime) { - DCHECK(runtime); +void Application::OnNewRuntimeAdded(Runtime* runtime) { runtime->set_remote_debugging_enabled(remote_debugging_enabled_); - runtimes_.insert(runtime); + runtime->set_observer(this); + runtime->set_ui_delegate( + DefaultRuntimeUIDelegate::Create(runtime, window_show_params_)); + runtime->Show(); + runtimes_.push_back(runtime); } -void Application::OnRuntimeRemoved(Runtime* runtime) { - DCHECK(runtime); - runtimes_.erase(runtime); +void Application::OnRuntimeClosed(Runtime* runtime) { + auto found = std::find(runtimes_.begin(), runtimes_.end(), runtime); + CHECK(found != runtimes_.end()); + LOG(INFO) << "Application::OnRuntimeClosed " << runtime; + runtimes_.erase(found); - if (runtimes_.empty()) { -#if defined(OS_TIZEN_MOBILE) - runtime->CloseRootWindow(); -#endif + if (runtimes_.empty()) base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&Application::NotifyTermination, weak_factory_.GetWeakPtr())); - } } void Application::RenderProcessExited(RenderProcessHost* host, @@ -299,6 +309,11 @@ void Application::NotifyTermination() { observer_->OnApplicationTerminated(this); } +void Application::RenderChannelCreated() { + CHECK(!runtimes_.empty()); + runtimes_.front()->Show(); +} + bool Application::UseExtension(const std::string& extension_name) const { // TODO(Bai): Tells whether the application contains the specified extension return true; @@ -392,9 +407,9 @@ bool Application::SetPermission(PermissionType type, void Application::InitSecurityPolicy() { // CSP policy takes precedence over WARP. if (data_->HasCSPDefined()) - security_policy_.reset(new SecurityPolicyCSP(this)); + security_policy_.reset(new ApplicationSecurityPolicyCSP(this)); else if (data_->manifest_type() == Manifest::TYPE_WIDGET) - security_policy_.reset(new SecurityPolicyWARP(this)); + security_policy_.reset(new ApplicationSecurityPolicyWARP(this)); if (security_policy_) security_policy_->Enforce();