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

Side by Side Diff: content/browser/web_contents/web_contents_impl.cc

Issue 1086283002: Track frame openers in FrameTreeNodes instead of WebContents (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Second round of feedback Created 5 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/web_contents/web_contents_impl.h" 5 #include "content/browser/web_contents/web_contents_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 200 }
201 201
202 void SetAccessibilityModeOnFrame(AccessibilityMode mode, 202 void SetAccessibilityModeOnFrame(AccessibilityMode mode,
203 RenderFrameHost* frame_host) { 203 RenderFrameHost* frame_host) {
204 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode); 204 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode);
205 } 205 }
206 206
207 } // namespace 207 } // namespace
208 208
209 WebContents* WebContents::Create(const WebContents::CreateParams& params) { 209 WebContents* WebContents::Create(const WebContents::CreateParams& params) {
210 return WebContentsImpl::CreateWithOpener( 210 FrameTreeNode* opener_node = nullptr;
211 params, static_cast<WebContentsImpl*>(params.opener)); 211 if (params.opener_render_frame_id != MSG_ROUTING_NONE) {
212 RenderFrameHostImpl* opener_rfh = RenderFrameHostImpl::FromID(
213 params.opener_render_process_id, params.opener_render_frame_id);
214 if (opener_rfh)
215 opener_node = opener_rfh->frame_tree_node();
216 }
217 return WebContentsImpl::CreateWithOpener(params, opener_node);
212 } 218 }
213 219
214 WebContents* WebContents::CreateWithSessionStorage( 220 WebContents* WebContents::CreateWithSessionStorage(
215 const WebContents::CreateParams& params, 221 const WebContents::CreateParams& params,
216 const SessionStorageNamespaceMap& session_storage_namespace_map) { 222 const SessionStorageNamespaceMap& session_storage_namespace_map) {
217 WebContentsImpl* new_contents = new WebContentsImpl( 223 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
218 params.browser_context, NULL);
219 224
220 for (SessionStorageNamespaceMap::const_iterator it = 225 for (SessionStorageNamespaceMap::const_iterator it =
221 session_storage_namespace_map.begin(); 226 session_storage_namespace_map.begin();
222 it != session_storage_namespace_map.end(); 227 it != session_storage_namespace_map.end();
223 ++it) { 228 ++it) {
224 new_contents->GetController() 229 new_contents->GetController()
225 .SetSessionStorageNamespace(it->first, it->second.get()); 230 .SetSessionStorageNamespace(it->first, it->second.get());
226 } 231 }
227 232
228 new_contents->Init(params); 233 new_contents->Init(params);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 render_frame_id(render_frame_id), 289 render_frame_id(render_frame_id),
285 chooser(chooser), 290 chooser(chooser),
286 identifier(identifier) { 291 identifier(identifier) {
287 } 292 }
288 293
289 WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() { 294 WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
290 } 295 }
291 296
292 // WebContentsImpl ------------------------------------------------------------- 297 // WebContentsImpl -------------------------------------------------------------
293 298
294 WebContentsImpl::WebContentsImpl(BrowserContext* browser_context, 299 WebContentsImpl::WebContentsImpl(BrowserContext* browser_context)
295 WebContentsImpl* opener)
296 : delegate_(NULL), 300 : delegate_(NULL),
297 controller_(this, browser_context), 301 controller_(this, browser_context),
298 render_view_host_delegate_view_(NULL), 302 render_view_host_delegate_view_(NULL),
299 opener_(opener), 303 created_with_opener_(false),
300 created_with_opener_(!!opener),
301 #if defined(OS_WIN) 304 #if defined(OS_WIN)
302 accessible_parent_(NULL), 305 accessible_parent_(NULL),
303 #endif 306 #endif
304 frame_tree_(new NavigatorImpl(&controller_, this), 307 frame_tree_(new NavigatorImpl(&controller_, this),
305 this, 308 this,
306 this, 309 this,
307 this, 310 this,
308 this), 311 this),
309 is_loading_(false), 312 is_loading_(false),
310 is_load_to_different_document_(false), 313 is_load_to_different_document_(false),
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 ResetWebContents()); 422 ResetWebContents());
420 423
421 SetDelegate(NULL); 424 SetDelegate(NULL);
422 425
423 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(), 426 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
424 destruction_observers_.end()); 427 destruction_observers_.end());
425 } 428 }
426 429
427 WebContentsImpl* WebContentsImpl::CreateWithOpener( 430 WebContentsImpl* WebContentsImpl::CreateWithOpener(
428 const WebContents::CreateParams& params, 431 const WebContents::CreateParams& params,
429 WebContentsImpl* opener) { 432 FrameTreeNode* opener) {
430 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener"); 433 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
431 WebContentsImpl* new_contents = new WebContentsImpl( 434 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
432 params.browser_context, params.opener_suppressed ? NULL : opener);
433 435
436 if (!params.opener_suppressed && opener) {
437 new_contents->GetFrameTree()->root()->SetOpener(opener);
438 new_contents->created_with_opener_ = true;
439 }
440
441 // This may be true even when opener is null, such as when opening blocked
442 // popups.
434 if (params.created_with_opener) 443 if (params.created_with_opener)
435 new_contents->created_with_opener_ = true; 444 new_contents->created_with_opener_ = true;
436 445
437 if (params.guest_delegate) { 446 if (params.guest_delegate) {
438 // This makes |new_contents| act as a guest. 447 // This makes |new_contents| act as a guest.
439 // For more info, see comment above class BrowserPluginGuest. 448 // For more info, see comment above class BrowserPluginGuest.
440 BrowserPluginGuest::Create(new_contents, params.guest_delegate); 449 BrowserPluginGuest::Create(new_contents, params.guest_delegate);
441 // We are instantiating a WebContents for browser plugin. Set its subframe 450 // We are instantiating a WebContents for browser plugin. Set its subframe
442 // bit to true. 451 // bit to true.
443 new_contents->is_subframe_ = true; 452 new_contents->is_subframe_ = true;
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition); 1175 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition);
1167 } 1176 }
1168 1177
1169 void WebContentsImpl::Stop() { 1178 void WebContentsImpl::Stop() {
1170 GetRenderManager()->Stop(); 1179 GetRenderManager()->Stop();
1171 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped()); 1180 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
1172 } 1181 }
1173 1182
1174 WebContents* WebContentsImpl::Clone() { 1183 WebContents* WebContentsImpl::Clone() {
1175 // We use our current SiteInstance since the cloned entry will use it anyway. 1184 // We use our current SiteInstance since the cloned entry will use it anyway.
1176 // We pass our own opener so that the cloned page can access it if it was 1185 // We pass our own opener so that the cloned page can access it if it was set
1177 // before. 1186 // before.
1178 CreateParams create_params(GetBrowserContext(), GetSiteInstance()); 1187 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
1179 create_params.initial_size = GetContainerBounds().size(); 1188 create_params.initial_size = GetContainerBounds().size();
1180 WebContentsImpl* tc = CreateWithOpener(create_params, opener_); 1189 WebContentsImpl* tc =
1190 CreateWithOpener(create_params, frame_tree_.root()->opener());
1181 tc->GetController().CopyStateFrom(controller_); 1191 tc->GetController().CopyStateFrom(controller_);
1182 FOR_EACH_OBSERVER(WebContentsObserver, 1192 FOR_EACH_OBSERVER(WebContentsObserver,
1183 observers_, 1193 observers_,
1184 DidCloneToNewWebContents(this, tc)); 1194 DidCloneToNewWebContents(this, tc));
1185 return tc; 1195 return tc;
1186 } 1196 }
1187 1197
1188 void WebContentsImpl::Observe(int type, 1198 void WebContentsImpl::Observe(int type,
1189 const NotificationSource& source, 1199 const NotificationSource& source,
1190 const NotificationDetails& details) { 1200 const NotificationDetails& details) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1251 // Regular WebContentsView. 1261 // Regular WebContentsView.
1252 view_.reset(CreateWebContentsView( 1262 view_.reset(CreateWebContentsView(
1253 this, delegate, &render_view_host_delegate_view_)); 1263 this, delegate, &render_view_host_delegate_view_));
1254 } 1264 }
1255 CHECK(render_view_host_delegate_view_); 1265 CHECK(render_view_host_delegate_view_);
1256 CHECK(view_.get()); 1266 CHECK(view_.get());
1257 1267
1258 gfx::Size initial_size = params.initial_size; 1268 gfx::Size initial_size = params.initial_size;
1259 view_->CreateView(initial_size, params.context); 1269 view_->CreateView(initial_size, params.context);
1260 1270
1261 // Listen for whether our opener gets destroyed.
1262 if (opener_)
1263 AddDestructionObserver(opener_);
1264
1265 #if defined(ENABLE_PLUGINS) 1271 #if defined(ENABLE_PLUGINS)
1266 plugin_content_origin_whitelist_.reset( 1272 plugin_content_origin_whitelist_.reset(
1267 new PluginContentOriginWhitelist(this)); 1273 new PluginContentOriginWhitelist(this));
1268 #endif 1274 #endif
1269 1275
1270 registrar_.Add(this, 1276 registrar_.Add(this,
1271 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, 1277 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1272 NotificationService::AllBrowserContextsAndSources()); 1278 NotificationService::AllBrowserContextsAndSources());
1273 1279
1274 screen_orientation_dispatcher_host_.reset( 1280 screen_orientation_dispatcher_host_.reset(
(...skipping 26 matching lines...) Expand all
1301 // main RenderFrameHost. It must be done here for main frames, since the 1307 // main RenderFrameHost. It must be done here for main frames, since the
1302 // NotifySwappedFromRenderManager expects view_ to already be created and that 1308 // NotifySwappedFromRenderManager expects view_ to already be created and that
1303 // happens after RenderFrameHostManager::Init. 1309 // happens after RenderFrameHostManager::Init.
1304 NotifySwappedFromRenderManager( 1310 NotifySwappedFromRenderManager(
1305 nullptr, GetRenderManager()->current_frame_host(), true); 1311 nullptr, GetRenderManager()->current_frame_host(), true);
1306 } 1312 }
1307 1313
1308 void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) { 1314 void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1309 RemoveDestructionObserver(web_contents); 1315 RemoveDestructionObserver(web_contents);
1310 1316
1311 // Clear the opener if it has been closed.
1312 if (web_contents == opener_) {
1313 opener_ = NULL;
1314 return;
1315 }
1316 // Clear a pending contents that has been closed before being shown. 1317 // Clear a pending contents that has been closed before being shown.
1317 for (PendingContents::iterator iter = pending_contents_.begin(); 1318 for (PendingContents::iterator iter = pending_contents_.begin();
1318 iter != pending_contents_.end(); 1319 iter != pending_contents_.end();
1319 ++iter) { 1320 ++iter) {
1320 if (iter->second != web_contents) 1321 if (iter->second != web_contents)
1321 continue; 1322 continue;
1322 pending_contents_.erase(iter); 1323 pending_contents_.erase(iter);
1323 return; 1324 return;
1324 } 1325 }
1325 NOTREACHED(); 1326 NOTREACHED();
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1607 main_frame_route_id); 1608 main_frame_route_id);
1608 return; 1609 return;
1609 } 1610 }
1610 1611
1611 // Create the new web contents. This will automatically create the new 1612 // Create the new web contents. This will automatically create the new
1612 // WebContentsView. In the future, we may want to create the view separately. 1613 // WebContentsView. In the future, we may want to create the view separately.
1613 CreateParams create_params(GetBrowserContext(), site_instance.get()); 1614 CreateParams create_params(GetBrowserContext(), site_instance.get());
1614 create_params.routing_id = route_id; 1615 create_params.routing_id = route_id;
1615 create_params.main_frame_routing_id = main_frame_route_id; 1616 create_params.main_frame_routing_id = main_frame_route_id;
1616 create_params.main_frame_name = base::UTF16ToUTF8(params.frame_name); 1617 create_params.main_frame_name = base::UTF16ToUTF8(params.frame_name);
1617 create_params.opener = this; 1618 create_params.opener_render_process_id = GetRenderProcessHost()->GetID();
1619 create_params.opener_render_frame_id = params.opener_render_frame_id;
1618 create_params.opener_suppressed = params.opener_suppressed; 1620 create_params.opener_suppressed = params.opener_suppressed;
1619 if (params.disposition == NEW_BACKGROUND_TAB) 1621 if (params.disposition == NEW_BACKGROUND_TAB)
1620 create_params.initially_hidden = true; 1622 create_params.initially_hidden = true;
1621 create_params.renderer_initiated_creation = 1623 create_params.renderer_initiated_creation =
1622 main_frame_route_id != MSG_ROUTING_NONE; 1624 main_frame_route_id != MSG_ROUTING_NONE;
1623 1625
1624 WebContentsImpl* new_contents = NULL; 1626 WebContentsImpl* new_contents = NULL;
1625 if (!is_guest) { 1627 if (!is_guest) {
1626 create_params.context = view_->GetNativeView(); 1628 create_params.context = view_->GetNativeView();
1627 create_params.initial_size = GetContainerBounds().size(); 1629 create_params.initial_size = GetContainerBounds().size();
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after
2477 bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) { 2479 bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
2478 if (GetBrowserPluginGuest()) 2480 if (GetBrowserPluginGuest())
2479 return GetBrowserPluginGuest()->LockMouse(allowed); 2481 return GetBrowserPluginGuest()->LockMouse(allowed);
2480 2482
2481 return GetRenderViewHost() 2483 return GetRenderViewHost()
2482 ? GetRenderViewHost()->GotResponseToLockMouseRequest(allowed) 2484 ? GetRenderViewHost()->GotResponseToLockMouseRequest(allowed)
2483 : false; 2485 : false;
2484 } 2486 }
2485 2487
2486 bool WebContentsImpl::HasOpener() const { 2488 bool WebContentsImpl::HasOpener() const {
2487 return opener_ != NULL; 2489 return GetOpener() != NULL;
2488 } 2490 }
2489 2491
2490 WebContents* WebContentsImpl::GetOpener() const { 2492 WebContentsImpl* WebContentsImpl::GetOpener() const {
2491 return static_cast<WebContents*>(opener_); 2493 FrameTreeNode* opener_ftn = frame_tree_.root()->opener();
2494 return opener_ftn ? FromFrameTreeNode(opener_ftn) : nullptr;
2492 } 2495 }
2493 2496
2494 void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) { 2497 void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
2495 if (!color_chooser_info_.get()) 2498 if (!color_chooser_info_.get())
2496 return; 2499 return;
2497 RenderFrameHost* rfh = RenderFrameHost::FromID( 2500 RenderFrameHost* rfh = RenderFrameHost::FromID(
2498 color_chooser_info_->render_process_id, 2501 color_chooser_info_->render_process_id,
2499 color_chooser_info_->render_frame_id); 2502 color_chooser_info_->render_frame_id);
2500 if (!rfh) 2503 if (!rfh)
2501 return; 2504 return;
(...skipping 1333 matching lines...) Expand 10 before | Expand all | Expand 10 after
3835 // Update the URL display. 3838 // Update the URL display.
3836 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); 3839 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
3837 } 3840 }
3838 3841
3839 void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host, 3842 void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host,
3840 const std::string& name) { 3843 const std::string& name) {
3841 FOR_EACH_OBSERVER(WebContentsObserver, observers_, 3844 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3842 FrameNameChanged(render_frame_host, name)); 3845 FrameNameChanged(render_frame_host, name));
3843 } 3846 }
3844 3847
3845 void WebContentsImpl::DidDisownOpener(RenderFrameHost* render_frame_host) {
3846 // No action is necessary if the opener has already been cleared.
3847 if (!opener_)
3848 return;
3849
3850 // Clear our opener so that future cross-process navigations don't have an
3851 // opener assigned.
3852 RemoveDestructionObserver(opener_);
3853 opener_ = NULL;
3854
3855 // Notify all swapped out RenderViewHosts for this tab. This is important
3856 // in case we go back to them, or if another window in those processes tries
3857 // to access window.opener.
3858 GetRenderManager()->DidDisownOpener(render_frame_host);
3859 }
3860
3861 void WebContentsImpl::DocumentOnLoadCompleted( 3848 void WebContentsImpl::DocumentOnLoadCompleted(
3862 RenderFrameHost* render_frame_host) { 3849 RenderFrameHost* render_frame_host) {
3863 FOR_EACH_OBSERVER(WebContentsObserver, observers_, 3850 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3864 DocumentOnLoadCompletedInMainFrame()); 3851 DocumentOnLoadCompletedInMainFrame());
3865 3852
3866 // TODO(avi): Remove. http://crbug.com/170921 3853 // TODO(avi): Remove. http://crbug.com/170921
3867 NotificationService::current()->Notify( 3854 NotificationService::current()->Notify(
3868 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, 3855 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3869 Source<WebContents>(this), 3856 Source<WebContents>(this),
3870 NotificationService::NoDetails()); 3857 NotificationService::NoDetails());
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
4127 } 4114 }
4128 4115
4129 void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager( 4116 void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager(
4130 RenderViewHost* old_host, 4117 RenderViewHost* old_host,
4131 RenderViewHost* new_host) { 4118 RenderViewHost* new_host) {
4132 NotifyViewSwapped(old_host, new_host); 4119 NotifyViewSwapped(old_host, new_host);
4133 } 4120 }
4134 4121
4135 int WebContentsImpl::CreateOpenerRenderViewsForRenderManager( 4122 int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
4136 SiteInstance* instance) { 4123 SiteInstance* instance) {
4137 if (!opener_) 4124 WebContentsImpl* opener = GetOpener();
4125 if (!opener)
4138 return MSG_ROUTING_NONE; 4126 return MSG_ROUTING_NONE;
4139 4127
4140 // Recursively create RenderViews for anything else in the opener chain. 4128 // Recursively create RenderViews for anything else in the opener chain.
4141 return opener_->CreateOpenerRenderViews(instance); 4129 return opener->CreateOpenerRenderViews(instance);
4142 } 4130 }
4143 4131
4144 int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) { 4132 int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
4145 int opener_route_id = MSG_ROUTING_NONE; 4133 int opener_route_id = MSG_ROUTING_NONE;
4146 4134
4147 // If this tab has an opener, ensure it has a RenderView in the given 4135 // If this tab has an opener, ensure it has a RenderView in the given
4148 // SiteInstance as well. 4136 // SiteInstance as well.
4149 if (opener_) 4137 WebContentsImpl* opener = GetOpener();
4150 opener_route_id = opener_->CreateOpenerRenderViews(instance); 4138 if (opener)
4139 opener_route_id = opener->CreateOpenerRenderViews(instance);
4151 4140
4152 // If any of the renderers (current, pending, or swapped out) for this 4141 // If any of the renderers (current, pending, or swapped out) for this
4153 // WebContents has the same SiteInstance, use it. 4142 // WebContents has the same SiteInstance, use it.
4154 if (GetRenderManager()->current_host()->GetSiteInstance() == instance) 4143 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
4155 return GetRenderManager()->current_host()->GetRoutingID(); 4144 return GetRenderManager()->current_host()->GetRoutingID();
4156 4145
4157 if (GetRenderManager()->pending_render_view_host() && 4146 if (GetRenderManager()->pending_render_view_host() &&
4158 GetRenderManager()->pending_render_view_host()->GetSiteInstance() == 4147 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
4159 instance) 4148 instance)
4160 return GetRenderManager()->pending_render_view_host()->GetRoutingID(); 4149 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
4458 player_map->erase(it); 4447 player_map->erase(it);
4459 } 4448 }
4460 4449
4461 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { 4450 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4462 force_disable_overscroll_content_ = force_disable; 4451 force_disable_overscroll_content_ = force_disable;
4463 if (view_) 4452 if (view_)
4464 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); 4453 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4465 } 4454 }
4466 4455
4467 } // namespace content 4456 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_impl.h ('k') | content/public/browser/content_browser_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698