Chromium Code Reviews| 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 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1191 view->SetActive(true); | 1191 view->SetActive(true); |
| 1192 #endif | 1192 #endif |
| 1193 } | 1193 } |
| 1194 } | 1194 } |
| 1195 | 1195 |
| 1196 last_active_time_ = base::TimeTicks::Now(); | 1196 last_active_time_ = base::TimeTicks::Now(); |
| 1197 | 1197 |
| 1198 // The resize rect might have changed while this was inactive -- send the new | 1198 // The resize rect might have changed while this was inactive -- send the new |
| 1199 // one to make sure it's up to date. | 1199 // one to make sure it's up to date. |
| 1200 RenderViewHostImpl* rvh = GetRenderViewHost(); | 1200 RenderViewHostImpl* rvh = GetRenderViewHost(); |
| 1201 if (rvh) | 1201 if (rvh) { |
| 1202 rvh->GetWidget()->ResizeRectChanged(GetRootWindowResizerRect()); | 1202 rvh->GetWidget()->ResizeRectChanged( |
| 1203 GetRootWindowResizerRect(rvh->GetWidget())); | |
| 1204 } | |
| 1203 | 1205 |
| 1204 // Restore power save blocker if there are active video players running. | 1206 // Restore power save blocker if there are active video players running. |
| 1205 if (!active_video_players_.empty() && !video_power_save_blocker_) | 1207 if (!active_video_players_.empty() && !video_power_save_blocker_) |
| 1206 CreateVideoPowerSaveBlocker(); | 1208 CreateVideoPowerSaveBlocker(); |
| 1207 | 1209 |
| 1208 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown()); | 1210 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown()); |
| 1209 | 1211 |
| 1210 should_normally_be_visible_ = true; | 1212 should_normally_be_visible_ = true; |
| 1211 } | 1213 } |
| 1212 | 1214 |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1658 | 1660 |
| 1659 bool WebContentsImpl::IsFullscreenForCurrentTab() const { | 1661 bool WebContentsImpl::IsFullscreenForCurrentTab() const { |
| 1660 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false; | 1662 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false; |
| 1661 } | 1663 } |
| 1662 | 1664 |
| 1663 blink::WebDisplayMode WebContentsImpl::GetDisplayMode() const { | 1665 blink::WebDisplayMode WebContentsImpl::GetDisplayMode() const { |
| 1664 return delegate_ ? delegate_->GetDisplayMode(this) | 1666 return delegate_ ? delegate_->GetDisplayMode(this) |
| 1665 : blink::WebDisplayModeBrowser; | 1667 : blink::WebDisplayModeBrowser; |
| 1666 } | 1668 } |
| 1667 | 1669 |
| 1668 void WebContentsImpl::RequestToLockMouse(bool user_gesture, | 1670 void WebContentsImpl::RequestToLockMouse( |
| 1669 bool last_unlocked_by_target) { | 1671 RenderWidgetHostImpl* render_widget_host, |
| 1670 if (delegate_) { | 1672 bool user_gesture, |
| 1673 bool last_unlocked_by_target) { | |
| 1674 if (render_widget_host != GetRenderViewHost()->GetWidget()) { | |
| 1675 GotResponseToLockMouseRequest(false); | |
|
ncarter (slow)
2015/11/02 17:46:56
Should be:
render_widget_host->GotResponseToLockM
Avi (use Gerrit)
2015/11/02 18:42:13
Done.
| |
| 1676 return; | |
| 1677 } | |
| 1678 | |
| 1679 if (delegate_) | |
| 1671 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target); | 1680 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target); |
| 1672 } else { | 1681 else |
| 1673 GotResponseToLockMouseRequest(false); | 1682 GotResponseToLockMouseRequest(false); |
| 1674 } | |
| 1675 } | 1683 } |
| 1676 | 1684 |
| 1677 void WebContentsImpl::LostMouseLock() { | 1685 void WebContentsImpl::LostMouseLock() { |
| 1678 if (delegate_) | 1686 if (delegate_) |
| 1679 delegate_->LostMouseLock(); | 1687 delegate_->LostMouseLock(); |
| 1680 } | 1688 } |
| 1681 | 1689 |
| 1682 void WebContentsImpl::CreateNewWindow( | 1690 void WebContentsImpl::CreateNewWindow( |
| 1683 SiteInstance* source_site_instance, | 1691 SiteInstance* source_site_instance, |
| 1684 int32_t route_id, | 1692 int32_t route_id, |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2162 focused_frame->Send(new InputMsg_AdjustSelectionByCharacterOffset( | 2170 focused_frame->Send(new InputMsg_AdjustSelectionByCharacterOffset( |
| 2163 focused_frame->GetRoutingID(), start_adjust, end_adjust)); | 2171 focused_frame->GetRoutingID(), start_adjust, end_adjust)); |
| 2164 } | 2172 } |
| 2165 | 2173 |
| 2166 void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) { | 2174 void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) { |
| 2167 const gfx::Size old_size = GetPreferredSize(); | 2175 const gfx::Size old_size = GetPreferredSize(); |
| 2168 preferred_size_ = pref_size; | 2176 preferred_size_ = pref_size; |
| 2169 OnPreferredSizeChanged(old_size); | 2177 OnPreferredSizeChanged(old_size); |
| 2170 } | 2178 } |
| 2171 | 2179 |
| 2172 void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) { | 2180 void WebContentsImpl::ResizeDueToAutoResize( |
| 2181 RenderWidgetHostImpl* render_widget_host, | |
| 2182 const gfx::Size& new_size) { | |
| 2183 if (render_widget_host != GetRenderViewHost()->GetWidget()) | |
| 2184 return; | |
| 2185 | |
| 2173 if (delegate_) | 2186 if (delegate_) |
| 2174 delegate_->ResizeDueToAutoResize(this, new_size); | 2187 delegate_->ResizeDueToAutoResize(this, new_size); |
| 2175 } | 2188 } |
| 2176 | 2189 |
| 2177 WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) { | 2190 WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) { |
| 2178 if (!delegate_) | 2191 if (!delegate_) |
| 2179 return NULL; | 2192 return NULL; |
| 2180 | 2193 |
| 2181 WebContents* new_contents = delegate_->OpenURLFromTab(this, params); | 2194 WebContents* new_contents = delegate_->OpenURLFromTab(this, params); |
| 2182 return new_contents; | 2195 return new_contents; |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2607 } | 2620 } |
| 2608 | 2621 |
| 2609 void WebContentsImpl::SystemDragEnded() { | 2622 void WebContentsImpl::SystemDragEnded() { |
| 2610 if (GetRenderViewHost()) | 2623 if (GetRenderViewHost()) |
| 2611 GetRenderViewHost()->DragSourceSystemDragEnded(); | 2624 GetRenderViewHost()->DragSourceSystemDragEnded(); |
| 2612 if (browser_plugin_embedder_.get()) | 2625 if (browser_plugin_embedder_.get()) |
| 2613 browser_plugin_embedder_->SystemDragEnded(); | 2626 browser_plugin_embedder_->SystemDragEnded(); |
| 2614 } | 2627 } |
| 2615 | 2628 |
| 2616 void WebContentsImpl::UserGestureDone() { | 2629 void WebContentsImpl::UserGestureDone() { |
| 2617 OnUserGesture(); | 2630 OnUserGesture(GetRenderViewHost()->GetWidget()); |
| 2618 } | 2631 } |
| 2619 | 2632 |
| 2620 void WebContentsImpl::SetClosedByUserGesture(bool value) { | 2633 void WebContentsImpl::SetClosedByUserGesture(bool value) { |
| 2621 closed_by_user_gesture_ = value; | 2634 closed_by_user_gesture_ = value; |
| 2622 } | 2635 } |
| 2623 | 2636 |
| 2624 bool WebContentsImpl::GetClosedByUserGesture() const { | 2637 bool WebContentsImpl::GetClosedByUserGesture() const { |
| 2625 return closed_by_user_gesture_; | 2638 return closed_by_user_gesture_; |
| 2626 } | 2639 } |
| 2627 | 2640 |
| (...skipping 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3770 | 3783 |
| 3771 RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() { | 3784 RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() { |
| 3772 return render_view_host_delegate_view_; | 3785 return render_view_host_delegate_view_; |
| 3773 } | 3786 } |
| 3774 | 3787 |
| 3775 RendererPreferences WebContentsImpl::GetRendererPrefs( | 3788 RendererPreferences WebContentsImpl::GetRendererPrefs( |
| 3776 BrowserContext* browser_context) const { | 3789 BrowserContext* browser_context) const { |
| 3777 return renderer_preferences_; | 3790 return renderer_preferences_; |
| 3778 } | 3791 } |
| 3779 | 3792 |
| 3780 gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const { | 3793 gfx::Rect WebContentsImpl::GetRootWindowResizerRect( |
| 3794 RenderWidgetHostImpl* render_widget_host) const { | |
| 3795 if (render_widget_host != GetRenderViewHost()->GetWidget()) | |
| 3796 return gfx::Rect(); | |
| 3797 | |
| 3781 if (delegate_) | 3798 if (delegate_) |
| 3782 return delegate_->GetRootWindowResizerRect(); | 3799 return delegate_->GetRootWindowResizerRect(); |
| 3783 return gfx::Rect(); | 3800 return gfx::Rect(); |
| 3784 } | 3801 } |
| 3785 | 3802 |
| 3786 void WebContentsImpl::RemoveBrowserPluginEmbedder() { | 3803 void WebContentsImpl::RemoveBrowserPluginEmbedder() { |
| 3787 if (browser_plugin_embedder_) | 3804 if (browser_plugin_embedder_) |
| 3788 browser_plugin_embedder_.reset(); | 3805 browser_plugin_embedder_.reset(); |
| 3789 } | 3806 } |
| 3790 | 3807 |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4201 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) { | 4218 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) { |
| 4202 GetRenderManager()->CreateRenderFrameProxy(instance); | 4219 GetRenderManager()->CreateRenderFrameProxy(instance); |
| 4203 } else { | 4220 } else { |
| 4204 GetRenderManager()->CreateRenderFrame( | 4221 GetRenderManager()->CreateRenderFrame( |
| 4205 instance, nullptr, CREATE_RF_SWAPPED_OUT | CREATE_RF_HIDDEN, | 4222 instance, nullptr, CREATE_RF_SWAPPED_OUT | CREATE_RF_HIDDEN, |
| 4206 &render_view_routing_id); | 4223 &render_view_routing_id); |
| 4207 } | 4224 } |
| 4208 return render_view_routing_id; | 4225 return render_view_routing_id; |
| 4209 } | 4226 } |
| 4210 | 4227 |
| 4211 void WebContentsImpl::OnUserGesture() { | 4228 void WebContentsImpl::OnUserGesture(RenderWidgetHostImpl* render_widget_host) { |
| 4229 if (render_widget_host != GetRenderViewHost()->GetWidget()) | |
| 4230 return; | |
| 4231 | |
| 4212 // Notify observers. | 4232 // Notify observers. |
| 4213 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture()); | 4233 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture()); |
| 4214 | 4234 |
| 4215 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); | 4235 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); |
| 4216 if (rdh) // NULL in unittests. | 4236 if (rdh) // NULL in unittests. |
| 4217 rdh->OnUserGesture(this); | 4237 rdh->OnUserGesture(this); |
| 4218 } | 4238 } |
| 4219 | 4239 |
| 4220 void WebContentsImpl::OnUserInteraction(const blink::WebInputEvent::Type type) { | 4240 void WebContentsImpl::OnUserInteraction(const blink::WebInputEvent::Type type) { |
| 4221 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 4241 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 4222 DidGetUserInteraction(type)); | 4242 DidGetUserInteraction(type)); |
| 4223 } | 4243 } |
| 4224 | 4244 |
| 4225 void WebContentsImpl::OnIgnoredUIEvent() { | 4245 void WebContentsImpl::OnIgnoredUIEvent() { |
| 4226 // Notify observers. | 4246 // Notify observers. |
| 4227 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent()); | 4247 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent()); |
| 4228 } | 4248 } |
| 4229 | 4249 |
| 4230 void WebContentsImpl::RendererUnresponsive(RenderViewHost* render_view_host) { | 4250 void WebContentsImpl::RendererUnresponsive( |
| 4251 RenderWidgetHostImpl* render_widget_host) { | |
| 4231 // Don't show hung renderer dialog for a swapped out RVH. | 4252 // Don't show hung renderer dialog for a swapped out RVH. |
| 4232 if (render_view_host != GetRenderViewHost()) | 4253 if (render_widget_host != GetRenderViewHost()->GetWidget()) |
| 4233 return; | 4254 return; |
| 4234 | 4255 |
| 4235 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(render_view_host); | |
| 4236 RenderFrameHostImpl* rfhi = | 4256 RenderFrameHostImpl* rfhi = |
| 4237 static_cast<RenderFrameHostImpl*>(rvhi->GetMainFrame()); | 4257 static_cast<RenderFrameHostImpl*>(GetRenderViewHost()->GetMainFrame()); |
| 4238 | 4258 |
| 4239 // Ignore renderer unresponsive event if debugger is attached to the tab | 4259 // Ignore renderer unresponsive event if debugger is attached to the tab |
| 4240 // since the event may be a result of the renderer sitting on a breakpoint. | 4260 // since the event may be a result of the renderer sitting on a breakpoint. |
| 4241 // See http://crbug.com/65458 | 4261 // See http://crbug.com/65458 |
| 4242 if (DevToolsAgentHost::IsDebuggerAttached(this)) | 4262 if (DevToolsAgentHost::IsDebuggerAttached(this)) |
| 4243 return; | 4263 return; |
| 4244 | 4264 |
| 4245 if (rfhi->is_waiting_for_beforeunload_ack() || | 4265 if (rfhi->is_waiting_for_beforeunload_ack() || |
| 4246 rfhi->IsWaitingForUnloadACK()) { | 4266 rfhi->IsWaitingForUnloadACK()) { |
| 4247 // Hang occurred while firing the beforeunload/unload handler. | 4267 // Hang occurred while firing the beforeunload/unload handler. |
| 4248 // Pretend the handler fired so tab closing continues as if it had. | 4268 // Pretend the handler fired so tab closing continues as if it had. |
| 4249 rvhi->set_sudden_termination_allowed(true); | 4269 GetRenderViewHost()->set_sudden_termination_allowed(true); |
| 4250 | 4270 |
| 4251 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer()) | 4271 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer()) |
| 4252 return; | 4272 return; |
| 4253 | 4273 |
| 4254 // If the tab hangs in the beforeunload/unload handler there's really | 4274 // If the tab hangs in the beforeunload/unload handler there's really |
| 4255 // nothing we can do to recover. If the hang is in the beforeunload handler, | 4275 // nothing we can do to recover. If the hang is in the beforeunload handler, |
| 4256 // pretend the beforeunload listeners have all fired and allow the delegate | 4276 // pretend the beforeunload listeners have all fired and allow the delegate |
| 4257 // to continue closing; the user will not have the option of cancelling the | 4277 // to continue closing; the user will not have the option of cancelling the |
| 4258 // close. Otherwise, pretend the unload listeners have all fired and close | 4278 // close. Otherwise, pretend the unload listeners have all fired and close |
| 4259 // the tab. | 4279 // the tab. |
| 4260 bool close = true; | 4280 bool close = true; |
| 4261 if (rfhi->is_waiting_for_beforeunload_ack() && delegate_) { | 4281 if (rfhi->is_waiting_for_beforeunload_ack() && delegate_) { |
| 4262 delegate_->BeforeUnloadFired(this, true, &close); | 4282 delegate_->BeforeUnloadFired(this, true, &close); |
| 4263 } | 4283 } |
| 4264 if (close) | 4284 if (close) |
| 4265 Close(rvhi); | 4285 Close(); |
| 4266 return; | 4286 return; |
| 4267 } | 4287 } |
| 4268 | 4288 |
| 4269 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive()) | 4289 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive()) |
| 4270 return; | 4290 return; |
| 4271 | 4291 |
| 4272 if (delegate_) | 4292 if (delegate_) |
| 4273 delegate_->RendererUnresponsive(this); | 4293 delegate_->RendererUnresponsive(this); |
| 4274 } | 4294 } |
| 4275 | 4295 |
| 4276 void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) { | 4296 void WebContentsImpl::RendererResponsive( |
| 4297 RenderWidgetHostImpl* render_widget_host) { | |
| 4298 if (render_widget_host != GetRenderViewHost()->GetWidget()) | |
| 4299 return; | |
| 4300 | |
| 4277 if (delegate_) | 4301 if (delegate_) |
| 4278 delegate_->RendererResponsive(this); | 4302 delegate_->RendererResponsive(this); |
| 4279 } | 4303 } |
| 4280 | 4304 |
| 4281 void WebContentsImpl::LoadStateChanged( | 4305 void WebContentsImpl::LoadStateChanged( |
| 4282 const GURL& url, | 4306 const GURL& url, |
| 4283 const net::LoadStateWithParam& load_state, | 4307 const net::LoadStateWithParam& load_state, |
| 4284 uint64 upload_position, | 4308 uint64 upload_position, |
| 4285 uint64 upload_size) { | 4309 uint64 upload_size) { |
| 4286 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285 | 4310 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285 |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4679 return NULL; | 4703 return NULL; |
| 4680 } | 4704 } |
| 4681 | 4705 |
| 4682 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { | 4706 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
| 4683 force_disable_overscroll_content_ = force_disable; | 4707 force_disable_overscroll_content_ = force_disable; |
| 4684 if (view_) | 4708 if (view_) |
| 4685 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); | 4709 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
| 4686 } | 4710 } |
| 4687 | 4711 |
| 4688 } // namespace content | 4712 } // namespace content |
| OLD | NEW |