Skip to content

Commit

Permalink
Allow create webview in new process.
Browse files Browse the repository at this point in the history
Attribute 'usenewprocess' added on webview. If used it ensure that webview is started in new process. If not used chrome will decide whether or not new process will be used.
  • Loading branch information
janRucka committed Feb 22, 2016
1 parent 954f9e5 commit 617020e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const char kAttributeAllowTransparency[] = "allowtransparency";
const char kAttributeAllowScaling[] = "allowscaling";
const char kAttributeName[] = "name";
const char kAttributeSrc[] = "src";
const char kAttributeUseNewProcess[] = "usenewprocess";

// API namespace.
const char kAPINamespace[] = "webViewInternal";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ extern const char kAttributeAllowTransparency[];
extern const char kAttributeAllowScaling[];
extern const char kAttributeName[];
extern const char kAttributeSrc[];
extern const char kAttributeUseNewProcess[];

// API namespace.
// TODO(kalman): Consolidate this with the other API constants.
Expand Down
16 changes: 10 additions & 6 deletions extensions/browser/guest_view/web_view/web_view_guest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,17 @@ void WebViewGuest::CreateWebContents(
persist_storage ? "persist" : "",
url_encoded_partition.c_str()));

// If we already have a webview tag in the same app using the same storage
// partition, we should use the same SiteInstance so the existing tag and
// the new tag can script each other.
auto guest_view_manager = GuestViewManager::FromBrowserContext(
bool useNewProcess = false;
create_params.GetBoolean(webview::kAttributeUseNewProcess, &useNewProcess);
content::SiteInstance* guest_site_instance = nullptr;
if (!useNewProcess) {
// If we already have a webview tag in the same app using the same storage
// partition, we should use the same SiteInstance so the existing tag and
// the new tag can script each other.
auto guest_view_manager = GuestViewManager::FromBrowserContext(
owner_render_process_host->GetBrowserContext());
content::SiteInstance* guest_site_instance =
guest_view_manager->GetGuestSiteInstance(guest_site);
guest_site_instance = guest_view_manager->GetGuestSiteInstance(guest_site);
}
if (!guest_site_instance) {
// Create the SiteInstance in a new BrowsingInstance, which will ensure
// that webview tags are also not allowed to send messages across
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,21 @@ SrcAttribute.prototype.parse = function() {
WebViewInternal.navigate(this.view.guest.getId(), this.getValue());
};

// -----------------------------------------------------------------------------
// UseNewProcessAttribute object.

// Attribute that specifies whether new process should be used.
function UseNewProcessAttribute(view) {
GuestViewAttributes.BooleanAttribute.call(
this, WebViewConstants.ATTRIBUTE_USENEWPROCESS, view);
}

UseNewProcessAttribute.prototype.__proto__ =
GuestViewAttributes.BooleanAttribute.prototype;

UseNewProcessAttribute.prototype.handleMutation =
UseNewProcessAttribute.prototype.handleMutation;

// -----------------------------------------------------------------------------

// Sets up all of the webview attributes.
Expand All @@ -265,6 +280,8 @@ WebViewImpl.prototype.setupAttributes = function() {
new PartitionAttribute(this);
this.attributes[WebViewConstants.ATTRIBUTE_SRC] =
new SrcAttribute(this);
this.attributes[WebViewConstants.ATTRIBUTE_USENEWPROCESS] =
new UseNewProcessAttribute(this);

var autosizeAttributes = [WebViewConstants.ATTRIBUTE_MAXHEIGHT,
WebViewConstants.ATTRIBUTE_MAXWIDTH,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var WebViewConstants = {
ATTRIBUTE_MINWIDTH: 'minwidth',
ATTRIBUTE_NAME: 'name',
ATTRIBUTE_PARTITION: 'partition',
ATTRIBUTE_USENEWPROCESS: 'usenewprocess',
ATTRIBUTE_SRC: 'src',

// Error/warning messages.
Expand Down

0 comments on commit 617020e

Please sign in to comment.