]> khamidou — GitHub mirrors - electron.git/commitdiff
Don't fork renderer process for guest
authorCheng Zhao <zcbenz@gmail.com>
Fri, 24 Oct 2014 10:44:15 +0000 (18:44 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 24 Oct 2014 11:08:26 +0000 (19:08 +0800)
atom/browser/api/atom_api_web_contents.cc
atom/browser/api/lib/web-contents.coffee
atom/browser/atom_browser_client.cc
atom/browser/lib/guest-view-manager.coffee
atom/renderer/api/atom_api_web_frame.cc
atom/renderer/api/atom_api_web_frame.h
atom/renderer/atom_renderer_client.cc
atom/renderer/lib/guest-view-internal.coffee
atom/renderer/lib/init.coffee
atom/renderer/lib/web-view.coffee

index f3520bc968e5a834f78f2c5d97f93faa63d9a79b..deef2ff1480e9ac97939564e0726d455c23b6cf0 100644 (file)
@@ -160,7 +160,7 @@ content::WebContents* WebContents::CreateNewGuestWindow(
 void WebContents::DidAttach() {
   base::ListValue args;
   args.Append(extra_params_.release());
-  Emit("internal-did-attach", args);
+  Emit("did-attach", args);
 }
 
 int WebContents::GetGuestInstanceID() const {
index c5f8b99321d06c7e07e7e434d3f0544fcf50ebfc..318769eab535c74f7ae45a4ab88e6c342d157a49 100644 (file)
@@ -26,10 +26,6 @@ module.exports.wrap = (webContents) ->
   webContents.getId = -> "#{@getProcessId()}-#{@getRoutingId()}"
   webContents.equal = (other) -> @getId() is other.getId()
 
-  # Set frame name of WebContents.
-  webContents.setName = (name) ->
-    @send 'ATOM_SHELL_WEB_CONTENTS_SET_NAME', name
-
   # Tell the rpc server that a render view has been deleted and we need to
   # release all objects owned by it.
   webContents.on 'render-view-deleted', (event, processId, routingId) ->
index 22ff32ad219e3a5f28fac1603968e0cb97662bc2..746011016bc984f7afb35275e907555aee303fe5 100644 (file)
@@ -11,6 +11,7 @@
 #include "atom/browser/atom_speech_recognition_manager_delegate.h"
 #include "atom/browser/native_window.h"
 #include "atom/browser/window_list.h"
+#include "base/command_line.h"
 #include "chrome/browser/printing/printing_message_filter.h"
 #include "chrome/browser/speech/tts_message_filter.h"
 #include "content/public/browser/render_process_host.h"
@@ -148,6 +149,9 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches(
 
   if (window != NULL)
     window->AppendExtraCommandLineSwitches(command_line, child_process_id);
+  else
+    // If we can not find a owner window then it is a guest web view.
+    command_line->AppendSwitch("guest");
 
   dying_render_process_ = NULL;
 }
index 10de5a5d6d5e0f031cc18c7f9ade0aa1dbd6b703..3dda909cae66805f01aa686ca569a8d54cbd8768 100644 (file)
@@ -26,7 +26,7 @@ createGuest = (embedder, params) ->
     destroyGuest id
 
   # Init guest web view after attached.
-  guest.once 'internal-did-attach', (event, params) ->
+  guest.once 'did-attach', (event, params) ->
     min = width: params.minwidth, height: params.minheight
     max = width: params.maxwidth, height: params.maxheight
     @setAutoSize params.autosize, min, max
index 905c68d9bcab6741b2eb123b37812609d49b6a52..00085ee9ab37ebfa533ff5f0679b6dc9be81287d 100644 (file)
@@ -24,6 +24,10 @@ WebFrame::WebFrame()
 WebFrame::~WebFrame() {
 }
 
+void WebFrame::SetName(const std::string& name) {
+  web_frame_->setName(blink::WebString::fromUTF8(name));
+}
+
 double WebFrame::SetZoomLevel(double level) {
   return web_frame_->view()->setZoomLevel(level);
 }
@@ -50,6 +54,7 @@ v8::Handle<v8::Value> WebFrame::RegisterEmbedderCustomElement(
 mate::ObjectTemplateBuilder WebFrame::GetObjectTemplateBuilder(
     v8::Isolate* isolate) {
   return mate::ObjectTemplateBuilder(isolate)
+      .SetMethod("setName", &WebFrame::SetName)
       .SetMethod("setZoomLevel", &WebFrame::SetZoomLevel)
       .SetMethod("getZoomLevel", &WebFrame::GetZoomLevel)
       .SetMethod("setZoomFactor", &WebFrame::SetZoomFactor)
index 4ac8beb4bb0a58ff59c26db126031b61f819a9db..b237c5e0f00f88ef6072c6f6490fede6b82ad368 100644 (file)
@@ -5,6 +5,8 @@
 #ifndef ATOM_RENDERER_API_ATOM_API_WEB_FRAME_H_
 #define ATOM_RENDERER_API_ATOM_API_WEB_FRAME_H_
 
+#include <string>
+
 #include "native_mate/handle.h"
 #include "native_mate/wrappable.h"
 
@@ -24,6 +26,8 @@ class WebFrame : public mate::Wrappable {
   WebFrame();
   virtual ~WebFrame();
 
+  void SetName(const std::string& name);
+
   double SetZoomLevel(double level);
   double GetZoomLevel() const;
   double SetZoomFactor(double factor);
index fa035f9bc4e7f5a039e94bbab392cc4b11deeace..18b651c546b15e176e3bab3d820179348a7c31e9 100644 (file)
@@ -214,6 +214,10 @@ bool AtomRendererClient::ShouldFork(blink::WebFrame* frame,
                                     bool is_initial_navigation,
                                     bool is_server_redirect,
                                     bool* send_referrer) {
+  // Never fork renderer process for guests.
+  if (frame->uniqueName().utf8() == "ATOM_SHELL_GUEST_WEB_VIEW")
+    return false;
+
   // Handle all the navigations and reloads in browser.
   // FIXME We only support GET here because http method will be ignored when
   // the OpenURLFromTab is triggered, which means form posting would not work,
index 9f3b33dc19d993797dd5b94d4edd1a26362f0c23..7fc2de3f2dde0c0e80704daa8c0a42edb2d1d915 100644 (file)
@@ -1,10 +1,7 @@
 ipc = require 'ipc'
-webFrame = require 'web-frame'
 
 requestId = 0
 
-ipc.on 'ATOM_SHELL_WEB_CONTENTS_SET_NAME', (name) ->
-
 module.exports =
   createGuest: (type, params, callback) ->
     requestId++
index cdb38fc2a2e43eeff3e87bf904879686e69e76ec..9d3d8df6992f38a43ec265db2a7dbf3c42b3c333 100644 (file)
@@ -47,6 +47,11 @@ else
   global.__filename = __filename
   global.__dirname = __dirname
 
+if '--guest' in process.argv
+  # This is a guest web view.
+  isGuest = true
+  require('web-frame').setName 'ATOM_SHELL_GUEST_WEB_VIEW'
+
 if location.protocol is 'chrome-devtools:'
   # Override some inspector APIs.
   require path.join(__dirname, 'inspector')
index 0063f5c1189833057841c618679f294b1d6b6ac2..751304b3893a1ee480be52db076a2943326f2436 100644 (file)
@@ -175,11 +175,6 @@ class WebView
       # No setter.
       enumerable: true
 
-    Object.defineProperty @webviewNode, 'name',
-      get: => @name
-      set: (value) => @webviewNode.setAttribute 'name', value
-      enumerable: true
-
     Object.defineProperty @webviewNode, 'partition',
       get: => @partition.toAttribute()
       set: (value) =>
@@ -243,19 +238,6 @@ class WebView
       return unless @guestInstanceId
 
       guestViewInternal.setAllowTransparency @guestInstanceId, @allowtransparency
-    else if name is 'name'
-      # We treat null attribute (attribute removed) and the empty string as
-      # one case.
-      oldValue ?= ''
-      newValue ?= ''
-
-      return if oldValue is newValue
-      @name = newValue
-
-      return unless @guestInstanceId
-
-      # FIXME
-      # WebViewInternal.setName @guestInstanceId, newValue
     else if name is 'src'
       # We treat null attribute (attribute removed) and the empty string as
       # one case.
@@ -399,13 +381,6 @@ class WebView
       @attachWindow guestInstanceId, false
     @pendingGuestCreation = true
 
-  onFrameNameChanged: (name) ->
-    @name ?= ''
-    if @name is ''
-      @webviewNode.removeAttribute 'name'
-    else
-      @webviewNode.setAttribute 'name', @name
-
   @dispatchEvent = (webViewEvent) ->
     @webviewNode.dispatchEvent webViewEvent
 
@@ -446,7 +421,6 @@ class WebView
     maxwidth: parseInt @maxwidth || 0
     minheight: parseInt @minheight || 0
     minwidth: parseInt @minwidth || 0
-    name: @name
     # We don't need to navigate new window from here.
     src: if isNewWindow then undefined else @src
     # If we have a partition from the opener, that will also be already
@@ -520,7 +494,7 @@ registerWebViewElement = ->
       internal.elementAttached = true
       internal.parseAttributes()
 
-  window.WebView = webView.registerEmbedderCustomElement 'webview',
+  window.WebView = webFrame.registerEmbedderCustomElement 'webview',
     prototype: proto
 
   # Delete the callbacks so developers cannot call them and produce unexpected