Run Tizen Webapps in single process mode 05/183805/7
authorsurya.kumar7 <surya.kumar7@samsung.com>
Fri, 29 Jun 2018 17:19:29 +0000 (22:49 +0530)
committerjaekuk lee <juku1999@samsung.com>
Thu, 19 Jul 2018 05:24:51 +0000 (05:24 +0000)
Since Tizen Web Apps don't need node support on the renderer
side, removed node dependency on the renderer and made it
run in single process

Cherry-picked from: https://review.tizen.org/gerrit/#/c/176224/

Change-Id: I4d0cd00862538ac85dab5b321e8ab4fbf91f0b4b
Signed-off-by: surya.kumar7 <surya.kumar7@samsung.com>
33 files changed:
atom/app/node_main.cc
atom/browser/api/atom_api_app.cc
atom/browser/api/atom_api_auto_updater.cc
atom/browser/api/atom_api_menu.cc
atom/browser/api/atom_api_protocol.cc
atom/browser/api/atom_api_session.cc
atom/browser/api/atom_api_web_contents.cc
atom/browser/api/atom_api_window.cc
atom/browser/api/event_emitter.h
atom/browser/api/frame_subscriber.cc
atom/browser/api/save_page_handler.cc
atom/browser/atom_blob_reader.cc
atom/browser/atom_browser_main_parts.cc
atom/browser/atom_download_manager_delegate.cc
atom/browser/browser.cc
atom/browser/javascript_environment.cc
atom/browser/javascript_environment.h
atom/browser/net/js_asker.cc
atom/browser/node_debugger.cc
atom/browser/node_debugger.h
atom/common/api/locker.cc
atom/common/api/locker.h
atom/common/native_mate_converters/callback.cc
atom/common/native_mate_converters/callback.h
atom/common/node_bindings.cc
atom/renderer/atom_renderer_client.cc
chromium_src/chrome/browser/printing/print_preview_message_handler.cc
tizen/common/common.gyp
tizen/common/env_variables.cc [new file with mode: 0644]
tizen/common/env_variables.h [new file with mode: 0644]
tizen/src/wrt_main.cc
vendor/node/src/node.cc
vendor/node/src/node.h

index 9e80ef2..dbfbfae 100644 (file)
@@ -44,7 +44,7 @@ int NodeMain(int argc, char *argv[]) {
 
     int exec_argc;
     const char** exec_argv;
-    node::Init(&argc, const_cast<const char**>(argv), &exec_argc, &exec_argv);
+    // node::Init(&argc, const_cast<const char**>(argv), &exec_argc, &exec_argv); not called
 
     node::IsolateData isolate_data(gin_env.isolate(), loop);
     node::Environment* env = node::CreateEnvironment(
@@ -52,9 +52,9 @@ int NodeMain(int argc, char *argv[]) {
         exec_argc, exec_argv);
 
     // Start our custom debugger implementation.
-    NodeDebugger node_debugger(gin_env.isolate());
-    if (node_debugger.IsRunning())
-      env->AssignToContext(v8::Debug::GetDebugContext(gin_env.isolate()));
+    // NodeDebugger node_debugger(gin_env.isolate()); not called
+    // if (node_debugger.IsRunning())
+    //   env->AssignToContext(v8::Debug::GetDebugContext(gin_env.isolate()));
 
     mate::Dictionary process(gin_env.isolate(), env->process_object());
 #if defined(OS_WIN)
index 638a769..1471c86 100644 (file)
@@ -42,6 +42,7 @@
 #include "native_mate/dictionary.h"
 #include "native_mate/object_template_builder.h"
 #include "net/ssl/ssl_cert_request_info.h"
+#include "tizen/common/env_variables.h"
 #include "ui/base/l10n/l10n_util.h"
 #include "ui/gfx/image/image.h"
 
@@ -476,7 +477,8 @@ int ImportIntoCertStore(
 void OnIconDataAvailable(v8::Isolate* isolate,
                          const App::FileIconCallback& callback,
                          gfx::Image* icon) {
-  v8::Locker locker(isolate);
+  if (!::tizen::is_single_process)
+    v8::Locker locker(isolate);
   v8::HandleScope handle_scope(isolate);
 
   if (icon && !icon->IsEmpty()) {
@@ -567,7 +569,8 @@ void App::OnContinueUserActivity(
 
 void App::OnLogin(LoginHandler* login_handler,
                   const base::DictionaryValue& request_details) {
-  v8::Locker locker(isolate());
+  if (!::tizen::is_single_process)
+    v8::Locker locker(isolate());
   v8::HandleScope handle_scope(isolate());
   bool prevent_default = Emit(
       "login",
@@ -589,7 +592,8 @@ void App::OnCreateWindow(
     const scoped_refptr<content::ResourceRequestBodyImpl>& body,
     int render_process_id,
     int render_frame_id) {
-  v8::Locker locker(isolate());
+  if (!::tizen::is_single_process)
+    v8::Locker locker(isolate());
   v8::HandleScope handle_scope(isolate());
   content::RenderFrameHost* rfh =
       content::RenderFrameHost::FromID(render_process_id, render_frame_id);
@@ -616,7 +620,8 @@ void App::AllowCertificateError(
     bool expired_previous_decision,
     const base::Callback<void(content::CertificateRequestResultType)>&
         callback) {
-  v8::Locker locker(isolate());
+  if (!::tizen::is_single_process)
+    v8::Locker locker(isolate());
   v8::HandleScope handle_scope(isolate());
   bool prevent_default = Emit("certificate-error",
                               WebContents::CreateFrom(isolate(), web_contents),
@@ -882,7 +887,8 @@ void App::GetFileIcon(const base::FilePath& path,
   IconLoader::IconSize icon_size;
   FileIconCallback callback;
 
-  v8::Locker locker(isolate());
+  if (!::tizen::is_single_process)
+    v8::Locker locker(isolate());
   v8::HandleScope handle_scope(isolate());
 
   base::FilePath normalized_path = path.NormalizePathSeparators();
index c23e488..2c6cd3e 100644 (file)
@@ -13,6 +13,7 @@
 #include "base/time/time.h"
 #include "native_mate/dictionary.h"
 #include "native_mate/object_template_builder.h"
+#include "tizen/common/env_variables.h"
 
 namespace mate {
 
@@ -45,7 +46,8 @@ AutoUpdater::~AutoUpdater() {
 }
 
 void AutoUpdater::OnError(const std::string& message) {
-  v8::Locker locker(isolate());
+  if (!::tizen::is_single_process)
+    v8::Locker locker(isolate());
   v8::HandleScope handle_scope(isolate());
   auto error = v8::Exception::Error(mate::StringToV8(isolate(), message));
   mate::EmitEvent(
index da208b3..77314d7 100644 (file)
@@ -12,6 +12,7 @@
 #include "native_mate/constructor.h"
 #include "native_mate/dictionary.h"
 #include "native_mate/object_template_builder.h"
+#include "tizen/common/env_variables.h"
 
 #include "atom/common/node_includes.h"
 
@@ -58,7 +59,8 @@ bool Menu::GetAcceleratorForCommandIdWithParams(
     int command_id,
     bool use_default_accelerator,
     ui::Accelerator* accelerator) const {
-  v8::Locker locker(isolate());
+  if (!::tizen::is_single_process)
+    v8::Locker locker(isolate());
   v8::HandleScope handle_scope(isolate());
   v8::Local<v8::Value> val = get_accelerator_.Run(
       command_id, use_default_accelerator);
index e3b15ed..35bdf24 100644 (file)
@@ -19,6 +19,7 @@
 #include "base/strings/string_util.h"
 #include "content/public/browser/child_process_security_policy.h"
 #include "native_mate/dictionary.h"
+#include "tizen/common/env_variables.h"
 #include "url/url_util.h"
 
 using content::BrowserThread;
@@ -153,7 +154,8 @@ void Protocol::OnIOCompleted(
   if (callback.is_null())
     return;
 
-  v8::Locker locker(isolate());
+  if (!::tizen::is_single_process)
+    v8::Locker locker(isolate());
   v8::HandleScope handle_scope(isolate());
 
   if (error == PROTOCOL_OK) {
index 83d103a..bb3161b 100644 (file)
@@ -49,6 +49,7 @@
 #include "net/url_request/static_http_user_agent_settings.h"
 #include "net/url_request/url_request_context.h"
 #include "net/url_request/url_request_context_getter.h"
+#include "tizen/common/env_variables.h"
 #include "ui/base/l10n/l10n_util.h"
 
 using atom::api::Cookies;
@@ -459,7 +460,8 @@ void Session::OnDownloadCreated(content::DownloadManager* manager,
   if (item->IsSavePackageDownload())
     return;
 
-  v8::Locker locker(isolate());
+  if (!::tizen::is_single_process)
+    v8::Locker locker(isolate());
   v8::HandleScope handle_scope(isolate());
   auto handle = DownloadItem::Create(isolate(), item);
   if (item->GetState() == content::DownloadItem::INTERRUPTED)
index 4365e2e..99cb90a 100644 (file)
@@ -77,6 +77,7 @@
 #include "net/url_request/url_request_context.h"
 #include "third_party/WebKit/public/platform/WebInputEvent.h"
 #include "third_party/WebKit/public/web/WebFindOptions.h"
+#include "tizen/common/env_variables.h"
 #include "ui/display/screen.h"
 
 #if defined(USE_EFL)
@@ -466,7 +467,8 @@ void WebContents::WebContentsCreated(content::WebContents* source_contents,
                                      const std::string& frame_name,
                                      const GURL& target_url,
                                      content::WebContents* new_contents) {
-  v8::Locker locker(isolate());
+  if (!::tizen::is_single_process)
+    v8::Locker locker(isolate());
   v8::HandleScope handle_scope(isolate());
   auto api_web_contents = CreateFrom(isolate(), new_contents, BROWSER_WINDOW);
   Emit("-web-contents-created", api_web_contents, target_url, frame_name);
@@ -478,7 +480,8 @@ void WebContents::AddNewContents(content::WebContents* source,
                                  const gfx::Rect& initial_rect,
                                  bool user_gesture,
                                  bool* was_blocked) {
-  v8::Locker locker(isolate());
+  if (!::tizen::is_single_process)
+    v8::Locker locker(isolate());
   v8::HandleScope handle_scope(isolate());
   auto api_web_contents = CreateFrom(isolate(), new_contents);
   if (Emit("-add-new-contents", api_web_contents, disposition, user_gesture,
@@ -630,7 +633,8 @@ void WebContents::FindReply(content::WebContents* web_contents,
   if (!final_update)
     return;
 
-  v8::Locker locker(isolate());
+  if (!::tizen::is_single_process)
+    v8::Locker locker(isolate());
   v8::HandleScope handle_scope(isolate());
   mate::Dictionary result = mate::Dictionary::CreateEmpty(isolate());
   result.Set("requestId", request_id);
@@ -886,7 +890,8 @@ void WebContents::DevToolsFocused() {
 }
 
 void WebContents::DevToolsOpened() {
-  v8::Locker locker(isolate());
+  if (!::tizen::is_single_process)
+    v8::Locker locker(isolate());
   v8::HandleScope handle_scope(isolate());
   auto handle = WebContents::CreateFrom(
       isolate(), managed_web_contents()->GetDevToolsWebContents());
@@ -906,7 +911,8 @@ void WebContents::DevToolsOpened() {
 }
 
 void WebContents::DevToolsClosed() {
-  v8::Locker locker(isolate());
+  if (!::tizen::is_single_process)
+    v8::Locker locker(isolate());
   v8::HandleScope handle_scope(isolate());
   devtools_web_contents_.Reset();
 
index db323ae..d4a975b 100644 (file)
@@ -23,6 +23,7 @@
 #include "content/public/common/content_switches.h"
 #include "native_mate/constructor.h"
 #include "native_mate/dictionary.h"
+#include "tizen/common/env_variables.h"
 #include "ui/gfx/geometry/rect.h"
 
 #if defined(TOOLKIT_VIEWS)
@@ -163,7 +164,8 @@ void Window::WillCloseWindow(bool* prevent_default) {
 
 void Window::WillDestroyNativeObject() {
   // Close all child windows before closing current window.
-  v8::Locker locker(isolate());
+  if (!::tizen::is_single_process)
+    v8::Locker locker(isolate());
   v8::HandleScope handle_scope(isolate());
   for (v8::Local<v8::Value> value : child_windows_.Values(isolate())) {
     mate::Handle<Window> child;
index ead3bed..b3884b7 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "atom/common/api/event_emitter_caller.h"
 #include "native_mate/wrappable.h"
+#include "tizen/common/env_variables.h"
 
 namespace content {
 class WebContents;
@@ -77,7 +78,8 @@ class EventEmitter : public Wrappable<T> {
                       content::WebContents* sender,
                       IPC::Message* message,
                       const Args&... args) {
-    v8::Locker locker(isolate());
+    if (!::tizen::is_single_process)
+        v8::Locker locker(isolate());
     v8::HandleScope handle_scope(isolate());
     v8::Local<v8::Object> event = internal::CreateJSEvent(
         isolate(), GetWrapper(), sender, message);
@@ -93,7 +95,8 @@ class EventEmitter : public Wrappable<T> {
   bool EmitWithEvent(const base::StringPiece& name,
                      v8::Local<v8::Object> event,
                      const Args&... args) {
-    v8::Locker locker(isolate());
+    if (!::tizen::is_single_process)
+        v8::Locker locker(isolate());
     v8::HandleScope handle_scope(isolate());
     EmitEvent(isolate(), GetWrapper(), name, event, args...);
     return event->Get(
index b5009e1..e4386c5 100644 (file)
@@ -7,6 +7,7 @@
 #include "atom/common/native_mate_converters/gfx_converter.h"
 #include "base/bind.h"
 #include "content/public/browser/render_widget_host.h"
+#include "tizen/common/env_variables.h"
 #include "ui/display/display.h"
 #include "ui/display/screen.h"
 
@@ -71,7 +72,8 @@ void FrameSubscriber::OnFrameDelivered(const FrameCaptureCallback& callback,
   if (response != content::ReadbackResponse::READBACK_SUCCESS)
     return;
 
-  v8::Locker locker(isolate_);
+  if (!::tizen::is_single_process)
+    v8::Locker locker(isolate_);
   v8::HandleScope handle_scope(isolate_);
 
   size_t rgb_arr_size = bitmap.width() * bitmap.height() *
index e07ec3a..a5541e3 100644 (file)
@@ -10,6 +10,7 @@
 #include "base/callback.h"
 #include "base/files/file_path.h"
 #include "content/public/browser/web_contents.h"
+#include "tizen/common/env_variables.h"
 
 namespace atom {
 
@@ -55,7 +56,8 @@ bool SavePageHandler::Handle(const base::FilePath& full_path,
 void SavePageHandler::OnDownloadUpdated(content::DownloadItem* item) {
   if (item->IsDone()) {
     v8::Isolate* isolate = v8::Isolate::GetCurrent();
-    v8::Locker locker(isolate);
+    if (!::tizen::is_single_process)
+      v8::Locker locker(isolate);
     v8::HandleScope handle_scope(isolate);
     if (item->GetState() == content::DownloadItem::COMPLETE) {
       callback_.Run(v8::Null(isolate));
index fd251c7..42ee96b 100644 (file)
@@ -12,6 +12,7 @@
 #include "storage/browser/blob/blob_reader.h"
 #include "storage/browser/blob/blob_storage_context.h"
 #include "storage/browser/fileapi/file_system_context.h"
+#include "tizen/common/env_variables.h"
 
 #include "atom/common/node_includes.h"
 
@@ -32,7 +33,8 @@ void RunCallbackInUI(
   DCHECK_CURRENTLY_ON(BrowserThread::UI);
 
   v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::Locker locker(isolate);
+  if (!::tizen::is_single_process)
+    v8::Locker locker(isolate);
   v8::HandleScope handle_scope(isolate);
   if (blob_data) {
     v8::Local<v8::Value> buffer = node::Buffer::New(isolate,
index 3ea0c3e..10d8583 100644 (file)
@@ -87,13 +87,14 @@ AtomBrowserMainParts::AtomBrowserMainParts()
     atom_bindings_ = std::move(self_atom_bindings);
 
     js_env_ = std::move(self_js_env);
+    js_env_->SetupLocker();
     node_debugger_ = std::move(self_node_debugger);
     bridge_task_runner_ = self_bridge_task_runner;
     node_env_ = std::move(self_node_env);
   } else {
     browser_.reset(new Browser);
     node_bindings_.reset(NodeBindings::Create(NodeBindings::BROWSER));
-    atom_bindings_.reset(new AtomBindings(uv_default_loop()));
+    atom_bindings_.reset(new AtomBindings(node_bindings_->uv_loop()));
   }
   self_ = this;
   // Register extension scheme as web safe scheme.
@@ -140,10 +141,10 @@ void AtomBrowserMainParts::SetNodeEnvironment() {
 
   self_js_env.reset(new atom::JavascriptEnvironment);
   self_node_bindings.reset(atom::NodeBindings::Create(atom::NodeBindings::BROWSER));
-  self_atom_bindings.reset(new atom::AtomBindings(uv_default_loop()));
+  self_atom_bindings.reset(new atom::AtomBindings(self_node_bindings->uv_loop()));
   self_node_bindings->Initialize();
 
-  self_node_debugger.reset(new atom::NodeDebugger(self_js_env->isolate()));
+  self_node_debugger.reset(new atom::NodeDebugger(self_js_env->isolate(), self_node_bindings->uv_loop()));
   env_ = self_node_bindings->CreateEnvironment(self_js_env->context());
   self_node_env.reset(new atom::NodeEnvironment(env_));
 
@@ -196,11 +197,12 @@ void AtomBrowserMainParts::PostEarlyInitialization() {
   // The ProxyResolverV8 has setup a complete V8 environment, in order to
   // avoid conflicts we only initialize our V8 environment after that.
   js_env_.reset(new JavascriptEnvironment);
+  js_env_->SetupLocker();
 
   node_bindings_->Initialize();
 
   // Support the "--debug" switch.
-  node_debugger_.reset(new NodeDebugger(js_env_->isolate()));
+  node_debugger_.reset(new NodeDebugger(js_env_->isolate(), node_bindings_->uv_loop()));
 
   // Create the global environment.
   node::Environment* env =
index ccbc434..dc42d4e 100644 (file)
@@ -18,6 +18,7 @@
 #include "content/public/browser/browser_thread.h"
 #include "content/public/browser/download_manager.h"
 #include "net/base/filename_util.h"
+#include "tizen/common/env_variables.h"
 
 namespace atom {
 
@@ -38,7 +39,8 @@ AtomDownloadManagerDelegate::~AtomDownloadManagerDelegate() {
 void AtomDownloadManagerDelegate::GetItemSavePath(content::DownloadItem* item,
                                                   base::FilePath* path) {
   v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::Locker locker(isolate);
+  if (!::tizen::is_single_process)
+    v8::Locker locker(isolate);
   v8::HandleScope handle_scope(isolate);
   api::DownloadItem* download = api::DownloadItem::FromWrappedClass(isolate,
                                                                     item);
@@ -102,7 +104,8 @@ void AtomDownloadManagerDelegate::OnDownloadPathGenerated(
                                           path.DirName());
 
     v8::Isolate* isolate = v8::Isolate::GetCurrent();
-    v8::Locker locker(isolate);
+    if (!::tizen::is_single_process)
+      v8::Locker locker(isolate);
     v8::HandleScope handle_scope(isolate);
     api::DownloadItem* download_item = api::DownloadItem::FromWrappedClass(
         isolate, item);
index 0cd2e39..dcbe344 100644 (file)
@@ -27,6 +27,8 @@
 #include "wgt_manifest_handlers/launch_screen_handler.h"
 #endif  // defined(OS_TIZEN)
 
+#include "tizen/common/env_variables.h"
+
 namespace atom {
 
 Browser::Browser()
@@ -118,8 +120,13 @@ void Browser::Shutdown() {
     observer.OnQuit();
 
   if (base::ThreadTaskRunnerHandle::IsSet()) {
-    base::ThreadTaskRunnerHandle::Get()->PostTask(
+    if (::tizen::is_single_process) {
+      base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
+        FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), base::TimeDelta::FromSeconds(1));
+    } else {
+      base::ThreadTaskRunnerHandle::Get()->PostTask(
         FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
+    }
     ui_app_exit();
   } else {
     // There is no message loop available so we are in early stage.
index b3e01c1..7ee10c1 100644 (file)
@@ -11,6 +11,7 @@
 #include "content/public/common/content_switches.h"
 #include "gin/array_buffer.h"
 #include "gin/v8_initializer.h"
+#include "tizen/common/env_variables.h"
 
 #include "atom/common/node_includes.h"
 
@@ -20,7 +21,6 @@ JavascriptEnvironment::JavascriptEnvironment()
     : initialized_(Initialize()),
       isolate_(isolate_holder_.isolate()),
       isolate_scope_(isolate_),
-      locker_(isolate_),
       handle_scope_(isolate_),
       context_(isolate_, v8::Context::New(isolate_)),
       context_scope_(v8::Local<v8::Context>::New(isolate_, context_)) {
@@ -34,6 +34,11 @@ void JavascriptEnvironment::OnMessageLoopDestroying() {
   isolate_holder_.RemoveRunMicrotasksObserver();
 }
 
+void JavascriptEnvironment::SetupLocker() {
+  if (!::tizen::is_single_process)
+    locker_.reset(new v8::Locker(isolate_));
+}
+
 bool JavascriptEnvironment::Initialize() {
   auto cmd = base::CommandLine::ForCurrentProcess();
 
index 43a7295..5887353 100644 (file)
@@ -21,6 +21,7 @@ class JavascriptEnvironment {
 
   void OnMessageLoopCreated();
   void OnMessageLoopDestroying();
+  void SetupLocker();
 
   v8::Isolate* isolate() const { return isolate_; }
   v8::Local<v8::Context> context() const {
@@ -34,7 +35,7 @@ class JavascriptEnvironment {
   gin::IsolateHolder isolate_holder_;
   v8::Isolate* isolate_;
   v8::Isolate::Scope isolate_scope_;
-  v8::Locker locker_;
+  std::unique_ptr<v8::Locker> locker_;
   v8::HandleScope handle_scope_;
   v8::UniquePersistent<v8::Context> context_;
   v8::Context::Scope context_scope_;
index 67fb578..81f3918 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "atom/common/native_mate_converters/callback.h"
 #include "atom/common/native_mate_converters/v8_value_converter.h"
+#include "tizen/common/env_variables.h"
 
 namespace atom {
 
@@ -48,7 +49,8 @@ void AskForOptions(v8::Isolate* isolate,
                    const BeforeStartCallback& before_start,
                    const ResponseCallback& callback) {
   DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
-  v8::Locker locker(isolate);
+  if (!::tizen::is_single_process)
+    v8::Locker locker(isolate);
   v8::HandleScope handle_scope(isolate);
   v8::Local<v8::Context> context = isolate->GetCurrentContext();
   v8::Context::Scope context_scope(context);
index 9fdeb60..6d4fd84 100644 (file)
@@ -28,7 +28,7 @@ const char* kContentLength = "Content-Length";
 
 }  // namespace
 
-NodeDebugger::NodeDebugger(v8::Isolate* isolate)
+NodeDebugger::NodeDebugger(v8::Isolate* isolate, uv_loop_t* loop_)
     : isolate_(isolate),
       thread_("NodeDebugger"),
       content_length_(-1),
@@ -54,7 +54,7 @@ NodeDebugger::NodeDebugger(v8::Isolate* isolate)
     v8::Debug::SetMessageHandler(isolate_, DebugMessageHandler);
 
     weak_up_ui_handle_.data = this;
-    uv_async_init(uv_default_loop(), &weak_up_ui_handle_, ProcessMessageInUI);
+    uv_async_init(loop_, &weak_up_ui_handle_, ProcessMessageInUI);
 
     // Start a new IO thread.
     base::Thread::Options options;
index 118812a..4889fb2 100644 (file)
@@ -19,7 +19,7 @@ namespace atom {
 // Add support for node's "--debug" switch.
 class NodeDebugger : public net::test_server::StreamListenSocket::Delegate {
  public:
-  explicit NodeDebugger(v8::Isolate* isolate);
+  explicit NodeDebugger(v8::Isolate* isolate, uv_loop_t* loop_);
   virtual ~NodeDebugger();
 
   bool IsRunning() const;
index fe0b234..09a72fa 100644 (file)
@@ -3,12 +3,17 @@
 // found in the LICENSE.chromium file.
 
 #include "atom/common/api/locker.h"
+#include "base/logging.h"
+#include "tizen/common/env_variables.h"
 
 namespace mate {
 
 Locker::Locker(v8::Isolate* isolate) {
-  if (IsBrowserProcess())
+  if (::tizen::is_single_process)
+    return;
+  if (IsBrowserProcess()) {
     locker_.reset(new v8::Locker(isolate));
+  }
 }
 
 Locker::~Locker() {
index e64ef18..0a9eb26 100644 (file)
@@ -8,6 +8,7 @@
 #include <memory>
 
 #include "base/macros.h"
+#include "tizen/common/env_variables.h"
 #include "v8/include/v8.h"
 
 namespace mate {
@@ -20,7 +21,7 @@ class Locker {
 
   // Returns whether current process is browser process, currently we detect it
   // by checking whether current has used V8 Lock, but it might be a bad idea.
-  static inline bool IsBrowserProcess() { return v8::Locker::IsActive(); }
+  static inline bool IsBrowserProcess() { if (::tizen::is_single_process) return true; return v8::Locker::IsActive(); }
 
  private:
   void* operator new(size_t size);
index a6a500b..611e19c 100644 (file)
@@ -3,6 +3,7 @@
 // found in the LICENSE file.
 
 #include "atom/common/native_mate_converters/callback.h"
+#include "tizen/common/env_variables.h"
 
 using content::BrowserThread;
 
@@ -60,7 +61,7 @@ v8::Local<v8::Value> BindFunctionWith(v8::Isolate* isolate,
 struct DeleteOnUIThread {
   template<typename T>
   static void Destruct(const T* x) {
-    if (Locker::IsBrowserProcess() &&
+    if ((::tizen::is_single_process || Locker::IsBrowserProcess()) &&
         !BrowserThread::CurrentlyOn(BrowserThread::UI)) {
       BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, x);
     } else {
index 28bff3c..fb802a0 100644 (file)
@@ -46,7 +46,8 @@ struct V8FunctionInvoker<v8::Local<v8::Value>(ArgTypes...)> {
   static v8::Local<v8::Value> Go(v8::Isolate* isolate,
                                  const SafeV8Function& function,
                                  ArgTypes... raw) {
-    Locker locker(isolate);
+    if (!::tizen::is_single_process)
+      Locker locker(isolate);
     v8::EscapableHandleScope handle_scope(isolate);
     if (!function.IsAlive())
       return v8::Null(isolate);
@@ -66,7 +67,8 @@ struct V8FunctionInvoker<void(ArgTypes...)> {
   static void Go(v8::Isolate* isolate,
                  const SafeV8Function& function,
                  ArgTypes... raw) {
-    Locker locker(isolate);
+    if (!::tizen::is_single_process)
+      Locker locker(isolate);
     v8::HandleScope handle_scope(isolate);
     if (!function.IsAlive())
       return;
index e61b6eb..fe04520 100644 (file)
@@ -141,7 +141,7 @@ void NodeBindings::Initialize() {
 
   // Init node.
   // (we assume node::Init would not modify the parameters under embedded mode).
-  node::Init(nullptr, nullptr, nullptr, nullptr);
+  node::Init(nullptr, nullptr, nullptr, nullptr, uv_loop_);
 
 #if defined(OS_WIN)
   // uv_init overrides error mode to suppress the default crash dialog, bring
index 87be391..1e55cce 100644 (file)
@@ -34,6 +34,7 @@
 #include "native_mate/dictionary.h"
 #include "third_party/WebKit/public/web/WebDocument.h"
 #include "third_party/WebKit/public/web/WebLocalFrame.h"
+#include "tizen/common/env_variables.h"
 
 #include "atom/common/node_includes.h"
 
@@ -60,9 +61,11 @@ const char** StringVectorToArgArray(
 }  // namespace
 
 AtomRendererClient::AtomRendererClient()
-    : node_integration_initialized_(false),
-      node_bindings_(NodeBindings::Create(NodeBindings::RENDERER)),
-      atom_bindings_(new AtomBindings(uv_default_loop())) {
+    : node_integration_initialized_(false) {
+  if (!::tizen::is_single_process) {
+    node_bindings_.reset(NodeBindings::Create(NodeBindings::RENDERER));
+    atom_bindings_.reset(new AtomBindings(node_bindings_->uv_loop()));
+  }
   isolated_world_ = base::CommandLine::ForCurrentProcess()->HasSwitch(
       switches::kContextIsolation);
 }
@@ -114,6 +117,8 @@ void AtomRendererClient::RenderViewCreated(content::RenderView* render_view) {
 
 void AtomRendererClient::RunScriptsAtDocumentStart(
     content::RenderFrame* render_frame) {
+  if (::tizen::is_single_process)
+    return;
   // Inform the document start pharse.
   node::Environment* env = node_bindings_->uv_env();
   if (env) {
@@ -124,6 +129,8 @@ void AtomRendererClient::RunScriptsAtDocumentStart(
 
 void AtomRendererClient::RunScriptsAtDocumentEnd(
     content::RenderFrame* render_frame) {
+  if (::tizen::is_single_process)
+    return;
   // Inform the document end pharse.
   node::Environment* env = node_bindings_->uv_env();
   if (env) {
@@ -142,6 +149,8 @@ void AtomRendererClient::DidCreateScriptContext(
                         render_frame->GetWebFrame()->document().baseURL().string().utf8().c_str());
   }
 #endif
+  if (::tizen::is_single_process)
+    return;
   // Only allow node integration for the main frame, unless it is a devtools
   // extension page.
   if (!render_frame->IsMainFrame() && !IsDevToolsExtension(render_frame))
@@ -180,6 +189,8 @@ void AtomRendererClient::WillReleaseScriptContext(
   if (widget_)
     widget_->StopSession(context);
 #endif
+  if (::tizen::is_single_process)
+    return;
   // Only allow node integration for the main frame, unless it is a devtools
   // extension page.
   if (!render_frame->IsMainFrame() && !IsDevToolsExtension(render_frame))
index 7e44f64..6da9d44 100644 (file)
@@ -17,6 +17,7 @@
 #include "printing/page_size_margins.h"
 #include "printing/print_job_constants.h"
 #include "printing/pdf_metafile_skia.h"
+#include "tizen/common/env_variables.h"
 
 #include "atom/common/node_includes.h"
 
@@ -127,7 +128,8 @@ void PrintPreviewMessageHandler::RunPrintToPDFCallback(
   DCHECK_CURRENTLY_ON(BrowserThread::UI);
 
   v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::Locker locker(isolate);
+  if (!::tizen::is_single_process)
+    v8::Locker locker(isolate);
   v8::HandleScope handle_scope(isolate);
   if (data) {
     v8::Local<v8::Value> buffer = node::Buffer::New(isolate,
index 7706dd2..637f5c4 100644 (file)
@@ -28,6 +28,8 @@
         'app_db_sqlite.h',
         'application_data.h',
         'application_data.cc',
+        'env_variables.h',
+        'env_variables.cc',
         'locale_manager.h',
         'locale_manager.cc',
         'resource_manager.h',
diff --git a/tizen/common/env_variables.cc b/tizen/common/env_variables.cc
new file mode 100644 (file)
index 0000000..cab1fa0
--- /dev/null
@@ -0,0 +1,3 @@
+namespace tizen {
+  bool is_single_process = false;
+}
\ No newline at end of file
diff --git a/tizen/common/env_variables.h b/tizen/common/env_variables.h
new file mode 100644 (file)
index 0000000..4dd6207
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef TIZEN_ENV_VARIABLES
+#define TIZEN_ENV_VARIABLES
+
+namespace tizen {
+  extern bool is_single_process;
+}
+
+#endif // TIZEN_ENV_VARIABLES
\ No newline at end of file
index 3bfb612..35027bd 100644 (file)
@@ -3,6 +3,7 @@
 // found in the LICENSE file.
 
 #include "wrt_main.h"
+#include "tizen/common/env_variables.h"
 
 #include <stdlib.h>
 #include "atom/app/atom_main_delegate.h"  // NOLINT
 
 namespace {
 
+bool block_single_process = false; // set to true to disable single process mode altogether
+
 // Default command line flags for all profiles and platforms
 const char* kDefaultCommandLineFlags[] = {
   "allow-file-access-from-files",
   "enable-tizen-app-container",
+  "allow-universal-access-from-files",
+  "single-process",
+  "no-sandbox",
+  "no-zygote",
 };
 
+const int kElectronArgsCount = 2;
+const int kTizenWebappArgsCount = 6;
+
+bool isElectronWebApp() {
+  auto app_data = common::ApplicationDataManager::GetCurrentAppData();
+  if (app_data) {
+    if (app_data->content_info()) {
+      std::string startUrl = app_data->content_info()->src();
+      if (std::string::npos != startUrl.find(".json")) {
+        return true;
+      }
+    }
+  }
+  return false;
+}
+
+bool IsBrowserProcess() {
+  auto command_line = base::CommandLine::ForCurrentProcess();
+  std::string process_type = command_line->GetSwitchValueASCII("type");
+  return process_type.empty();
+}
+
 }  // namespace
 
 #define REFERENCE_MODULE(name) \
@@ -92,9 +121,19 @@ int main(int argc, char* argv[]) {
   // Add params for EFL port
   base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
 
+  int args_count = kElectronArgsCount;
+  if (IsBrowserProcess()) {
+    if (!block_single_process && !isElectronWebApp()) {
+      LOG(ERROR) << "will run in single process mode";
+      tizen::is_single_process = true;
+      args_count = kTizenWebappArgsCount;
+    } else LOG(ERROR) << "will run in non-single process mode";
+  } else LOG(ERROR) << "not a browser process";
+
   static std::vector<char*> flags;
-  for (auto arg : kDefaultCommandLineFlags)
-    command_line->AppendSwitch(const_cast<char*>(arg));
+  for (int i = 0; i < args_count; ++i)
+    command_line->AppendSwitch(const_cast<char*>(kDefaultCommandLineFlags[i]));
+
   efl::AppendPortParams(*command_line);
 
   atom::AtomMainDelegate delegate;
index aca7991..4b54bf8 100644 (file)
@@ -4232,9 +4232,10 @@ inline void PlatformInit() {
 void Init(int* argc,
           const char** argv,
           int* exec_argc,
-          const char*** exec_argv) {
+          const char*** exec_argv,
+          uv_loop_t* uv_loop_) {
   // Initialize prog_start_time to get relative uptime.
-  prog_start_time = static_cast<double>(uv_now(uv_default_loop()));
+  prog_start_time = static_cast<double>(uv_now(uv_loop_));
 
   if (g_upstream_node_mode) {  // No indent to minimize diff.
   // Make inherited handles noninheritable.
@@ -4243,7 +4244,7 @@ void Init(int* argc,
 
   // init async debug messages dispatching
   // Main thread uses uv_default_loop
-  CHECK_EQ(0, uv_async_init(uv_default_loop(),
+  CHECK_EQ(0, uv_async_init(uv_loop_,
                             &dispatch_debug_messages_async,
                             DispatchDebugMessagesAsyncCallback));
   uv_unref(reinterpret_cast<uv_handle_t*>(&dispatch_debug_messages_async));
@@ -4290,7 +4291,7 @@ void Init(int* argc,
   // performance penalty of frequent EINTR wakeups when the profiler is running.
   // Only do this for v8.log profiling, as it breaks v8::CpuProfiler users.
   if (v8_is_profiling) {
-    uv_loop_configure(uv_default_loop(), UV_LOOP_BLOCK_SIGNAL, SIGPROF);
+    uv_loop_configure(uv_loop_, UV_LOOP_BLOCK_SIGNAL, SIGPROF);
   }
 #endif
 
@@ -4439,7 +4440,7 @@ void FreeEnvironment(Environment* env) {
 }
 
 
-inline int Start(Isolate* isolate, IsolateData* isolate_data,
+inline int Start(Isolate* isolate, IsolateData* isolate_data, // not called
                  int argc, const char* const* argv,
                  int exec_argc, const char* const* exec_argv) {
   HandleScope handle_scope(isolate);
@@ -4500,7 +4501,7 @@ inline int Start(Isolate* isolate, IsolateData* isolate_data,
   return exit_code;
 }
 
-inline int Start(uv_loop_t* event_loop,
+inline int Start(uv_loop_t* event_loop, // not called
                  int argc, const char* const* argv,
                  int exec_argc, const char* const* exec_argv) {
   Isolate::CreateParams params;
@@ -4562,7 +4563,7 @@ int Start(int argc, char** argv) {
   // optional, in case you're wondering.
   int exec_argc;
   const char** exec_argv;
-  Init(&argc, const_cast<const char**>(argv), &exec_argc, &exec_argv);
+  // Init(&argc, const_cast<const char**>(argv), &exec_argc, &exec_argv);
 
 #if HAVE_OPENSSL
   if (const char* extra = secure_getenv("NODE_EXTRA_CA_CERTS"))
index f136158..bac44b0 100644 (file)
@@ -189,10 +189,11 @@ NODE_EXTERN extern bool g_standalone_mode;
 NODE_EXTERN extern bool g_upstream_node_mode;
 
 NODE_EXTERN int Start(int argc, char *argv[]);
-NODE_EXTERN void Init(int* argc,
+NODE_EXTERN void Init(int* argc, // apart from NodeBindings::Initialize(), no one seems to call
                       const char** argv,
                       int* exec_argc,
-                      const char*** exec_argv);
+                      const char*** exec_argv,
+                      uv_loop_t* uv_loop_);
 
 class IsolateData;
 class Environment;