diff options
-rw-r--r-- | ppapi/ppapi_shared.gypi | 2 | ||||
-rw-r--r-- | ppapi/proxy/ppapi_messages.h | 3 | ||||
-rw-r--r-- | ppapi/proxy/ppb_instance_proxy.cc | 32 | ||||
-rw-r--r-- | ppapi/proxy/ppb_instance_proxy.h | 7 | ||||
-rw-r--r-- | ppapi/thunk/ppb_instance_api.h | 9 | ||||
-rw-r--r-- | ppapi/thunk/ppb_messaging_thunk.cc | 32 | ||||
-rw-r--r-- | ppapi/thunk/ppb_zoom_thunk.cc | 43 | ||||
-rw-r--r-- | ppapi/thunk/thunk.h | 4 | ||||
-rw-r--r-- | webkit/plugins/ppapi/plugin_module.cc | 4 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.cc | 101 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.h | 15 |
11 files changed, 173 insertions, 79 deletions
diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi index 5422d94..476dc1f 100644 --- a/ppapi/ppapi_shared.gypi +++ b/ppapi/ppapi_shared.gypi @@ -106,6 +106,7 @@ 'thunk/ppb_instance_thunk.cc', 'thunk/ppb_layer_compositor_api.h', 'thunk/ppb_layer_compositor_thunk.cc', + 'thunk/ppb_messaging_thunk.cc', 'thunk/ppb_pdf_api.h', 'thunk/ppb_scrollbar_api.h', 'thunk/ppb_scrollbar_thunk.cc', @@ -125,6 +126,7 @@ 'thunk/ppb_video_layer_thunk.cc', 'thunk/ppb_widget_api.h', 'thunk/ppb_widget_thunk.cc', + 'thunk/ppb_zoom_thunk.cc', 'thunk/thunk.h', ], }, diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index 75f79ac..faba350 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -625,6 +625,9 @@ IPC_SYNC_MESSAGE_ROUTED1_2(PpapiHostMsg_PPBInstance_GetScreenSize, PP_Instance /* instance */, PP_Bool /* result */, PP_Size /* size */) +IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBInstance_PostMessage, + PP_Instance /* instance */, + pp::proxy::SerializedVar /* message */) IPC_SYNC_MESSAGE_ROUTED3_1( PpapiHostMsg_PPBPDF_GetFontFileWithFallback, diff --git a/ppapi/proxy/ppb_instance_proxy.cc b/ppapi/proxy/ppb_instance_proxy.cc index af12d28..98ae45d 100644 --- a/ppapi/proxy/ppb_instance_proxy.cc +++ b/ppapi/proxy/ppb_instance_proxy.cc @@ -16,6 +16,11 @@ #include "ppapi/thunk/enter.h" #include "ppapi/thunk/thunk.h" +// Windows headers interfere with this file. +#ifdef PostMessage +#undef PostMessage +#endif + using ppapi::thunk::EnterFunctionNoLock; using ppapi::thunk::EnterResourceNoLock; using ppapi::thunk::PPB_Instance_FunctionAPI; @@ -193,6 +198,26 @@ PP_Bool PPB_Instance_Proxy::GetScreenSize(PP_Instance instance, return result; } +void PPB_Instance_Proxy::ZoomChanged(PP_Instance instance, + double factor) { + // Not proxied yet. + NOTIMPLEMENTED(); +} + +void PPB_Instance_Proxy::ZoomLimitsChanged(PP_Instance instance, + double minimum_factor, + double maximium_factor) { + // Not proxied yet. + NOTIMPLEMENTED(); +} + +void PPB_Instance_Proxy::PostMessage(PP_Instance instance, + PP_Var message) { + dispatcher()->Send(new PpapiHostMsg_PPBInstance_PostMessage( + INTERFACE_ID_PPB_INSTANCE, + instance, SerializedVarSendInput(dispatcher(), message))); +} + void PPB_Instance_Proxy::OnMsgGetWindowObject( PP_Instance instance, SerializedVarReturnValue result) { @@ -264,5 +289,12 @@ void PPB_Instance_Proxy::OnMsgGetScreenSize(PP_Instance instance, *result = enter.functions()->GetScreenSize(instance, size); } +void PPB_Instance_Proxy::OnMsgPostMessage(PP_Instance instance, + SerializedVarReceiveInput message) { + EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, false); + if (enter.succeeded()) + enter.functions()->PostMessage(instance, message.Get(dispatcher())); +} + } // namespace proxy } // namespace pp diff --git a/ppapi/proxy/ppb_instance_proxy.h b/ppapi/proxy/ppb_instance_proxy.h index b765279..1a719ea6 100644 --- a/ppapi/proxy/ppb_instance_proxy.h +++ b/ppapi/proxy/ppb_instance_proxy.h @@ -51,6 +51,11 @@ class PPB_Instance_Proxy : public InterfaceProxy, virtual PP_Bool SetFullscreen(PP_Instance instance, PP_Bool fullscreen) OVERRIDE; virtual PP_Bool GetScreenSize(PP_Instance instance, PP_Size* size) OVERRIDE; + virtual void ZoomChanged(PP_Instance instance, double factor) OVERRIDE; + virtual void ZoomLimitsChanged(PP_Instance instance, + double minimum_factor, + double maximium_factor) OVERRIDE; + virtual void PostMessage(PP_Instance instance, PP_Var message) OVERRIDE; private: // Message handlers. @@ -72,6 +77,8 @@ class PPB_Instance_Proxy : public InterfaceProxy, void OnMsgGetScreenSize(PP_Instance instance, PP_Bool* result, PP_Size* size); + void OnMsgPostMessage(PP_Instance instance, + SerializedVarReceiveInput message); }; } // namespace proxy diff --git a/ppapi/thunk/ppb_instance_api.h b/ppapi/thunk/ppb_instance_api.h index 848a1fb..f77da8a 100644 --- a/ppapi/thunk/ppb_instance_api.h +++ b/ppapi/thunk/ppb_instance_api.h @@ -33,6 +33,15 @@ class PPB_Instance_FunctionAPI { virtual PP_Bool SetFullscreen(PP_Instance instance, PP_Bool fullscreen) = 0; virtual PP_Bool GetScreenSize(PP_Instance instance, PP_Size* size) = 0; + // Messaging. + virtual void PostMessage(PP_Instance instance, PP_Var message) = 0; + + // Zoom + virtual void ZoomChanged(PP_Instance instance, double factor) = 0; + virtual void ZoomLimitsChanged(PP_Instance instance, + double minimum_factor, + double maximium_factor) = 0; + static const ::pp::proxy::InterfaceID interface_id = ::pp::proxy::INTERFACE_ID_PPB_INSTANCE; }; diff --git a/ppapi/thunk/ppb_messaging_thunk.cc b/ppapi/thunk/ppb_messaging_thunk.cc new file mode 100644 index 0000000..8b534e0 --- /dev/null +++ b/ppapi/thunk/ppb_messaging_thunk.cc @@ -0,0 +1,32 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/c/ppb_messaging.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/thunk.h" +#include "ppapi/thunk/ppb_instance_api.h" + +namespace ppapi { +namespace thunk { + +namespace { + +void PostMessage(PP_Instance instance, PP_Var message) { + EnterFunction<PPB_Instance_FunctionAPI> enter(instance, true); + if (enter.succeeded()) + enter.functions()->PostMessage(instance, message); +} + +const PPB_Messaging g_ppb_messaging_thunk = { + &PostMessage +}; + +} // namespace + +const PPB_Messaging* GetPPB_Messaging_Thunk() { + return &g_ppb_messaging_thunk; +} + +} // namespace thunk +} // namespace ppapi diff --git a/ppapi/thunk/ppb_zoom_thunk.cc b/ppapi/thunk/ppb_zoom_thunk.cc new file mode 100644 index 0000000..e7e5236 --- /dev/null +++ b/ppapi/thunk/ppb_zoom_thunk.cc @@ -0,0 +1,43 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/c/dev/ppb_zoom_dev.h" +#include "ppapi/thunk/thunk.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_instance_api.h" + +namespace ppapi { +namespace thunk { + +namespace { + +void ZoomChanged(PP_Instance instance, double factor) { + EnterFunction<PPB_Instance_FunctionAPI> enter(instance, true); + if (enter.succeeded()) + enter.functions()->ZoomChanged(instance, factor); +} + +void ZoomLimitsChanged(PP_Instance instance, + double minimum_factor, + double maximum_factor) { + EnterFunction<PPB_Instance_FunctionAPI> enter(instance, true); + if (enter.succeeded()) { + enter.functions()->ZoomLimitsChanged(instance, + minimum_factor, maximum_factor); + } +} + +const PPB_Zoom_Dev g_ppb_zoom_thunk = { + &ZoomChanged, + &ZoomLimitsChanged +}; + +} // namespace + +const PPB_Zoom_Dev* GetPPB_Zoom_Thunk() { + return &g_ppb_zoom_thunk; +} + +} // namespace thunk +} // namespace ppapi diff --git a/ppapi/thunk/thunk.h b/ppapi/thunk/thunk.h index 9fb84b3..00c4ecf 100644 --- a/ppapi/thunk/thunk.h +++ b/ppapi/thunk/thunk.h @@ -35,6 +35,7 @@ struct PPB_ImageDataTrusted; struct PPB_Instance; struct PPB_Instance_Private; struct PPB_LayerCompositor_Dev; +struct PPB_Messaging; struct PPB_Scrollbar_0_4_Dev; struct PPB_Surface3D_Dev; struct PPB_Transport_Dev; @@ -45,6 +46,7 @@ struct PPB_URLResponseInfo; struct PPB_VideoDecoder_Dev; struct PPB_VideoLayer_Dev; struct PPB_Widget_Dev; +struct PPB_Zoom_Dev; #ifdef PPAPI_INSTANCE_REMOVE_SCRIPTING struct PPB_Instance_0_4; @@ -89,6 +91,7 @@ const PPB_Instance_0_4* GetPPB_Instance_0_4_Thunk(); const PPB_Instance_0_5* GetPPB_Instance_0_5_Thunk(); const PPB_Instance_Private* GetPPB_Instance_Private_Thunk(); const PPB_LayerCompositor_Dev* GetPPB_LayerCompositor_Thunk(); +const PPB_Messaging* GetPPB_Messaging_Thunk(); const PPB_Scrollbar_0_4_Dev* GetPPB_Scrollbar_Thunk(); const PPB_Surface3D_Dev* GetPPB_Surface3D_Thunk(); const PPB_Transport_Dev* GetPPB_Transport_Thunk(); @@ -99,6 +102,7 @@ const PPB_URLResponseInfo* GetPPB_URLResponseInfo_Thunk(); const PPB_VideoDecoder_Dev* GetPPB_VideoDecoder_Thunk(); const PPB_VideoLayer_Dev* GetPPB_VideoLayer_Thunk(); const PPB_Widget_Dev* GetPPB_Widget_Thunk(); +const PPB_Zoom_Dev* GetPPB_Zoom_Thunk(); } // namespace thunk } // namespace ppapi diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc index c9f98c6..db10e7f 100644 --- a/webkit/plugins/ppapi/plugin_module.cc +++ b/webkit/plugins/ppapi/plugin_module.cc @@ -297,7 +297,7 @@ const void* GetInterface(const char* name) { if (strcmp(name, PPB_MEMORY_DEV_INTERFACE) == 0) return PPB_Memory_Impl::GetInterface(); if (strcmp(name, PPB_MESSAGING_INTERFACE) == 0) - return PluginInstance::GetMessagingInterface(); + return ::ppapi::thunk::GetPPB_Messaging_Thunk(); if (strcmp(name, PPB_PROXY_PRIVATE_INTERFACE) == 0) return PPB_Proxy_Impl::GetInterface(); if (strcmp(name, PPB_SCROLLBAR_DEV_INTERFACE_0_4) == 0) @@ -327,7 +327,7 @@ const void* GetInterface(const char* name) { if (strcmp(name, PPB_WIDGET_DEV_INTERFACE) == 0) return ::ppapi::thunk::GetPPB_Widget_Thunk(); if (strcmp(name, PPB_ZOOM_DEV_INTERFACE) == 0) - return PluginInstance::GetZoomInterface(); + return ::ppapi::thunk::GetPPB_Zoom_Thunk(); #ifdef ENABLE_GPU // This should really refer to switches::kDisable3DAPIs. diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc index c166af0..a83bbf6 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc @@ -22,7 +22,6 @@ #include "ppapi/c/pp_var.h" #include "ppapi/c/ppb_core.h" #include "ppapi/c/ppb_instance.h" -#include "ppapi/c/ppb_messaging.h" #include "ppapi/c/ppp_instance.h" #include "ppapi/c/ppp_messaging.h" #include "ppapi/c/private/ppb_instance_private.h" @@ -182,59 +181,6 @@ void RectToPPRect(const gfx::Rect& input, PP_Rect* output) { input.width(), input.height()); } -void PostMessage(PP_Instance instance_id, PP_Var message) { - PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); - if (!instance) - return; - instance->PostMessage(message); -} - -const PPB_Messaging ppb_messaging = { - &PostMessage -}; - -void ZoomChanged(PP_Instance instance_id, double factor) { - PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); - if (!instance) - return; - - // We only want to tell the page to change its zoom if the whole page is the - // plugin. If we're in an iframe, then don't do anything. - if (!instance->IsFullPagePlugin()) - return; - - double zoom_level = WebView::zoomFactorToZoomLevel(factor); - // The conversino from zoom level to factor, and back, can introduce rounding - // errors. i.e. WebKit originally tells us 3.0, but by the time we tell the - // plugin and it tells us back, the level becomes 3.000000000004. Need to - // round or else otherwise if the user zooms out, it will go to 3.0 instead of - // 2.0. - int rounded = - static_cast<int>(zoom_level + (zoom_level > 0 ? 0.001 : -0.001)); - if (abs(rounded - zoom_level) < 0.001) - zoom_level = rounded; - instance->container()->zoomLevelChanged(zoom_level); -} - -void ZoomLimitsChanged(PP_Instance instance_id, - double minimum_factor, - double maximium_factor) { - if (minimum_factor > maximium_factor) { - NOTREACHED(); - return; - } - - PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); - if (!instance) - return; - instance->delegate()->ZoomLimitsChanged(minimum_factor, maximium_factor); -} - -const PPB_Zoom_Dev ppb_zoom = { - &ZoomChanged, - &ZoomLimitsChanged -}; - } // namespace // static @@ -315,16 +261,6 @@ PluginInstance::~PluginInstance() { ResourceTracker::Get()->InstanceDeleted(pp_instance_); } -// static -const PPB_Messaging* PluginInstance::GetMessagingInterface() { - return &ppb_messaging; -} - -// static -const PPB_Zoom_Dev* PluginInstance::GetZoomInterface() { - return &ppb_zoom; -} - // NOTE: Any of these methods that calls into the plugin needs to take into // account that the plugin may use Var to remove the <embed> from the DOM, which // will make the WebPluginImpl drop its reference, usually the last one. If a @@ -466,10 +402,6 @@ bool PluginInstance::SetCursor(PP_CursorType_Dev type, return true; } -void PluginInstance::PostMessage(PP_Var message) { - message_channel_->PostMessageToJavaScript(message); -} - bool PluginInstance::Initialize(WebPluginContainer* container, const std::vector<std::string>& arg_names, const std::vector<std::string>& arg_values, @@ -1508,5 +1440,38 @@ PP_Bool PluginInstance::GetScreenSize(PP_Instance instance, PP_Size* size) { return PP_TRUE; } +void PluginInstance::ZoomChanged(PP_Instance instance, double factor) { + // We only want to tell the page to change its zoom if the whole page is the + // plugin. If we're in an iframe, then don't do anything. + if (!IsFullPagePlugin()) + return; + + double zoom_level = WebView::zoomFactorToZoomLevel(factor); + // The conversino from zoom level to factor, and back, can introduce rounding + // errors. i.e. WebKit originally tells us 3.0, but by the time we tell the + // plugin and it tells us back, the level becomes 3.000000000004. Need to + // round or else otherwise if the user zooms out, it will go to 3.0 instead of + // 2.0. + int rounded = + static_cast<int>(zoom_level + (zoom_level > 0 ? 0.001 : -0.001)); + if (abs(rounded - zoom_level) < 0.001) + zoom_level = rounded; + container()->zoomLevelChanged(zoom_level); +} + +void PluginInstance::ZoomLimitsChanged(PP_Instance instance, + double minimum_factor, + double maximium_factor) { + if (minimum_factor > maximium_factor) { + NOTREACHED(); + return; + } + delegate()->ZoomLimitsChanged(minimum_factor, maximium_factor); +} + +void PluginInstance::PostMessage(PP_Instance instance, PP_Var message) { + message_channel_->PostMessageToJavaScript(message); +} + } // namespace ppapi } // namespace webkit diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.h b/webkit/plugins/ppapi/ppapi_plugin_instance.h index 7a5487c..9d8fc5de 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.h +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h @@ -34,8 +34,6 @@ typedef struct NPObject NPObject; struct PP_Var; -struct PPB_Messaging; -struct PPB_Zoom_Dev; struct PPP_Find_Dev; struct PPP_Instance_Private; struct PPP_Messaging; @@ -99,11 +97,6 @@ class PluginInstance : public base::RefCounted<PluginInstance>, // Delete should be called by the WebPlugin before this destructor. virtual ~PluginInstance(); - // Returns a pointer to the interface implementing PPB_Find that is - // exposed to the plugin. - static const PPB_Messaging* GetMessagingInterface(); - static const PPB_Zoom_Dev* GetZoomInterface(); - PluginDelegate* delegate() const { return delegate_; } PluginModule* module() const { return module_.get(); } MessageChannel& message_channel() { return *message_channel_; } @@ -241,8 +234,7 @@ class PluginInstance : public base::RefCounted<PluginInstance>, const char* target, bool from_user_action); - // Implementation of PPB_Messaging and PPP_Messaging. - void PostMessage(PP_Var message); + // Implementation of PPP_Messaging. void HandleMessage(PP_Var message); PluginDelegate::PlatformContext3D* CreateContext3D(); @@ -284,6 +276,11 @@ class PluginInstance : public base::RefCounted<PluginInstance>, virtual PP_Bool SetFullscreen(PP_Instance instance, PP_Bool fullscreen) OVERRIDE; virtual PP_Bool GetScreenSize(PP_Instance instance, PP_Size* size) OVERRIDE; + virtual void ZoomChanged(PP_Instance instance, double factor) OVERRIDE; + virtual void ZoomLimitsChanged(PP_Instance instance, + double minimum_factor, + double maximium_factor) OVERRIDE; + virtual void PostMessage(PP_Instance instance, PP_Var message) OVERRIDE; private: // See the static Create functions above for creating PluginInstance objects. |