Upstream version 6.35.131.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / browser / xwalk_runner.cc
index f9aa69f..c70b350 100644 (file)
@@ -7,20 +7,24 @@
 #include <vector>
 #include "base/command_line.h"
 #include "base/logging.h"
+#include "content/public/browser/render_process_host.h"
+#include "xwalk/application/browser/application.h"
+#include "xwalk/application/browser/application_service.h"
 #include "xwalk/application/browser/application_system.h"
 #include "xwalk/extensions/browser/xwalk_extension_service.h"
 #include "xwalk/runtime/browser/application_component.h"
 #include "xwalk/runtime/browser/runtime_context.h"
 #include "xwalk/runtime/browser/sysapps_component.h"
-#include "xwalk/runtime/browser/xwalk_component.h"
+#include "xwalk/runtime/browser/xwalk_app_extension_bridge.h"
 #include "xwalk/runtime/browser/xwalk_browser_main_parts.h"
+#include "xwalk/runtime/browser/xwalk_component.h"
 #include "xwalk/runtime/browser/xwalk_content_browser_client.h"
 #include "xwalk/runtime/common/xwalk_runtime_features.h"
 #include "xwalk/runtime/common/xwalk_switches.h"
 
 #if defined(OS_ANDROID)
 #include "xwalk/runtime/browser/xwalk_runner_android.h"
-#elif defined(OS_TIZEN_MOBILE)
+#elif defined(OS_TIZEN)
 #include "xwalk/runtime/browser/xwalk_runner_tizen.h"
 #endif
 
@@ -28,6 +32,7 @@ namespace xwalk {
 
 namespace {
 
+const char kDefaultLocale[] = "en-US";
 XWalkRunner* g_xwalk_runner = NULL;
 
 }  // namespace
@@ -65,14 +70,15 @@ application::ApplicationSystem* XWalkRunner::app_system() {
 
 void XWalkRunner::PreMainMessageLoopRun() {
   runtime_context_.reset(new RuntimeContext);
-
+  app_extension_bridge_.reset(new XWalkAppExtensionBridge());
   // FIXME(cmarcelo): Remove this check once we remove the --uninstall
   // command line.
   CommandLine* cmd_line = CommandLine::ForCurrentProcess();
   if (!cmd_line->HasSwitch(switches::kUninstall))
-    extension_service_.reset(new extensions::XWalkExtensionService);
-
+    extension_service_.reset(new extensions::XWalkExtensionService(
+        app_extension_bridge_.get()));
   CreateComponents();
+  app_extension_bridge_->SetApplicationSystem(app_component_->app_system());
 }
 
 void XWalkRunner::PostMainMessageLoopRun() {
@@ -81,6 +87,10 @@ void XWalkRunner::PostMainMessageLoopRun() {
   runtime_context_.reset();
 }
 
+std::string XWalkRunner::GetLocale() const {
+  return kDefaultLocale;
+}
+
 void XWalkRunner::CreateComponents() {
   scoped_ptr<ApplicationComponent> app_component(CreateAppComponent());
   // Keep a reference as some code still needs to call
@@ -113,7 +123,17 @@ scoped_ptr<SysAppsComponent> XWalkRunner::CreateSysAppsComponent() {
   return make_scoped_ptr(new SysAppsComponent());
 }
 
-void XWalkRunner::OnRenderProcessHostCreated(content::RenderProcessHost* host) {
+void XWalkRunner::InitializeRuntimeVariablesForExtensions(
+    const content::RenderProcessHost* host,
+    base::ValueMap& variables) {
+  application::Application* app = app_system()->application_service()->
+      GetApplicationByRenderHostID(host->GetID());
+
+  if (app)
+    variables["app_id"] = base::Value::CreateStringValue(app->id());
+}
+
+void XWalkRunner::OnRenderProcessWillLaunch(content::RenderProcessHost* host) {
   if (!extension_service_)
     return;
 
@@ -136,8 +156,11 @@ void XWalkRunner::OnRenderProcessHostCreated(content::RenderProcessHost* host) {
   main_parts->CreateInternalExtensionsForExtensionThread(
       host, &extension_thread_extensions);
 
-  extension_service_->OnRenderProcessHostCreated(
-      host, &ui_thread_extensions, &extension_thread_extensions);
+  base::ValueMap runtime_variables;
+  InitializeRuntimeVariablesForExtensions(host, runtime_variables);
+  extension_service_->OnRenderProcessWillLaunch(
+      host, &ui_thread_extensions, &extension_thread_extensions,
+      runtime_variables);
 }
 
 void XWalkRunner::OnRenderProcessHostGone(content::RenderProcessHost* host) {
@@ -151,7 +174,7 @@ scoped_ptr<XWalkRunner> XWalkRunner::Create() {
   XWalkRunner* runner = NULL;
 #if defined(OS_ANDROID)
   runner = new XWalkRunnerAndroid;
-#elif defined(OS_TIZEN_MOBILE)
+#elif defined(OS_TIZEN)
   runner = new XWalkRunnerTizen;
 #else
   runner = new XWalkRunner;