| 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/renderer_host/render_widget_host_impl.h" | 5 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 /////////////////////////////////////////////////////////////////////////////// | 166 /////////////////////////////////////////////////////////////////////////////// |
| 167 // RenderWidgetHostImpl | 167 // RenderWidgetHostImpl |
| 168 | 168 |
| 169 RenderWidgetHostImpl::RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate, | 169 RenderWidgetHostImpl::RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate, |
| 170 RenderProcessHost* process, | 170 RenderProcessHost* process, |
| 171 int32_t routing_id, | 171 int32_t routing_id, |
| 172 bool hidden) | 172 bool hidden) |
| 173 : view_(NULL), | 173 : view_(NULL), |
| 174 renderer_initialized_(false), | 174 renderer_initialized_(false), |
| 175 delegate_(delegate), | 175 delegate_(delegate), |
| 176 owner_delegate_(nullptr), |
| 176 process_(process), | 177 process_(process), |
| 177 routing_id_(routing_id), | 178 routing_id_(routing_id), |
| 178 is_loading_(false), | 179 is_loading_(false), |
| 179 is_hidden_(hidden), | 180 is_hidden_(hidden), |
| 180 repaint_ack_pending_(false), | 181 repaint_ack_pending_(false), |
| 181 resize_ack_pending_(false), | 182 resize_ack_pending_(false), |
| 182 color_profile_out_of_date_(false), | 183 color_profile_out_of_date_(false), |
| 183 auto_resize_enabled_(false), | 184 auto_resize_enabled_(false), |
| 184 waiting_for_screen_rects_ack_(false), | 185 waiting_for_screen_rects_ack_(false), |
| 185 needs_repainting_on_restore_(false), | 186 needs_repainting_on_restore_(false), |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 if (!hidden) | 219 if (!hidden) |
| 219 process_->WidgetRestored(); | 220 process_->WidgetRestored(); |
| 220 | 221 |
| 221 latency_tracker_.Initialize(routing_id_, GetProcess()->GetID()); | 222 latency_tracker_.Initialize(routing_id_, GetProcess()->GetID()); |
| 222 | 223 |
| 223 input_router_.reset(new InputRouterImpl( | 224 input_router_.reset(new InputRouterImpl( |
| 224 process_, this, this, routing_id_, GetInputRouterConfigForPlatform())); | 225 process_, this, this, routing_id_, GetInputRouterConfigForPlatform())); |
| 225 | 226 |
| 226 touch_emulator_.reset(); | 227 touch_emulator_.reset(); |
| 227 | 228 |
| 228 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 229 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 229 IsRenderView() ? RenderViewHost::From(this) : NULL); | |
| 230 if (BrowserPluginGuest::IsGuest(rvh) || | |
| 231 !base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 232 switches::kDisableHangMonitor)) { | 230 switches::kDisableHangMonitor)) { |
| 233 hang_monitor_timeout_.reset(new TimeoutMonitor( | 231 hang_monitor_timeout_.reset(new TimeoutMonitor( |
| 234 base::Bind(&RenderWidgetHostImpl::RendererIsUnresponsive, | 232 base::Bind(&RenderWidgetHostImpl::RendererIsUnresponsive, |
| 235 weak_factory_.GetWeakPtr()))); | 233 weak_factory_.GetWeakPtr()))); |
| 236 } | 234 } |
| 237 | 235 |
| 238 new_content_rendering_timeout_.reset(new TimeoutMonitor( | 236 new_content_rendering_timeout_.reset(new TimeoutMonitor( |
| 239 base::Bind(&RenderWidgetHostImpl::ClearDisplayedGraphics, | 237 base::Bind(&RenderWidgetHostImpl::ClearDisplayedGraphics, |
| 240 weak_factory_.GetWeakPtr()))); | 238 weak_factory_.GetWeakPtr()))); |
| 241 } | 239 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 266 int32_t routing_id) { | 264 int32_t routing_id) { |
| 267 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 265 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 268 RoutingIDWidgetMap* widgets = g_routing_id_widget_map.Pointer(); | 266 RoutingIDWidgetMap* widgets = g_routing_id_widget_map.Pointer(); |
| 269 RoutingIDWidgetMap::iterator it = widgets->find( | 267 RoutingIDWidgetMap::iterator it = widgets->find( |
| 270 RenderWidgetHostID(process_id, routing_id)); | 268 RenderWidgetHostID(process_id, routing_id)); |
| 271 return it == widgets->end() ? NULL : it->second; | 269 return it == widgets->end() ? NULL : it->second; |
| 272 } | 270 } |
| 273 | 271 |
| 274 // static | 272 // static |
| 275 scoped_ptr<RenderWidgetHostIterator> RenderWidgetHost::GetRenderWidgetHosts() { | 273 scoped_ptr<RenderWidgetHostIterator> RenderWidgetHost::GetRenderWidgetHosts() { |
| 276 RenderWidgetHostIteratorImpl* hosts = new RenderWidgetHostIteratorImpl(); | 274 scoped_ptr<RenderWidgetHostIteratorImpl> hosts( |
| 277 RoutingIDWidgetMap* widgets = g_routing_id_widget_map.Pointer(); | 275 new RenderWidgetHostIteratorImpl()); |
| 278 for (RoutingIDWidgetMap::const_iterator it = widgets->begin(); | 276 for (auto& it : g_routing_id_widget_map.Get()) { |
| 279 it != widgets->end(); | 277 RenderWidgetHost* widget = it.second; |
| 280 ++it) { | |
| 281 RenderWidgetHost* widget = it->second; | |
| 282 | 278 |
| 283 if (!widget->IsRenderView()) { | 279 RenderViewHost* rvh = RenderViewHost::From(widget); |
| 280 if (!rvh) { |
| 284 hosts->Add(widget); | 281 hosts->Add(widget); |
| 285 continue; | 282 continue; |
| 286 } | 283 } |
| 287 | 284 |
| 288 // Add only active RenderViewHosts. | 285 // For RenderViewHosts, add only active ones. |
| 289 RenderViewHost* rvh = RenderViewHost::From(widget); | |
| 290 if (static_cast<RenderViewHostImpl*>(rvh)->is_active()) | 286 if (static_cast<RenderViewHostImpl*>(rvh)->is_active()) |
| 291 hosts->Add(widget); | 287 hosts->Add(widget); |
| 292 } | 288 } |
| 293 | 289 |
| 294 return scoped_ptr<RenderWidgetHostIterator>(hosts); | 290 return hosts.Pass(); |
| 295 } | 291 } |
| 296 | 292 |
| 297 // static | 293 // static |
| 298 scoped_ptr<RenderWidgetHostIterator> | 294 scoped_ptr<RenderWidgetHostIterator> |
| 299 RenderWidgetHostImpl::GetAllRenderWidgetHosts() { | 295 RenderWidgetHostImpl::GetAllRenderWidgetHosts() { |
| 300 RenderWidgetHostIteratorImpl* hosts = new RenderWidgetHostIteratorImpl(); | 296 scoped_ptr<RenderWidgetHostIteratorImpl> hosts( |
| 301 RoutingIDWidgetMap* widgets = g_routing_id_widget_map.Pointer(); | 297 new RenderWidgetHostIteratorImpl()); |
| 302 for (RoutingIDWidgetMap::const_iterator it = widgets->begin(); | 298 for (auto& it : g_routing_id_widget_map.Get()) |
| 303 it != widgets->end(); | 299 hosts->Add(it.second); |
| 304 ++it) { | |
| 305 hosts->Add(it->second); | |
| 306 } | |
| 307 | 300 |
| 308 return scoped_ptr<RenderWidgetHostIterator>(hosts); | 301 return hosts.Pass(); |
| 309 } | 302 } |
| 310 | 303 |
| 311 // static | 304 // static |
| 312 RenderWidgetHostImpl* RenderWidgetHostImpl::From(RenderWidgetHost* rwh) { | 305 RenderWidgetHostImpl* RenderWidgetHostImpl::From(RenderWidgetHost* rwh) { |
| 313 return static_cast<RenderWidgetHostImpl*>(rwh); | 306 return static_cast<RenderWidgetHostImpl*>(rwh); |
| 314 } | 307 } |
| 315 | 308 |
| 316 void RenderWidgetHostImpl::SetView(RenderWidgetHostViewBase* view) { | 309 void RenderWidgetHostImpl::SetView(RenderWidgetHostViewBase* view) { |
| 317 if (view) | 310 if (view) |
| 318 view_weak_ = view->GetWeakPtr(); | 311 view_weak_ = view->GetWeakPtr(); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 DCHECK(rv); | 421 DCHECK(rv); |
| 429 } | 422 } |
| 430 | 423 |
| 431 Destroy(); | 424 Destroy(); |
| 432 } | 425 } |
| 433 | 426 |
| 434 bool RenderWidgetHostImpl::IsLoading() const { | 427 bool RenderWidgetHostImpl::IsLoading() const { |
| 435 return is_loading_; | 428 return is_loading_; |
| 436 } | 429 } |
| 437 | 430 |
| 438 bool RenderWidgetHostImpl::IsRenderView() const { | |
| 439 return false; | |
| 440 } | |
| 441 | |
| 442 bool RenderWidgetHostImpl::OnMessageReceived(const IPC::Message &msg) { | 431 bool RenderWidgetHostImpl::OnMessageReceived(const IPC::Message &msg) { |
| 443 bool handled = true; | 432 bool handled = true; |
| 444 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostImpl, msg) | 433 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostImpl, msg) |
| 445 IPC_MESSAGE_HANDLER(FrameHostMsg_RenderProcessGone, OnRenderProcessGone) | 434 IPC_MESSAGE_HANDLER(FrameHostMsg_RenderProcessGone, OnRenderProcessGone) |
| 446 IPC_MESSAGE_HANDLER(InputHostMsg_QueueSyntheticGesture, | 435 IPC_MESSAGE_HANDLER(InputHostMsg_QueueSyntheticGesture, |
| 447 OnQueueSyntheticGesture) | 436 OnQueueSyntheticGesture) |
| 448 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCancelComposition, | 437 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCancelComposition, |
| 449 OnImeCancelComposition) | 438 OnImeCancelComposition) |
| 450 IPC_MESSAGE_HANDLER(ViewHostMsg_Close, OnClose) | 439 IPC_MESSAGE_HANDLER(ViewHostMsg_Close, OnClose) |
| 451 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateScreenRects_ACK, | 440 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateScreenRects_ACK, |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 delegate_->RenderWidgetGotFocus(this); | 690 delegate_->RenderWidgetGotFocus(this); |
| 702 } | 691 } |
| 703 | 692 |
| 704 void RenderWidgetHostImpl::Focus() { | 693 void RenderWidgetHostImpl::Focus() { |
| 705 is_focused_ = true; | 694 is_focused_ = true; |
| 706 | 695 |
| 707 Send(new InputMsg_SetFocus(routing_id_, true)); | 696 Send(new InputMsg_SetFocus(routing_id_, true)); |
| 708 | 697 |
| 709 // Also send page-level focus state to other SiteInstances involved in | 698 // Also send page-level focus state to other SiteInstances involved in |
| 710 // rendering the current FrameTree. | 699 // rendering the current FrameTree. |
| 711 if (IsRenderView() && delegate_) | 700 if (RenderViewHost::From(this) && delegate_) |
| 712 delegate_->ReplicatePageFocus(true); | 701 delegate_->ReplicatePageFocus(true); |
| 713 } | 702 } |
| 714 | 703 |
| 715 void RenderWidgetHostImpl::Blur() { | 704 void RenderWidgetHostImpl::Blur() { |
| 716 is_focused_ = false; | 705 is_focused_ = false; |
| 717 | 706 |
| 718 // If there is a pending mouse lock request, we don't want to reject it at | 707 // If there is a pending mouse lock request, we don't want to reject it at |
| 719 // this point. The user can switch focus back to this view and approve the | 708 // this point. The user can switch focus back to this view and approve the |
| 720 // request later. | 709 // request later. |
| 721 if (IsMouseLocked()) | 710 if (IsMouseLocked()) |
| 722 view_->UnlockMouse(); | 711 view_->UnlockMouse(); |
| 723 | 712 |
| 724 if (touch_emulator_) | 713 if (touch_emulator_) |
| 725 touch_emulator_->CancelTouch(); | 714 touch_emulator_->CancelTouch(); |
| 726 | 715 |
| 727 Send(new InputMsg_SetFocus(routing_id_, false)); | 716 Send(new InputMsg_SetFocus(routing_id_, false)); |
| 728 | 717 |
| 729 // Also send page-level focus state to other SiteInstances involved in | 718 // Also send page-level focus state to other SiteInstances involved in |
| 730 // rendering the current FrameTree. | 719 // rendering the current FrameTree. |
| 731 if (IsRenderView() && delegate_) | 720 if (RenderViewHost::From(this) && delegate_) |
| 732 delegate_->ReplicatePageFocus(false); | 721 delegate_->ReplicatePageFocus(false); |
| 733 } | 722 } |
| 734 | 723 |
| 735 void RenderWidgetHostImpl::LostCapture() { | 724 void RenderWidgetHostImpl::LostCapture() { |
| 736 if (touch_emulator_) | 725 if (touch_emulator_) |
| 737 touch_emulator_->CancelTouch(); | 726 touch_emulator_->CancelTouch(); |
| 738 | 727 |
| 739 Send(new InputMsg_MouseCaptureLost(routing_id_)); | 728 Send(new InputMsg_MouseCaptureLost(routing_id_)); |
| 740 } | 729 } |
| 741 | 730 |
| (...skipping 1454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2196 } | 2185 } |
| 2197 | 2186 |
| 2198 #if defined(OS_WIN) | 2187 #if defined(OS_WIN) |
| 2199 gfx::NativeViewAccessible | 2188 gfx::NativeViewAccessible |
| 2200 RenderWidgetHostImpl::GetParentNativeViewAccessible() { | 2189 RenderWidgetHostImpl::GetParentNativeViewAccessible() { |
| 2201 return delegate_ ? delegate_->GetParentNativeViewAccessible() : NULL; | 2190 return delegate_ ? delegate_->GetParentNativeViewAccessible() : NULL; |
| 2202 } | 2191 } |
| 2203 #endif | 2192 #endif |
| 2204 | 2193 |
| 2205 } // namespace content | 2194 } // namespace content |
| OLD | NEW |