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

Unified Diff: content/browser/tab_contents/tab_contents_view_helper.cc

Issue 9325082: Create window in a new BrowsingInstance when opening a link in a new process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use correct navigation policy. Created 8 years, 10 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
Index: content/browser/tab_contents/tab_contents_view_helper.cc
diff --git a/content/browser/tab_contents/tab_contents_view_helper.cc b/content/browser/tab_contents/tab_contents_view_helper.cc
index 75896d3c6bc623159543b40ef119f022b8c9f000..9aa6ed9cd8457f4f31d5a538ba92f0a487d57cc2 100644
--- a/content/browser/tab_contents/tab_contents_view_helper.cc
+++ b/content/browser/tab_contents/tab_contents_view_helper.cc
@@ -12,6 +12,7 @@
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/notification_types.h"
+#include "content/public/browser/site_instance.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_view.h"
@@ -57,16 +58,44 @@ TabContents* TabContentsViewHelper::CreateNewWindow(
if (!should_create)
return NULL;
+ // We usually create the new window in the same BrowsingInstance (group of
+ // script-related windows), by passing in the current SiteInstance. However,
+ // if the opener is being suppressed, we create a new BrowsingInstance
+ // instead by passing a NULL SiteInstance. There's no risk of deleting the
+ // SiteInstance here, so we can use a normal pointer.
+ scoped_refptr<content::SiteInstance> site_instance =
+ params.opener_suppressed ?
+ content::SiteInstance::Create(web_contents->GetBrowserContext()) :
+ web_contents->GetSiteInstance();
+
// Create the new web contents. This will automatically create the new
// WebContentsView. In the future, we may want to create the view separately.
TabContents* new_contents =
new TabContents(web_contents->GetBrowserContext(),
- web_contents->GetSiteInstance(),
+ site_instance,
route_id,
static_cast<TabContents*>(web_contents),
NULL);
new_contents->set_opener_web_ui_type(
web_contents->GetWebUITypeForCurrentState());
+
+ if (params.opener_suppressed) {
+ // Now show and navigate it to the intended destination, since the original
+ // renderer can't access it anymore.
+ gfx::Rect initial_pos;
+ web_contents->AddNewContents(new_contents,
+ params.disposition,
+ initial_pos,
+ params.user_gesture);
+ content::OpenURLParams open_params(params.target_url, content::Referrer(),
+ CURRENT_TAB,
+ content::PAGE_TRANSITION_LINK,
+ true /* is_renderer_initiated */);
+ WebContents* opened_contents = new_contents->OpenURL(open_params);
+ DCHECK_EQ(new_contents, opened_contents);
+ return new_contents;
+ }
+
content::WebContentsView* new_view = new_contents->GetView();
// TODO(brettw): It seems bogus that we have to call this function on the
@@ -74,6 +103,7 @@ TabContents* TabContentsViewHelper::CreateNewWindow(
new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
// Save the created window associated with the route so we can show it later.
+ DCHECK_NE(MSG_ROUTING_NONE, route_id);
pending_contents_[route_id] = new_contents;
if (web_contents->GetDelegate())

Powered by Google App Engine
This is Rietveld 408576698