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/renderer/render_view_impl.h" | 5 #include "content/renderer/render_view_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 using WebKit::WebFloatRect; | 330 using WebKit::WebFloatRect; |
331 using WebKit::WebHitTestResult; | 331 using WebKit::WebHitTestResult; |
332 #endif | 332 #endif |
333 | 333 |
334 namespace content { | 334 namespace content { |
335 | 335 |
336 //----------------------------------------------------------------------------- | 336 //----------------------------------------------------------------------------- |
337 | 337 |
338 typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap; | 338 typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap; |
339 static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER; | 339 static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER; |
| 340 typedef std::map<int32, RenderViewImpl*> RoutingIDViewMap; |
| 341 static base::LazyInstance<RoutingIDViewMap> g_routing_id_view_map = |
| 342 LAZY_INSTANCE_INITIALIZER; |
340 | 343 |
341 // Time, in seconds, we delay before sending content state changes (such as form | 344 // Time, in seconds, we delay before sending content state changes (such as form |
342 // state and scroll position) to the browser. We delay sending changes to avoid | 345 // state and scroll position) to the browser. We delay sending changes to avoid |
343 // spamming the browser. | 346 // spamming the browser. |
344 // To avoid having tab/session restore require sending a message to get the | 347 // To avoid having tab/session restore require sending a message to get the |
345 // current content state during tab closing we use a shorter timeout for the | 348 // current content state during tab closing we use a shorter timeout for the |
346 // foreground renderer. This means there is a small window of time from which | 349 // foreground renderer. This means there is a small window of time from which |
347 // content state is modified and not sent to session restore, but this is | 350 // content state is modified and not sent to session restore, but this is |
348 // better than having to wake up all renderers during shutdown. | 351 // better than having to wake up all renderers during shutdown. |
349 static const int kDelaySecondsForContentStateSyncHidden = 5; | 352 static const int kDelaySecondsForContentStateSyncHidden = 5; |
(...skipping 11 matching lines...) Expand all Loading... |
361 #if defined(OS_ANDROID) | 364 #if defined(OS_ANDROID) |
362 // Delay between tapping in content and launching the associated android intent. | 365 // Delay between tapping in content and launching the associated android intent. |
363 // Used to allow users see what has been recognized as content. | 366 // Used to allow users see what has been recognized as content. |
364 static const size_t kContentIntentDelayMilliseconds = 700; | 367 static const size_t kContentIntentDelayMilliseconds = 700; |
365 #endif | 368 #endif |
366 | 369 |
367 static RenderViewImpl* (*g_create_render_view_impl)(RenderViewImplParams*) = | 370 static RenderViewImpl* (*g_create_render_view_impl)(RenderViewImplParams*) = |
368 NULL; | 371 NULL; |
369 | 372 |
370 static RenderViewImpl* FromRoutingID(int32 routing_id) { | 373 static RenderViewImpl* FromRoutingID(int32 routing_id) { |
371 return static_cast<RenderViewImpl*>( | 374 RoutingIDViewMap* views = g_routing_id_view_map.Pointer(); |
372 ChildThread::current()->ResolveRoute(routing_id)); | 375 RoutingIDViewMap::iterator it = views->find(routing_id); |
| 376 return it == views->end() ? NULL : it->second; |
373 } | 377 } |
374 | 378 |
375 static WebKit::WebFrame* FindFrameByID(WebKit::WebFrame* root, int frame_id) { | 379 static WebKit::WebFrame* FindFrameByID(WebKit::WebFrame* root, int frame_id) { |
376 for (WebFrame* frame = root; frame; frame = frame->traverseNext(false)) { | 380 for (WebFrame* frame = root; frame; frame = frame->traverseNext(false)) { |
377 if (frame->identifier() == frame_id) | 381 if (frame->identifier() == frame_id) |
378 return frame; | 382 return frame; |
379 } | 383 } |
380 return NULL; | 384 return NULL; |
381 } | 385 } |
382 | 386 |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 AddRef(); | 661 AddRef(); |
658 | 662 |
659 // If this is a popup, we must wait for the CreatingNew_ACK message before | 663 // If this is a popup, we must wait for the CreatingNew_ACK message before |
660 // completing initialization. Otherwise, we can finish it now. | 664 // completing initialization. Otherwise, we can finish it now. |
661 if (opener_id_ == MSG_ROUTING_NONE) { | 665 if (opener_id_ == MSG_ROUTING_NONE) { |
662 did_show_ = true; | 666 did_show_ = true; |
663 CompleteInit(); | 667 CompleteInit(); |
664 } | 668 } |
665 | 669 |
666 g_view_map.Get().insert(std::make_pair(webview(), this)); | 670 g_view_map.Get().insert(std::make_pair(webview(), this)); |
| 671 g_routing_id_view_map.Get().insert(std::make_pair(routing_id_, this)); |
667 webview()->setDeviceScaleFactor(device_scale_factor_); | 672 webview()->setDeviceScaleFactor(device_scale_factor_); |
668 webkit_preferences_.Apply(webview()); | 673 webkit_preferences_.Apply(webview()); |
669 webview()->initializeMainFrame(this); | 674 webview()->initializeMainFrame(this); |
670 if (!params->frame_name.empty()) | 675 if (!params->frame_name.empty()) |
671 webview()->mainFrame()->setName(params->frame_name); | 676 webview()->mainFrame()->setName(params->frame_name); |
672 webview()->settings()->setMinimumTimerInterval( | 677 webview()->settings()->setMinimumTimerInterval( |
673 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval : | 678 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval : |
674 webkit_glue::kForegroundTabTimerInterval); | 679 webkit_glue::kForegroundTabTimerInterval); |
675 | 680 |
676 OnSetRendererPrefs(params->renderer_prefs); | 681 OnSetRendererPrefs(params->renderer_prefs); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 // Destroy all fake plugin window handles on the browser side. | 746 // Destroy all fake plugin window handles on the browser side. |
742 while (!fake_plugin_window_handles_.empty()) { | 747 while (!fake_plugin_window_handles_.empty()) { |
743 // Make sure no NULL plugin window handles were inserted into this list. | 748 // Make sure no NULL plugin window handles were inserted into this list. |
744 DCHECK(*fake_plugin_window_handles_.begin()); | 749 DCHECK(*fake_plugin_window_handles_.begin()); |
745 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_. | 750 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_. |
746 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin()); | 751 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin()); |
747 } | 752 } |
748 #endif | 753 #endif |
749 | 754 |
750 #ifndef NDEBUG | 755 #ifndef NDEBUG |
751 // Make sure we are no longer referenced by the ViewMap. | 756 // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap. |
752 ViewMap* views = g_view_map.Pointer(); | 757 ViewMap* views = g_view_map.Pointer(); |
753 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) | 758 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) |
754 DCHECK_NE(this, it->second) << "Failed to call Close?"; | 759 DCHECK_NE(this, it->second) << "Failed to call Close?"; |
| 760 RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer(); |
| 761 for (RoutingIDViewMap::iterator it = routing_id_views->begin(); |
| 762 it != routing_id_views->end(); ++it) |
| 763 DCHECK_NE(this, it->second) << "Failed to call Close?"; |
755 #endif | 764 #endif |
756 | 765 |
757 FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone()); | 766 FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone()); |
758 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct()); | 767 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct()); |
759 } | 768 } |
760 | 769 |
761 /*static*/ | 770 /*static*/ |
762 RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) { | 771 RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) { |
763 ViewMap* views = g_view_map.Pointer(); | 772 ViewMap* views = g_view_map.Pointer(); |
764 ViewMap::iterator it = views->find(webview); | 773 ViewMap::iterator it = views->find(webview); |
(...skipping 4917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5682 void RenderViewImpl::OnSetEditCommandsForNextKeyEvent( | 5691 void RenderViewImpl::OnSetEditCommandsForNextKeyEvent( |
5683 const EditCommands& edit_commands) { | 5692 const EditCommands& edit_commands) { |
5684 edit_commands_ = edit_commands; | 5693 edit_commands_ = edit_commands; |
5685 } | 5694 } |
5686 | 5695 |
5687 void RenderViewImpl::Close() { | 5696 void RenderViewImpl::Close() { |
5688 // We need to grab a pointer to the doomed WebView before we destroy it. | 5697 // We need to grab a pointer to the doomed WebView before we destroy it. |
5689 WebView* doomed = webview(); | 5698 WebView* doomed = webview(); |
5690 RenderWidget::Close(); | 5699 RenderWidget::Close(); |
5691 g_view_map.Get().erase(doomed); | 5700 g_view_map.Get().erase(doomed); |
| 5701 g_routing_id_view_map.Get().erase(routing_id_); |
5692 } | 5702 } |
5693 | 5703 |
5694 void RenderViewImpl::DidHandleKeyEvent() { | 5704 void RenderViewImpl::DidHandleKeyEvent() { |
5695 ClearEditCommands(); | 5705 ClearEditCommands(); |
5696 } | 5706 } |
5697 | 5707 |
5698 bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { | 5708 bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
5699 possible_drag_event_info_.event_source = | 5709 possible_drag_event_info_.event_source = |
5700 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE; | 5710 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE; |
5701 possible_drag_event_info_.event_location = | 5711 possible_drag_event_info_.event_location = |
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6414 } | 6424 } |
6415 #endif | 6425 #endif |
6416 | 6426 |
6417 void RenderViewImpl::OnReleaseDisambiguationPopupDIB( | 6427 void RenderViewImpl::OnReleaseDisambiguationPopupDIB( |
6418 TransportDIB::Handle dib_handle) { | 6428 TransportDIB::Handle dib_handle) { |
6419 TransportDIB* dib = TransportDIB::CreateWithHandle(dib_handle); | 6429 TransportDIB* dib = TransportDIB::CreateWithHandle(dib_handle); |
6420 RenderProcess::current()->ReleaseTransportDIB(dib); | 6430 RenderProcess::current()->ReleaseTransportDIB(dib); |
6421 } | 6431 } |
6422 | 6432 |
6423 } // namespace content | 6433 } // namespace content |
OLD | NEW |