| 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 1156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1167 view->SetActive(true); | 1167 view->SetActive(true); |
| 1168 #endif | 1168 #endif |
| 1169 } | 1169 } |
| 1170 } | 1170 } |
| 1171 | 1171 |
| 1172 last_active_time_ = base::TimeTicks::Now(); | 1172 last_active_time_ = base::TimeTicks::Now(); |
| 1173 | 1173 |
| 1174 // The resize rect might have changed while this was inactive -- send the new | 1174 // The resize rect might have changed while this was inactive -- send the new |
| 1175 // one to make sure it's up to date. | 1175 // one to make sure it's up to date. |
| 1176 RenderViewHostImpl* rvh = GetRenderViewHost(); | 1176 RenderViewHostImpl* rvh = GetRenderViewHost(); |
| 1177 if (rvh) | 1177 if (rvh) { |
| 1178 rvh->GetWidget()->ResizeRectChanged(GetRootWindowResizerRect()); | 1178 rvh->GetWidget()->ResizeRectChanged( |
| 1179 GetRootWindowResizerRect(rvh->GetWidget())); |
| 1180 } |
| 1179 | 1181 |
| 1180 // Restore power save blocker if there are active video players running. | 1182 // Restore power save blocker if there are active video players running. |
| 1181 if (!active_video_players_.empty() && !video_power_save_blocker_) | 1183 if (!active_video_players_.empty() && !video_power_save_blocker_) |
| 1182 CreateVideoPowerSaveBlocker(); | 1184 CreateVideoPowerSaveBlocker(); |
| 1183 | 1185 |
| 1184 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown()); | 1186 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown()); |
| 1185 | 1187 |
| 1186 should_normally_be_visible_ = true; | 1188 should_normally_be_visible_ = true; |
| 1187 } | 1189 } |
| 1188 | 1190 |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1646 | 1648 |
| 1647 bool WebContentsImpl::IsFullscreenForCurrentTab() const { | 1649 bool WebContentsImpl::IsFullscreenForCurrentTab() const { |
| 1648 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false; | 1650 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false; |
| 1649 } | 1651 } |
| 1650 | 1652 |
| 1651 blink::WebDisplayMode WebContentsImpl::GetDisplayMode() const { | 1653 blink::WebDisplayMode WebContentsImpl::GetDisplayMode() const { |
| 1652 return delegate_ ? delegate_->GetDisplayMode(this) | 1654 return delegate_ ? delegate_->GetDisplayMode(this) |
| 1653 : blink::WebDisplayModeBrowser; | 1655 : blink::WebDisplayModeBrowser; |
| 1654 } | 1656 } |
| 1655 | 1657 |
| 1656 void WebContentsImpl::RequestToLockMouse(bool user_gesture, | 1658 void WebContentsImpl::RequestToLockMouse( |
| 1657 bool last_unlocked_by_target) { | 1659 RenderWidgetHostImpl* render_widget_host, |
| 1658 if (delegate_) { | 1660 bool user_gesture, |
| 1661 bool last_unlocked_by_target) { |
| 1662 if (render_widget_host != GetRenderViewHost()->GetWidget()) { |
| 1663 render_widget_host->GotResponseToLockMouseRequest(false); |
| 1664 return; |
| 1665 } |
| 1666 |
| 1667 if (delegate_) |
| 1659 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target); | 1668 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target); |
| 1660 } else { | 1669 else |
| 1661 GotResponseToLockMouseRequest(false); | 1670 GotResponseToLockMouseRequest(false); |
| 1662 } | |
| 1663 } | 1671 } |
| 1664 | 1672 |
| 1665 void WebContentsImpl::LostMouseLock() { | 1673 void WebContentsImpl::LostMouseLock() { |
| 1666 if (delegate_) | 1674 if (delegate_) |
| 1667 delegate_->LostMouseLock(); | 1675 delegate_->LostMouseLock(); |
| 1668 } | 1676 } |
| 1669 | 1677 |
| 1670 void WebContentsImpl::CreateNewWindow( | 1678 void WebContentsImpl::CreateNewWindow( |
| 1671 SiteInstance* source_site_instance, | 1679 SiteInstance* source_site_instance, |
| 1672 int32_t route_id, | 1680 int32_t route_id, |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2150 focused_frame->Send(new InputMsg_AdjustSelectionByCharacterOffset( | 2158 focused_frame->Send(new InputMsg_AdjustSelectionByCharacterOffset( |
| 2151 focused_frame->GetRoutingID(), start_adjust, end_adjust)); | 2159 focused_frame->GetRoutingID(), start_adjust, end_adjust)); |
| 2152 } | 2160 } |
| 2153 | 2161 |
| 2154 void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) { | 2162 void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) { |
| 2155 const gfx::Size old_size = GetPreferredSize(); | 2163 const gfx::Size old_size = GetPreferredSize(); |
| 2156 preferred_size_ = pref_size; | 2164 preferred_size_ = pref_size; |
| 2157 OnPreferredSizeChanged(old_size); | 2165 OnPreferredSizeChanged(old_size); |
| 2158 } | 2166 } |
| 2159 | 2167 |
| 2160 void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) { | 2168 void WebContentsImpl::ResizeDueToAutoResize( |
| 2169 RenderWidgetHostImpl* render_widget_host, |
| 2170 const gfx::Size& new_size) { |
| 2171 if (render_widget_host != GetRenderViewHost()->GetWidget()) |
| 2172 return; |
| 2173 |
| 2161 if (delegate_) | 2174 if (delegate_) |
| 2162 delegate_->ResizeDueToAutoResize(this, new_size); | 2175 delegate_->ResizeDueToAutoResize(this, new_size); |
| 2163 } | 2176 } |
| 2164 | 2177 |
| 2165 WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) { | 2178 WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) { |
| 2166 if (!delegate_) | 2179 if (!delegate_) |
| 2167 return NULL; | 2180 return NULL; |
| 2168 | 2181 |
| 2169 WebContents* new_contents = delegate_->OpenURLFromTab(this, params); | 2182 WebContents* new_contents = delegate_->OpenURLFromTab(this, params); |
| 2170 return new_contents; | 2183 return new_contents; |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2595 } | 2608 } |
| 2596 | 2609 |
| 2597 void WebContentsImpl::SystemDragEnded() { | 2610 void WebContentsImpl::SystemDragEnded() { |
| 2598 if (GetRenderViewHost()) | 2611 if (GetRenderViewHost()) |
| 2599 GetRenderViewHost()->DragSourceSystemDragEnded(); | 2612 GetRenderViewHost()->DragSourceSystemDragEnded(); |
| 2600 if (browser_plugin_embedder_.get()) | 2613 if (browser_plugin_embedder_.get()) |
| 2601 browser_plugin_embedder_->SystemDragEnded(); | 2614 browser_plugin_embedder_->SystemDragEnded(); |
| 2602 } | 2615 } |
| 2603 | 2616 |
| 2604 void WebContentsImpl::UserGestureDone() { | 2617 void WebContentsImpl::UserGestureDone() { |
| 2605 OnUserGesture(); | 2618 OnUserGesture(GetRenderViewHost()->GetWidget()); |
| 2606 } | 2619 } |
| 2607 | 2620 |
| 2608 void WebContentsImpl::SetClosedByUserGesture(bool value) { | 2621 void WebContentsImpl::SetClosedByUserGesture(bool value) { |
| 2609 closed_by_user_gesture_ = value; | 2622 closed_by_user_gesture_ = value; |
| 2610 } | 2623 } |
| 2611 | 2624 |
| 2612 bool WebContentsImpl::GetClosedByUserGesture() const { | 2625 bool WebContentsImpl::GetClosedByUserGesture() const { |
| 2613 return closed_by_user_gesture_; | 2626 return closed_by_user_gesture_; |
| 2614 } | 2627 } |
| 2615 | 2628 |
| (...skipping 1140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3756 | 3769 |
| 3757 RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() { | 3770 RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() { |
| 3758 return render_view_host_delegate_view_; | 3771 return render_view_host_delegate_view_; |
| 3759 } | 3772 } |
| 3760 | 3773 |
| 3761 RendererPreferences WebContentsImpl::GetRendererPrefs( | 3774 RendererPreferences WebContentsImpl::GetRendererPrefs( |
| 3762 BrowserContext* browser_context) const { | 3775 BrowserContext* browser_context) const { |
| 3763 return renderer_preferences_; | 3776 return renderer_preferences_; |
| 3764 } | 3777 } |
| 3765 | 3778 |
| 3766 gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const { | 3779 gfx::Rect WebContentsImpl::GetRootWindowResizerRect( |
| 3780 RenderWidgetHostImpl* render_widget_host) const { |
| 3781 if (!RenderViewHostImpl::From(render_widget_host)) |
| 3782 return gfx::Rect(); |
| 3783 |
| 3767 if (delegate_) | 3784 if (delegate_) |
| 3768 return delegate_->GetRootWindowResizerRect(); | 3785 return delegate_->GetRootWindowResizerRect(); |
| 3769 return gfx::Rect(); | 3786 return gfx::Rect(); |
| 3770 } | 3787 } |
| 3771 | 3788 |
| 3772 void WebContentsImpl::RemoveBrowserPluginEmbedder() { | 3789 void WebContentsImpl::RemoveBrowserPluginEmbedder() { |
| 3773 if (browser_plugin_embedder_) | 3790 if (browser_plugin_embedder_) |
| 3774 browser_plugin_embedder_.reset(); | 3791 browser_plugin_embedder_.reset(); |
| 3775 } | 3792 } |
| 3776 | 3793 |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4208 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) { | 4225 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) { |
| 4209 GetRenderManager()->CreateRenderFrameProxy(instance); | 4226 GetRenderManager()->CreateRenderFrameProxy(instance); |
| 4210 } else { | 4227 } else { |
| 4211 GetRenderManager()->CreateRenderFrame( | 4228 GetRenderManager()->CreateRenderFrame( |
| 4212 instance, nullptr, CREATE_RF_SWAPPED_OUT | CREATE_RF_HIDDEN, | 4229 instance, nullptr, CREATE_RF_SWAPPED_OUT | CREATE_RF_HIDDEN, |
| 4213 &render_view_routing_id); | 4230 &render_view_routing_id); |
| 4214 } | 4231 } |
| 4215 return render_view_routing_id; | 4232 return render_view_routing_id; |
| 4216 } | 4233 } |
| 4217 | 4234 |
| 4218 void WebContentsImpl::OnUserGesture() { | 4235 void WebContentsImpl::OnUserGesture(RenderWidgetHostImpl* render_widget_host) { |
| 4236 if (render_widget_host != GetRenderViewHost()->GetWidget()) |
| 4237 return; |
| 4238 |
| 4219 // Notify observers. | 4239 // Notify observers. |
| 4220 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture()); | 4240 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture()); |
| 4221 | 4241 |
| 4222 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); | 4242 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); |
| 4223 if (rdh) // NULL in unittests. | 4243 if (rdh) // NULL in unittests. |
| 4224 rdh->OnUserGesture(this); | 4244 rdh->OnUserGesture(this); |
| 4225 } | 4245 } |
| 4226 | 4246 |
| 4227 void WebContentsImpl::OnUserInteraction(const blink::WebInputEvent::Type type) { | 4247 void WebContentsImpl::OnUserInteraction(const blink::WebInputEvent::Type type) { |
| 4228 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 4248 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 4229 DidGetUserInteraction(type)); | 4249 DidGetUserInteraction(type)); |
| 4230 } | 4250 } |
| 4231 | 4251 |
| 4232 void WebContentsImpl::OnIgnoredUIEvent() { | 4252 void WebContentsImpl::OnIgnoredUIEvent() { |
| 4233 // Notify observers. | 4253 // Notify observers. |
| 4234 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent()); | 4254 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent()); |
| 4235 } | 4255 } |
| 4236 | 4256 |
| 4237 void WebContentsImpl::RendererUnresponsive(RenderViewHost* render_view_host) { | 4257 void WebContentsImpl::RendererUnresponsive( |
| 4258 RenderWidgetHostImpl* render_widget_host) { |
| 4238 // Don't show hung renderer dialog for a swapped out RVH. | 4259 // Don't show hung renderer dialog for a swapped out RVH. |
| 4239 if (render_view_host != GetRenderViewHost()) | 4260 if (render_widget_host != GetRenderViewHost()->GetWidget()) |
| 4240 return; | 4261 return; |
| 4241 | 4262 |
| 4242 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(render_view_host); | |
| 4243 RenderFrameHostImpl* rfhi = | 4263 RenderFrameHostImpl* rfhi = |
| 4244 static_cast<RenderFrameHostImpl*>(rvhi->GetMainFrame()); | 4264 static_cast<RenderFrameHostImpl*>(GetRenderViewHost()->GetMainFrame()); |
| 4245 | 4265 |
| 4246 // Ignore renderer unresponsive event if debugger is attached to the tab | 4266 // Ignore renderer unresponsive event if debugger is attached to the tab |
| 4247 // since the event may be a result of the renderer sitting on a breakpoint. | 4267 // since the event may be a result of the renderer sitting on a breakpoint. |
| 4248 // See http://crbug.com/65458 | 4268 // See http://crbug.com/65458 |
| 4249 if (DevToolsAgentHost::IsDebuggerAttached(this)) | 4269 if (DevToolsAgentHost::IsDebuggerAttached(this)) |
| 4250 return; | 4270 return; |
| 4251 | 4271 |
| 4252 if (rfhi->is_waiting_for_beforeunload_ack() || | 4272 if (rfhi->is_waiting_for_beforeunload_ack() || |
| 4253 rfhi->IsWaitingForUnloadACK()) { | 4273 rfhi->IsWaitingForUnloadACK()) { |
| 4254 // Hang occurred while firing the beforeunload/unload handler. | 4274 // Hang occurred while firing the beforeunload/unload handler. |
| 4255 // Pretend the handler fired so tab closing continues as if it had. | 4275 // Pretend the handler fired so tab closing continues as if it had. |
| 4256 rvhi->set_sudden_termination_allowed(true); | 4276 GetRenderViewHost()->set_sudden_termination_allowed(true); |
| 4257 | 4277 |
| 4258 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer()) | 4278 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer()) |
| 4259 return; | 4279 return; |
| 4260 | 4280 |
| 4261 // If the tab hangs in the beforeunload/unload handler there's really | 4281 // If the tab hangs in the beforeunload/unload handler there's really |
| 4262 // nothing we can do to recover. If the hang is in the beforeunload handler, | 4282 // nothing we can do to recover. If the hang is in the beforeunload handler, |
| 4263 // pretend the beforeunload listeners have all fired and allow the delegate | 4283 // pretend the beforeunload listeners have all fired and allow the delegate |
| 4264 // to continue closing; the user will not have the option of cancelling the | 4284 // to continue closing; the user will not have the option of cancelling the |
| 4265 // close. Otherwise, pretend the unload listeners have all fired and close | 4285 // close. Otherwise, pretend the unload listeners have all fired and close |
| 4266 // the tab. | 4286 // the tab. |
| 4267 bool close = true; | 4287 bool close = true; |
| 4268 if (rfhi->is_waiting_for_beforeunload_ack() && delegate_) { | 4288 if (rfhi->is_waiting_for_beforeunload_ack() && delegate_) { |
| 4269 delegate_->BeforeUnloadFired(this, true, &close); | 4289 delegate_->BeforeUnloadFired(this, true, &close); |
| 4270 } | 4290 } |
| 4271 if (close) | 4291 if (close) |
| 4272 Close(rvhi); | 4292 Close(); |
| 4273 return; | 4293 return; |
| 4274 } | 4294 } |
| 4275 | 4295 |
| 4276 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive()) | 4296 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive()) |
| 4277 return; | 4297 return; |
| 4278 | 4298 |
| 4279 if (delegate_) | 4299 if (delegate_) |
| 4280 delegate_->RendererUnresponsive(this); | 4300 delegate_->RendererUnresponsive(this); |
| 4281 } | 4301 } |
| 4282 | 4302 |
| 4283 void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) { | 4303 void WebContentsImpl::RendererResponsive( |
| 4304 RenderWidgetHostImpl* render_widget_host) { |
| 4305 if (render_widget_host != GetRenderViewHost()->GetWidget()) |
| 4306 return; |
| 4307 |
| 4284 if (delegate_) | 4308 if (delegate_) |
| 4285 delegate_->RendererResponsive(this); | 4309 delegate_->RendererResponsive(this); |
| 4286 } | 4310 } |
| 4287 | 4311 |
| 4288 void WebContentsImpl::LoadStateChanged( | 4312 void WebContentsImpl::LoadStateChanged( |
| 4289 const GURL& url, | 4313 const GURL& url, |
| 4290 const net::LoadStateWithParam& load_state, | 4314 const net::LoadStateWithParam& load_state, |
| 4291 uint64 upload_position, | 4315 uint64 upload_position, |
| 4292 uint64 upload_size) { | 4316 uint64 upload_size) { |
| 4293 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285 | 4317 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285 |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4686 return NULL; | 4710 return NULL; |
| 4687 } | 4711 } |
| 4688 | 4712 |
| 4689 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { | 4713 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
| 4690 force_disable_overscroll_content_ = force_disable; | 4714 force_disable_overscroll_content_ = force_disable; |
| 4691 if (view_) | 4715 if (view_) |
| 4692 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); | 4716 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
| 4693 } | 4717 } |
| 4694 | 4718 |
| 4695 } // namespace content | 4719 } // namespace content |
| OLD | NEW |