Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / browser / xwalk_browser_main_parts.cc
index 3fc5afb..37e4c83 100644 (file)
 #include "base/files/file_path.h"
 #include "base/message_loop/message_loop.h"
 #include "base/strings/string_number_conversions.h"
+#include "cc/base/switches.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/common/content_switches.h"
+#include "content/public/common/main_function_params.h"
+#include "content/public/common/url_constants.h"
+#include "content/public/common/result_codes.h"
+#include "extensions/browser/extension_system.h"
+#include "net/base/filename_util.h"
+#include "ui/gl/gl_switches.h"
 #include "xwalk/application/browser/application.h"
 #include "xwalk/application/browser/application_system.h"
 #include "xwalk/extensions/browser/xwalk_extension_service.h"
 #include "xwalk/extensions/common/xwalk_extension_switches.h"
-#include "xwalk/runtime/browser/devtools/remote_debugging_server.h"
 #include "xwalk/runtime/browser/runtime.h"
 #include "xwalk/runtime/browser/runtime_context.h"
 #include "xwalk/runtime/browser/xwalk_runner.h"
 #include "xwalk/runtime/common/xwalk_runtime_features.h"
 #include "xwalk/runtime/common/xwalk_switches.h"
-#include "cc/base/switches.h"
-#include "content/public/common/content_switches.h"
-#include "content/public/common/main_function_params.h"
-#include "content/public/common/url_constants.h"
-#include "content/public/common/result_codes.h"
-#include "net/base/net_util.h"
-#include "ui/gl/gl_switches.h"
+
+#if !defined(DISABLE_NACL)
+#include "components/nacl/browser/nacl_browser.h"
+#include "components/nacl/browser/nacl_process_host.h"
+#include "xwalk/runtime/browser/nacl_host/nacl_browser_delegate_impl.h"
+#endif
 
 #if defined(USE_AURA) && defined(USE_X11)
 #include "ui/base/ime/input_method_initializer.h"
@@ -61,7 +68,6 @@ GURL GetURLFromCommandLine(const CommandLine& command_line) {
 
 namespace xswitches {
 // Redefine settings not exposed by content module.
-const char kEnableViewport[] = "enable-viewport";
 const char kEnableOverlayScrollbars[] = "enable-overlay-scrollbars";
 }
 
@@ -70,7 +76,7 @@ namespace xwalk {
 XWalkBrowserMainParts::XWalkBrowserMainParts(
     const content::MainFunctionParams& parameters)
     : xwalk_runner_(XWalkRunner::GetInstance()),
-      startup_url_(content::kAboutBlankURL),
+      startup_url_(url::kAboutBlankURL),
       parameters_(parameters),
       run_default_message_loop_(true) {
 #if defined(OS_LINUX)
@@ -91,7 +97,8 @@ XWalkBrowserMainParts::~XWalkBrowserMainParts() {
 
 void XWalkBrowserMainParts::PreMainMessageLoopStart() {
   CommandLine* command_line = CommandLine::ForCurrentProcess();
-  command_line->AppendSwitch(xswitches::kEnableViewport);
+  command_line->AppendSwitch(switches::kEnableViewport);
+  command_line->AppendSwitch(switches::kEnableViewportMeta);
 
   command_line->AppendSwitch(xswitches::kEnableOverlayScrollbars);
 
@@ -99,12 +106,20 @@ void XWalkBrowserMainParts::PreMainMessageLoopStart() {
   // This also enables pinch on Tizen.
   command_line->AppendSwitch(switches::kEnableThreadedCompositing);
 
-  // Show feedback on touch.
-  command_line->AppendSwitch(switches::kEnableGestureTapHighlight);
-
   // FIXME: Add comment why this is needed on Android and Tizen.
   command_line->AppendSwitch(switches::kAllowFileAccessFromFiles);
 
+  // Enable SIMD.JS API by default.
+  /*
+  std::string js_flags("--simd_object");
+  if (command_line->HasSwitch(switches::kJavaScriptFlags)) {
+    js_flags += " ";
+    js_flags +=
+        command_line->GetSwitchValueASCII(switches::kJavaScriptFlags);
+  }
+  command_line->AppendSwitchASCII(switches::kJavaScriptFlags, js_flags);
+  */
+
   startup_url_ = GetURLFromCommandLine(*command_line);
 }
 
@@ -125,10 +140,15 @@ void XWalkBrowserMainParts::RegisterExternalExtensions() {
   CommandLine* cmd_line = CommandLine::ForCurrentProcess();
 
 #if defined(OS_TIZEN)
-  static const std::string tec_path = "/usr/lib/tizen-extensions-crosswalk";
   std::string value = cmd_line->GetSwitchValueASCII(
       switches::kXWalkExternalExtensionsPath);
 
+#if defined(ARCH_CPU_64_BITS)
+  const char tec_path[] = "/usr/lib64/tizen-extensions-crosswalk";
+#else
+  const char tec_path[] = "/usr/lib/tizen-extensions-crosswalk";
+#endif
+
   if (value.empty())
     cmd_line->AppendSwitchASCII(switches::kXWalkExternalExtensionsPath,
         tec_path);
@@ -145,7 +165,7 @@ void XWalkBrowserMainParts::RegisterExternalExtensions() {
 
   if (!cmd_line->HasSwitch(
           switches::kXWalkAllowExternalExtensionsForRemoteSources) &&
-      !startup_url_.SchemeIsFile()) {
+      (!startup_url_.is_empty() && !startup_url_.SchemeIsFile())) {
     VLOG(0) << "Unsupported scheme for external extensions: " <<
           startup_url_.scheme();
     return;
@@ -165,52 +185,42 @@ void XWalkBrowserMainParts::RegisterExternalExtensions() {
 void XWalkBrowserMainParts::PreMainMessageLoopRun() {
   xwalk_runner_->PreMainMessageLoopRun();
 
-  runtime_context_ = xwalk_runner_->runtime_context();
   extension_service_ = xwalk_runner_->extension_service();
 
   if (extension_service_)
     RegisterExternalExtensions();
 
+#if !defined(DISABLE_NACL)
+  NaClBrowserDelegateImpl* delegate = new NaClBrowserDelegateImpl();
+  nacl::NaClBrowser::SetDelegate(delegate);
+
+  content::BrowserThread::PostTask(
+      content::BrowserThread::IO,
+      FROM_HERE,
+      base::Bind(nacl::NaClProcessHost::EarlyStartup));
+#endif
+
   CommandLine* command_line = CommandLine::ForCurrentProcess();
   if (command_line->HasSwitch(switches::kRemoteDebuggingPort)) {
     std::string port_str =
         command_line->GetSwitchValueASCII(switches::kRemoteDebuggingPort);
     int port;
-    const char* local_ip = "0.0.0.0";
-    if (base::StringToInt(port_str, &port) && port > 0 && port < 65535) {
-      remote_debugging_server_.reset(
-          new RemoteDebuggingServer(runtime_context_,
-              local_ip, port, std::string()));
-    }
+    base::StringToInt(port_str, &port);
+    xwalk_runner_->EnableRemoteDebugging(port);
   }
 
   NativeAppWindow::Initialize();
 
-  application::ApplicationSystem* app_system = xwalk_runner_->app_system();
-  if (app_system->HandleApplicationManagementCommands(
-      *command_line, startup_url_,
-      run_default_message_loop_)) {
-    return;
-  }
-
   if (command_line->HasSwitch(switches::kListFeaturesFlags)) {
     XWalkRuntimeFeatures::GetInstance()->DumpFeaturesFlags();
     run_default_message_loop_ = false;
     return;
   }
 
-  if (xwalk_runner_->is_running_as_service()) {
-    // In service mode, Crosswalk doesn't launch anything, just waits
-    // for external requests to launch apps.
-    VLOG(1) << "Crosswalk running as Service.";
-    return;
-  }
-
-  if (app_system->LaunchFromCommandLine(*command_line, startup_url_,
-      run_default_message_loop_)) {
-    return;
-  }
-
+#if !defined(SHARED_PROCESS_MODE)
+  application::ApplicationSystem* app_system = xwalk_runner_->app_system();
+  app_system->LaunchFromCommandLine(*command_line, startup_url_,
+                                    run_default_message_loop_);
   // If the |ui_task| is specified in main function parameter, it indicates
   // that we will run this UI task instead of running the the default main
   // message loop. See |content::BrowserTestBase::SetUp| for |ui_task| usage
@@ -220,6 +230,7 @@ void XWalkBrowserMainParts::PreMainMessageLoopRun() {
     delete parameters_.ui_task;
     run_default_message_loop_ = false;
   }
+#endif
 }
 
 bool XWalkBrowserMainParts::MainMessageLoopRun(int* result_code) {