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 <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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 } | 165 } |
166 | 166 |
167 // Helper function for retrieving all the sites in a frame tree. | 167 // Helper function for retrieving all the sites in a frame tree. |
168 bool CollectSites(BrowserContext* context, | 168 bool CollectSites(BrowserContext* context, |
169 std::set<GURL>* sites, | 169 std::set<GURL>* sites, |
170 FrameTreeNode* node) { | 170 FrameTreeNode* node) { |
171 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url())); | 171 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url())); |
172 return true; | 172 return true; |
173 } | 173 } |
174 | 174 |
| 175 bool FindMatchingProcess(int render_process_id, |
| 176 bool* did_match_process, |
| 177 FrameTreeNode* node) { |
| 178 if (node->current_frame_host()->GetProcess()->GetID() == render_process_id) { |
| 179 *did_match_process = true; |
| 180 return false; |
| 181 } |
| 182 return true; |
| 183 } |
| 184 |
175 bool ForEachFrameInternal( | 185 bool ForEachFrameInternal( |
176 const base::Callback<void(RenderFrameHost*)>& on_frame, | 186 const base::Callback<void(RenderFrameHost*)>& on_frame, |
177 FrameTreeNode* node) { | 187 FrameTreeNode* node) { |
178 on_frame.Run(node->current_frame_host()); | 188 on_frame.Run(node->current_frame_host()); |
179 return true; | 189 return true; |
180 } | 190 } |
181 | 191 |
182 bool ForEachPendingFrameInternal( | 192 bool ForEachPendingFrameInternal( |
183 const base::Callback<void(RenderFrameHost*)>& on_frame, | 193 const base::Callback<void(RenderFrameHost*)>& on_frame, |
184 FrameTreeNode* node) { | 194 FrameTreeNode* node) { |
(...skipping 1414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1599 GotResponseToLockMouseRequest(false); | 1609 GotResponseToLockMouseRequest(false); |
1600 } | 1610 } |
1601 } | 1611 } |
1602 | 1612 |
1603 void WebContentsImpl::LostMouseLock() { | 1613 void WebContentsImpl::LostMouseLock() { |
1604 if (delegate_) | 1614 if (delegate_) |
1605 delegate_->LostMouseLock(); | 1615 delegate_->LostMouseLock(); |
1606 } | 1616 } |
1607 | 1617 |
1608 void WebContentsImpl::CreateNewWindow( | 1618 void WebContentsImpl::CreateNewWindow( |
1609 int render_process_id, | 1619 SiteInstance* source_site_instance, |
1610 int route_id, | 1620 int route_id, |
1611 int main_frame_route_id, | 1621 int main_frame_route_id, |
1612 const ViewHostMsg_CreateWindow_Params& params, | 1622 const ViewHostMsg_CreateWindow_Params& params, |
1613 SessionStorageNamespace* session_storage_namespace) { | 1623 SessionStorageNamespace* session_storage_namespace) { |
1614 // We usually create the new window in the same BrowsingInstance (group of | 1624 // We usually create the new window in the same BrowsingInstance (group of |
1615 // script-related windows), by passing in the current SiteInstance. However, | 1625 // script-related windows), by passing in the current SiteInstance. However, |
1616 // if the opener is being suppressed (in a non-guest), we create a new | 1626 // if the opener is being suppressed (in a non-guest), we create a new |
1617 // SiteInstance in its own BrowsingInstance. | 1627 // SiteInstance in its own BrowsingInstance. |
1618 bool is_guest = BrowserPluginGuest::IsGuest(this); | 1628 bool is_guest = BrowserPluginGuest::IsGuest(this); |
1619 | 1629 |
1620 if (is_guest && | 1630 if (is_guest && |
1621 base::CommandLine::ForCurrentProcess()->HasSwitch( | 1631 base::CommandLine::ForCurrentProcess()->HasSwitch( |
1622 switches::kSitePerProcess)) { | 1632 switches::kSitePerProcess)) { |
1623 // TODO(lazyboy): CreateNewWindow doesn't work for OOPIF-based <webview> | 1633 // TODO(lazyboy): CreateNewWindow doesn't work for OOPIF-based <webview> |
1624 // yet. | 1634 // yet. |
1625 NOTREACHED(); | 1635 NOTREACHED(); |
1626 } | 1636 } |
1627 | 1637 |
1628 // If the opener is to be suppressed, the new window can be in any process. | 1638 // If the opener is to be suppressed, the new window can be in any process. |
1629 // Since routing ids are process specific, we must not have one passed in | 1639 // Since routing ids are process specific, we must not have one passed in |
1630 // as argument here. | 1640 // as argument here. |
1631 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE); | 1641 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE); |
1632 | 1642 |
1633 scoped_refptr<SiteInstance> site_instance = | 1643 scoped_refptr<SiteInstance> site_instance = |
1634 params.opener_suppressed && !is_guest ? | 1644 params.opener_suppressed && !is_guest |
1635 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) : | 1645 ? SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) |
1636 GetSiteInstance(); | 1646 : source_site_instance; |
1637 | 1647 |
1638 // A message to create a new window can only come from the active process for | 1648 // A message to create a new window can only come from a process for a frame |
1639 // this WebContentsImpl instance. If any other process sends the request, | 1649 // in this WebContents' FrameTree. If any other process sends the request, it |
1640 // it is invalid and the process must be terminated. | 1650 // is invalid and the process must be terminated. |
1641 if (GetRenderProcessHost()->GetID() != render_process_id) { | 1651 int render_process_id = source_site_instance->GetProcess()->GetID(); |
1642 RenderProcessHost* rph = RenderProcessHost::FromID(render_process_id); | 1652 bool did_match_process = false; |
| 1653 frame_tree_.ForEach( |
| 1654 base::Bind(&FindMatchingProcess, render_process_id, &did_match_process)); |
| 1655 if (!did_match_process) { |
| 1656 RenderProcessHost* rph = source_site_instance->GetProcess(); |
1643 base::ProcessHandle process_handle = rph->GetHandle(); | 1657 base::ProcessHandle process_handle = rph->GetHandle(); |
1644 if (process_handle != base::kNullProcessHandle) { | 1658 if (process_handle != base::kNullProcessHandle) { |
1645 RecordAction( | 1659 RecordAction( |
1646 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow")); | 1660 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow")); |
1647 rph->Shutdown(RESULT_CODE_KILLED, false); | 1661 rph->Shutdown(RESULT_CODE_KILLED, false); |
1648 } | 1662 } |
1649 return; | 1663 return; |
1650 } | 1664 } |
1651 | 1665 |
1652 // We must assign the SessionStorageNamespace before calling Init(). | 1666 // We must assign the SessionStorageNamespace before calling Init(). |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1684 main_frame_route_id); | 1698 main_frame_route_id); |
1685 return; | 1699 return; |
1686 } | 1700 } |
1687 | 1701 |
1688 // Create the new web contents. This will automatically create the new | 1702 // Create the new web contents. This will automatically create the new |
1689 // WebContentsView. In the future, we may want to create the view separately. | 1703 // WebContentsView. In the future, we may want to create the view separately. |
1690 CreateParams create_params(GetBrowserContext(), site_instance.get()); | 1704 CreateParams create_params(GetBrowserContext(), site_instance.get()); |
1691 create_params.routing_id = route_id; | 1705 create_params.routing_id = route_id; |
1692 create_params.main_frame_routing_id = main_frame_route_id; | 1706 create_params.main_frame_routing_id = main_frame_route_id; |
1693 create_params.main_frame_name = params.frame_name; | 1707 create_params.main_frame_name = params.frame_name; |
1694 create_params.opener_render_process_id = GetRenderProcessHost()->GetID(); | 1708 create_params.opener_render_process_id = render_process_id; |
1695 create_params.opener_render_frame_id = params.opener_render_frame_id; | 1709 create_params.opener_render_frame_id = params.opener_render_frame_id; |
1696 create_params.opener_suppressed = params.opener_suppressed; | 1710 create_params.opener_suppressed = params.opener_suppressed; |
1697 if (params.disposition == NEW_BACKGROUND_TAB) | 1711 if (params.disposition == NEW_BACKGROUND_TAB) |
1698 create_params.initially_hidden = true; | 1712 create_params.initially_hidden = true; |
1699 create_params.renderer_initiated_creation = | 1713 create_params.renderer_initiated_creation = |
1700 main_frame_route_id != MSG_ROUTING_NONE; | 1714 main_frame_route_id != MSG_ROUTING_NONE; |
1701 | 1715 |
1702 WebContentsImpl* new_contents = NULL; | 1716 WebContentsImpl* new_contents = NULL; |
1703 if (!is_guest) { | 1717 if (!is_guest) { |
1704 create_params.context = view_->GetNativeView(); | 1718 create_params.context = view_->GetNativeView(); |
(...skipping 2782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4487 player_map->erase(it); | 4501 player_map->erase(it); |
4488 } | 4502 } |
4489 | 4503 |
4490 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { | 4504 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
4491 force_disable_overscroll_content_ = force_disable; | 4505 force_disable_overscroll_content_ = force_disable; |
4492 if (view_) | 4506 if (view_) |
4493 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); | 4507 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
4494 } | 4508 } |
4495 | 4509 |
4496 } // namespace content | 4510 } // namespace content |
OLD | NEW |