| 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 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 webview_(nullptr), | 632 webview_(nullptr), |
| 633 has_scrolled_focused_editable_node_into_rect_(false), | 633 has_scrolled_focused_editable_node_into_rect_(false), |
| 634 page_zoom_level_(params.page_zoom_level), | 634 page_zoom_level_(params.page_zoom_level), |
| 635 main_render_frame_(nullptr), | 635 main_render_frame_(nullptr), |
| 636 frame_widget_(nullptr), | 636 frame_widget_(nullptr), |
| 637 speech_recognition_dispatcher_(NULL), | 637 speech_recognition_dispatcher_(NULL), |
| 638 mouse_lock_dispatcher_(NULL), | 638 mouse_lock_dispatcher_(NULL), |
| 639 #if defined(OS_ANDROID) | 639 #if defined(OS_ANDROID) |
| 640 expected_content_intent_id_(0), | 640 expected_content_intent_id_(0), |
| 641 #endif | 641 #endif |
| 642 #if defined(ENABLE_PLUGINS) | |
| 643 focused_pepper_plugin_(NULL), | |
| 644 pepper_last_mouse_event_target_(NULL), | |
| 645 #endif | |
| 646 enumeration_completion_id_(0), | 642 enumeration_completion_id_(0), |
| 647 session_storage_namespace_id_(params.session_storage_namespace_id) { | 643 session_storage_namespace_id_(params.session_storage_namespace_id) { |
| 648 GetWidget()->set_owner_delegate(this); | 644 GetWidget()->set_owner_delegate(this); |
| 649 } | 645 } |
| 650 | 646 |
| 651 void RenderViewImpl::Initialize(const ViewMsg_New_Params& params, | 647 void RenderViewImpl::Initialize(const ViewMsg_New_Params& params, |
| 652 bool was_created_by_renderer) { | 648 bool was_created_by_renderer) { |
| 653 SetRoutingID(params.view_id); | 649 SetRoutingID(params.view_id); |
| 654 | 650 |
| 655 int opener_view_routing_id; | 651 int opener_view_routing_id; |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1150 void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) { | 1146 void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) { |
| 1151 observer->RenderViewGone(); | 1147 observer->RenderViewGone(); |
| 1152 observers_.RemoveObserver(observer); | 1148 observers_.RemoveObserver(observer); |
| 1153 } | 1149 } |
| 1154 | 1150 |
| 1155 blink::WebView* RenderViewImpl::webview() const { | 1151 blink::WebView* RenderViewImpl::webview() const { |
| 1156 return webview_; | 1152 return webview_; |
| 1157 } | 1153 } |
| 1158 | 1154 |
| 1159 #if defined(ENABLE_PLUGINS) | 1155 #if defined(ENABLE_PLUGINS) |
| 1160 void RenderViewImpl::PepperInstanceCreated( | |
| 1161 PepperPluginInstanceImpl* instance) { | |
| 1162 active_pepper_instances_.insert(instance); | |
| 1163 | |
| 1164 RenderFrameImpl* const render_frame = instance->render_frame(); | |
| 1165 render_frame->Send( | |
| 1166 new FrameHostMsg_PepperInstanceCreated(render_frame->GetRoutingID())); | |
| 1167 } | |
| 1168 | |
| 1169 void RenderViewImpl::PepperInstanceDeleted( | |
| 1170 PepperPluginInstanceImpl* instance) { | |
| 1171 active_pepper_instances_.erase(instance); | |
| 1172 | |
| 1173 if (pepper_last_mouse_event_target_ == instance) | |
| 1174 pepper_last_mouse_event_target_ = NULL; | |
| 1175 if (focused_pepper_plugin_ == instance) | |
| 1176 PepperFocusChanged(instance, false); | |
| 1177 | |
| 1178 RenderFrameImpl* const render_frame = instance->render_frame(); | |
| 1179 if (render_frame) | |
| 1180 render_frame->Send( | |
| 1181 new FrameHostMsg_PepperInstanceDeleted(render_frame->GetRoutingID())); | |
| 1182 } | |
| 1183 | |
| 1184 void RenderViewImpl::PepperFocusChanged(PepperPluginInstanceImpl* instance, | |
| 1185 bool focused) { | |
| 1186 if (focused) | |
| 1187 focused_pepper_plugin_ = instance; | |
| 1188 else if (focused_pepper_plugin_ == instance) | |
| 1189 focused_pepper_plugin_ = NULL; | |
| 1190 | |
| 1191 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME); | |
| 1192 UpdateSelectionBounds(); | |
| 1193 } | |
| 1194 | 1156 |
| 1195 #if defined(OS_MACOSX) | 1157 #if defined(OS_MACOSX) |
| 1196 void RenderViewImpl::OnGetRenderedText() { | 1158 void RenderViewImpl::OnGetRenderedText() { |
| 1197 if (!webview()) | 1159 if (!webview()) |
| 1198 return; | 1160 return; |
| 1199 | 1161 |
| 1200 if (!webview()->mainFrame()->isWebLocalFrame()) | 1162 if (!webview()->mainFrame()->isWebLocalFrame()) |
| 1201 return; | 1163 return; |
| 1202 | 1164 |
| 1203 // Get rendered text from WebLocalFrame. | 1165 // Get rendered text from WebLocalFrame. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1251 return false; | 1213 return false; |
| 1252 } | 1214 } |
| 1253 | 1215 |
| 1254 bool RenderViewImpl::RenderWidgetWillHandleMouseEvent( | 1216 bool RenderViewImpl::RenderWidgetWillHandleMouseEvent( |
| 1255 const blink::WebMouseEvent& event) { | 1217 const blink::WebMouseEvent& event) { |
| 1256 possible_drag_event_info_.event_source = | 1218 possible_drag_event_info_.event_source = |
| 1257 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE; | 1219 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE; |
| 1258 possible_drag_event_info_.event_location = | 1220 possible_drag_event_info_.event_location = |
| 1259 gfx::Point(event.globalX, event.globalY); | 1221 gfx::Point(event.globalX, event.globalY); |
| 1260 | 1222 |
| 1261 #if defined(ENABLE_PLUGINS) | |
| 1262 // This method is called for every mouse event that the render view receives. | |
| 1263 // And then the mouse event is forwarded to WebKit, which dispatches it to the | |
| 1264 // event target. Potentially a Pepper plugin will receive the event. | |
| 1265 // In order to tell whether a plugin gets the last mouse event and which it | |
| 1266 // is, we set |pepper_last_mouse_event_target_| to NULL here. If a plugin gets | |
| 1267 // the event, it will notify us via DidReceiveMouseEvent() and set itself as | |
| 1268 // |pepper_last_mouse_event_target_|. | |
| 1269 pepper_last_mouse_event_target_ = NULL; | |
| 1270 #endif | |
| 1271 | |
| 1272 // If the mouse is locked, only the current owner of the mouse lock can | 1223 // If the mouse is locked, only the current owner of the mouse lock can |
| 1273 // process mouse events. | 1224 // process mouse events. |
| 1274 return mouse_lock_dispatcher_->WillHandleMouseEvent(event); | 1225 return mouse_lock_dispatcher_->WillHandleMouseEvent(event); |
| 1275 } | 1226 } |
| 1276 | 1227 |
| 1277 // IPC::Listener implementation ---------------------------------------------- | 1228 // IPC::Listener implementation ---------------------------------------------- |
| 1278 | 1229 |
| 1279 bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) { | 1230 bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) { |
| 1280 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; | 1231 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; |
| 1281 if (main_frame && main_frame->isWebLocalFrame()) | 1232 if (main_frame && main_frame->isWebLocalFrame()) |
| (...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2065 // (SnowLeopard, which has Aqua scrollbars which need synchronous updates). | 2016 // (SnowLeopard, which has Aqua scrollbars which need synchronous updates). |
| 2066 use_threaded_event_handling = compositor_deps_->IsElasticOverscrollEnabled(); | 2017 use_threaded_event_handling = compositor_deps_->IsElasticOverscrollEnabled(); |
| 2067 #endif | 2018 #endif |
| 2068 if (use_threaded_event_handling) { | 2019 if (use_threaded_event_handling) { |
| 2069 RenderThreadImpl* render_thread = RenderThreadImpl::current(); | 2020 RenderThreadImpl* render_thread = RenderThreadImpl::current(); |
| 2070 // render_thread may be NULL in tests. | 2021 // render_thread may be NULL in tests. |
| 2071 InputHandlerManager* input_handler_manager = | 2022 InputHandlerManager* input_handler_manager = |
| 2072 render_thread ? render_thread->input_handler_manager() : NULL; | 2023 render_thread ? render_thread->input_handler_manager() : NULL; |
| 2073 if (input_handler_manager) { | 2024 if (input_handler_manager) { |
| 2074 input_handler_manager->AddInputHandler( | 2025 input_handler_manager->AddInputHandler( |
| 2075 GetRoutingID(), rwc->GetInputHandler(), AsWeakPtr(), | 2026 GetRoutingID(), rwc->GetInputHandler(), |
| 2027 base::SupportsWeakPtr<RenderViewImpl>::AsWeakPtr(), |
| 2076 webkit_preferences_.enable_scroll_animator, | 2028 webkit_preferences_.enable_scroll_animator, |
| 2077 UseGestureBasedWheelScrolling()); | 2029 UseGestureBasedWheelScrolling()); |
| 2078 } | 2030 } |
| 2079 } | 2031 } |
| 2080 } | 2032 } |
| 2081 | 2033 |
| 2082 bool RenderViewImpl::allowsBrokenNullLayerTreeView() const { | 2034 bool RenderViewImpl::allowsBrokenNullLayerTreeView() const { |
| 2083 return RenderWidget::allowsBrokenNullLayerTreeView(); | 2035 return RenderWidget::allowsBrokenNullLayerTreeView(); |
| 2084 } | 2036 } |
| 2085 | 2037 |
| (...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2721 | 2673 |
| 2722 top_controls_shrink_blink_size_ = params.top_controls_shrink_blink_size; | 2674 top_controls_shrink_blink_size_ = params.top_controls_shrink_blink_size; |
| 2723 top_controls_height_ = params.top_controls_height; | 2675 top_controls_height_ = params.top_controls_height; |
| 2724 | 2676 |
| 2725 RenderWidget::OnResize(params); | 2677 RenderWidget::OnResize(params); |
| 2726 | 2678 |
| 2727 if (old_visible_viewport_size != visible_viewport_size_) | 2679 if (old_visible_viewport_size != visible_viewport_size_) |
| 2728 has_scrolled_focused_editable_node_into_rect_ = false; | 2680 has_scrolled_focused_editable_node_into_rect_ = false; |
| 2729 } | 2681 } |
| 2730 | 2682 |
| 2731 void RenderViewImpl::RenderWidgetDidCommitAndDrawCompositorFrame() { | |
| 2732 #if defined(ENABLE_PLUGINS) | |
| 2733 // Notify all instances that we painted. The same caveats apply as for | |
| 2734 // ViewFlushedPaint regarding instances closing themselves, so we take | |
| 2735 // similar precautions. | |
| 2736 PepperPluginSet plugins = active_pepper_instances_; | |
| 2737 for (PepperPluginSet::iterator i = plugins.begin(); i != plugins.end(); ++i) { | |
| 2738 if (active_pepper_instances_.find(*i) != active_pepper_instances_.end()) | |
| 2739 (*i)->ViewInitiatedPaint(); | |
| 2740 } | |
| 2741 #endif | |
| 2742 } | |
| 2743 | |
| 2744 void RenderViewImpl::RenderWidgetDidFlushPaint() { | 2683 void RenderViewImpl::RenderWidgetDidFlushPaint() { |
| 2745 // If the RenderWidget is closing down then early-exit, otherwise we'll crash. | 2684 // If the RenderWidget is closing down then early-exit, otherwise we'll crash. |
| 2746 // See crbug.com/112921. | 2685 // See crbug.com/112921. |
| 2747 if (!webview()) | 2686 if (!webview()) |
| 2748 return; | 2687 return; |
| 2749 | 2688 |
| 2750 WebFrame* main_frame = webview()->mainFrame(); | 2689 WebFrame* main_frame = webview()->mainFrame(); |
| 2751 for (WebFrame* frame = main_frame; frame; | 2690 for (WebFrame* frame = main_frame; frame; |
| 2752 frame = frame->traverseNext(false)) { | 2691 frame = frame->traverseNext(false)) { |
| 2753 // TODO(nasko): This is a hack for the case in which the top-level | 2692 // TODO(nasko): This is a hack for the case in which the top-level |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2826 | 2765 |
| 2827 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC) | 2766 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC) |
| 2828 RenderThreadImpl::current()->video_capture_impl_manager()-> | 2767 RenderThreadImpl::current()->video_capture_impl_manager()-> |
| 2829 SuspendDevices(true); | 2768 SuspendDevices(true); |
| 2830 if (speech_recognition_dispatcher_) | 2769 if (speech_recognition_dispatcher_) |
| 2831 speech_recognition_dispatcher_->AbortAllRecognitions(); | 2770 speech_recognition_dispatcher_->AbortAllRecognitions(); |
| 2832 #endif | 2771 #endif |
| 2833 | 2772 |
| 2834 if (webview()) | 2773 if (webview()) |
| 2835 webview()->setVisibilityState(visibilityState(), false); | 2774 webview()->setVisibilityState(visibilityState(), false); |
| 2836 | |
| 2837 #if defined(ENABLE_PLUGINS) | |
| 2838 for (PepperPluginSet::iterator i = active_pepper_instances_.begin(); | |
| 2839 i != active_pepper_instances_.end(); ++i) | |
| 2840 (*i)->PageVisibilityChanged(false); | |
| 2841 #endif // ENABLE_PLUGINS | |
| 2842 } | 2775 } |
| 2843 | 2776 |
| 2844 void RenderViewImpl::OnWasShown(bool needs_repainting, | 2777 void RenderViewImpl::OnWasShown(bool needs_repainting, |
| 2845 const ui::LatencyInfo& latency_info) { | 2778 const ui::LatencyInfo& latency_info) { |
| 2846 RenderWidget::OnWasShown(needs_repainting, latency_info); | 2779 RenderWidget::OnWasShown(needs_repainting, latency_info); |
| 2847 | 2780 |
| 2848 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC) | 2781 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC) |
| 2849 RenderThreadImpl::current()->video_capture_impl_manager()-> | 2782 RenderThreadImpl::current()->video_capture_impl_manager()-> |
| 2850 SuspendDevices(false); | 2783 SuspendDevices(false); |
| 2851 #endif | 2784 #endif |
| 2852 | 2785 |
| 2853 if (webview()) | 2786 if (webview()) |
| 2854 webview()->setVisibilityState(visibilityState(), false); | 2787 webview()->setVisibilityState(visibilityState(), false); |
| 2855 | |
| 2856 #if defined(ENABLE_PLUGINS) | |
| 2857 for (PepperPluginSet::iterator i = active_pepper_instances_.begin(); | |
| 2858 i != active_pepper_instances_.end(); ++i) | |
| 2859 (*i)->PageVisibilityChanged(true); | |
| 2860 #endif // ENABLE_PLUGINS | |
| 2861 } | 2788 } |
| 2862 | 2789 |
| 2863 GURL RenderViewImpl::GetURLForGraphicsContext3D() { | 2790 GURL RenderViewImpl::GetURLForGraphicsContext3D() { |
| 2864 DCHECK(webview()); | 2791 DCHECK(webview()); |
| 2865 if (webview()->mainFrame()->isWebLocalFrame()) | 2792 if (webview()->mainFrame()->isWebLocalFrame()) |
| 2866 return GURL(webview()->mainFrame()->document().url()); | 2793 return GURL(webview()->mainFrame()->document().url()); |
| 2867 else | 2794 else |
| 2868 return GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D"); | 2795 return GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D"); |
| 2869 } | 2796 } |
| 2870 | 2797 |
| 2871 void RenderViewImpl::OnSetFocus(bool enable) { | 2798 void RenderViewImpl::OnSetFocus(bool enable) { |
| 2872 // This message must always be received when the main frame is a | 2799 // This message must always be received when the main frame is a |
| 2873 // WebLocalFrame. | 2800 // WebLocalFrame. |
| 2874 CHECK(webview()->mainFrame()->isWebLocalFrame()); | 2801 CHECK(webview()->mainFrame()->isWebLocalFrame()); |
| 2875 SetFocus(enable); | 2802 SetFocus(enable); |
| 2876 } | 2803 } |
| 2877 | 2804 |
| 2878 void RenderViewImpl::SetFocus(bool enable) { | 2805 void RenderViewImpl::SetFocus(bool enable) { |
| 2879 has_focus_ = enable; | 2806 has_focus_ = enable; |
| 2880 RenderWidget::OnSetFocus(enable); | 2807 RenderWidget::OnSetFocus(enable); |
| 2881 | 2808 |
| 2882 #if defined(ENABLE_PLUGINS) | |
| 2883 // Notify all Pepper plugins. | |
| 2884 for (PepperPluginSet::iterator i = active_pepper_instances_.begin(); | |
| 2885 i != active_pepper_instances_.end(); ++i) | |
| 2886 (*i)->SetContentAreaFocus(enable); | |
| 2887 #endif | |
| 2888 // Notify all BrowserPlugins of the RenderView's focus state. | 2809 // Notify all BrowserPlugins of the RenderView's focus state. |
| 2889 if (BrowserPluginManager::Get()) | 2810 if (BrowserPluginManager::Get()) |
| 2890 BrowserPluginManager::Get()->UpdateFocusState(); | 2811 BrowserPluginManager::Get()->UpdateFocusState(); |
| 2891 } | 2812 } |
| 2892 | 2813 |
| 2893 void RenderViewImpl::OnImeSetComposition( | 2814 void RenderViewImpl::OnImeSetComposition( |
| 2894 const base::string16& text, | 2815 const base::string16& text, |
| 2895 const std::vector<blink::WebCompositionUnderline>& underlines, | 2816 const std::vector<blink::WebCompositionUnderline>& underlines, |
| 2896 const gfx::Range& replacement_range, | 2817 const gfx::Range& replacement_range, |
| 2897 int selection_start, | 2818 int selection_start, |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3182 base::UTF8ToUTF16(content.text), content.intent_url); | 3103 base::UTF8ToUTF16(content.text), content.intent_url); |
| 3183 } | 3104 } |
| 3184 } | 3105 } |
| 3185 return WebContentDetectionResult(); | 3106 return WebContentDetectionResult(); |
| 3186 } | 3107 } |
| 3187 | 3108 |
| 3188 void RenderViewImpl::scheduleContentIntent(const WebURL& intent, | 3109 void RenderViewImpl::scheduleContentIntent(const WebURL& intent, |
| 3189 bool is_main_frame) { | 3110 bool is_main_frame) { |
| 3190 // Introduce a short delay so that the user can notice the content. | 3111 // Introduce a short delay so that the user can notice the content. |
| 3191 base::MessageLoop::current()->PostDelayedTask( | 3112 base::MessageLoop::current()->PostDelayedTask( |
| 3192 FROM_HERE, | 3113 FROM_HERE, base::Bind(&RenderViewImpl::LaunchAndroidContentIntent, |
| 3193 base::Bind(&RenderViewImpl::LaunchAndroidContentIntent, AsWeakPtr(), | 3114 base::SupportsWeakPtr<RenderViewImpl>::AsWeakPtr(), |
| 3194 intent, expected_content_intent_id_, is_main_frame), | 3115 intent, expected_content_intent_id_, is_main_frame), |
| 3195 base::TimeDelta::FromMilliseconds(kContentIntentDelayMilliseconds)); | 3116 base::TimeDelta::FromMilliseconds(kContentIntentDelayMilliseconds)); |
| 3196 } | 3117 } |
| 3197 | 3118 |
| 3198 void RenderViewImpl::cancelScheduledContentIntents() { | 3119 void RenderViewImpl::cancelScheduledContentIntents() { |
| 3199 ++expected_content_intent_id_; | 3120 ++expected_content_intent_id_; |
| 3200 } | 3121 } |
| 3201 | 3122 |
| 3202 void RenderViewImpl::LaunchAndroidContentIntent(const GURL& intent, | 3123 void RenderViewImpl::LaunchAndroidContentIntent(const GURL& intent, |
| 3203 size_t request_id, | 3124 size_t request_id, |
| 3204 bool is_main_frame) { | 3125 bool is_main_frame) { |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3427 if (IsUseZoomForDSFEnabled()) { | 3348 if (IsUseZoomForDSFEnabled()) { |
| 3428 webview()->setZoomFactorForDeviceScaleFactor(device_scale_factor_); | 3349 webview()->setZoomFactorForDeviceScaleFactor(device_scale_factor_); |
| 3429 } else { | 3350 } else { |
| 3430 webview()->setDeviceScaleFactor(device_scale_factor_); | 3351 webview()->setDeviceScaleFactor(device_scale_factor_); |
| 3431 } | 3352 } |
| 3432 webview()->settings()->setPreferCompositingToLCDTextEnabled( | 3353 webview()->settings()->setPreferCompositingToLCDTextEnabled( |
| 3433 PreferCompositingToLCDText(compositor_deps_, device_scale_factor_)); | 3354 PreferCompositingToLCDText(compositor_deps_, device_scale_factor_)); |
| 3434 } | 3355 } |
| 3435 | 3356 |
| 3436 } // namespace content | 3357 } // namespace content |
| OLD | NEW |