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/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 // TODO(port): these files are currently Windows only because they concern: | 191 // TODO(port): these files are currently Windows only because they concern: |
192 // * theming | 192 // * theming |
193 #include "ui/native_theme/native_theme_win.h" | 193 #include "ui/native_theme/native_theme_win.h" |
194 #elif defined(USE_X11) | 194 #elif defined(USE_X11) |
195 #include "ui/native_theme/native_theme.h" | 195 #include "ui/native_theme/native_theme.h" |
196 #elif defined(OS_MACOSX) | 196 #elif defined(OS_MACOSX) |
197 #include "skia/ext/skia_utils_mac.h" | 197 #include "skia/ext/skia_utils_mac.h" |
198 #endif | 198 #endif |
199 | 199 |
200 #if defined(ENABLE_PLUGINS) | 200 #if defined(ENABLE_PLUGINS) |
201 #include "content/renderer/npapi/webplugin_delegate_proxy.h" | |
202 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 201 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
203 #include "content/renderer/pepper/pepper_plugin_registry.h" | 202 #include "content/renderer/pepper/pepper_plugin_registry.h" |
204 #endif | 203 #endif |
205 | 204 |
206 #if defined(ENABLE_WEBRTC) | 205 #if defined(ENABLE_WEBRTC) |
207 #include "content/renderer/media/rtc_peer_connection_handler.h" | 206 #include "content/renderer/media/rtc_peer_connection_handler.h" |
208 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" | 207 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" |
209 #endif | 208 #endif |
210 | 209 |
211 using blink::WebAXObject; | 210 using blink::WebAXObject; |
(...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1182 bool focused) { | 1181 bool focused) { |
1183 if (focused) | 1182 if (focused) |
1184 focused_pepper_plugin_ = instance; | 1183 focused_pepper_plugin_ = instance; |
1185 else if (focused_pepper_plugin_ == instance) | 1184 else if (focused_pepper_plugin_ == instance) |
1186 focused_pepper_plugin_ = NULL; | 1185 focused_pepper_plugin_ = NULL; |
1187 | 1186 |
1188 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME); | 1187 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME); |
1189 UpdateSelectionBounds(); | 1188 UpdateSelectionBounds(); |
1190 } | 1189 } |
1191 | 1190 |
1192 void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) { | |
1193 plugin_delegates_.insert(delegate); | |
1194 // If the renderer is visible, set initial visibility and focus state. | |
1195 if (!is_hidden()) { | |
1196 #if defined(OS_MACOSX) | 1191 #if defined(OS_MACOSX) |
1197 delegate->SetContainerVisibility(true); | |
1198 if (webview() && webview()->isActive()) | |
1199 delegate->SetWindowFocus(true); | |
1200 #endif | |
1201 } | |
1202 // Plugins start assuming the content has focus (so that they work in | |
1203 // environments where RenderView isn't hosting them), so we always have to | |
1204 // set the initial state. See webplugin_delegate_impl.h for details. | |
1205 delegate->SetContentAreaFocus(has_focus()); | |
1206 } | |
1207 | |
1208 void RenderViewImpl::UnregisterPluginDelegate( | |
1209 WebPluginDelegateProxy* delegate) { | |
1210 plugin_delegates_.erase(delegate); | |
1211 } | |
1212 | |
1213 #if defined(OS_MACOSX) | |
1214 void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) { | |
1215 Send(new ViewHostMsg_PluginFocusChanged(GetRoutingID(), focused, plugin_id)); | |
1216 } | |
1217 | |
1218 void RenderViewImpl::OnGetRenderedText() { | 1192 void RenderViewImpl::OnGetRenderedText() { |
1219 if (!webview()) | 1193 if (!webview()) |
1220 return; | 1194 return; |
1221 | 1195 |
1222 if (!webview()->mainFrame()->isWebLocalFrame()) | 1196 if (!webview()->mainFrame()->isWebLocalFrame()) |
1223 return; | 1197 return; |
1224 | 1198 |
1225 // Get rendered text from WebLocalFrame. | 1199 // Get rendered text from WebLocalFrame. |
1226 // TODO: Currently IPC truncates any data that has a | 1200 // TODO: Currently IPC truncates any data that has a |
1227 // size > kMaximumMessageSize. May be split the text into smaller chunks and | 1201 // size > kMaximumMessageSize. May be split the text into smaller chunks and |
1228 // send back using multiple IPC. See http://crbug.com/393444. | 1202 // send back using multiple IPC. See http://crbug.com/393444. |
1229 static const size_t kMaximumMessageSize = 8 * 1024 * 1024; | 1203 static const size_t kMaximumMessageSize = 8 * 1024 * 1024; |
1230 // TODO(dglazkov): Using this API is wrong. It's not OOPIF-compatible and | 1204 // TODO(dglazkov): Using this API is wrong. It's not OOPIF-compatible and |
1231 // sends text in the wrong order. See http://crbug.com/584798. | 1205 // sends text in the wrong order. See http://crbug.com/584798. |
1232 // TODO(dglazkov): WebFrameContentDumper should only be used for | 1206 // TODO(dglazkov): WebFrameContentDumper should only be used for |
1233 // testing purposes. See http://crbug.com/585164. | 1207 // testing purposes. See http://crbug.com/585164. |
1234 std::string text = | 1208 std::string text = |
1235 WebFrameContentDumper::dumpFrameTreeAsText( | 1209 WebFrameContentDumper::dumpFrameTreeAsText( |
1236 webview()->mainFrame()->toWebLocalFrame(), kMaximumMessageSize) | 1210 webview()->mainFrame()->toWebLocalFrame(), kMaximumMessageSize) |
1237 .utf8(); | 1211 .utf8(); |
1238 | 1212 |
1239 Send(new ViewMsg_GetRenderedTextCompleted(GetRoutingID(), text)); | 1213 Send(new ViewMsg_GetRenderedTextCompleted(GetRoutingID(), text)); |
1240 } | 1214 } |
1241 | |
1242 void RenderViewImpl::StartPluginIme() { | |
1243 IPC::Message* msg = new ViewHostMsg_StartPluginIme(GetRoutingID()); | |
1244 // This message can be sent during event-handling, and needs to be delivered | |
1245 // within that context. | |
1246 msg->set_unblock(true); | |
1247 Send(msg); | |
1248 } | |
1249 #endif // defined(OS_MACOSX) | 1215 #endif // defined(OS_MACOSX) |
1250 | 1216 |
1251 #endif // ENABLE_PLUGINS | 1217 #endif // ENABLE_PLUGINS |
1252 | 1218 |
1253 void RenderViewImpl::TransferActiveWheelFlingAnimation( | 1219 void RenderViewImpl::TransferActiveWheelFlingAnimation( |
1254 const blink::WebActiveWheelFlingParameters& params) { | 1220 const blink::WebActiveWheelFlingParameters& params) { |
1255 if (webview()) | 1221 if (webview()) |
1256 webview()->transferActiveWheelFlingAnimation(params); | 1222 webview()->transferActiveWheelFlingAnimation(params); |
1257 } | 1223 } |
1258 | 1224 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1383 IPC_MESSAGE_HANDLER(ViewMsg_SelectWordAroundCaret, OnSelectWordAroundCaret) | 1349 IPC_MESSAGE_HANDLER(ViewMsg_SelectWordAroundCaret, OnSelectWordAroundCaret) |
1384 IPC_MESSAGE_HANDLER(PageMsg_UpdateWindowScreenRect, | 1350 IPC_MESSAGE_HANDLER(PageMsg_UpdateWindowScreenRect, |
1385 OnUpdateWindowScreenRect) | 1351 OnUpdateWindowScreenRect) |
1386 #if defined(OS_ANDROID) | 1352 #if defined(OS_ANDROID) |
1387 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTopControlsState, | 1353 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTopControlsState, |
1388 OnUpdateTopControlsState) | 1354 OnUpdateTopControlsState) |
1389 IPC_MESSAGE_HANDLER(ViewMsg_ExtractSmartClipData, OnExtractSmartClipData) | 1355 IPC_MESSAGE_HANDLER(ViewMsg_ExtractSmartClipData, OnExtractSmartClipData) |
1390 #elif defined(OS_MACOSX) | 1356 #elif defined(OS_MACOSX) |
1391 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedText, | 1357 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedText, |
1392 OnGetRenderedText) | 1358 OnGetRenderedText) |
1393 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted, | |
1394 OnPluginImeCompositionCompleted) | |
1395 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose) | 1359 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose) |
1396 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility) | |
1397 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged) | |
1398 #endif | 1360 #endif |
1399 // Adding a new message? Add platform independent ones first, then put the | 1361 // Adding a new message? Add platform independent ones first, then put the |
1400 // platform specific ones at the end. | 1362 // platform specific ones at the end. |
1401 | 1363 |
1402 // Have the super handle all other messages. | 1364 // Have the super handle all other messages. |
1403 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) | 1365 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) |
1404 IPC_END_MESSAGE_MAP() | 1366 IPC_END_MESSAGE_MAP() |
1405 | 1367 |
1406 return handled; | 1368 return handled; |
1407 } | 1369 } |
(...skipping 1323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2731 void RenderViewImpl::OnSetBackgroundOpaque(bool opaque) { | 2693 void RenderViewImpl::OnSetBackgroundOpaque(bool opaque) { |
2732 if (frame_widget_) | 2694 if (frame_widget_) |
2733 frame_widget_->setIsTransparent(!opaque); | 2695 frame_widget_->setIsTransparent(!opaque); |
2734 if (compositor_) | 2696 if (compositor_) |
2735 compositor_->setHasTransparentBackground(!opaque); | 2697 compositor_->setHasTransparentBackground(!opaque); |
2736 } | 2698 } |
2737 | 2699 |
2738 void RenderViewImpl::OnSetActive(bool active) { | 2700 void RenderViewImpl::OnSetActive(bool active) { |
2739 if (webview()) | 2701 if (webview()) |
2740 webview()->setIsActive(active); | 2702 webview()->setIsActive(active); |
2741 | |
2742 #if defined(ENABLE_PLUGINS) && defined(OS_MACOSX) | |
2743 std::set<WebPluginDelegateProxy*>::iterator plugin_it; | |
2744 for (plugin_it = plugin_delegates_.begin(); | |
2745 plugin_it != plugin_delegates_.end(); ++plugin_it) { | |
2746 (*plugin_it)->SetWindowFocus(active); | |
2747 } | |
2748 #endif | |
2749 } | 2703 } |
2750 | 2704 |
2751 #if defined(OS_MACOSX) | |
2752 void RenderViewImpl::OnSetWindowVisibility(bool visible) { | |
2753 #if defined(ENABLE_PLUGINS) | |
2754 // Inform plugins that their container has changed visibility. | |
2755 std::set<WebPluginDelegateProxy*>::iterator plugin_it; | |
2756 for (plugin_it = plugin_delegates_.begin(); | |
2757 plugin_it != plugin_delegates_.end(); ++plugin_it) { | |
2758 (*plugin_it)->SetContainerVisibility(visible); | |
2759 } | |
2760 #endif | |
2761 } | |
2762 | |
2763 void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame, | |
2764 const gfx::Rect& view_frame) { | |
2765 #if defined(ENABLE_PLUGINS) | |
2766 // Inform plugins that their window's frame has changed. | |
2767 std::set<WebPluginDelegateProxy*>::iterator plugin_it; | |
2768 for (plugin_it = plugin_delegates_.begin(); | |
2769 plugin_it != plugin_delegates_.end(); ++plugin_it) { | |
2770 (*plugin_it)->WindowFrameChanged(window_frame, view_frame); | |
2771 } | |
2772 #endif | |
2773 } | |
2774 | |
2775 void RenderViewImpl::OnPluginImeCompositionCompleted(const base::string16& text, | |
2776 int plugin_id) { | |
2777 // WebPluginDelegateProxy is responsible for figuring out if this event | |
2778 // applies to it or not, so inform all the delegates. | |
2779 std::set<WebPluginDelegateProxy*>::iterator plugin_it; | |
2780 for (plugin_it = plugin_delegates_.begin(); | |
2781 plugin_it != plugin_delegates_.end(); ++plugin_it) { | |
2782 (*plugin_it)->ImeCompositionCompleted(text, plugin_id); | |
2783 } | |
2784 } | |
2785 #endif // OS_MACOSX | |
2786 | |
2787 void RenderViewImpl::CloseForFrame() { | 2705 void RenderViewImpl::CloseForFrame() { |
2788 DCHECK(frame_widget_); | 2706 DCHECK(frame_widget_); |
2789 frame_widget_->close(); | 2707 frame_widget_->close(); |
2790 frame_widget_ = nullptr; | 2708 frame_widget_ = nullptr; |
2791 } | 2709 } |
2792 | 2710 |
2793 void RenderViewImpl::Close() { | 2711 void RenderViewImpl::Close() { |
2794 // We need to grab a pointer to the doomed WebView before we destroy it. | 2712 // We need to grab a pointer to the doomed WebView before we destroy it. |
2795 WebView* doomed = webview(); | 2713 WebView* doomed = webview(); |
2796 RenderWidget::Close(); | 2714 RenderWidget::Close(); |
(...skipping 12 matching lines...) Expand all Loading... |
2809 speech_recognition_dispatcher_->AbortAllRecognitions(); | 2727 speech_recognition_dispatcher_->AbortAllRecognitions(); |
2810 #endif | 2728 #endif |
2811 | 2729 |
2812 if (webview()) | 2730 if (webview()) |
2813 webview()->setVisibilityState(visibilityState(), false); | 2731 webview()->setVisibilityState(visibilityState(), false); |
2814 | 2732 |
2815 #if defined(ENABLE_PLUGINS) | 2733 #if defined(ENABLE_PLUGINS) |
2816 for (PepperPluginSet::iterator i = active_pepper_instances_.begin(); | 2734 for (PepperPluginSet::iterator i = active_pepper_instances_.begin(); |
2817 i != active_pepper_instances_.end(); ++i) | 2735 i != active_pepper_instances_.end(); ++i) |
2818 (*i)->PageVisibilityChanged(false); | 2736 (*i)->PageVisibilityChanged(false); |
2819 | |
2820 #if defined(OS_MACOSX) | |
2821 // Inform NPAPI plugins that their container is no longer visible. | |
2822 std::set<WebPluginDelegateProxy*>::iterator plugin_it; | |
2823 for (plugin_it = plugin_delegates_.begin(); | |
2824 plugin_it != plugin_delegates_.end(); ++plugin_it) { | |
2825 (*plugin_it)->SetContainerVisibility(false); | |
2826 } | |
2827 #endif // OS_MACOSX | |
2828 #endif // ENABLE_PLUGINS | 2737 #endif // ENABLE_PLUGINS |
2829 } | 2738 } |
2830 | 2739 |
2831 void RenderViewImpl::OnWasShown(bool needs_repainting, | 2740 void RenderViewImpl::OnWasShown(bool needs_repainting, |
2832 const ui::LatencyInfo& latency_info) { | 2741 const ui::LatencyInfo& latency_info) { |
2833 RenderWidget::OnWasShown(needs_repainting, latency_info); | 2742 RenderWidget::OnWasShown(needs_repainting, latency_info); |
2834 | 2743 |
2835 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC) | 2744 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC) |
2836 RenderThreadImpl::current()->video_capture_impl_manager()-> | 2745 RenderThreadImpl::current()->video_capture_impl_manager()-> |
2837 SuspendDevices(false); | 2746 SuspendDevices(false); |
2838 #endif | 2747 #endif |
2839 | 2748 |
2840 if (webview()) | 2749 if (webview()) |
2841 webview()->setVisibilityState(visibilityState(), false); | 2750 webview()->setVisibilityState(visibilityState(), false); |
2842 | 2751 |
2843 #if defined(ENABLE_PLUGINS) | 2752 #if defined(ENABLE_PLUGINS) |
2844 for (PepperPluginSet::iterator i = active_pepper_instances_.begin(); | 2753 for (PepperPluginSet::iterator i = active_pepper_instances_.begin(); |
2845 i != active_pepper_instances_.end(); ++i) | 2754 i != active_pepper_instances_.end(); ++i) |
2846 (*i)->PageVisibilityChanged(true); | 2755 (*i)->PageVisibilityChanged(true); |
2847 | |
2848 #if defined(OS_MACOSX) | |
2849 // Inform NPAPI plugins that their container is now visible. | |
2850 std::set<WebPluginDelegateProxy*>::iterator plugin_it; | |
2851 for (plugin_it = plugin_delegates_.begin(); | |
2852 plugin_it != plugin_delegates_.end(); ++plugin_it) { | |
2853 (*plugin_it)->SetContainerVisibility(true); | |
2854 } | |
2855 #endif // OS_MACOSX | |
2856 #endif // ENABLE_PLUGINS | 2756 #endif // ENABLE_PLUGINS |
2857 } | 2757 } |
2858 | 2758 |
2859 GURL RenderViewImpl::GetURLForGraphicsContext3D() { | 2759 GURL RenderViewImpl::GetURLForGraphicsContext3D() { |
2860 DCHECK(webview()); | 2760 DCHECK(webview()); |
2861 if (webview()->mainFrame()->isWebLocalFrame()) | 2761 if (webview()->mainFrame()->isWebLocalFrame()) |
2862 return GURL(webview()->mainFrame()->document().url()); | 2762 return GURL(webview()->mainFrame()->document().url()); |
2863 else | 2763 else |
2864 return GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D"); | 2764 return GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D"); |
2865 } | 2765 } |
2866 | 2766 |
2867 void RenderViewImpl::OnSetFocus(bool enable) { | 2767 void RenderViewImpl::OnSetFocus(bool enable) { |
2868 // This message must always be received when the main frame is a | 2768 // This message must always be received when the main frame is a |
2869 // WebLocalFrame. | 2769 // WebLocalFrame. |
2870 CHECK(webview()->mainFrame()->isWebLocalFrame()); | 2770 CHECK(webview()->mainFrame()->isWebLocalFrame()); |
2871 SetFocus(enable); | 2771 SetFocus(enable); |
2872 } | 2772 } |
2873 | 2773 |
2874 void RenderViewImpl::SetFocus(bool enable) { | 2774 void RenderViewImpl::SetFocus(bool enable) { |
2875 has_focus_ = enable; | 2775 has_focus_ = enable; |
2876 RenderWidget::OnSetFocus(enable); | 2776 RenderWidget::OnSetFocus(enable); |
2877 | 2777 |
2878 #if defined(ENABLE_PLUGINS) | 2778 #if defined(ENABLE_PLUGINS) |
2879 if (webview() && webview()->isActive()) { | |
2880 // Notify all NPAPI plugins. | |
2881 std::set<WebPluginDelegateProxy*>::iterator plugin_it; | |
2882 for (plugin_it = plugin_delegates_.begin(); | |
2883 plugin_it != plugin_delegates_.end(); ++plugin_it) { | |
2884 #if defined(OS_MACOSX) | |
2885 // RenderWidget's call to setFocus can cause the underlying webview's | |
2886 // activation state to change just like a call to setIsActive. | |
2887 if (enable) | |
2888 (*plugin_it)->SetWindowFocus(true); | |
2889 #endif | |
2890 (*plugin_it)->SetContentAreaFocus(enable); | |
2891 } | |
2892 } | |
2893 // Notify all Pepper plugins. | 2779 // Notify all Pepper plugins. |
2894 for (PepperPluginSet::iterator i = active_pepper_instances_.begin(); | 2780 for (PepperPluginSet::iterator i = active_pepper_instances_.begin(); |
2895 i != active_pepper_instances_.end(); ++i) | 2781 i != active_pepper_instances_.end(); ++i) |
2896 (*i)->SetContentAreaFocus(enable); | 2782 (*i)->SetContentAreaFocus(enable); |
2897 #endif | 2783 #endif |
2898 // Notify all BrowserPlugins of the RenderView's focus state. | 2784 // Notify all BrowserPlugins of the RenderView's focus state. |
2899 if (BrowserPluginManager::Get()) | 2785 if (BrowserPluginManager::Get()) |
2900 BrowserPluginManager::Get()->UpdateFocusState(); | 2786 BrowserPluginManager::Get()->UpdateFocusState(); |
2901 } | 2787 } |
2902 | 2788 |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3441 if (IsUseZoomForDSFEnabled()) { | 3327 if (IsUseZoomForDSFEnabled()) { |
3442 webview()->setZoomFactorForDeviceScaleFactor(device_scale_factor_); | 3328 webview()->setZoomFactorForDeviceScaleFactor(device_scale_factor_); |
3443 } else { | 3329 } else { |
3444 webview()->setDeviceScaleFactor(device_scale_factor_); | 3330 webview()->setDeviceScaleFactor(device_scale_factor_); |
3445 } | 3331 } |
3446 webview()->settings()->setPreferCompositingToLCDTextEnabled( | 3332 webview()->settings()->setPreferCompositingToLCDTextEnabled( |
3447 PreferCompositingToLCDText(compositor_deps_, device_scale_factor_)); | 3333 PreferCompositingToLCDText(compositor_deps_, device_scale_factor_)); |
3448 } | 3334 } |
3449 | 3335 |
3450 } // namespace content | 3336 } // namespace content |
OLD | NEW |