Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2841)

Unified Diff: chrome/browser/ui/browser.cc

Issue 9837074: Make it so that allow_js_access: false can be used with background pages created by window.open. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix indentation. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/browser.h ('k') | chrome/common/extensions/extension.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/browser.cc
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index 2920d28b6d7529feb98fe56f1ab8be7a06461708..7e2a5dddcd0736b4b1ee196babb6f4dae088ad4a 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -2289,9 +2289,10 @@ void Browser::OpenBookmarkManagerEditNode(int64 node_id) {
}
bool Browser::MaybeCreateBackgroundContents(int route_id,
- SiteInstance* site,
- const GURL& opener_url,
- const string16& frame_name) {
+ WebContents* opener_web_contents,
+ const string16& frame_name,
+ const GURL& target_url) {
+ GURL opener_url = opener_web_contents->GetURL();
ExtensionService* extensions_service = profile_->GetExtensionService();
if (!opener_url.is_valid() ||
@@ -2317,9 +2318,11 @@ bool Browser::MaybeCreateBackgroundContents(int route_id,
return false;
// Ensure that we're trying to open this from the extension's process.
+ SiteInstance* opener_site_instance = opener_web_contents->GetSiteInstance();
extensions::ProcessMap* process_map = extensions_service->process_map();
- if (!site->GetProcess() ||
- !process_map->Contains(extension->id(), site->GetProcess()->GetID())) {
+ if (!opener_site_instance->GetProcess() ||
+ !process_map->Contains(
+ extension->id(), opener_site_instance->GetProcess()->GetID())) {
return false;
}
@@ -2332,10 +2335,32 @@ bool Browser::MaybeCreateBackgroundContents(int route_id,
delete existing;
}
+ // If script access is not allowed, create the the background contents in a
+ // new SiteInstance, so that a separate process is used.
+ bool allow_js_access = extension->allow_background_js_access();
+ scoped_refptr<content::SiteInstance> site_instance =
+ allow_js_access ?
+ opener_site_instance :
+ content::SiteInstance::Create(opener_web_contents->GetBrowserContext());
+
// Passed all the checks, so this should be created as a BackgroundContents.
- BackgroundContents* contents =
- service->CreateBackgroundContents(site, route_id, profile_, frame_name,
- ASCIIToUTF16(extension->id()));
+ BackgroundContents* contents = service->CreateBackgroundContents(
+ site_instance,
+ route_id,
+ profile_,
+ frame_name,
+ ASCIIToUTF16(extension->id()));
+
+ // When a separate process is used, the original renderer cannot access the
+ // new window later, thus we need to navigate the window now.
+ if (contents && !allow_js_access) {
+ contents->web_contents()->GetController().LoadURL(
+ target_url,
+ content::Referrer(),
+ content::PAGE_TRANSITION_LINK,
+ std::string()); // No extra headers.
+ }
+
return contents != NULL;
}
@@ -4072,14 +4097,12 @@ bool Browser::ShouldCreateWebContents(
WebContents* web_contents,
int route_id,
WindowContainerType window_container_type,
- const string16& frame_name) {
+ const string16& frame_name,
+ const GURL& target_url) {
if (window_container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
// If a BackgroundContents is created, suppress the normal WebContents.
return !MaybeCreateBackgroundContents(
- route_id,
- web_contents->GetSiteInstance(),
- web_contents->GetURL(),
- frame_name);
+ route_id, web_contents, frame_name, target_url);
}
return true;
« no previous file with comments | « chrome/browser/ui/browser.h ('k') | chrome/common/extensions/extension.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698