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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 #include "content/common/page_state_serialization.h" | 84 #include "content/common/page_state_serialization.h" |
85 #include "content/common/site_isolation_policy.h" | 85 #include "content/common/site_isolation_policy.h" |
86 #include "content/common/view_messages.h" | 86 #include "content/common/view_messages.h" |
87 #include "content/public/browser/ax_event_notification_details.h" | 87 #include "content/public/browser/ax_event_notification_details.h" |
88 #include "content/public/browser/browser_context.h" | 88 #include "content/public/browser/browser_context.h" |
89 #include "content/public/browser/browser_plugin_guest_manager.h" | 89 #include "content/public/browser/browser_plugin_guest_manager.h" |
90 #include "content/public/browser/content_browser_client.h" | 90 #include "content/public/browser/content_browser_client.h" |
91 #include "content/public/browser/devtools_agent_host.h" | 91 #include "content/public/browser/devtools_agent_host.h" |
92 #include "content/public/browser/download_manager.h" | 92 #include "content/public/browser/download_manager.h" |
93 #include "content/public/browser/download_url_parameters.h" | 93 #include "content/public/browser/download_url_parameters.h" |
| 94 #include "content/public/browser/guest_mode.h" |
94 #include "content/public/browser/invalidate_type.h" | 95 #include "content/public/browser/invalidate_type.h" |
95 #include "content/public/browser/javascript_dialog_manager.h" | 96 #include "content/public/browser/javascript_dialog_manager.h" |
96 #include "content/public/browser/load_notification_details.h" | 97 #include "content/public/browser/load_notification_details.h" |
97 #include "content/public/browser/navigation_details.h" | 98 #include "content/public/browser/navigation_details.h" |
98 #include "content/public/browser/notification_details.h" | 99 #include "content/public/browser/notification_details.h" |
99 #include "content/public/browser/notification_service.h" | 100 #include "content/public/browser/notification_service.h" |
100 #include "content/public/browser/notification_types.h" | 101 #include "content/public/browser/notification_types.h" |
101 #include "content/public/browser/render_widget_host_iterator.h" | 102 #include "content/public/browser/render_widget_host_iterator.h" |
102 #include "content/public/browser/resource_request_details.h" | 103 #include "content/public/browser/resource_request_details.h" |
103 #include "content/public/browser/screen_orientation_dispatcher_host.h" | 104 #include "content/public/browser/screen_orientation_dispatcher_host.h" |
(...skipping 1292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1396 } | 1397 } |
1397 | 1398 |
1398 void WebContentsImpl::DispatchBeforeUnload() { | 1399 void WebContentsImpl::DispatchBeforeUnload() { |
1399 bool for_cross_site_transition = false; | 1400 bool for_cross_site_transition = false; |
1400 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition, false); | 1401 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition, false); |
1401 } | 1402 } |
1402 | 1403 |
1403 void WebContentsImpl::AttachToOuterWebContentsFrame( | 1404 void WebContentsImpl::AttachToOuterWebContentsFrame( |
1404 WebContents* outer_web_contents, | 1405 WebContents* outer_web_contents, |
1405 RenderFrameHost* outer_contents_frame) { | 1406 RenderFrameHost* outer_contents_frame) { |
1406 CHECK(BrowserPluginGuestMode::UseCrossProcessFramesForGuests()); | 1407 CHECK(GuestMode::IsInnerWebContentsUsingCrossProcessFrames(this)); |
1407 RenderFrameHostManager* render_manager = GetRenderManager(); | 1408 RenderFrameHostManager* render_manager = GetRenderManager(); |
1408 | 1409 |
1409 // When the WebContents being initialized has an opener, the browser side | 1410 // When the WebContents being initialized has an opener, the browser side |
1410 // Render{View,Frame}Host must be initialized and the RenderWidgetHostView | 1411 // Render{View,Frame}Host must be initialized and the RenderWidgetHostView |
1411 // created. This is needed because the usual initialization happens during | 1412 // created. This is needed because the usual initialization happens during |
1412 // the first navigation, but when attaching a new window we don't navigate | 1413 // the first navigation, but when attaching a new window we don't navigate |
1413 // before attaching. If the browser side is already initialized, the calls | 1414 // before attaching. If the browser side is already initialized, the calls |
1414 // below will just early return. | 1415 // below will just early return. |
1415 render_manager->InitRenderView(GetRenderViewHost(), nullptr); | 1416 render_manager->InitRenderView(GetRenderViewHost(), nullptr); |
1416 GetMainFrame()->Init(); | 1417 GetMainFrame()->Init(); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1552 switches::kUseMusInRenderer)) { | 1553 switches::kUseMusInRenderer)) { |
1553 ui::Window* mus_window = aura::GetMusWindow(params.context); | 1554 ui::Window* mus_window = aura::GetMusWindow(params.context); |
1554 if (mus_window) { | 1555 if (mus_window) { |
1555 view_.reset(new WebContentsViewMus(mus_window, this, delegate, | 1556 view_.reset(new WebContentsViewMus(mus_window, this, delegate, |
1556 &render_view_host_delegate_view_)); | 1557 &render_view_host_delegate_view_)); |
1557 } | 1558 } |
1558 } | 1559 } |
1559 #endif | 1560 #endif |
1560 | 1561 |
1561 if (!view_) { | 1562 if (!view_) { |
1562 if (browser_plugin_guest_ && | 1563 if (GuestMode::IsInnerWebContentsUsingCrossProcessFrames(this)) { |
1563 BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) { | |
1564 view_.reset(new WebContentsViewChildFrame( | 1564 view_.reset(new WebContentsViewChildFrame( |
1565 this, delegate, &render_view_host_delegate_view_)); | 1565 this, delegate, &render_view_host_delegate_view_)); |
1566 } else { | 1566 } else { |
1567 view_.reset(CreateWebContentsView(this, delegate, | 1567 view_.reset(CreateWebContentsView(this, delegate, |
1568 &render_view_host_delegate_view_)); | 1568 &render_view_host_delegate_view_)); |
1569 } | 1569 } |
1570 } | 1570 } |
1571 | 1571 |
1572 if (browser_plugin_guest_ && | 1572 if (browser_plugin_guest_ && |
1573 !BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) { | 1573 !GuestMode::IsInnerWebContentsUsingCrossProcessFrames(this)) { |
1574 view_.reset(new WebContentsViewGuest(this, browser_plugin_guest_.get(), | 1574 view_.reset(new WebContentsViewGuest(this, browser_plugin_guest_.get(), |
1575 std::move(view_), | 1575 std::move(view_), |
1576 &render_view_host_delegate_view_)); | 1576 &render_view_host_delegate_view_)); |
1577 } | 1577 } |
1578 CHECK(render_view_host_delegate_view_); | 1578 CHECK(render_view_host_delegate_view_); |
1579 CHECK(view_.get()); | 1579 CHECK(view_.get()); |
1580 | 1580 |
1581 gfx::Size initial_size = params.initial_size; | 1581 gfx::Size initial_size = params.initial_size; |
1582 view_->CreateView(initial_size, params.context); | 1582 view_->CreateView(initial_size, params.context); |
1583 | 1583 |
(...skipping 2604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4188 return delegate_->GetRootWindowResizerRect(); | 4188 return delegate_->GetRootWindowResizerRect(); |
4189 return gfx::Rect(); | 4189 return gfx::Rect(); |
4190 } | 4190 } |
4191 | 4191 |
4192 void WebContentsImpl::RemoveBrowserPluginEmbedder() { | 4192 void WebContentsImpl::RemoveBrowserPluginEmbedder() { |
4193 if (browser_plugin_embedder_) | 4193 if (browser_plugin_embedder_) |
4194 browser_plugin_embedder_.reset(); | 4194 browser_plugin_embedder_.reset(); |
4195 } | 4195 } |
4196 | 4196 |
4197 WebContentsImpl* WebContentsImpl::GetOuterWebContents() { | 4197 WebContentsImpl* WebContentsImpl::GetOuterWebContents() { |
4198 if (BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) { | 4198 if (GuestMode::IsInnerWebContentsUsingCrossProcessFrames(this) && node_) |
4199 if (node_) | 4199 return node_->outer_web_contents(); |
4200 return node_->outer_web_contents(); | 4200 |
4201 } else { | 4201 if (browser_plugin_guest_) |
4202 if (GetBrowserPluginGuest()) | 4202 return browser_plugin_guest_->embedder_web_contents(); |
4203 return GetBrowserPluginGuest()->embedder_web_contents(); | 4203 |
4204 } | |
4205 return nullptr; | 4204 return nullptr; |
4206 } | 4205 } |
4207 | 4206 |
4208 WebContentsImpl* WebContentsImpl::GetFocusedWebContents() { | 4207 WebContentsImpl* WebContentsImpl::GetFocusedWebContents() { |
4209 // There is no inner or outer web contents. | 4208 // There is no inner or outer web contents. |
4210 if (!node_ && !GetBrowserPluginGuest()) | 4209 if (!node_ && !GetBrowserPluginGuest()) |
4211 return this; | 4210 return this; |
4212 | 4211 |
4213 // We may need to create a node_ on the outermost contents in the | 4212 // We may need to create a node_ on the outermost contents in the |
4214 // BrowserPlugin case. | 4213 // BrowserPlugin case. |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4624 | 4623 |
4625 void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) { | 4624 void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) { |
4626 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>( | 4625 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>( |
4627 WebContents::FromRenderFrameHost(source_rfh)); | 4626 WebContents::FromRenderFrameHost(source_rfh)); |
4628 | 4627 |
4629 if (source_web_contents) { | 4628 if (source_web_contents) { |
4630 // If this message is going to outer WebContents from inner WebContents, | 4629 // If this message is going to outer WebContents from inner WebContents, |
4631 // then we should not create a RenderView. AttachToOuterWebContentsFrame() | 4630 // then we should not create a RenderView. AttachToOuterWebContentsFrame() |
4632 // already created a RenderFrameProxyHost for that purpose. | 4631 // already created a RenderFrameProxyHost for that purpose. |
4633 if (GetBrowserPluginEmbedder() && | 4632 if (GetBrowserPluginEmbedder() && |
4634 BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) { | 4633 GuestMode::IsInnerWebContentsUsingCrossProcessFrames( |
| 4634 source_web_contents)) { |
4635 return; | 4635 return; |
4636 } | 4636 } |
4637 | 4637 |
4638 if (this != source_web_contents && GetBrowserPluginGuest()) { | 4638 if (this != source_web_contents && GetBrowserPluginGuest()) { |
4639 // We create a RenderFrameProxyHost for the embedder in the guest's render | 4639 // We create a RenderFrameProxyHost for the embedder in the guest's render |
4640 // process but we intentionally do not expose the embedder's opener chain | 4640 // process but we intentionally do not expose the embedder's opener chain |
4641 // to it. | 4641 // to it. |
4642 source_web_contents->GetRenderManager()->CreateRenderFrameProxy( | 4642 source_web_contents->GetRenderManager()->CreateRenderFrameProxy( |
4643 GetSiteInstance()); | 4643 GetSiteInstance()); |
4644 } else { | 4644 } else { |
4645 RenderFrameHostImpl* source_rfhi = | 4645 RenderFrameHostImpl* source_rfhi = |
4646 static_cast<RenderFrameHostImpl*>(source_rfh); | 4646 static_cast<RenderFrameHostImpl*>(source_rfh); |
4647 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies( | 4647 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies( |
4648 GetSiteInstance(), nullptr); | 4648 GetSiteInstance(), nullptr); |
4649 } | 4649 } |
4650 } | 4650 } |
4651 } | 4651 } |
4652 | 4652 |
4653 void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node, | 4653 void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node, |
4654 SiteInstance* source) { | 4654 SiteInstance* source) { |
4655 if (!BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) { | 4655 if (!GuestMode::IsInnerWebContentsUsingCrossProcessFrames(this) && |
| 4656 browser_plugin_guest_) { |
4656 frame_tree_.SetFocusedFrame(node, source); | 4657 frame_tree_.SetFocusedFrame(node, source); |
4657 return; | 4658 return; |
4658 } | 4659 } |
4659 | 4660 |
4660 // 1. Find old focused frame and unfocus it. | 4661 // 1. Find old focused frame and unfocus it. |
4661 // 2. Focus the new frame in the current FrameTree. | 4662 // 2. Focus the new frame in the current FrameTree. |
4662 // 3. Set current WebContents as focused. | 4663 // 3. Set current WebContents as focused. |
4663 WebContentsImpl* old_focused_contents = GetFocusedWebContents(); | 4664 WebContentsImpl* old_focused_contents = GetFocusedWebContents(); |
4664 if (old_focused_contents != this) { | 4665 if (old_focused_contents != this) { |
4665 // Focus is moving between frame trees, unfocus the frame in the old tree. | 4666 // Focus is moving between frame trees, unfocus the frame in the old tree. |
4666 old_focused_contents->frame_tree_.SetFocusedFrame(nullptr, source); | 4667 old_focused_contents->frame_tree_.SetFocusedFrame(nullptr, source); |
4667 GetOutermostWebContents()->node_->SetFocusedWebContents(this); | 4668 GetOutermostWebContents()->node_->SetFocusedWebContents(this); |
4668 } | 4669 } |
4669 | 4670 |
4670 frame_tree_.SetFocusedFrame(node, source); | 4671 frame_tree_.SetFocusedFrame(node, source); |
4671 | 4672 |
4672 // TODO(avallee): Remove this once page focus is fixed. | 4673 // TODO(avallee): Remove this once page focus is fixed. |
4673 RenderWidgetHostImpl* rwh = node->current_frame_host()->GetRenderWidgetHost(); | 4674 RenderWidgetHostImpl* rwh = node->current_frame_host()->GetRenderWidgetHost(); |
4674 if (rwh && old_focused_contents != this && | 4675 if (rwh && old_focused_contents != this) |
4675 BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) | |
4676 rwh->Focus(); | 4676 rwh->Focus(); |
4677 } | 4677 } |
4678 | 4678 |
4679 bool WebContentsImpl::AddMessageToConsole(int32_t level, | 4679 bool WebContentsImpl::AddMessageToConsole(int32_t level, |
4680 const base::string16& message, | 4680 const base::string16& message, |
4681 int32_t line_no, | 4681 int32_t line_no, |
4682 const base::string16& source_id) { | 4682 const base::string16& source_id) { |
4683 if (!delegate_) | 4683 if (!delegate_) |
4684 return false; | 4684 return false; |
4685 return delegate_->AddMessageToConsole(this, level, message, line_no, | 4685 return delegate_->AddMessageToConsole(this, level, message, line_no, |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5203 for (RenderViewHost* render_view_host : render_view_host_set) | 5203 for (RenderViewHost* render_view_host : render_view_host_set) |
5204 render_view_host->OnWebkitPreferencesChanged(); | 5204 render_view_host->OnWebkitPreferencesChanged(); |
5205 } | 5205 } |
5206 | 5206 |
5207 void WebContentsImpl::SetJavaScriptDialogManagerForTesting( | 5207 void WebContentsImpl::SetJavaScriptDialogManagerForTesting( |
5208 JavaScriptDialogManager* dialog_manager) { | 5208 JavaScriptDialogManager* dialog_manager) { |
5209 dialog_manager_ = dialog_manager; | 5209 dialog_manager_ = dialog_manager; |
5210 } | 5210 } |
5211 | 5211 |
5212 } // namespace content | 5212 } // namespace content |
OLD | NEW |