Don't fork renderer process for guest

This commit is contained in:
Cheng Zhao 2014-10-24 18:44:15 +08:00
parent 4ccb0cccf3
commit 58a38d90b8
10 changed files with 25 additions and 36 deletions

View file

@ -160,7 +160,7 @@ content::WebContents* WebContents::CreateNewGuestWindow(
void WebContents::DidAttach() { void WebContents::DidAttach() {
base::ListValue args; base::ListValue args;
args.Append(extra_params_.release()); args.Append(extra_params_.release());
Emit("internal-did-attach", args); Emit("did-attach", args);
} }
int WebContents::GetGuestInstanceID() const { int WebContents::GetGuestInstanceID() const {

View file

@ -26,10 +26,6 @@ module.exports.wrap = (webContents) ->
webContents.getId = -> "#{@getProcessId()}-#{@getRoutingId()}" webContents.getId = -> "#{@getProcessId()}-#{@getRoutingId()}"
webContents.equal = (other) -> @getId() is other.getId() 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 # Tell the rpc server that a render view has been deleted and we need to
# release all objects owned by it. # release all objects owned by it.
webContents.on 'render-view-deleted', (event, processId, routingId) -> webContents.on 'render-view-deleted', (event, processId, routingId) ->

View file

@ -11,6 +11,7 @@
#include "atom/browser/atom_speech_recognition_manager_delegate.h" #include "atom/browser/atom_speech_recognition_manager_delegate.h"
#include "atom/browser/native_window.h" #include "atom/browser/native_window.h"
#include "atom/browser/window_list.h" #include "atom/browser/window_list.h"
#include "base/command_line.h"
#include "chrome/browser/printing/printing_message_filter.h" #include "chrome/browser/printing/printing_message_filter.h"
#include "chrome/browser/speech/tts_message_filter.h" #include "chrome/browser/speech/tts_message_filter.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
@ -148,6 +149,9 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches(
if (window != NULL) if (window != NULL)
window->AppendExtraCommandLineSwitches(command_line, child_process_id); 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; dying_render_process_ = NULL;
} }

View file

@ -26,7 +26,7 @@ createGuest = (embedder, params) ->
destroyGuest id destroyGuest id
# Init guest web view after attached. # 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 min = width: params.minwidth, height: params.minheight
max = width: params.maxwidth, height: params.maxheight max = width: params.maxwidth, height: params.maxheight
@setAutoSize params.autosize, min, max @setAutoSize params.autosize, min, max

View file

@ -24,6 +24,10 @@ WebFrame::WebFrame()
WebFrame::~WebFrame() { WebFrame::~WebFrame() {
} }
void WebFrame::SetName(const std::string& name) {
web_frame_->setName(blink::WebString::fromUTF8(name));
}
double WebFrame::SetZoomLevel(double level) { double WebFrame::SetZoomLevel(double level) {
return web_frame_->view()->setZoomLevel(level); return web_frame_->view()->setZoomLevel(level);
} }
@ -50,6 +54,7 @@ v8::Handle<v8::Value> WebFrame::RegisterEmbedderCustomElement(
mate::ObjectTemplateBuilder WebFrame::GetObjectTemplateBuilder( mate::ObjectTemplateBuilder WebFrame::GetObjectTemplateBuilder(
v8::Isolate* isolate) { v8::Isolate* isolate) {
return mate::ObjectTemplateBuilder(isolate) return mate::ObjectTemplateBuilder(isolate)
.SetMethod("setName", &WebFrame::SetName)
.SetMethod("setZoomLevel", &WebFrame::SetZoomLevel) .SetMethod("setZoomLevel", &WebFrame::SetZoomLevel)
.SetMethod("getZoomLevel", &WebFrame::GetZoomLevel) .SetMethod("getZoomLevel", &WebFrame::GetZoomLevel)
.SetMethod("setZoomFactor", &WebFrame::SetZoomFactor) .SetMethod("setZoomFactor", &WebFrame::SetZoomFactor)

View file

@ -5,6 +5,8 @@
#ifndef ATOM_RENDERER_API_ATOM_API_WEB_FRAME_H_ #ifndef ATOM_RENDERER_API_ATOM_API_WEB_FRAME_H_
#define 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/handle.h"
#include "native_mate/wrappable.h" #include "native_mate/wrappable.h"
@ -24,6 +26,8 @@ class WebFrame : public mate::Wrappable {
WebFrame(); WebFrame();
virtual ~WebFrame(); virtual ~WebFrame();
void SetName(const std::string& name);
double SetZoomLevel(double level); double SetZoomLevel(double level);
double GetZoomLevel() const; double GetZoomLevel() const;
double SetZoomFactor(double factor); double SetZoomFactor(double factor);

View file

@ -214,6 +214,10 @@ bool AtomRendererClient::ShouldFork(blink::WebFrame* frame,
bool is_initial_navigation, bool is_initial_navigation,
bool is_server_redirect, bool is_server_redirect,
bool* send_referrer) { 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. // Handle all the navigations and reloads in browser.
// FIXME We only support GET here because http method will be ignored when // FIXME We only support GET here because http method will be ignored when
// the OpenURLFromTab is triggered, which means form posting would not work, // the OpenURLFromTab is triggered, which means form posting would not work,

View file

@ -1,10 +1,7 @@
ipc = require 'ipc' ipc = require 'ipc'
webFrame = require 'web-frame'
requestId = 0 requestId = 0
ipc.on 'ATOM_SHELL_WEB_CONTENTS_SET_NAME', (name) ->
module.exports = module.exports =
createGuest: (type, params, callback) -> createGuest: (type, params, callback) ->
requestId++ requestId++

View file

@ -47,6 +47,11 @@ else
global.__filename = __filename global.__filename = __filename
global.__dirname = __dirname 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:' if location.protocol is 'chrome-devtools:'
# Override some inspector APIs. # Override some inspector APIs.
require path.join(__dirname, 'inspector') require path.join(__dirname, 'inspector')

View file

@ -175,11 +175,6 @@ class WebView
# No setter. # No setter.
enumerable: true enumerable: true
Object.defineProperty @webviewNode, 'name',
get: => @name
set: (value) => @webviewNode.setAttribute 'name', value
enumerable: true
Object.defineProperty @webviewNode, 'partition', Object.defineProperty @webviewNode, 'partition',
get: => @partition.toAttribute() get: => @partition.toAttribute()
set: (value) => set: (value) =>
@ -243,19 +238,6 @@ class WebView
return unless @guestInstanceId return unless @guestInstanceId
guestViewInternal.setAllowTransparency @guestInstanceId, @allowtransparency 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' else if name is 'src'
# We treat null attribute (attribute removed) and the empty string as # We treat null attribute (attribute removed) and the empty string as
# one case. # one case.
@ -399,13 +381,6 @@ class WebView
@attachWindow guestInstanceId, false @attachWindow guestInstanceId, false
@pendingGuestCreation = true @pendingGuestCreation = true
onFrameNameChanged: (name) ->
@name ?= ''
if @name is ''
@webviewNode.removeAttribute 'name'
else
@webviewNode.setAttribute 'name', @name
@dispatchEvent = (webViewEvent) -> @dispatchEvent = (webViewEvent) ->
@webviewNode.dispatchEvent webViewEvent @webviewNode.dispatchEvent webViewEvent
@ -446,7 +421,6 @@ class WebView
maxwidth: parseInt @maxwidth || 0 maxwidth: parseInt @maxwidth || 0
minheight: parseInt @minheight || 0 minheight: parseInt @minheight || 0
minwidth: parseInt @minwidth || 0 minwidth: parseInt @minwidth || 0
name: @name
# We don't need to navigate new window from here. # We don't need to navigate new window from here.
src: if isNewWindow then undefined else @src src: if isNewWindow then undefined else @src
# If we have a partition from the opener, that will also be already # If we have a partition from the opener, that will also be already
@ -520,7 +494,7 @@ registerWebViewElement = ->
internal.elementAttached = true internal.elementAttached = true
internal.parseAttributes() internal.parseAttributes()
window.WebView = webView.registerEmbedderCustomElement 'webview', window.WebView = webFrame.registerEmbedderCustomElement 'webview',
prototype: proto prototype: proto
# Delete the callbacks so developers cannot call them and produce unexpected # Delete the callbacks so developers cannot call them and produce unexpected