| OLD | NEW |
| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 }; | 258 }; |
| 259 | 259 |
| 260 // Helper for GetInnerWebContents(). | 260 // Helper for GetInnerWebContents(). |
| 261 bool GetInnerWebContentsHelper( | 261 bool GetInnerWebContentsHelper( |
| 262 std::vector<WebContentsImpl*>* all_guest_contents, | 262 std::vector<WebContentsImpl*>* all_guest_contents, |
| 263 WebContents* guest_contents) { | 263 WebContents* guest_contents) { |
| 264 all_guest_contents->push_back(static_cast<WebContentsImpl*>(guest_contents)); | 264 all_guest_contents->push_back(static_cast<WebContentsImpl*>(guest_contents)); |
| 265 return false; | 265 return false; |
| 266 } | 266 } |
| 267 | 267 |
| 268 } // namespace | 268 FrameTreeNode* FindOpener(const WebContents::CreateParams& params) { |
| 269 | |
| 270 WebContents* WebContents::Create(const WebContents::CreateParams& params) { | |
| 271 FrameTreeNode* opener_node = nullptr; | 269 FrameTreeNode* opener_node = nullptr; |
| 272 if (params.opener_render_frame_id != MSG_ROUTING_NONE) { | 270 if (params.opener_render_frame_id != MSG_ROUTING_NONE) { |
| 273 RenderFrameHostImpl* opener_rfh = RenderFrameHostImpl::FromID( | 271 RenderFrameHostImpl* opener_rfh = RenderFrameHostImpl::FromID( |
| 274 params.opener_render_process_id, params.opener_render_frame_id); | 272 params.opener_render_process_id, params.opener_render_frame_id); |
| 275 if (opener_rfh) | 273 if (opener_rfh) |
| 276 opener_node = opener_rfh->frame_tree_node(); | 274 opener_node = opener_rfh->frame_tree_node(); |
| 277 } | 275 } |
| 278 return WebContentsImpl::CreateWithOpener(params, opener_node); | 276 return opener_node; |
| 277 } |
| 278 |
| 279 } // namespace |
| 280 |
| 281 WebContents* WebContents::Create(const WebContents::CreateParams& params) { |
| 282 return WebContentsImpl::CreateWithOpener(params, FindOpener(params)); |
| 279 } | 283 } |
| 280 | 284 |
| 281 WebContents* WebContents::CreateWithSessionStorage( | 285 WebContents* WebContents::CreateWithSessionStorage( |
| 282 const WebContents::CreateParams& params, | 286 const WebContents::CreateParams& params, |
| 283 const SessionStorageNamespaceMap& session_storage_namespace_map) { | 287 const SessionStorageNamespaceMap& session_storage_namespace_map) { |
| 284 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context); | 288 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context); |
| 289 new_contents->SetOpenerForNewContents(FindOpener(params), |
| 290 params.opener_suppressed); |
| 285 | 291 |
| 286 for (SessionStorageNamespaceMap::const_iterator it = | 292 for (SessionStorageNamespaceMap::const_iterator it = |
| 287 session_storage_namespace_map.begin(); | 293 session_storage_namespace_map.begin(); |
| 288 it != session_storage_namespace_map.end(); | 294 it != session_storage_namespace_map.end(); |
| 289 ++it) { | 295 ++it) { |
| 290 new_contents->GetController() | 296 new_contents->GetController() |
| 291 .SetSessionStorageNamespace(it->first, it->second.get()); | 297 .SetSessionStorageNamespace(it->first, it->second.get()); |
| 292 } | 298 } |
| 293 | 299 |
| 294 new_contents->Init(params); | 300 new_contents->Init(params); |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 observer.ResetWebContents(); | 636 observer.ResetWebContents(); |
| 631 | 637 |
| 632 SetDelegate(NULL); | 638 SetDelegate(NULL); |
| 633 } | 639 } |
| 634 | 640 |
| 635 WebContentsImpl* WebContentsImpl::CreateWithOpener( | 641 WebContentsImpl* WebContentsImpl::CreateWithOpener( |
| 636 const WebContents::CreateParams& params, | 642 const WebContents::CreateParams& params, |
| 637 FrameTreeNode* opener) { | 643 FrameTreeNode* opener) { |
| 638 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener"); | 644 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener"); |
| 639 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context); | 645 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context); |
| 640 | 646 new_contents->SetOpenerForNewContents(opener, params.opener_suppressed); |
| 641 FrameTreeNode* new_root = new_contents->GetFrameTree()->root(); | |
| 642 | |
| 643 if (opener) { | |
| 644 // For the "original opener", track the opener's main frame instead, because | |
| 645 // if the opener is a subframe, the opener tracking could be easily bypassed | |
| 646 // by spawning from a subframe and deleting the subframe. | |
| 647 // https://crbug.com/705316 | |
| 648 new_root->SetOriginalOpener(opener->frame_tree()->root()); | |
| 649 | |
| 650 if (!params.opener_suppressed) { | |
| 651 new_root->SetOpener(opener); | |
| 652 new_contents->created_with_opener_ = true; | |
| 653 } | |
| 654 } | |
| 655 | 647 |
| 656 // If the opener is sandboxed, a new popup must inherit the opener's sandbox | 648 // If the opener is sandboxed, a new popup must inherit the opener's sandbox |
| 657 // flags, and these flags take effect immediately. An exception is if the | 649 // flags, and these flags take effect immediately. An exception is if the |
| 658 // opener's sandbox flags lack the PropagatesToAuxiliaryBrowsingContexts | 650 // opener's sandbox flags lack the PropagatesToAuxiliaryBrowsingContexts |
| 659 // bit (which is controlled by the "allow-popups-to-escape-sandbox" token). | 651 // bit (which is controlled by the "allow-popups-to-escape-sandbox" token). |
| 660 // See https://html.spec.whatwg.org/#attr-iframe-sandbox. | 652 // See https://html.spec.whatwg.org/#attr-iframe-sandbox. |
| 653 FrameTreeNode* new_root = new_contents->GetFrameTree()->root(); |
| 661 if (opener) { | 654 if (opener) { |
| 662 blink::WebSandboxFlags opener_flags = opener->effective_sandbox_flags(); | 655 blink::WebSandboxFlags opener_flags = opener->effective_sandbox_flags(); |
| 663 const blink::WebSandboxFlags inherit_flag = | 656 const blink::WebSandboxFlags inherit_flag = |
| 664 blink::WebSandboxFlags::kPropagatesToAuxiliaryBrowsingContexts; | 657 blink::WebSandboxFlags::kPropagatesToAuxiliaryBrowsingContexts; |
| 665 if ((opener_flags & inherit_flag) == inherit_flag) { | 658 if ((opener_flags & inherit_flag) == inherit_flag) { |
| 666 new_root->SetPendingSandboxFlags(opener_flags); | 659 new_root->SetPendingSandboxFlags(opener_flags); |
| 667 new_root->CommitPendingFramePolicy(); | 660 new_root->CommitPendingFramePolicy(); |
| 668 } | 661 } |
| 669 } | 662 } |
| 670 | 663 |
| (...skipping 1529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2200 StoragePartition* partition = BrowserContext::GetStoragePartition( | 2193 StoragePartition* partition = BrowserContext::GetStoragePartition( |
| 2201 GetBrowserContext(), site_instance.get()); | 2194 GetBrowserContext(), site_instance.get()); |
| 2202 DOMStorageContextWrapper* dom_storage_context = | 2195 DOMStorageContextWrapper* dom_storage_context = |
| 2203 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext()); | 2196 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext()); |
| 2204 SessionStorageNamespaceImpl* session_storage_namespace_impl = | 2197 SessionStorageNamespaceImpl* session_storage_namespace_impl = |
| 2205 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace); | 2198 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace); |
| 2206 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context)); | 2199 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context)); |
| 2207 | 2200 |
| 2208 if (delegate_ && | 2201 if (delegate_ && |
| 2209 !delegate_->ShouldCreateWebContents( | 2202 !delegate_->ShouldCreateWebContents( |
| 2210 this, source_site_instance, render_view_route_id, main_frame_route_id, | 2203 this, opener, source_site_instance, render_view_route_id, |
| 2211 main_frame_widget_route_id, params.window_container_type, | 2204 main_frame_route_id, main_frame_widget_route_id, |
| 2212 opener->GetLastCommittedURL(), params.frame_name, params.target_url, | 2205 params.window_container_type, opener->GetLastCommittedURL(), |
| 2213 partition_id, session_storage_namespace)) { | 2206 params.frame_name, params.target_url, partition_id, |
| 2207 session_storage_namespace)) { |
| 2214 // Note: even though we're not creating a WebContents here, it could have | 2208 // Note: even though we're not creating a WebContents here, it could have |
| 2215 // been created by the embedder so ensure that the RenderFrameHost is | 2209 // been created by the embedder so ensure that the RenderFrameHost is |
| 2216 // properly initialized. | 2210 // properly initialized. |
| 2217 // It's safe to only target the frame because the render process will not | 2211 // It's safe to only target the frame because the render process will not |
| 2218 // have a chance to create more frames at this point. | 2212 // have a chance to create more frames at this point. |
| 2219 RenderFrameHostImpl* rfh = | 2213 RenderFrameHostImpl* rfh = |
| 2220 RenderFrameHostImpl::FromID(render_process_id, main_frame_route_id); | 2214 RenderFrameHostImpl::FromID(render_process_id, main_frame_route_id); |
| 2221 if (rfh) { | 2215 if (rfh) { |
| 2222 DCHECK(rfh->IsRenderFrameLive()); | 2216 DCHECK(rfh->IsRenderFrameLive()); |
| 2223 rfh->Init(); | 2217 rfh->Init(); |
| (...skipping 1117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3341 current->mouse_lock_widget_ = nullptr; | 3335 current->mouse_lock_widget_ = nullptr; |
| 3342 } | 3336 } |
| 3343 | 3337 |
| 3344 return false; | 3338 return false; |
| 3345 } | 3339 } |
| 3346 | 3340 |
| 3347 bool WebContentsImpl::HasOpener() const { | 3341 bool WebContentsImpl::HasOpener() const { |
| 3348 return GetOpener() != NULL; | 3342 return GetOpener() != NULL; |
| 3349 } | 3343 } |
| 3350 | 3344 |
| 3351 WebContentsImpl* WebContentsImpl::GetOpener() const { | 3345 RenderFrameHostImpl* WebContentsImpl::GetOpener() const { |
| 3352 FrameTreeNode* opener_ftn = frame_tree_.root()->opener(); | 3346 FrameTreeNode* opener_ftn = frame_tree_.root()->opener(); |
| 3353 return opener_ftn ? FromFrameTreeNode(opener_ftn) : nullptr; | 3347 return opener_ftn ? opener_ftn->current_frame_host() : nullptr; |
| 3354 } | 3348 } |
| 3355 | 3349 |
| 3356 bool WebContentsImpl::HasOriginalOpener() const { | 3350 bool WebContentsImpl::HasOriginalOpener() const { |
| 3357 return GetOriginalOpener() != NULL; | 3351 return GetOriginalOpener() != NULL; |
| 3358 } | 3352 } |
| 3359 | 3353 |
| 3360 WebContents* WebContentsImpl::GetOriginalOpener() const { | 3354 RenderFrameHostImpl* WebContentsImpl::GetOriginalOpener() const { |
| 3361 FrameTreeNode* opener_ftn = frame_tree_.root()->original_opener(); | 3355 FrameTreeNode* opener_ftn = frame_tree_.root()->original_opener(); |
| 3362 return opener_ftn ? FromFrameTreeNode(opener_ftn) : nullptr; | 3356 return opener_ftn ? opener_ftn->current_frame_host() : nullptr; |
| 3363 } | 3357 } |
| 3364 | 3358 |
| 3365 void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) { | 3359 void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) { |
| 3366 if (!color_chooser_info_.get()) | 3360 if (!color_chooser_info_.get()) |
| 3367 return; | 3361 return; |
| 3368 RenderFrameHost* rfh = RenderFrameHost::FromID( | 3362 RenderFrameHost* rfh = RenderFrameHost::FromID( |
| 3369 color_chooser_info_->render_process_id, | 3363 color_chooser_info_->render_process_id, |
| 3370 color_chooser_info_->render_frame_id); | 3364 color_chooser_info_->render_frame_id); |
| 3371 if (!rfh) | 3365 if (!rfh) |
| 3372 return; | 3366 return; |
| (...skipping 2228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5601 continue; | 5595 continue; |
| 5602 RenderViewHost* render_view_host = RenderViewHost::From(render_widget_host); | 5596 RenderViewHost* render_view_host = RenderViewHost::From(render_widget_host); |
| 5603 if (!render_view_host) | 5597 if (!render_view_host) |
| 5604 continue; | 5598 continue; |
| 5605 render_view_host_set.insert(render_view_host); | 5599 render_view_host_set.insert(render_view_host); |
| 5606 } | 5600 } |
| 5607 for (RenderViewHost* render_view_host : render_view_host_set) | 5601 for (RenderViewHost* render_view_host : render_view_host_set) |
| 5608 render_view_host->OnWebkitPreferencesChanged(); | 5602 render_view_host->OnWebkitPreferencesChanged(); |
| 5609 } | 5603 } |
| 5610 | 5604 |
| 5605 void WebContentsImpl::SetOpenerForNewContents(FrameTreeNode* opener, |
| 5606 bool opener_suppressed) { |
| 5607 if (opener) { |
| 5608 FrameTreeNode* new_root = GetFrameTree()->root(); |
| 5609 |
| 5610 // For the "original opener", track the opener's main frame instead, because |
| 5611 // if the opener is a subframe, the opener tracking could be easily bypassed |
| 5612 // by spawning from a subframe and deleting the subframe. |
| 5613 // https://crbug.com/705316 |
| 5614 new_root->SetOriginalOpener(opener->frame_tree()->root()); |
| 5615 |
| 5616 if (!opener_suppressed) { |
| 5617 new_root->SetOpener(opener); |
| 5618 created_with_opener_ = true; |
| 5619 } |
| 5620 } |
| 5621 } |
| 5622 |
| 5611 } // namespace content | 5623 } // namespace content |
| OLD | NEW |