Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(501)

Unified Diff: webkit/plugins/ppapi/ppapi_plugin_instance.cc

Issue 6538028: A proposal for an initial postMessage interface. This will allow JavaScript ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webkit/plugins/ppapi/ppapi_plugin_instance.cc
===================================================================
--- webkit/plugins/ppapi/ppapi_plugin_instance.cc (revision 77426)
+++ webkit/plugins/ppapi/ppapi_plugin_instance.cc (working copy)
@@ -42,6 +42,7 @@
#include "webkit/plugins/ppapi/common.h"
#include "webkit/plugins/ppapi/event_conversion.h"
#include "webkit/plugins/ppapi/fullscreen_container.h"
+#include "webkit/plugins/ppapi/message_channel.h"
#include "webkit/plugins/ppapi/plugin_delegate.h"
#include "webkit/plugins/ppapi/plugin_module.h"
#include "webkit/plugins/ppapi/plugin_object.h"
@@ -99,7 +100,8 @@
namespace {
#define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, np_name) \
- COMPILE_ASSERT(int(WebCursorInfo::webkit_name) == int(np_name), \
+ COMPILE_ASSERT(static_cast<int>(WebCursorInfo::webkit_name) \
+ == static_cast<int>(np_name), \
mismatching_enums)
COMPILE_ASSERT_MATCHING_ENUM(TypePointer, PP_CURSORTYPE_POINTER);
@@ -201,12 +203,20 @@
return instance->ExecuteScript(script, exception);
}
+void PostMessage(PP_Instance instance_id, PP_Var message) {
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
+ if (!instance)
+ return;
+ instance->PostMessage(message);
+}
+
const PPB_Instance ppb_instance = {
&GetWindowObject,
&GetOwnerElementObject,
&BindGraphics,
&IsFullFrame,
&ExecuteScript,
+ &PostMessage
};
void NumberOfFindResultsChanged(PP_Instance instance_id,
@@ -314,7 +324,8 @@
PluginInstance::PluginInstance(PluginDelegate* delegate,
PluginModule* module,
- const PPP_Instance* instance_interface)
+ const PPP_Instance* instance_interface,
+ InterfaceOwner ppp_instance_owner)
: delegate_(delegate),
module_(module),
instance_interface_(instance_interface),
@@ -335,13 +346,16 @@
plugin_graphics_3d_interface_(NULL),
always_on_top_(false),
fullscreen_container_(NULL),
- fullscreen_(false) {
+ fullscreen_(false),
+ message_channel_(NULL),
+ ppp_instance_owner_(ppp_instance_owner) {
pp_instance_ = ResourceTracker::Get()->AddInstance(this);
memset(&current_print_settings_, 0, sizeof(current_print_settings_));
DCHECK(delegate);
module_->InstanceCreated(this);
delegate_->InstanceCreated(this);
+ message_channel_.reset(new MessageChannel(this));
}
PluginInstance::~PluginInstance() {
@@ -363,11 +377,25 @@
#if defined(OS_LINUX)
ranges_.clear();
#endif // defined(OS_LINUX)
+
+ if (BROWSER_OWNS_INTERFACE == ppp_instance_owner_)
+ delete const_cast<PPP_Instance*>(instance_interface_);
}
// static
-const PPB_Instance* PluginInstance::GetInterface() {
- return &ppb_instance;
+const void* PluginInstance::GetInterface(const std::string& interface) {
+ // At the time of writing, we support both 0.4 and 0.5. But for future-
+ // proofing, we also compare to PPB_INSTANCE_INTERFACE so that we can work
+ // with later versions, assuming other parts work. If PPB_Instance changes
+ // in a fashion that breaks the struct layout (e.g. modifying or deleting
+ // functions), this code must either get more complicated (to return a
+ // different, backwards-compatible struct) or just get rid of support for
+ // 0.4 and 0.5.
+ if ((interface == PPB_INSTANCE_INTERFACE_0_4)
+ || (interface == PPB_INSTANCE_INTERFACE_0_5)
+ || (interface == PPB_INSTANCE_INTERFACE))
+ return &ppb_instance;
+ return NULL;
}
// static
@@ -590,6 +618,10 @@
return ret;
}
+void PluginInstance::PostMessage(PP_Var message) {
+ message_channel_->PostMessageToJavaScript(message);
+}
+
void PluginInstance::Delete() {
// Keep a reference on the stack. See NOTE above.
scoped_refptr<PluginInstance> ref(this);
@@ -649,6 +681,13 @@
return rv;
}
+void PluginInstance::HandleMessage(PP_Var message) {
+ if ((instance_interface_ != NULL) &&
+ (instance_interface_->HandleMessage != NULL)) {
+ instance_interface_->HandleMessage(pp_instance(), message);
+ }
+}
+
PP_Var PluginInstance::GetInstanceObject() {
return instance_interface_->GetInstanceObject(pp_instance());
}

Powered by Google App Engine
This is Rietveld 408576698