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/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 <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
| 14 #include "base/hash_tables.h" | |
| 14 #include "base/i18n/rtl.h" | 15 #include "base/i18n/rtl.h" |
| 15 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
| 16 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
| 17 #include "base/metrics/field_trial.h" | 18 #include "base/metrics/field_trial.h" |
| 18 #include "base/metrics/histogram.h" | 19 #include "base/metrics/histogram.h" |
| 19 #include "base/string_number_conversions.h" | 20 #include "base/string_number_conversions.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 21 #include "cc/output/compositor_frame.h" | 22 #include "cc/output/compositor_frame.h" |
| 22 #include "cc/output/compositor_frame_ack.h" | 23 #include "cc/output/compositor_frame_ack.h" |
| 23 #include "content/browser/accessibility/browser_accessibility_state_impl.h" | 24 #include "content/browser/accessibility/browser_accessibility_state_impl.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 using base::TimeDelta; | 76 using base::TimeDelta; |
| 76 using base::TimeTicks; | 77 using base::TimeTicks; |
| 77 using webkit::npapi::WebPluginDelegateImpl; | 78 using webkit::npapi::WebPluginDelegateImpl; |
| 78 using WebKit::WebGestureEvent; | 79 using WebKit::WebGestureEvent; |
| 79 using WebKit::WebInputEvent; | 80 using WebKit::WebInputEvent; |
| 80 using WebKit::WebKeyboardEvent; | 81 using WebKit::WebKeyboardEvent; |
| 81 using WebKit::WebMouseEvent; | 82 using WebKit::WebMouseEvent; |
| 82 using WebKit::WebMouseWheelEvent; | 83 using WebKit::WebMouseWheelEvent; |
| 83 using WebKit::WebTextDirection; | 84 using WebKit::WebTextDirection; |
| 84 | 85 |
| 86 namespace { | |
| 87 | |
| 88 struct RenderWidgetID { | |
| 89 RenderWidgetID(int32 process_id, int32 routing_id) | |
| 90 : process_id_(process_id), | |
| 91 routing_id_(routing_id) {} | |
| 92 size_t hash() const { | |
| 93 return (process_id_ << sizeof(int32)) | routing_id_; | |
|
dcheng
2013/06/11 00:34:58
Is it intentional that you're only left shifting b
| |
| 94 } | |
| 95 bool operator==(const RenderWidgetID& rwh) const { | |
| 96 return process_id_ == rwh.process_id_ && routing_id_ == rwh.routing_id_; | |
| 97 } | |
| 98 bool operator<(const RenderWidgetID& rwh) const { | |
| 99 return hash() < rwh.hash(); | |
| 100 } | |
| 101 int32 process_id_; | |
|
dcheng
2013/06/11 00:34:58
Nit: No _ when naming structs.
Also, I might perso
| |
| 102 int32 routing_id_; | |
| 103 }; | |
| 104 | |
| 105 } // namespace | |
| 106 | |
| 107 namespace BASE_HASH_NAMESPACE { | |
| 108 #if defined(COMPILER_GCC) | |
| 109 template <> | |
| 110 struct hash<RenderWidgetID> { | |
| 111 size_t operator()(const RenderWidgetID& rwh) const { | |
| 112 return rwh.hash(); | |
| 113 } | |
| 114 }; | |
| 115 #elif defined(COMPILER_MSVC) | |
| 116 inline size_t hash_value(const RenderWidgetID& rwh) { | |
| 117 return rwh.hash(); | |
| 118 } | |
| 119 #endif | |
| 120 } // namespace BASE_HASH_NAMESPACE | |
| 121 | |
| 122 | |
| 85 namespace content { | 123 namespace content { |
| 86 namespace { | 124 namespace { |
| 87 | 125 |
| 88 bool g_check_for_pending_resize_ack = true; | 126 bool g_check_for_pending_resize_ack = true; |
| 89 | 127 |
| 90 // How long to (synchronously) wait for the renderer to respond with a | 128 // How long to (synchronously) wait for the renderer to respond with a |
| 91 // PaintRect message, when our backing-store is invalid, before giving up and | 129 // PaintRect message, when our backing-store is invalid, before giving up and |
| 92 // returning a null or incorrectly sized backing-store from GetBackingStore. | 130 // returning a null or incorrectly sized backing-store from GetBackingStore. |
| 93 // This timeout impacts the "choppiness" of our window resize perf. | 131 // This timeout impacts the "choppiness" of our window resize perf. |
| 94 const int kPaintMsgTimeoutMS = 50; | 132 const int kPaintMsgTimeoutMS = 50; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 110 | 148 |
| 111 float GetAccelerationRatio(float accelerated_delta, float unaccelerated_delta) { | 149 float GetAccelerationRatio(float accelerated_delta, float unaccelerated_delta) { |
| 112 if (unaccelerated_delta == 0.f || accelerated_delta == 0.f) | 150 if (unaccelerated_delta == 0.f || accelerated_delta == 0.f) |
| 113 return 1.f; | 151 return 1.f; |
| 114 return unaccelerated_delta / accelerated_delta; | 152 return unaccelerated_delta / accelerated_delta; |
| 115 } | 153 } |
| 116 | 154 |
| 117 base::LazyInstance<std::vector<RenderWidgetHost::CreatedCallback> > | 155 base::LazyInstance<std::vector<RenderWidgetHost::CreatedCallback> > |
| 118 g_created_callbacks = LAZY_INSTANCE_INITIALIZER; | 156 g_created_callbacks = LAZY_INSTANCE_INITIALIZER; |
| 119 | 157 |
| 158 | |
| 120 } // namespace | 159 } // namespace |
| 121 | 160 |
| 122 | 161 |
| 162 typedef base::hash_map<RenderWidgetID, RenderWidgetHostImpl*> | |
| 163 RoutingIDWidgetMap; | |
| 164 static base::LazyInstance<RoutingIDWidgetMap> g_routing_id_widget_map = | |
| 165 LAZY_INSTANCE_INITIALIZER; | |
| 166 | |
| 123 // static | 167 // static |
| 124 void RenderWidgetHost::RemoveAllBackingStores() { | 168 void RenderWidgetHost::RemoveAllBackingStores() { |
| 125 BackingStoreManager::RemoveAllBackingStores(); | 169 BackingStoreManager::RemoveAllBackingStores(); |
| 126 } | 170 } |
| 127 | 171 |
| 128 // static | 172 // static |
| 129 size_t RenderWidgetHost::BackingStoreMemorySize() { | 173 size_t RenderWidgetHost::BackingStoreMemorySize() { |
| 130 return BackingStoreManager::MemorySize(); | 174 return BackingStoreManager::MemorySize(); |
| 131 } | 175 } |
| 132 | 176 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 // problem, for example by tracking in the RenderWidgetHelper the routing id | 235 // problem, for example by tracking in the RenderWidgetHelper the routing id |
| 192 // (and surface id) that have been created, but whose RWH haven't yet. | 236 // (and surface id) that have been created, but whose RWH haven't yet. |
| 193 surface_id_ = GpuSurfaceTracker::Get()->LookupSurfaceForRenderer( | 237 surface_id_ = GpuSurfaceTracker::Get()->LookupSurfaceForRenderer( |
| 194 process_->GetID(), | 238 process_->GetID(), |
| 195 routing_id_); | 239 routing_id_); |
| 196 DCHECK(surface_id_); | 240 DCHECK(surface_id_); |
| 197 } | 241 } |
| 198 | 242 |
| 199 is_threaded_compositing_enabled_ = IsThreadedCompositingEnabled(); | 243 is_threaded_compositing_enabled_ = IsThreadedCompositingEnabled(); |
| 200 | 244 |
| 201 process_->Attach(this, routing_id_); | 245 g_routing_id_widget_map.Get().insert(std::make_pair( |
| 246 RenderWidgetID(process->GetID(), routing_id_), this)); | |
| 247 process_->AddRoute(routing_id_, this); | |
| 202 // Because the widget initializes as is_hidden_ == false, | 248 // Because the widget initializes as is_hidden_ == false, |
| 203 // tell the process host that we're alive. | 249 // tell the process host that we're alive. |
| 204 process_->WidgetRestored(); | 250 process_->WidgetRestored(); |
| 205 | 251 |
| 206 accessibility_mode_ = | 252 accessibility_mode_ = |
| 207 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode(); | 253 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode(); |
| 208 | 254 |
| 209 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) | 255 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) |
| 210 g_created_callbacks.Get().at(i).Run(this); | 256 g_created_callbacks.Get().at(i).Run(this); |
| 211 | 257 |
| 212 #if defined(USE_AURA) | 258 #if defined(USE_AURA) |
| 213 bool overscroll_enabled = CommandLine::ForCurrentProcess()-> | 259 bool overscroll_enabled = CommandLine::ForCurrentProcess()-> |
| 214 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) == "1"; | 260 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) == "1"; |
| 215 SetOverscrollControllerEnabled(overscroll_enabled); | 261 SetOverscrollControllerEnabled(overscroll_enabled); |
| 216 #endif | 262 #endif |
| 217 } | 263 } |
| 218 | 264 |
| 219 RenderWidgetHostImpl::~RenderWidgetHostImpl() { | 265 RenderWidgetHostImpl::~RenderWidgetHostImpl() { |
| 220 SetView(NULL); | 266 SetView(NULL); |
| 221 | 267 |
| 222 // Clear our current or cached backing store if either remains. | 268 // Clear our current or cached backing store if either remains. |
| 223 BackingStoreManager::RemoveBackingStore(this); | 269 BackingStoreManager::RemoveBackingStore(this); |
| 224 | 270 |
| 225 GpuSurfaceTracker::Get()->RemoveSurface(surface_id_); | 271 GpuSurfaceTracker::Get()->RemoveSurface(surface_id_); |
| 226 surface_id_ = 0; | 272 surface_id_ = 0; |
| 227 | 273 |
| 228 process_->Release(routing_id_); | 274 process_->RemoveRoute(routing_id_); |
| 275 g_routing_id_widget_map.Get().erase( | |
| 276 RenderWidgetID(process_->GetID(), routing_id_)); | |
| 229 | 277 |
| 230 if (delegate_) | 278 if (delegate_) |
| 231 delegate_->RenderWidgetDeleted(this); | 279 delegate_->RenderWidgetDeleted(this); |
| 232 } | 280 } |
| 233 | 281 |
| 234 // static | 282 // static |
| 283 RenderWidgetHost* RenderWidgetHost::FromID( | |
| 284 int32 process_id, | |
| 285 int32 routing_id) { | |
| 286 return RenderWidgetHostImpl::FromID(process_id, routing_id); | |
| 287 } | |
| 288 | |
| 289 // static | |
| 290 RenderWidgetHostImpl* RenderWidgetHostImpl::FromID( | |
| 291 int32 process_id, | |
| 292 int32 routing_id) { | |
| 293 RoutingIDWidgetMap* widgets = g_routing_id_widget_map.Pointer(); | |
| 294 RoutingIDWidgetMap::iterator it = widgets->find( | |
| 295 RenderWidgetID(process_id, routing_id)); | |
| 296 return it == widgets->end() ? NULL : it->second; | |
| 297 } | |
| 298 | |
| 299 // static | |
| 300 scoped_ptr<std::vector<RenderWidgetHost*> > | |
| 301 RenderWidgetHost::GetRenderWidgetHosts() { | |
|
dcheng
2013/06/11 00:34:58
From what I can see, it's fine to just use return
| |
| 302 scoped_ptr<std::vector<RenderWidgetHost*> > hosts( | |
| 303 new std::vector<RenderWidgetHost*>()); | |
| 304 RoutingIDWidgetMap* widgets = g_routing_id_widget_map.Pointer(); | |
| 305 for (RoutingIDWidgetMap::const_iterator it = widgets->begin(); | |
| 306 it != widgets->end(); | |
| 307 ++it) { | |
| 308 hosts->push_back(it->second); | |
| 309 } | |
| 310 return hosts.Pass(); | |
| 311 } | |
| 312 | |
| 313 // static | |
| 235 RenderWidgetHostImpl* RenderWidgetHostImpl::From(RenderWidgetHost* rwh) { | 314 RenderWidgetHostImpl* RenderWidgetHostImpl::From(RenderWidgetHost* rwh) { |
| 236 return rwh->AsRenderWidgetHostImpl(); | 315 return rwh->AsRenderWidgetHostImpl(); |
| 237 } | 316 } |
| 238 | 317 |
| 239 // static | 318 // static |
| 240 void RenderWidgetHost::AddCreatedCallback(const CreatedCallback& callback) { | 319 void RenderWidgetHost::AddCreatedCallback(const CreatedCallback& callback) { |
| 241 g_created_callbacks.Get().push_back(callback); | 320 g_created_callbacks.Get().push_back(callback); |
| 242 } | 321 } |
| 243 | 322 |
| 244 // static | 323 // static |
| (...skipping 2291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2536 const ui::LatencyInfo& latency_info) { | 2615 const ui::LatencyInfo& latency_info) { |
| 2537 for (ui::LatencyInfo::LatencyMap::const_iterator b = | 2616 for (ui::LatencyInfo::LatencyMap::const_iterator b = |
| 2538 latency_info.latency_components.begin(); | 2617 latency_info.latency_components.begin(); |
| 2539 b != latency_info.latency_components.end(); | 2618 b != latency_info.latency_components.end(); |
| 2540 ++b) { | 2619 ++b) { |
| 2541 if (b->first.first != ui::INPUT_EVENT_LATENCY_COMPONENT) | 2620 if (b->first.first != ui::INPUT_EVENT_LATENCY_COMPONENT) |
| 2542 continue; | 2621 continue; |
| 2543 // Matches with GetLatencyComponentId | 2622 // Matches with GetLatencyComponentId |
| 2544 int routing_id = b->first.second & 0xffffffff; | 2623 int routing_id = b->first.second & 0xffffffff; |
| 2545 int process_id = (b->first.second >> 32) & 0xffffffff; | 2624 int process_id = (b->first.second >> 32) & 0xffffffff; |
| 2546 RenderProcessHost* host = RenderProcessHost::FromID(process_id); | 2625 RenderWidgetHost* rwh = |
| 2547 if (!host) | 2626 RenderWidgetHost::FromID(process_id, routing_id); |
| 2548 continue; | |
| 2549 RenderWidgetHost* rwh = host->GetRenderWidgetHostByID(routing_id); | |
| 2550 if (!rwh) | 2627 if (!rwh) |
| 2551 continue; | 2628 continue; |
| 2552 RenderWidgetHostImpl::From(rwh)->FrameSwapped(latency_info); | 2629 RenderWidgetHostImpl::From(rwh)->FrameSwapped(latency_info); |
| 2553 } | 2630 } |
| 2554 } | 2631 } |
| 2555 | 2632 |
| 2556 } // namespace content | 2633 } // namespace content |
| OLD | NEW |