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 1435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1446 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr(); | 1446 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr(); |
1447 RenderWidgetHostView* view = host->GetView(); | 1447 RenderWidgetHostView* view = host->GetView(); |
1448 if (view == GetFullscreenRenderWidgetHostView()) { | 1448 if (view == GetFullscreenRenderWidgetHostView()) { |
1449 // We cannot just call view_->RestoreFocus() here. On some platforms, | 1449 // We cannot just call view_->RestoreFocus() here. On some platforms, |
1450 // attempting to focus the currently-invisible WebContentsView will be | 1450 // attempting to focus the currently-invisible WebContentsView will be |
1451 // flat-out ignored. Therefore, this boolean is used to track whether | 1451 // flat-out ignored. Therefore, this boolean is used to track whether |
1452 // we will request focus after the fullscreen widget has been | 1452 // we will request focus after the fullscreen widget has been |
1453 // destroyed. | 1453 // destroyed. |
1454 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus()); | 1454 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus()); |
1455 } else { | 1455 } else { |
1456 for (PendingWidgetViews::iterator i = pending_widget_views_.begin(); | 1456 for (auto i = pending_widget_views_.begin(); |
1457 i != pending_widget_views_.end(); ++i) { | 1457 i != pending_widget_views_.end(); ++i) { |
1458 if (host->GetView() == i->second) { | 1458 if (host->GetView() == i->second) { |
1459 pending_widget_views_.erase(i); | 1459 pending_widget_views_.erase(i); |
1460 break; | 1460 break; |
1461 } | 1461 } |
1462 } | 1462 } |
1463 } | 1463 } |
1464 break; | 1464 break; |
1465 } | 1465 } |
1466 default: | 1466 default: |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1589 // NotifySwappedFromRenderManager expects view_ to already be created and that | 1589 // NotifySwappedFromRenderManager expects view_ to already be created and that |
1590 // happens after RenderFrameHostManager::Init. | 1590 // happens after RenderFrameHostManager::Init. |
1591 NotifySwappedFromRenderManager( | 1591 NotifySwappedFromRenderManager( |
1592 nullptr, GetRenderManager()->current_frame_host(), true); | 1592 nullptr, GetRenderManager()->current_frame_host(), true); |
1593 } | 1593 } |
1594 | 1594 |
1595 void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) { | 1595 void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) { |
1596 RemoveDestructionObserver(web_contents); | 1596 RemoveDestructionObserver(web_contents); |
1597 | 1597 |
1598 // Clear a pending contents that has been closed before being shown. | 1598 // Clear a pending contents that has been closed before being shown. |
1599 for (PendingContents::iterator iter = pending_contents_.begin(); | 1599 for (auto iter = pending_contents_.begin(); iter != pending_contents_.end(); |
1600 iter != pending_contents_.end(); | |
1601 ++iter) { | 1600 ++iter) { |
1602 if (iter->second != web_contents) | 1601 if (iter->second != web_contents) |
1603 continue; | 1602 continue; |
1604 pending_contents_.erase(iter); | 1603 pending_contents_.erase(iter); |
1605 return; | 1604 return; |
1606 } | 1605 } |
1607 NOTREACHED(); | 1606 NOTREACHED(); |
1608 } | 1607 } |
1609 | 1608 |
1610 void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) { | 1609 void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) { |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2034 WebContentsView* new_view = new_contents->view_.get(); | 2033 WebContentsView* new_view = new_contents->view_.get(); |
2035 | 2034 |
2036 // TODO(brettw): It seems bogus that we have to call this function on the | 2035 // TODO(brettw): It seems bogus that we have to call this function on the |
2037 // newly created object and give it one of its own member variables. | 2036 // newly created object and give it one of its own member variables. |
2038 new_view->CreateViewForWidget( | 2037 new_view->CreateViewForWidget( |
2039 new_contents->GetRenderViewHost()->GetWidget(), false); | 2038 new_contents->GetRenderViewHost()->GetWidget(), false); |
2040 } | 2039 } |
2041 // Save the created window associated with the route so we can show it | 2040 // Save the created window associated with the route so we can show it |
2042 // later. | 2041 // later. |
2043 DCHECK_NE(MSG_ROUTING_NONE, route_id); | 2042 DCHECK_NE(MSG_ROUTING_NONE, route_id); |
2044 pending_contents_[route_id] = new_contents; | 2043 pending_contents_[std::make_pair(render_process_id, route_id)] = |
| 2044 new_contents; |
2045 AddDestructionObserver(new_contents); | 2045 AddDestructionObserver(new_contents); |
2046 } | 2046 } |
2047 | 2047 |
2048 if (delegate_) { | 2048 if (delegate_) { |
2049 delegate_->WebContentsCreated( | 2049 delegate_->WebContentsCreated( |
2050 this, params.opener_render_frame_id, params.frame_name, | 2050 this, params.opener_render_frame_id, params.frame_name, |
2051 params.target_url, new_contents); | 2051 params.target_url, new_contents); |
2052 } | 2052 } |
2053 | 2053 |
2054 if (params.opener_suppressed) { | 2054 if (params.opener_suppressed) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2116 RenderWidgetHostViewBase* widget_view = | 2116 RenderWidgetHostViewBase* widget_view = |
2117 static_cast<RenderWidgetHostViewBase*>( | 2117 static_cast<RenderWidgetHostViewBase*>( |
2118 view_->CreateViewForPopupWidget(widget_host)); | 2118 view_->CreateViewForPopupWidget(widget_host)); |
2119 if (!widget_view) | 2119 if (!widget_view) |
2120 return; | 2120 return; |
2121 if (!is_fullscreen) { | 2121 if (!is_fullscreen) { |
2122 // Popups should not get activated. | 2122 // Popups should not get activated. |
2123 widget_view->SetPopupType(popup_type); | 2123 widget_view->SetPopupType(popup_type); |
2124 } | 2124 } |
2125 // Save the created widget associated with the route so we can show it later. | 2125 // Save the created widget associated with the route so we can show it later. |
2126 pending_widget_views_[route_id] = widget_view; | 2126 pending_widget_views_[std::make_pair(render_process_id, route_id)] = |
| 2127 widget_view; |
2127 | 2128 |
2128 #if defined(OS_MACOSX) | 2129 #if defined(OS_MACOSX) |
2129 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it | 2130 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it |
2130 // to allow it to survive the trip without being hosted. | 2131 // to allow it to survive the trip without being hosted. |
2131 base::mac::NSObjectRetain(widget_view->GetNativeView()); | 2132 base::mac::NSObjectRetain(widget_view->GetNativeView()); |
2132 #endif | 2133 #endif |
2133 } | 2134 } |
2134 | 2135 |
2135 void WebContentsImpl::ShowCreatedWindow(int route_id, | 2136 void WebContentsImpl::ShowCreatedWindow(int process_id, |
| 2137 int route_id, |
2136 WindowOpenDisposition disposition, | 2138 WindowOpenDisposition disposition, |
2137 const gfx::Rect& initial_rect, | 2139 const gfx::Rect& initial_rect, |
2138 bool user_gesture) { | 2140 bool user_gesture) { |
2139 WebContentsImpl* contents = GetCreatedWindow(route_id); | 2141 WebContentsImpl* contents = GetCreatedWindow(process_id, route_id); |
2140 if (contents) { | 2142 if (contents) { |
2141 WebContentsDelegate* delegate = GetDelegate(); | 2143 WebContentsDelegate* delegate = GetDelegate(); |
2142 contents->is_resume_pending_ = true; | 2144 contents->is_resume_pending_ = true; |
2143 if (!delegate || delegate->ShouldResumeRequestsForCreatedWindow()) | 2145 if (!delegate || delegate->ShouldResumeRequestsForCreatedWindow()) |
2144 contents->ResumeLoadingCreatedWebContents(); | 2146 contents->ResumeLoadingCreatedWebContents(); |
2145 | 2147 |
2146 if (delegate) { | 2148 if (delegate) { |
2147 delegate->AddNewContents( | 2149 delegate->AddNewContents( |
2148 this, contents, disposition, initial_rect, user_gesture, NULL); | 2150 this, contents, disposition, initial_rect, user_gesture, NULL); |
2149 } | 2151 } |
2150 } | 2152 } |
2151 } | 2153 } |
2152 | 2154 |
2153 void WebContentsImpl::ShowCreatedWidget(int route_id, | 2155 void WebContentsImpl::ShowCreatedWidget(int process_id, |
| 2156 int route_id, |
2154 const gfx::Rect& initial_rect) { | 2157 const gfx::Rect& initial_rect) { |
2155 ShowCreatedWidget(route_id, false, initial_rect); | 2158 ShowCreatedWidget(process_id, route_id, false, initial_rect); |
2156 } | 2159 } |
2157 | 2160 |
2158 void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) { | 2161 void WebContentsImpl::ShowCreatedFullscreenWidget(int process_id, |
2159 ShowCreatedWidget(route_id, true, gfx::Rect()); | 2162 int route_id) { |
| 2163 ShowCreatedWidget(process_id, route_id, true, gfx::Rect()); |
2160 } | 2164 } |
2161 | 2165 |
2162 void WebContentsImpl::ShowCreatedWidget(int route_id, | 2166 void WebContentsImpl::ShowCreatedWidget(int process_id, |
| 2167 int route_id, |
2163 bool is_fullscreen, | 2168 bool is_fullscreen, |
2164 const gfx::Rect& initial_rect) { | 2169 const gfx::Rect& initial_rect) { |
2165 RenderWidgetHostViewBase* widget_host_view = | 2170 RenderWidgetHostViewBase* widget_host_view = |
2166 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id)); | 2171 static_cast<RenderWidgetHostViewBase*>( |
| 2172 GetCreatedWidget(process_id, route_id)); |
2167 if (!widget_host_view) | 2173 if (!widget_host_view) |
2168 return; | 2174 return; |
2169 | 2175 |
2170 RenderWidgetHostView* view = NULL; | 2176 RenderWidgetHostView* view = NULL; |
2171 if (GetOuterWebContents()) { | 2177 if (GetOuterWebContents()) { |
2172 view = GetOuterWebContents()->GetRenderWidgetHostView(); | 2178 view = GetOuterWebContents()->GetRenderWidgetHostView(); |
2173 } else { | 2179 } else { |
2174 view = GetRenderWidgetHostView(); | 2180 view = GetRenderWidgetHostView(); |
2175 } | 2181 } |
2176 | 2182 |
(...skipping 26 matching lines...) Expand all Loading... |
2203 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen); | 2209 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen); |
2204 | 2210 |
2205 #if defined(OS_MACOSX) | 2211 #if defined(OS_MACOSX) |
2206 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's | 2212 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's |
2207 // properly embedded (or purposefully ignored) we can release the retain we | 2213 // properly embedded (or purposefully ignored) we can release the retain we |
2208 // took in CreateNewWidget(). | 2214 // took in CreateNewWidget(). |
2209 base::mac::NSObjectRelease(widget_host_view->GetNativeView()); | 2215 base::mac::NSObjectRelease(widget_host_view->GetNativeView()); |
2210 #endif | 2216 #endif |
2211 } | 2217 } |
2212 | 2218 |
2213 WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) { | 2219 WebContentsImpl* WebContentsImpl::GetCreatedWindow(int process_id, |
2214 PendingContents::iterator iter = pending_contents_.find(route_id); | 2220 int route_id) { |
| 2221 auto iter = pending_contents_.find(std::make_pair(process_id, route_id)); |
2215 | 2222 |
2216 // Certain systems can block the creation of new windows. If we didn't succeed | 2223 // Certain systems can block the creation of new windows. If we didn't succeed |
2217 // in creating one, just return NULL. | 2224 // in creating one, just return NULL. |
2218 if (iter == pending_contents_.end()) { | 2225 if (iter == pending_contents_.end()) |
2219 return NULL; | 2226 return nullptr; |
2220 } | |
2221 | 2227 |
2222 WebContentsImpl* new_contents = iter->second; | 2228 WebContentsImpl* new_contents = iter->second; |
2223 pending_contents_.erase(route_id); | 2229 pending_contents_.erase(std::make_pair(process_id, route_id)); |
2224 RemoveDestructionObserver(new_contents); | 2230 RemoveDestructionObserver(new_contents); |
2225 | 2231 |
2226 // Don't initialize the guest WebContents immediately. | 2232 // Don't initialize the guest WebContents immediately. |
2227 if (BrowserPluginGuest::IsGuest(new_contents)) | 2233 if (BrowserPluginGuest::IsGuest(new_contents)) |
2228 return new_contents; | 2234 return new_contents; |
2229 | 2235 |
2230 if (!new_contents->GetRenderProcessHost()->HasConnection() || | 2236 if (!new_contents->GetRenderProcessHost()->HasConnection() || |
2231 !new_contents->GetRenderViewHost()->GetWidget()->GetView()) | 2237 !new_contents->GetRenderViewHost()->GetWidget()->GetView()) |
2232 return NULL; | 2238 return nullptr; |
2233 | 2239 |
2234 return new_contents; | 2240 return new_contents; |
2235 } | 2241 } |
2236 | 2242 |
2237 RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) { | 2243 RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int process_id, |
2238 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id); | 2244 int route_id) { |
| 2245 auto iter = pending_widget_views_.find(std::make_pair(process_id, route_id)); |
2239 if (iter == pending_widget_views_.end()) { | 2246 if (iter == pending_widget_views_.end()) { |
2240 DCHECK(false); | 2247 DCHECK(false); |
2241 return NULL; | 2248 return nullptr; |
2242 } | 2249 } |
2243 | 2250 |
2244 RenderWidgetHostView* widget_host_view = iter->second; | 2251 RenderWidgetHostView* widget_host_view = iter->second; |
2245 pending_widget_views_.erase(route_id); | 2252 pending_widget_views_.erase(std::make_pair(process_id, route_id)); |
2246 | 2253 |
2247 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost(); | 2254 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost(); |
2248 if (!widget_host->GetProcess()->HasConnection()) { | 2255 if (!widget_host->GetProcess()->HasConnection()) { |
2249 // The view has gone away or the renderer crashed. Nothing to do. | 2256 // The view has gone away or the renderer crashed. Nothing to do. |
2250 return NULL; | 2257 return nullptr; |
2251 } | 2258 } |
2252 | 2259 |
2253 return widget_host_view; | 2260 return widget_host_view; |
2254 } | 2261 } |
2255 | 2262 |
2256 void WebContentsImpl::RequestMediaAccessPermission( | 2263 void WebContentsImpl::RequestMediaAccessPermission( |
2257 const MediaStreamRequest& request, | 2264 const MediaStreamRequest& request, |
2258 const MediaResponseCallback& callback) { | 2265 const MediaResponseCallback& callback) { |
2259 if (delegate_) { | 2266 if (delegate_) { |
2260 delegate_->RequestMediaAccessPermission(this, request, callback); | 2267 delegate_->RequestMediaAccessPermission(this, request, callback); |
(...skipping 2778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5039 for (RenderViewHost* render_view_host : render_view_host_set) | 5046 for (RenderViewHost* render_view_host : render_view_host_set) |
5040 render_view_host->OnWebkitPreferencesChanged(); | 5047 render_view_host->OnWebkitPreferencesChanged(); |
5041 } | 5048 } |
5042 | 5049 |
5043 void WebContentsImpl::SetJavaScriptDialogManagerForTesting( | 5050 void WebContentsImpl::SetJavaScriptDialogManagerForTesting( |
5044 JavaScriptDialogManager* dialog_manager) { | 5051 JavaScriptDialogManager* dialog_manager) { |
5045 dialog_manager_ = dialog_manager; | 5052 dialog_manager_ = dialog_manager; |
5046 } | 5053 } |
5047 | 5054 |
5048 } // namespace content | 5055 } // namespace content |
OLD | NEW |