summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ppapi/c/dev/ppb_font_dev.h8
-rw-r--r--ppapi/c/dev/ppb_testing_dev.h9
-rw-r--r--ppapi/c/private/ppb_flash.h37
-rw-r--r--ppapi/ppapi.gyp2
-rw-r--r--ppapi/proxy/dispatcher.h1
-rw-r--r--ppapi/proxy/host_dispatcher.h1
-rw-r--r--ppapi/proxy/host_var_serialization_rules.cc14
-rw-r--r--ppapi/proxy/host_var_serialization_rules.h10
-rw-r--r--ppapi/proxy/image_data.cc7
-rw-r--r--ppapi/proxy/image_data.h9
-rw-r--r--ppapi/proxy/plugin_dispatcher.cc16
-rw-r--r--ppapi/proxy/plugin_dispatcher.h37
-rw-r--r--ppapi/proxy/plugin_resource.cc4
-rw-r--r--ppapi/proxy/plugin_resource.h13
-rw-r--r--ppapi/proxy/plugin_resource_tracker.cc32
-rw-r--r--ppapi/proxy/plugin_resource_tracker.h23
-rw-r--r--ppapi/proxy/plugin_var_serialization_rules.cc44
-rw-r--r--ppapi/proxy/plugin_var_serialization_rules.h12
-rw-r--r--ppapi/proxy/plugin_var_tracker.cc250
-rw-r--r--ppapi/proxy/plugin_var_tracker.h148
-rw-r--r--ppapi/proxy/ppapi_messages_internal.h19
-rw-r--r--ppapi/proxy/ppb_audio_config_proxy.cc36
-rw-r--r--ppapi/proxy/ppb_audio_proxy.cc32
-rw-r--r--ppapi/proxy/ppb_buffer_proxy.cc15
-rw-r--r--ppapi/proxy/ppb_char_set_proxy.cc22
-rw-r--r--ppapi/proxy/ppb_core_proxy.cc5
-rw-r--r--ppapi/proxy/ppb_cursor_control_proxy.cc36
-rw-r--r--ppapi/proxy/ppb_flash_proxy.cc126
-rw-r--r--ppapi/proxy/ppb_flash_proxy.h8
-rw-r--r--ppapi/proxy/ppb_font_proxy.cc56
-rw-r--r--ppapi/proxy/ppb_fullscreen_proxy.cc12
-rw-r--r--ppapi/proxy/ppb_graphics_2d_proxy.cc53
-rw-r--r--ppapi/proxy/ppb_image_data_proxy.cc47
-rw-r--r--ppapi/proxy/ppb_instance_proxy.cc31
-rw-r--r--ppapi/proxy/ppb_pdf_proxy.cc21
-rw-r--r--ppapi/proxy/ppb_testing_proxy.cc31
-rw-r--r--ppapi/proxy/ppb_testing_proxy.h6
-rw-r--r--ppapi/proxy/ppb_url_loader_proxy.cc75
-rw-r--r--ppapi/proxy/ppb_url_loader_proxy.h3
-rw-r--r--ppapi/proxy/ppb_url_request_info_proxy.cc50
-rw-r--r--ppapi/proxy/ppb_url_response_info_proxy.cc17
-rw-r--r--ppapi/proxy/ppb_url_response_info_proxy.h4
-rw-r--r--ppapi/proxy/ppb_var_deprecated_proxy.cc8
-rw-r--r--ppapi/proxy/ppp_instance_proxy.cc2
-rw-r--r--ppapi/proxy/serialized_var.cc38
-rw-r--r--ppapi/proxy/serialized_var.h2
-rw-r--r--ppapi/proxy/var_serialization_rules.h23
-rw-r--r--ppapi/shared_impl/DEPS4
-rw-r--r--ppapi/shared_impl/image_data_impl.cc29
-rw-r--r--ppapi/shared_impl/image_data_impl.h32
-rw-r--r--ppapi/tests/test_var_deprecated.cc16
-rw-r--r--webkit/plugins/ppapi/plugin_module.cc9
-rw-r--r--webkit/plugins/ppapi/ppb_audio_impl.cc12
-rw-r--r--webkit/plugins/ppapi/ppb_flash_impl.cc21
-rw-r--r--webkit/plugins/ppapi/ppb_flash_impl.h22
-rw-r--r--webkit/plugins/ppapi/ppb_flash_impl_linux.cc30
-rw-r--r--webkit/plugins/ppapi/ppb_font_impl.cc2
-rw-r--r--webkit/plugins/ppapi/ppb_image_data_impl.cc17
-rw-r--r--webkit/plugins/ppapi/ppb_image_data_impl.h12
-rw-r--r--webkit/plugins/ppapi/resource_tracker.cc19
-rw-r--r--webkit/plugins/ppapi/resource_tracker.h4
-rw-r--r--webkit/plugins/ppapi/resource_tracker_unittest.cc14
62 files changed, 1141 insertions, 557 deletions
diff --git a/ppapi/c/dev/ppb_font_dev.h b/ppapi/c/dev/ppb_font_dev.h
index e2bba3c..e15c11d 100644
--- a/ppapi/c/dev/ppb_font_dev.h
+++ b/ppapi/c/dev/ppb_font_dev.h
@@ -155,19 +155,23 @@ struct PPB_Font_Dev {
// Note that this function handles complex scripts such as Arabic, combining
// accents, etc. so that adding the width of substrings won't necessarily
// produce the correct width of the entire string.
+ //
+ // Returns -1 on failure.
int32_t (*MeasureText)(PP_Resource font,
const struct PP_TextRun_Dev* text);
// Returns the character at the given pixel X position from the beginning of
// the string. This handles complex scripts such as Arabic, where characters
- // may be combined or replaced depending on the context.
+ // may be combined or replaced depending on the context. Returns (uint32)-1
+ // on failure.
uint32_t (*CharacterOffsetForPixel)(PP_Resource font,
const struct PP_TextRun_Dev* text,
int32_t pixel_position);
// Returns the horizontal advance to the given character if the string was
// placed at the given position. This handles complex scripts such as Arabic,
- // where characters may be combined or replaced depending on context.
+ // where characters may be combined or replaced depending on context. Returns
+ // -1 on error.
int32_t (*PixelOffsetForCharacter)(PP_Resource font,
const struct PP_TextRun_Dev* text,
uint32_t char_offset);
diff --git a/ppapi/c/dev/ppb_testing_dev.h b/ppapi/c/dev/ppb_testing_dev.h
index 7383a65..30c004c1 100644
--- a/ppapi/c/dev/ppb_testing_dev.h
+++ b/ppapi/c/dev/ppb_testing_dev.h
@@ -6,13 +6,13 @@
#define PPAPI_C_DEV_PPB_TESTING_DEV_H_
#include "ppapi/c/pp_bool.h"
-#include "ppapi/c/pp_module.h"
+#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_resource.h"
#include "ppapi/c/pp_stdint.h"
struct PP_Point;
-#define PPB_TESTING_DEV_INTERFACE "PPB_Testing(Dev);0.4"
+#define PPB_TESTING_DEV_INTERFACE "PPB_Testing(Dev);0.5"
// This interface contains functions used for unit testing. Do not use in
// production code. They are not guaranteed to be available in normal plugin
@@ -64,8 +64,9 @@ struct PPB_Testing_Dev {
void (*QuitMessageLoop)();
// Returns the number of live objects (resources + strings + objects)
- // associated with this plugin module. Used for detecting leaks.
- uint32_t (*GetLiveObjectCount)(PP_Module module);
+ // associated with this plugin instance. Used for detecting leaks. Returns
+ // (uint32_t)-1 on failure.
+ uint32_t (*GetLiveObjectsForInstance)(PP_Instance instance);
};
#endif /* PPAPI_C_DEV_PPB_TESTING_DEV_H_ */
diff --git a/ppapi/c/private/ppb_flash.h b/ppapi/c/private/ppb_flash.h
index f689772..a7a5bab 100644
--- a/ppapi/c/private/ppb_flash.h
+++ b/ppapi/c/private/ppb_flash.h
@@ -9,6 +9,7 @@
#include <windows.h>
#endif
+#include "ppapi/c/pp_bool.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_point.h"
@@ -18,7 +19,7 @@
// PPB_Flash -------------------------------------------------------------------
-#define PPB_FLASH_INTERFACE "PPB_Flash;3"
+#define PPB_FLASH_INTERFACE "PPB_Flash;4"
#ifdef _WIN32
typedef HANDLE PP_FileHandle;
@@ -34,7 +35,7 @@ struct PP_FileInfo_Dev;
struct PP_DirEntry_Dev {
const char* name;
- bool is_dir;
+ PP_Bool is_dir;
};
struct PP_DirContents_Dev {
@@ -46,18 +47,18 @@ struct PPB_Flash {
// Sets or clears the rendering hint that the given plugin instance is always
// on top of page content. Somewhat more optimized painting can be used in
// this case.
- void (*SetInstanceAlwaysOnTop)(PP_Instance instance, bool on_top);
-
- bool (*DrawGlyphs)(PP_Instance instance,
- PP_Resource pp_image_data,
- const PP_FontDescription_Dev* font_desc,
- uint32_t color,
- PP_Point position,
- PP_Rect clip,
- const float transformation[3][3],
- uint32_t glyph_count,
- const uint16_t glyph_indices[],
- const PP_Point glyph_advances[]);
+ void (*SetInstanceAlwaysOnTop)(PP_Instance instance, PP_Bool on_top);
+
+ PP_Bool (*DrawGlyphs)(PP_Instance instance,
+ PP_Resource pp_image_data,
+ const PP_FontDescription_Dev* font_desc,
+ uint32_t color,
+ PP_Point position,
+ PP_Rect clip,
+ const float transformation[3][3],
+ uint32_t glyph_count,
+ const uint16_t glyph_indices[],
+ const PP_Point glyph_advances[]);
// Retrieves the proxy that will be used for the given URL. The result will
// be a string in PAC format, or an undefined var on error.
@@ -85,7 +86,7 @@ struct PPB_Flash {
// case of failure.
int32_t (*DeleteModuleLocalFileOrDir)(PP_Instance instance,
const char* path,
- bool recursive);
+ PP_Bool recursive);
// Creates a module-local directory. The return value is the ppapi error,
// PP_OK if success, one of the PP_ERROR_* in case of failure.
@@ -112,9 +113,9 @@ struct PPB_Flash {
// Navigate to URL. May open a new tab if target is not "_self". Return true
// if success. This differs from javascript:window.open() in that it bypasses
// the popup blocker, even when this is not called from an event handler.
- bool (*NavigateToURL)(PP_Instance instance,
- const char* url,
- const char* target);
+ PP_Bool (*NavigateToURL)(PP_Instance instance,
+ const char* url,
+ const char* target);
};
// PPB_Flash_NetConnector ------------------------------------------------------
diff --git a/ppapi/ppapi.gyp b/ppapi/ppapi.gyp
index 1a04afa..90bd2d1 100644
--- a/ppapi/ppapi.gyp
+++ b/ppapi/ppapi.gyp
@@ -576,6 +576,8 @@
'sources': [
'shared_impl/audio_impl.cc',
'shared_impl/audio_impl.h',
+ 'shared_impl/image_data_impl.cc',
+ 'shared_impl/image_data_impl.h',
],
'conditions': [
['OS=="win"', {
diff --git a/ppapi/proxy/dispatcher.h b/ppapi/proxy/dispatcher.h
index 2aec49c..8ef243b 100644
--- a/ppapi/proxy/dispatcher.h
+++ b/ppapi/proxy/dispatcher.h
@@ -18,7 +18,6 @@
#include "ppapi/c/pp_module.h"
#include "ppapi/proxy/callback_tracker.h"
#include "ppapi/proxy/interface_id.h"
-#include "ppapi/proxy/plugin_resource_tracker.h"
#include "ppapi/proxy/plugin_var_tracker.h"
class MessageLoop;
diff --git a/ppapi/proxy/host_dispatcher.h b/ppapi/proxy/host_dispatcher.h
index 44d133a..2112405 100644
--- a/ppapi/proxy/host_dispatcher.h
+++ b/ppapi/proxy/host_dispatcher.h
@@ -13,7 +13,6 @@
#include "base/scoped_ptr.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi/proxy/dispatcher.h"
-#include "ppapi/proxy/plugin_resource_tracker.h"
#include "ppapi/proxy/plugin_var_tracker.h"
struct PPB_Var_Deprecated;
diff --git a/ppapi/proxy/host_var_serialization_rules.cc b/ppapi/proxy/host_var_serialization_rules.cc
index 9ca6a15..f6f00f7 100644
--- a/ppapi/proxy/host_var_serialization_rules.cc
+++ b/ppapi/proxy/host_var_serialization_rules.cc
@@ -20,15 +20,17 @@ HostVarSerializationRules::HostVarSerializationRules(
HostVarSerializationRules::~HostVarSerializationRules() {
}
-void HostVarSerializationRules::SendCallerOwned(const PP_Var& var,
- std::string* str_val) {
+PP_Var HostVarSerializationRules::SendCallerOwned(const PP_Var& var,
+ std::string* str_val) {
if (var.type == PP_VARTYPE_STRING)
VarToString(var, str_val);
+ return var;
}
PP_Var HostVarSerializationRules::BeginReceiveCallerOwned(
const PP_Var& var,
- const std::string* str_val) {
+ const std::string* str_val,
+ Dispatcher* /* dispatcher */) {
if (var.type == PP_VARTYPE_STRING) {
// Convert the string to the context of the current process.
return var_interface_->VarFromUtf8(pp_module_, str_val->c_str(),
@@ -45,7 +47,8 @@ void HostVarSerializationRules::EndReceiveCallerOwned(const PP_Var& var) {
}
PP_Var HostVarSerializationRules::ReceivePassRef(const PP_Var& var,
- const std::string& str_val) {
+ const std::string& str_val,
+ Dispatcher* /* dispatcher */) {
if (var.type == PP_VARTYPE_STRING) {
// Convert the string to the context of the current process.
return var_interface_->VarFromUtf8(pp_module_, str_val.c_str(),
@@ -58,12 +61,13 @@ PP_Var HostVarSerializationRules::ReceivePassRef(const PP_Var& var,
return var;
}
-void HostVarSerializationRules::BeginSendPassRef(const PP_Var& var,
+PP_Var HostVarSerializationRules::BeginSendPassRef(const PP_Var& var,
std::string* str_val) {
// See PluginVarSerialization::ReceivePassRef for an example. We don't need
// to do anything here other than convert the string.
if (var.type == PP_VARTYPE_STRING)
VarToString(var, str_val);
+ return var;
}
void HostVarSerializationRules::EndSendPassRef(const PP_Var& var) {
diff --git a/ppapi/proxy/host_var_serialization_rules.h b/ppapi/proxy/host_var_serialization_rules.h
index 92e294f..2455c81 100644
--- a/ppapi/proxy/host_var_serialization_rules.h
+++ b/ppapi/proxy/host_var_serialization_rules.h
@@ -24,13 +24,15 @@ class HostVarSerializationRules : public VarSerializationRules {
~HostVarSerializationRules();
// VarSerialization implementation.
- virtual void SendCallerOwned(const PP_Var& var, std::string* str_val);
+ virtual PP_Var SendCallerOwned(const PP_Var& var, std::string* str_val);
virtual PP_Var BeginReceiveCallerOwned(const PP_Var& var,
- const std::string* str_val);
+ const std::string* str_val,
+ Dispatcher* dispatcher);
virtual void EndReceiveCallerOwned(const PP_Var& var);
virtual PP_Var ReceivePassRef(const PP_Var& var,
- const std::string& str_val);
- virtual void BeginSendPassRef(const PP_Var& var, std::string* str_val);
+ const std::string& str_val,
+ Dispatcher* dispatcher);
+ virtual PP_Var BeginSendPassRef(const PP_Var& var, std::string* str_val);
virtual void EndSendPassRef(const PP_Var& var);
virtual void ReleaseObjectRef(const PP_Var& var);
diff --git a/ppapi/proxy/image_data.cc b/ppapi/proxy/image_data.cc
index 65da4bb..8042c38 100644
--- a/ppapi/proxy/image_data.cc
+++ b/ppapi/proxy/image_data.cc
@@ -16,8 +16,11 @@
namespace pp {
namespace proxy {
-ImageData::ImageData(const PP_ImageDataDesc& desc, ImageHandle handle)
- : desc_(desc),
+ImageData::ImageData(PP_Instance instance,
+ const PP_ImageDataDesc& desc,
+ ImageHandle handle)
+ : PluginResource(instance),
+ desc_(desc),
handle_(handle),
mapped_data_(NULL) {
}
diff --git a/ppapi/proxy/image_data.h b/ppapi/proxy/image_data.h
index 6e962ab..539a475 100644
--- a/ppapi/proxy/image_data.h
+++ b/ppapi/proxy/image_data.h
@@ -6,16 +6,21 @@
#define PPAPI_PROXY_IMAGE_DATA_H_
#include "base/shared_memory.h"
+#include "ppapi/c/pp_instance.h"
#include "ppapi/c/ppb_image_data.h"
#include "ppapi/proxy/plugin_resource.h"
#include "ppapi/proxy/serialized_structs.h"
+#include "ppapi/shared_impl/image_data_impl.h"
namespace pp {
namespace proxy {
-class ImageData : public PluginResource {
+class ImageData : public PluginResource,
+ public pp::shared_impl::ImageDataImpl {
public:
- ImageData(const PP_ImageDataDesc& desc, ImageHandle handle);
+ ImageData(PP_Instance instance,
+ const PP_ImageDataDesc& desc,
+ ImageHandle handle);
virtual ~ImageData();
// Resource overrides.
diff --git a/ppapi/proxy/plugin_dispatcher.cc b/ppapi/proxy/plugin_dispatcher.cc
index ff7ccb7..8de9cea 100644
--- a/ppapi/proxy/plugin_dispatcher.cc
+++ b/ppapi/proxy/plugin_dispatcher.cc
@@ -36,13 +36,8 @@ PluginDispatcher::PluginDispatcher(base::ProcessHandle remote_process_handle,
ShutdownModuleFunc shutdown_module)
: Dispatcher(remote_process_handle, get_interface),
init_module_(init_module),
- shutdown_module_(shutdown_module),
- plugin_resource_tracker_(new PluginResourceTracker(
- ALLOW_THIS_IN_INITIALIZER_LIST(this))),
- plugin_var_tracker_(new PluginVarTracker(
- ALLOW_THIS_IN_INITIALIZER_LIST(this))) {
- SetSerializationRules(
- new PluginVarSerializationRules(plugin_var_tracker_.get()));
+ shutdown_module_(shutdown_module) {
+ SetSerializationRules(new PluginVarSerializationRules);
// As a plugin, we always support the PPP_Class interface. There's no
// GetInterface call or name for it, so we insert it into our table now.
@@ -66,6 +61,13 @@ void PluginDispatcher::SetGlobal(PluginDispatcher* dispatcher) {
g_dispatcher = dispatcher;
}
+// static
+PluginDispatcher* PluginDispatcher::GetForInstance(PP_Instance instance) {
+ // TODO(brettw) implement "real" per-instance dispatcher map.
+ DCHECK(instance != 0);
+ return Get();
+}
+
bool PluginDispatcher::IsPlugin() const {
return true;
}
diff --git a/ppapi/proxy/plugin_dispatcher.h b/ppapi/proxy/plugin_dispatcher.h
index 924b611..6ce5c14 100644
--- a/ppapi/proxy/plugin_dispatcher.h
+++ b/ppapi/proxy/plugin_dispatcher.h
@@ -9,10 +9,8 @@
#include "base/process.h"
#include "base/scoped_ptr.h"
-#include "ppapi/proxy/callback_tracker.h"
+#include "ppapi/c/pp_instance.h"
#include "ppapi/proxy/dispatcher.h"
-#include "ppapi/proxy/plugin_resource_tracker.h"
-#include "ppapi/proxy/plugin_var_tracker.h"
class MessageLoop;
@@ -36,30 +34,30 @@ class PluginDispatcher : public Dispatcher {
ShutdownModuleFunc shutdown_module);
~PluginDispatcher();
- // The plugin maintains a global Dispatcher pointer. There is only one since
- // there is only one connection to the browser. Don't call this on the
- // browser side, see GetForInstnace.
+ // Sets/gets the global dispatcher pointer. New code should use the
+ // GetForInstance version below, this is currently here as a stopgap while
+ // the transition is being made.
+ //
+ // TODO(brettw) remove this.
static PluginDispatcher* Get();
static void SetGlobal(PluginDispatcher* dispatcher);
+ // The plugin side maintains a mapping from PP_Instance to Dispatcher so
+ // that we can send the messages to the right channel if there are multiple
+ // renderers sharing the same plugin.
+ static PluginDispatcher* GetForInstance(PP_Instance instance);
+ /* TODO(brettw) enable this when Get() is removed.
+ static void SetForInstance(PP_Instance instance,
+ PluginDispatcher* dispatcher);
+ static void RemoveForInstance(PP_Instance instance);
+ */
+
// Dispatcher overrides.
virtual bool IsPlugin() const;
// IPC::Channel::Listener implementation.
virtual bool OnMessageReceived(const IPC::Message& msg);
- // Returns the resource tracker for the plugin. In the browser process this
- // will return NULL.
- PluginResourceTracker* plugin_resource_tracker() {
- return plugin_resource_tracker_.get();
- }
-
- // Returns the var tracker for the plugin. In the browser process this
- // will return NULL.
- PluginVarTracker* plugin_var_tracker() {
- return plugin_var_tracker_.get();
- }
-
private:
// IPC message handlers.
void OnMsgInitializeModule(PP_Module pp_module, bool* result);
@@ -68,9 +66,6 @@ class PluginDispatcher : public Dispatcher {
InitModuleFunc init_module_;
ShutdownModuleFunc shutdown_module_;
- scoped_ptr<PluginResourceTracker> plugin_resource_tracker_;
- scoped_ptr<PluginVarTracker> plugin_var_tracker_;
-
DISALLOW_COPY_AND_ASSIGN(PluginDispatcher);
};
diff --git a/ppapi/proxy/plugin_resource.cc b/ppapi/proxy/plugin_resource.cc
index 05803ef..809ea40 100644
--- a/ppapi/proxy/plugin_resource.cc
+++ b/ppapi/proxy/plugin_resource.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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.
@@ -7,7 +7,7 @@
namespace pp {
namespace proxy {
-PluginResource::PluginResource() {
+PluginResource::PluginResource(PP_Instance instance) : instance_(instance) {
}
PluginResource::~PluginResource() {
diff --git a/ppapi/proxy/plugin_resource.h b/ppapi/proxy/plugin_resource.h
index 780a2bd..8eee931 100644
--- a/ppapi/proxy/plugin_resource.h
+++ b/ppapi/proxy/plugin_resource.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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.
@@ -6,6 +6,7 @@
#define PPAPI_PROXY_PLUGIN_RESOURCE_H_
#include "base/basictypes.h"
+#include "ppapi/c/pp_instance.h"
#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/plugin_resource_tracker.h"
@@ -32,19 +33,20 @@ FOR_ALL_PLUGIN_RESOURCES(DECLARE_RESOURCE_CLASS)
class PluginResource {
public:
- PluginResource();
+ PluginResource(PP_Instance instance);
virtual ~PluginResource();
// Returns NULL if the resource is invalid or is a different type.
template<typename T> static T* GetAs(PP_Resource res) {
PluginResource* resource =
- PluginDispatcher::Get()->plugin_resource_tracker()->GetResourceObject(
- res);
+ PluginResourceTracker::GetInstance()->GetResourceObject(res);
return resource ? resource->Cast<T>() : NULL;
}
template <typename T> T* Cast() { return NULL; }
+ PP_Instance instance() const { return instance_; }
+
private:
// Type-specific getters for individual resource types. These will return
// NULL if the resource does not match the specified type. Used by the Cast()
@@ -54,6 +56,9 @@ class PluginResource {
FOR_ALL_PLUGIN_RESOURCES(DEFINE_TYPE_GETTER)
#undef DEFINE_TYPE_GETTER
+ // Instance this resource is associated with.
+ PP_Instance instance_;
+
DISALLOW_COPY_AND_ASSIGN(PluginResource);
};
diff --git a/ppapi/proxy/plugin_resource_tracker.cc b/ppapi/proxy/plugin_resource_tracker.cc
index 84a0054..f81a5f3 100644
--- a/ppapi/proxy/plugin_resource_tracker.cc
+++ b/ppapi/proxy/plugin_resource_tracker.cc
@@ -5,6 +5,7 @@
#include "ppapi/proxy/plugin_resource_tracker.h"
#include "base/logging.h"
+#include "base/singleton.h"
#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/plugin_resource.h"
@@ -38,13 +39,17 @@ PluginResourceTracker::ResourceInfo::operator=(
return *this;
}
-PluginResourceTracker::PluginResourceTracker(PluginDispatcher* dispatcher)
- : dispatcher_(dispatcher) {
+PluginResourceTracker::PluginResourceTracker() {
}
PluginResourceTracker::~PluginResourceTracker() {
}
+// static
+PluginResourceTracker* PluginResourceTracker::GetInstance() {
+ return Singleton<PluginResourceTracker>::get();
+}
+
PluginResource* PluginResourceTracker::GetResourceObject(
PP_Resource pp_resource) {
ResourceMap::iterator found = resource_map_.find(pp_resource);
@@ -81,8 +86,8 @@ bool PluginResourceTracker::PreparePreviouslyTrackedResource(
// in the plugin for the additional ref, and then a Release in the renderer
// because the code in the renderer addrefed on behalf of the caller.
found->second.ref_count++;
- dispatcher_->Send(new PpapiHostMsg_PPBCore_ReleaseResource(
- INTERFACE_ID_PPB_CORE, resource));
+
+ SendReleaseResourceToHost(resource, found->second.resource.get());
return true;
}
@@ -94,13 +99,24 @@ void PluginResourceTracker::ReleasePluginResourceRef(
return;
found->second.ref_count--;
if (found->second.ref_count == 0) {
- if (notify_browser_on_release) {
- dispatcher_->Send(new PpapiHostMsg_PPBCore_ReleaseResource(
- INTERFACE_ID_PPB_CORE, resource));
- }
+ if (notify_browser_on_release)
+ SendReleaseResourceToHost(resource, found->second.resource.get());
resource_map_.erase(found);
}
}
+void PluginResourceTracker::SendReleaseResourceToHost(
+ PP_Resource resource_id,
+ PluginResource* resource) {
+ PluginDispatcher* dispatcher =
+ PluginDispatcher::GetForInstance(resource->instance());
+ if (dispatcher) {
+ dispatcher->Send(new PpapiHostMsg_PPBCore_ReleaseResource(
+ INTERFACE_ID_PPB_CORE, resource_id));
+ } else {
+ NOTREACHED();
+ }
+}
+
} // namespace proxy
} // namespace pp
diff --git a/ppapi/proxy/plugin_resource_tracker.h b/ppapi/proxy/plugin_resource_tracker.h
index a758744..ba6ddb3 100644
--- a/ppapi/proxy/plugin_resource_tracker.h
+++ b/ppapi/proxy/plugin_resource_tracker.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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.
@@ -13,6 +13,8 @@
#include "ppapi/c/pp_resource.h"
#include "ppapi/c/pp_var.h"
+template<typename T> struct DefaultSingletonTraits;
+
namespace pp {
namespace proxy {
@@ -21,8 +23,8 @@ class PluginResource;
class PluginResourceTracker {
public:
- PluginResourceTracker(PluginDispatcher* dispatcher);
- ~PluginResourceTracker();
+ // Returns the global singleton resource tracker for the plugin.
+ static PluginResourceTracker* GetInstance();
// Returns the object associated with the given resource ID, or NULL if
// there isn't one.
@@ -50,15 +52,20 @@ class PluginResourceTracker {
//
// PP_Resource result;
// dispatcher->Send(new MyMessage(..., &result));
- // if (dispatcher->plugin_resource_tracker()->
+ // if (PluginResourceTracker::GetInstance()->
// PreparePreviouslyTrackedResource(result))
// return result;
// ... create resource object ...
- // dispatcher->plugin_resource_tracker()->AddResource(result, object);
+ // PluginResourceTracker::GetInstance()->AddResource(result, object);
// return result;
bool PreparePreviouslyTrackedResource(PP_Resource resource);
private:
+ friend struct DefaultSingletonTraits<PluginResourceTracker>;
+
+ PluginResourceTracker();
+ ~PluginResourceTracker();
+
struct ResourceInfo {
ResourceInfo();
ResourceInfo(int ref_count, linked_ptr<PluginResource> r);
@@ -74,8 +81,10 @@ class PluginResourceTracker {
void ReleasePluginResourceRef(const PP_Resource& var,
bool notify_browser_on_release);
- // Pointer to the dispatcher that owns us.
- PluginDispatcher* dispatcher_;
+ // Sends a ReleaseResource message to the host corresponding to the given
+ // resource.
+ void SendReleaseResourceToHost(PP_Resource resource_id,
+ PluginResource* resource);
typedef std::map<PP_Resource, ResourceInfo> ResourceMap;
ResourceMap resource_map_;
diff --git a/ppapi/proxy/plugin_var_serialization_rules.cc b/ppapi/proxy/plugin_var_serialization_rules.cc
index d01f8d5..7828587 100644
--- a/ppapi/proxy/plugin_var_serialization_rules.cc
+++ b/ppapi/proxy/plugin_var_serialization_rules.cc
@@ -1,33 +1,39 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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/proxy/plugin_var_serialization_rules.h"
+#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/plugin_var_tracker.h"
namespace pp {
namespace proxy {
-PluginVarSerializationRules::PluginVarSerializationRules(
- PluginVarTracker* var_tracker)
- : var_tracker_(var_tracker) {
+PluginVarSerializationRules::PluginVarSerializationRules()
+ : var_tracker_(PluginVarTracker::GetInstance()) {
}
PluginVarSerializationRules::~PluginVarSerializationRules() {
}
-void PluginVarSerializationRules::SendCallerOwned(const PP_Var& var,
- std::string* str_val) {
+PP_Var PluginVarSerializationRules::SendCallerOwned(const PP_Var& var,
+ std::string* str_val) {
+ // Objects need special translations to get the IDs valid in the host.
+ if (var.type == PP_VARTYPE_OBJECT)
+ return var_tracker_->GetHostObject(var);
+
// Nothing to do since we manage the refcount, other than retrieve the string
// to use for IPC.
if (var.type == PP_VARTYPE_STRING)
*str_val = var_tracker_->GetString(var);
+ return var;
}
PP_Var PluginVarSerializationRules::BeginReceiveCallerOwned(
const PP_Var& var,
- const std::string* str_val) {
+ const std::string* str_val,
+ Dispatcher* dispatcher) {
if (var.type == PP_VARTYPE_STRING) {
// Convert the string to the context of the current process.
PP_Var ret;
@@ -36,6 +42,9 @@ PP_Var PluginVarSerializationRules::BeginReceiveCallerOwned(
return ret;
}
+ if (var.type == PP_VARTYPE_OBJECT)
+ return var_tracker_->TrackObjectWithNoReference(var, dispatcher);
+
return var;
}
@@ -43,11 +52,14 @@ void PluginVarSerializationRules::EndReceiveCallerOwned(const PP_Var& var) {
if (var.type == PP_VARTYPE_STRING) {
// Destroy the string BeginReceiveCallerOwned created above.
var_tracker_->Release(var);
+ } else if (var.type == PP_VARTYPE_OBJECT) {
+ var_tracker_->StopTrackingObjectWithNoReference(var);
}
}
PP_Var PluginVarSerializationRules::ReceivePassRef(const PP_Var& var,
- const std::string& str_val) {
+ const std::string& str_val,
+ Dispatcher* dispatcher) {
if (var.type == PP_VARTYPE_STRING) {
// Convert the string to the context of the current process.
PP_Var ret;
@@ -72,13 +84,16 @@ PP_Var PluginVarSerializationRules::ReceivePassRef(const PP_Var& var,
// on behalf of the caller. This needs to be transferred to the plugin and
// folded in to its set of refs it maintains (with one ref representing all
// fo them in the browser).
- if (var.type == PP_VARTYPE_OBJECT)
- var_tracker_->ReceiveObjectPassRef(var);
+ if (var.type == PP_VARTYPE_OBJECT) {
+ return var_tracker_->ReceiveObjectPassRef(var, dispatcher);
+ }
+
+ // Other types are unchanged.
return var;
}
-void PluginVarSerializationRules::BeginSendPassRef(const PP_Var& var,
- std::string* str_val) {
+PP_Var PluginVarSerializationRules::BeginSendPassRef(const PP_Var& var,
+ std::string* str_val) {
// Overview of sending an object with "pass ref" from the plugin to the
// browser:
// Example 1 Example 2
@@ -94,8 +109,13 @@ void PluginVarSerializationRules::BeginSendPassRef(const PP_Var& var,
// transferring the object ref to the browser involves no net change in the
// browser's refcount.
+ // Objects need special translations to get the IDs valid in the host.
+ if (var.type == PP_VARTYPE_OBJECT)
+ return var_tracker_->GetHostObject(var);
+
if (var.type == PP_VARTYPE_STRING)
*str_val = var_tracker_->GetString(var);
+ return var;
}
void PluginVarSerializationRules::EndSendPassRef(const PP_Var& var) {
diff --git a/ppapi/proxy/plugin_var_serialization_rules.h b/ppapi/proxy/plugin_var_serialization_rules.h
index 6f302f2..36e58e7 100644
--- a/ppapi/proxy/plugin_var_serialization_rules.h
+++ b/ppapi/proxy/plugin_var_serialization_rules.h
@@ -18,17 +18,19 @@ class PluginVarSerializationRules : public VarSerializationRules {
public:
// This class will use the given non-owning pointer to the var tracker to
// handle object refcounting and string conversion.
- PluginVarSerializationRules(PluginVarTracker* tracker);
+ PluginVarSerializationRules();
~PluginVarSerializationRules();
// VarSerialization implementation.
- virtual void SendCallerOwned(const PP_Var& var, std::string* str_val);
+ virtual PP_Var SendCallerOwned(const PP_Var& var, std::string* str_val);
virtual PP_Var BeginReceiveCallerOwned(const PP_Var& var,
- const std::string* str_val);
+ const std::string* str_val,
+ Dispatcher* dispatcher);
virtual void EndReceiveCallerOwned(const PP_Var& var);
virtual PP_Var ReceivePassRef(const PP_Var& var,
- const std::string& str_val);
- virtual void BeginSendPassRef(const PP_Var& var, std::string* str_val);
+ const std::string& str_val,
+ Dispatcher* dispatcher);
+ virtual PP_Var BeginSendPassRef(const PP_Var& var, std::string* str_val);
virtual void EndSendPassRef(const PP_Var& var);
virtual void ReleaseObjectRef(const PP_Var& var);
diff --git a/ppapi/proxy/plugin_var_tracker.cc b/ppapi/proxy/plugin_var_tracker.cc
index 6ad396a..42370be 100644
--- a/ppapi/proxy/plugin_var_tracker.cc
+++ b/ppapi/proxy/plugin_var_tracker.cc
@@ -1,13 +1,14 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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/proxy/plugin_var_tracker.h"
#include "base/ref_counted.h"
+#include "base/singleton.h"
#include "ppapi/c/ppb_var.h"
-#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/proxy/interface_id.h"
namespace pp {
namespace proxy {
@@ -32,28 +33,52 @@ class RefCountedString : public base::RefCounted<RefCountedString> {
// When running in the plugin, this will convert the string ID to the object
// using casting. No validity checking is done.
-RefCountedString* PluginStringFromID(int64 id) {
+RefCountedString* PluginStringFromID(PluginVarTracker::VarID id) {
return reinterpret_cast<RefCountedString*>(static_cast<intptr_t>(id));
}
} // namespace
-PluginVarTracker::PluginVarTracker(PluginDispatcher* dispatcher)
- : dispatcher_(dispatcher) {
+PluginVarTracker::HostVar::HostVar(Sender* d, VarID i)
+ : channel(d),
+ host_object_id(i) {
}
-PluginVarTracker::~PluginVarTracker() {}
+bool PluginVarTracker::HostVar::operator<(const HostVar& other) const {
+ if (channel < other.channel)
+ return true;
+ if (other.channel < channel)
+ return false;
+ return host_object_id < other.host_object_id;
+}
+
+PluginVarTracker::PluginVarInfo::PluginVarInfo(const HostVar& host_var)
+ : host_var(host_var),
+ ref_count(0),
+ track_with_no_reference_count(0) {
+}
-int64 PluginVarTracker::MakeString(const std::string& str) {
+PluginVarTracker::PluginVarTracker() : last_plugin_object_id_(0) {
+}
+
+PluginVarTracker::~PluginVarTracker() {
+}
+
+PluginVarTracker* PluginVarTracker::GetInstance() {
+ return Singleton<PluginVarTracker>::get();
+}
+
+PluginVarTracker::VarID PluginVarTracker::MakeString(const std::string& str) {
RefCountedString* out = new RefCountedString(str);
out->AddRef();
- return static_cast<int64>(reinterpret_cast<intptr_t>(out));
+ return static_cast<VarID>(reinterpret_cast<intptr_t>(out));
}
-int64 PluginVarTracker::MakeString(const char* str, uint32_t len) {
+PluginVarTracker::VarID PluginVarTracker::MakeString(const char* str,
+ uint32_t len) {
RefCountedString* out = new RefCountedString(str, len);
out->AddRef();
- return static_cast<int64>(reinterpret_cast<intptr_t>(out));
+ return static_cast<VarID>(reinterpret_cast<intptr_t>(out));
}
std::string PluginVarTracker::GetString(const PP_Var& var) const {
@@ -72,16 +97,20 @@ void PluginVarTracker::AddRef(const PP_Var& var) {
if (var.type == PP_VARTYPE_STRING) {
PluginStringFromID(var.value.as_id)->AddRef();
} else if (var.type == PP_VARTYPE_OBJECT && var.value.as_id != 0) {
- int& ref_count = object_ref_count_[var.value.as_id];
- ref_count++;
- if (ref_count == 1) {
- // We must handle the case where we got requested to AddRef an object
- // that we've never seen before. This should tell the browser we've
- // taken a ref. This comes up when the browser passes an object as an
- // input param and holds a ref for us. We may not have seen that object
- // and the plugin handler may want to AddRef and release it internally.
- SendAddRefObjectMsg(var.value.as_id);
+ PluginVarInfoMap::iterator found = plugin_var_info_.find(var.value.as_id);
+ if (found == plugin_var_info_.end()) {
+ NOTREACHED() << "Requesting to addref an unknown object.";
+ return;
+ }
+
+ PluginVarInfo& info = found->second;
+ if (info.ref_count == 0) {
+ // Got an AddRef for an object we have no existing reference for.
+ // We need to tell the browser we've taken a ref. This comes up when the
+ // browser passes an object as an input param and holds a ref for us.
+ SendAddRefObjectMsg(info.host_var);
}
+ info.ref_count++;
}
}
@@ -89,47 +118,168 @@ void PluginVarTracker::Release(const PP_Var& var) {
if (var.type == PP_VARTYPE_STRING) {
PluginStringFromID(var.value.as_id)->Release();
} else if (var.type == PP_VARTYPE_OBJECT) {
- ObjectRefCount::iterator found = object_ref_count_.find(var.value.as_id);
- if (found == object_ref_count_.end())
- return; // Invalid object.
- found->second--;
-
- if (found->second == 0) {
- // Plugin has released all of its refs, tell the browser.
- object_ref_count_.erase(found);
- SendReleaseObjectMsg(var.value.as_id);
+ PluginVarInfoMap::iterator found = plugin_var_info_.find(var.value.as_id);
+ if (found == plugin_var_info_.end()) {
+ NOTREACHED() << "Requesting to release an unknown object.";
+ return;
}
+
+ PluginVarInfo& info = found->second;
+ if (info.ref_count == 0) {
+ NOTREACHED() << "Releasing an object with zero ref.";
+ return;
+ }
+
+ info.ref_count--;
+ if (info.ref_count == 0)
+ SendReleaseObjectMsg(info.host_var);
+ DeletePluginVarInfoIfNecessary(found);
}
}
-void PluginVarTracker::ReceiveObjectPassRef(const PP_Var& var) {
- // We're the plugin and the renderer just sent us a ref. The renderer has
- // addrefed the var in its tracker for us since it's returning it.
- //
- // - If We don't have a reference to this already, then we just add it to
- // our tracker and use that one ref.
- //
- // - If we do already have a reference to it, that means the renderer now
- // has two references on our behalf. We want to transfer that extra
- // reference to our list. This means we addref in the plugin, and release
- // the extra one in the renderer.
- ObjectRefCount::iterator found = object_ref_count_.find(var.value.as_id);
- if (found == object_ref_count_.end()) {
- object_ref_count_[var.value.as_id] = 1;
+PP_Var PluginVarTracker::ReceiveObjectPassRef(const PP_Var& var,
+ Sender* channel) {
+ DCHECK(var.type == PP_VARTYPE_OBJECT);
+
+ // Find the plugin info.
+ PluginVarInfoMap::iterator found =
+ FindOrMakePluginVarFromHostVar(var, channel);
+ if (found == plugin_var_info_.end()) {
+ // The above code should have always made an entry in the map.
+ NOTREACHED();
+ return PP_MakeUndefined();
+ }
+
+ // Fix up the references. The host (renderer) just sent us a ref. The
+ // renderer has addrefed the var in its tracker for us since it's returning
+ // it.
+ PluginVarInfo& info = found->second;
+ if (info.ref_count == 0) {
+ // We don't have a reference to this already, then we just add it to our
+ // tracker and use that one ref.
+ info.ref_count = 1;
} else {
- SendReleaseObjectMsg(var.value.as_id);
- found->second++;
+ // We already have a reference to it, that means the renderer now has two
+ // references on our behalf. We want to transfer that extra reference to
+ // our list. This means we addref in the plugin, and release the extra one
+ // in the renderer.
+ SendReleaseObjectMsg(info.host_var);
+ info.ref_count++;
}
+
+ PP_Var ret;
+ ret.type = PP_VARTYPE_OBJECT;
+ ret.value.as_id = found->first;
+ return ret;
}
-void PluginVarTracker::SendAddRefObjectMsg(int64_t id) {
- dispatcher_->Send(new PpapiHostMsg_PPBVar_AddRefObject(
- INTERFACE_ID_PPB_VAR_DEPRECATED, id));
+PP_Var PluginVarTracker::TrackObjectWithNoReference(const PP_Var& host_var,
+ Sender* channel) {
+ DCHECK(host_var.type == PP_VARTYPE_OBJECT);
+
+ PluginVarInfoMap::iterator found =
+ FindOrMakePluginVarFromHostVar(host_var, channel);
+ if (found == plugin_var_info_.end()) {
+ // The above code should have always made an entry in the map.
+ NOTREACHED();
+ return PP_MakeUndefined();
+ }
+
+ found->second.track_with_no_reference_count++;
+
+ PP_Var ret;
+ ret.type = PP_VARTYPE_OBJECT;
+ ret.value.as_id = found->first;
+ return ret;
}
-void PluginVarTracker::SendReleaseObjectMsg(int64_t id) {
- dispatcher_->Send(new PpapiHostMsg_PPBVar_ReleaseObject(
- INTERFACE_ID_PPB_VAR_DEPRECATED, id));
+void PluginVarTracker::StopTrackingObjectWithNoReference(
+ const PP_Var& plugin_var) {
+ DCHECK(plugin_var.type == PP_VARTYPE_OBJECT);
+ PluginVarInfoMap::iterator found = plugin_var_info_.find(
+ plugin_var.value.as_id);
+ if (found == plugin_var_info_.end()) {
+ NOTREACHED();
+ return;
+ }
+
+ found->second.track_with_no_reference_count--;
+ DeletePluginVarInfoIfNecessary(found);
+}
+
+PP_Var PluginVarTracker::GetHostObject(const PP_Var& plugin_object) const {
+ DCHECK(plugin_object.type == PP_VARTYPE_OBJECT);
+ PluginVarInfoMap::const_iterator found = plugin_var_info_.find(
+ plugin_object.value.as_id);
+ if (found == plugin_var_info_.end()) {
+ NOTREACHED();
+ return PP_MakeUndefined();
+ }
+ PP_Var ret;
+ ret.type = PP_VARTYPE_OBJECT;
+ ret.value.as_id = found->second.host_var.host_object_id;
+ return ret;
+}
+
+int PluginVarTracker::GetRefCountForObject(const PP_Var& plugin_object) {
+ PluginVarInfoMap::iterator found = plugin_var_info_.find(
+ plugin_object.value.as_id);
+ if (found == plugin_var_info_.end())
+ return -1;
+ return found->second.ref_count;
+}
+
+int PluginVarTracker::GetTrackedWithNoReferenceCountForObject(
+ const PP_Var& plugin_object) {
+ PluginVarInfoMap::iterator found = plugin_var_info_.find(
+ plugin_object.value.as_id);
+ if (found == plugin_var_info_.end())
+ return -1;
+ return found->second.track_with_no_reference_count;
+}
+
+void PluginVarTracker::SendAddRefObjectMsg(const HostVar& host_var) {
+ host_var.channel->Send(new PpapiHostMsg_PPBVar_AddRefObject(
+ INTERFACE_ID_PPB_VAR_DEPRECATED, host_var.host_object_id));
+}
+
+void PluginVarTracker::SendReleaseObjectMsg(const HostVar& host_var) {
+ host_var.channel->Send(new PpapiHostMsg_PPBVar_ReleaseObject(
+ INTERFACE_ID_PPB_VAR_DEPRECATED, host_var.host_object_id));
+}
+
+PluginVarTracker::PluginVarInfoMap::iterator
+PluginVarTracker::FindOrMakePluginVarFromHostVar(const PP_Var& var,
+ Sender* channel) {
+ DCHECK(var.type == PP_VARTYPE_OBJECT);
+ HostVar host_var(channel, var.value.as_id);
+
+ HostVarToPluginVarMap::iterator found =
+ host_var_to_plugin_var_.find(host_var);
+ if (found != host_var_to_plugin_var_.end()) {
+ PluginVarInfoMap::iterator ret = plugin_var_info_.find(found->second);
+ DCHECK(ret != plugin_var_info_.end());
+ return ret; // Already know about this var return the ID.
+ }
+
+ // Make a new var, adding references to both maps.
+ VarID new_plugin_var_id = ++last_plugin_object_id_;
+ host_var_to_plugin_var_[host_var] = new_plugin_var_id;
+ return plugin_var_info_.insert(
+ std::make_pair(new_plugin_var_id, PluginVarInfo(host_var))).first;
+}
+
+void PluginVarTracker::DeletePluginVarInfoIfNecessary(
+ PluginVarInfoMap::iterator iter) {
+ if (iter->second.ref_count != 0 ||
+ iter->second.track_with_no_reference_count != 0)
+ return; // Object still alive.
+
+ // Object ref counts are all zero, delete from both maps.
+ DCHECK(host_var_to_plugin_var_.find(iter->second.host_var) !=
+ host_var_to_plugin_var_.end());
+ host_var_to_plugin_var_.erase(iter->second.host_var);
+ plugin_var_info_.erase(iter);
}
} // namesace proxy
diff --git a/ppapi/proxy/plugin_var_tracker.h b/ppapi/proxy/plugin_var_tracker.h
index 9a1b9ab..4d6c49c 100644
--- a/ppapi/proxy/plugin_var_tracker.h
+++ b/ppapi/proxy/plugin_var_tracker.h
@@ -8,64 +8,152 @@
#include <map>
#include <string>
+#include "ipc/ipc_channel.h"
#include "ppapi/c/pp_stdint.h"
#include "ppapi/c/pp_var.h"
struct PPB_Var;
+template<typename T> struct DefaultSingletonTraits;
+
namespace pp {
namespace proxy {
-class PluginDispatcher;
-
-// Tracks live strings and objects in the plugin process. We maintain our own
-// reference count for these objects. In the case of JS objects, we maintain
-// a single ref in the renderer process whenever we have a nonzero refcount
-// in the plugin process. This allows AddRef and Release to not initiate too
-// much IPC chat.
+// Tracks live strings and objects in the plugin process.
+//
+// This object maintains its own object IDs that are used by the plugin. These
+// IDs can be mapped to the renderer that created them, and that renderer's ID.
+// This way, we can maintain multiple renderers each giving us objects, and the
+// plugin can work with them using a uniform set of unique IDs.
+//
+// We maintain our own reference count for objects. a single ref in the
+// renderer process whenever we have a nonzero refcount in the plugin process.
+// This allows AddRef and Release to not initiate too much IPC chat.
+//
+// In addition to the local reference count, we also maintain "tracked objects"
+// which are objects that the plugin is aware of, but doesn't hold a reference
+// to. This will happen when the plugin is passed an object as an argument from
+// the host (renderer) but where a reference is not passed.
class PluginVarTracker {
public:
- // You must call Init() after creation to set up the correct interfaces. We
- // do this to avoid having to depend on the dispatcher in the constructor,
- // which is probably just being created from our constructor.
- PluginVarTracker(PluginDispatcher* dispatcher);
+ typedef int64_t VarID;
- ~PluginVarTracker();
+ // This uses the PluginDispatcher to identify the source of vars so that
+ // the proper messages can be sent back. However, since all we need is the
+ // ability to send messages, we can always use the Sender base class of
+ // Dispatcher in this class, which makes it easy to unit test.
+ typedef IPC::Channel::Sender Sender;
- // Must be called after construction.
- void Init();
+ // Returns the global var tracker for the plugin object.
+ static PluginVarTracker* GetInstance();
// Allocates a string and returns the ID of it. The refcount will be 1.
- int64_t MakeString(const std::string& str);
- int64_t MakeString(const char* str, uint32_t len);
+ VarID MakeString(const std::string& str);
+ VarID MakeString(const char* str, uint32_t len);
// Returns the string associated with the given string var. The var must be
// of type string and must be valid or this function will crash.
- std::string GetString(const PP_Var& var) const;
+ std::string GetString(const PP_Var& plugin_var) const;
// Returns a pointer to the given string if it exists, or NULL if the var
// isn't a string var.
- const std::string* GetExistingString(const PP_Var& var) const;
+ const std::string* GetExistingString(const PP_Var& plugin_var) const;
- void AddRef(const PP_Var& var);
- void Release(const PP_Var& var);
+ void AddRef(const PP_Var& plugin_var);
+ void Release(const PP_Var& plugin_var);
// Manages tracking for receiving a VARTYPE_OBJECT from the remote side
// (either the plugin or the renderer) that has already had its reference
// count incremented on behalf of the caller.
- void ReceiveObjectPassRef(const PP_Var& var);
+ PP_Var ReceiveObjectPassRef(const PP_Var& var, Sender* channel);
- private:
- // Sends an addref or release message to the browser for the given object ID.
- void SendAddRefObjectMsg(int64_t id);
- void SendReleaseObjectMsg(int64_t id);
+ PP_Var TrackObjectWithNoReference(const PP_Var& host_var,
+ Sender* channel);
+ void StopTrackingObjectWithNoReference(const PP_Var& plugin_var);
- PluginDispatcher* dispatcher_;
+ // Returns the host var for the corresponding plugin object var. The object
+ // should be a VARTYPE_OBJECT
+ PP_Var GetHostObject(const PP_Var& plugin_object) const;
- // Tracks object references to the reference count of that object on the
- // plugin side.
- typedef std::map<int64_t, int> ObjectRefCount;
- ObjectRefCount object_ref_count_;
+ // Retrieves the internal reference counts for testing. Returns 0 if we
+ // know about the object but the corresponding value is 0, or -1 if the
+ // given object ID isn't in our map.
+ int GetRefCountForObject(const PP_Var& plugin_object);
+ int GetTrackedWithNoReferenceCountForObject(const PP_Var& plugin_object);
+
+ private:
+ friend struct DefaultSingletonTraits<PluginVarTracker>;
+
+ // Represents a var as received from the host.
+ struct HostVar {
+ HostVar(Sender* s, int64_t i);
+
+ bool operator<(const HostVar& other) const;
+
+ // The host that sent us this object. This is used so we know how to send
+ // back requests on this object.
+ Sender* channel;
+
+ // The object ID that the host generated to identify the object. This is
+ // unique only within that host: different hosts could give us different
+ // objects with the same ID.
+ VarID host_object_id;
+ };
+
+ // The information associated with a var object in the plugin.
+ struct PluginVarInfo {
+ PluginVarInfo(const HostVar& host_var);
+
+ // Maps back to the original var in the host.
+ HostVar host_var;
+
+ // Explicit reference count. This value is affected by the renderer calling
+ // AddRef and Release. A nonzero value here is represented by a single
+ // reference in the host on our behalf (this reduces IPC traffic).
+ int32_t ref_count;
+
+ // Tracked object count (see class comment above).
+ //
+ // "TrackObjectWithNoReference" might be called recursively in rare cases.
+ // For example, say the host calls a plugin function with an object as an
+ // argument, and in response, the plugin calls a host function that then
+ // calls another (or the same) plugin function with the same object.
+ //
+ // This value tracks the number of calls to TrackObjectWithNoReference so
+ // we know when we can stop tracking this object.
+ int32_t track_with_no_reference_count;
+ };
+
+ typedef std::map<int64_t, PluginVarInfo> PluginVarInfoMap;
+
+ PluginVarTracker();
+ ~PluginVarTracker();
+
+ // Sends an addref or release message to the browser for the given object ID.
+ void SendAddRefObjectMsg(const HostVar& host_var);
+ void SendReleaseObjectMsg(const HostVar& host_var);
+
+ PluginVarInfoMap::iterator FindOrMakePluginVarFromHostVar(
+ const PP_Var& var,
+ Sender* channel);
+
+ // Checks the reference counds of the given plugin var info and removes the
+ // tracking information if necessary. We're done with the object when its
+ // explicit reference count and its "tracked with no reference" count both
+ // reach zero.
+ void DeletePluginVarInfoIfNecessary(PluginVarInfoMap::iterator iter);
+
+ // Tracks all information about plugin vars.
+ PluginVarInfoMap plugin_var_info_;
+
+ // Maps host vars to plugin vars. This allows us to know if we've previously
+ // seen a host var and re-use the information.
+ typedef std::map<HostVar, VarID> HostVarToPluginVarMap;
+ HostVarToPluginVarMap host_var_to_plugin_var_;
+
+ // The last plugin object ID we've handed out. This must be unique for the
+ // process.
+ VarID last_plugin_object_id_;
};
} // namespace proxy
diff --git a/ppapi/proxy/ppapi_messages_internal.h b/ppapi/proxy/ppapi_messages_internal.h
index 6302bad..84a54fd 100644
--- a/ppapi/proxy/ppapi_messages_internal.h
+++ b/ppapi/proxy/ppapi_messages_internal.h
@@ -230,12 +230,12 @@ IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBCursorControl_CanLockCursor,
// PPB_Flash.
IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBFlash_SetInstanceAlwaysOnTop,
PP_Instance /* instance */,
- bool /* on_top */)
+ PP_Bool /* on_top */)
// This has to be synchronous becuase the caller may want to composite on
// top of the resulting text after the call is complete.
IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBFlash_DrawGlyphs,
pp::proxy::PPBFlash_DrawGlyphs_Params /* params */,
- bool /* result */)
+ PP_Bool /* result */)
IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBFlash_GetProxyForURL,
PP_Instance /* instance */,
std::string /* url */,
@@ -254,7 +254,7 @@ IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBFlash_RenameModuleLocalFile,
IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBFlash_DeleteModuleLocalFileOrDir,
PP_Instance /* instance */,
std::string /* path */,
- bool /* recursive */,
+ PP_Bool /* recursive */,
int32_t /* result */)
IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBFlash_CreateModuleLocalDir,
PP_Instance /* instance */,
@@ -275,7 +275,7 @@ IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBFlash_NavigateToURL,
PP_Instance /* instance */,
std::string /* url */,
std::string /* target */,
- bool /* result */)
+ PP_Bool /* result */)
// PPB_Font.
IPC_SYNC_MESSAGE_ROUTED2_3(
@@ -343,13 +343,6 @@ IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBGraphics2D_Flush,
PP_Resource /* graphics_2d */)
// PPB_ImageData.
-IPC_SYNC_MESSAGE_ROUTED0_1(
- PpapiHostMsg_PPBImageData_GetNativeImageDataFormat,
- int32 /* result_format */)
-IPC_SYNC_MESSAGE_ROUTED1_1(
- PpapiHostMsg_PPBImageData_IsImageDataFormatSupported,
- int32 /* format */,
- PP_Bool /* result */)
IPC_SYNC_MESSAGE_ROUTED4_3(PpapiHostMsg_PPBImageData_Create,
PP_Instance /* instance */,
int32 /* format */,
@@ -400,8 +393,8 @@ IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBTesting_ReadImageData,
IPC_SYNC_MESSAGE_ROUTED0_1(PpapiHostMsg_PPBTesting_RunMessageLoop,
bool /* dummy since there's no 0_0 variant */)
IPC_MESSAGE_ROUTED0(PpapiHostMsg_PPBTesting_QuitMessageLoop)
-IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBTesting_GetLiveObjectCount,
- PP_Module /* module */,
+IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance,
+ PP_Instance /* instance */,
uint32 /* result */)
// PPB_URLLoader.
diff --git a/ppapi/proxy/ppb_audio_config_proxy.cc b/ppapi/proxy/ppb_audio_config_proxy.cc
index 0d0e6a7..8bf62c3 100644
--- a/ppapi/proxy/ppb_audio_config_proxy.cc
+++ b/ppapi/proxy/ppb_audio_config_proxy.cc
@@ -14,8 +14,11 @@ namespace proxy {
class AudioConfig : public PluginResource {
public:
- AudioConfig(PP_AudioSampleRate sample_rate, uint32_t sample_frame_count)
- : sample_rate_(sample_rate),
+ AudioConfig(PP_Instance instance,
+ PP_AudioSampleRate sample_rate,
+ uint32_t sample_frame_count)
+ : PluginResource(instance),
+ sample_rate_(sample_rate),
sample_frame_count_(sample_frame_count) {
}
virtual ~AudioConfig() {}
@@ -39,28 +42,31 @@ PP_Resource CreateStereo16bit(PP_Instance instance,
PP_AudioSampleRate sample_rate,
uint32_t sample_frame_count) {
PP_Resource result = 0;
- PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBAudioConfig_Create(
- INTERFACE_ID_PPB_AUDIO_CONFIG, instance,
- static_cast<int32_t>(sample_rate), sample_frame_count,
- &result));
+ PluginDispatcher::GetForInstance(instance)->Send(
+ new PpapiHostMsg_PPBAudioConfig_Create(
+ INTERFACE_ID_PPB_AUDIO_CONFIG, instance,
+ static_cast<int32_t>(sample_rate), sample_frame_count,
+ &result));
if (!result)
return 0;
linked_ptr<AudioConfig> object(
- new AudioConfig(sample_rate, sample_frame_count));
- PluginDispatcher::Get()->plugin_resource_tracker()->AddResource(
- result, object);
+ new AudioConfig(instance, sample_rate, sample_frame_count));
+ PluginResourceTracker::GetInstance()->AddResource(result, object);
return result;
}
uint32_t RecommendSampleFrameCount(PP_AudioSampleRate sample_rate,
uint32_t requested_sample_frame_count) {
- uint32_t result = 0;
- PluginDispatcher::Get()->Send(
- new PpapiHostMsg_PPBAudioConfig_RecommendSampleFrameCount(
- INTERFACE_ID_PPB_AUDIO_CONFIG, static_cast<int32_t>(sample_rate),
- requested_sample_frame_count, &result));
- return result;
+ // TODO(brettw) Currently we don't actually query to get a value from the
+ // hardware, so we always return the input for in-range values.
+ //
+ // Danger: this code is duplicated in the audio config implementation.
+ if (requested_sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT)
+ return PP_AUDIOMINSAMPLEFRAMECOUNT;
+ if (requested_sample_frame_count > PP_AUDIOMAXSAMPLEFRAMECOUNT)
+ return PP_AUDIOMAXSAMPLEFRAMECOUNT;
+ return requested_sample_frame_count;
}
PP_Bool IsAudioConfig(PP_Resource resource) {
diff --git a/ppapi/proxy/ppb_audio_proxy.cc b/ppapi/proxy/ppb_audio_proxy.cc
index aa8ab92..837637a 100644
--- a/ppapi/proxy/ppb_audio_proxy.cc
+++ b/ppapi/proxy/ppb_audio_proxy.cc
@@ -19,15 +19,17 @@ namespace proxy {
class Audio : public PluginResource, public pp::shared_impl::AudioImpl {
public:
- Audio(PP_Resource config_id, PPB_Audio_Callback callback, void* user_data)
- : config_(config_id) {
+ Audio(PP_Instance instance,
+ PP_Resource config_id,
+ PPB_Audio_Callback callback,
+ void* user_data)
+ : PluginResource(instance),
+ config_(config_id) {
SetCallback(callback, user_data);
- PluginDispatcher::Get()->plugin_resource_tracker()->AddRefResource(
- config_);
+ PluginResourceTracker::GetInstance()->AddRefResource(config_);
}
virtual ~Audio() {
- PluginDispatcher::Get()->plugin_resource_tracker()->ReleaseResource(
- config_);
+ PluginResourceTracker::GetInstance()->ReleaseResource(config_);
}
// Resource overrides.
@@ -39,15 +41,17 @@ class Audio : public PluginResource, public pp::shared_impl::AudioImpl {
if (playing())
return;
SetStartPlaybackState();
- PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBAudio_StartOrStop(
- INTERFACE_ID_PPB_AUDIO, resource, true));
+ PluginDispatcher::GetForInstance(instance())->Send(
+ new PpapiHostMsg_PPBAudio_StartOrStop(
+ INTERFACE_ID_PPB_AUDIO, resource, true));
}
void StopPlayback(PP_Resource resource) {
if (!playing())
return;
- PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBAudio_StartOrStop(
- INTERFACE_ID_PPB_AUDIO, resource, false));
+ PluginDispatcher::GetForInstance(instance())->Send(
+ new PpapiHostMsg_PPBAudio_StartOrStop(
+ INTERFACE_ID_PPB_AUDIO, resource, false));
SetStopPlaybackState();
}
@@ -69,9 +73,9 @@ PP_Resource Create(PP_Instance instance_id,
if (!result)
return 0;
- linked_ptr<Audio> object(new Audio(config_id, callback, user_data));
- PluginDispatcher::Get()->plugin_resource_tracker()->AddResource(
- result, object);
+ linked_ptr<Audio> object(new Audio(instance_id, config_id,
+ callback, user_data));
+ PluginResourceTracker::GetInstance()->AddResource(result, object);
return result;
}
@@ -85,7 +89,7 @@ PP_Resource GetCurrentConfiguration(PP_Resource audio_id) {
if (!object)
return 0;
PP_Resource result = object->config();
- PluginDispatcher::Get()->plugin_resource_tracker()->AddRefResource(result);
+ PluginResourceTracker::GetInstance()->AddRefResource(result);
return result;
}
diff --git a/ppapi/proxy/ppb_buffer_proxy.cc b/ppapi/proxy/ppb_buffer_proxy.cc
index 4963b7b..d224572 100644
--- a/ppapi/proxy/ppb_buffer_proxy.cc
+++ b/ppapi/proxy/ppb_buffer_proxy.cc
@@ -20,7 +20,7 @@ namespace proxy {
class Buffer : public PluginResource {
public:
- Buffer(int memory_handle, uint32_t size);
+ Buffer(PP_Instance instance, int memory_handle, uint32_t size);
virtual ~Buffer();
// Resource overrides.
@@ -40,8 +40,9 @@ class Buffer : public PluginResource {
DISALLOW_COPY_AND_ASSIGN(Buffer);
};
-Buffer::Buffer(int memory_handle, uint32_t size)
- : memory_handle_(memory_handle),
+Buffer::Buffer(PP_Instance instance, int memory_handle, uint32_t size)
+ : PluginResource(instance),
+ memory_handle_(memory_handle),
size_(size),
mapped_data_(NULL) {
}
@@ -64,16 +65,16 @@ namespace {
PP_Resource Create(PP_Instance instance, uint32_t size) {
PP_Resource result = 0;
int32_t shm_handle = -1;
- PluginDispatcher::Get()->Send(
+ PluginDispatcher::GetForInstance(instance)->Send(
new PpapiHostMsg_PPBBuffer_Create(
INTERFACE_ID_PPB_BUFFER, instance, size,
&result, &shm_handle));
if (!result)
return 0;
- linked_ptr<Buffer> object(new Buffer(static_cast<int>(shm_handle), size));
- PluginDispatcher::Get()->plugin_resource_tracker()->AddResource(
- result, object);
+ linked_ptr<Buffer> object(new Buffer(instance, static_cast<int>(shm_handle),
+ size));
+ PluginResourceTracker::GetInstance()->AddResource(result, object);
return result;
}
diff --git a/ppapi/proxy/ppb_char_set_proxy.cc b/ppapi/proxy/ppb_char_set_proxy.cc
index e0be4aa..73ca61b 100644
--- a/ppapi/proxy/ppb_char_set_proxy.cc
+++ b/ppapi/proxy/ppb_char_set_proxy.cc
@@ -20,9 +20,14 @@ char* UTF16ToCharSet(PP_Instance instance,
const char* output_char_set,
PP_CharSet_ConversionError on_error,
uint32_t* output_length) {
+ *output_length = 0;
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return NULL;
+
bool output_is_success = false;
std::string result;
- PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBCharSet_UTF16ToCharSet(
+ dispatcher->Send(new PpapiHostMsg_PPBCharSet_UTF16ToCharSet(
INTERFACE_ID_PPB_CHAR_SET, instance,
string16(reinterpret_cast<const char16*>(utf16), utf16_len),
std::string(output_char_set), static_cast<int32_t>(on_error),
@@ -41,9 +46,14 @@ uint16_t* CharSetToUTF16(PP_Instance instance,
const char* input_char_set,
PP_CharSet_ConversionError on_error,
uint32_t* output_length) {
+ *output_length = 0;
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return NULL;
+
bool output_is_success = false;
string16 result;
- PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBCharSet_CharSetToUTF16(
+ dispatcher->Send(new PpapiHostMsg_PPBCharSet_CharSetToUTF16(
INTERFACE_ID_PPB_CHAR_SET, instance,
std::string(input, input_len),
std::string(input_char_set), static_cast<int32_t>(on_error),
@@ -59,10 +69,14 @@ uint16_t* CharSetToUTF16(PP_Instance instance,
}
PP_Var GetDefaultCharSet(PP_Instance instance) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return PP_MakeUndefined();
+
ReceiveSerializedVarReturnValue result;
- PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBCharSet_GetDefaultCharSet(
+ dispatcher->Send(new PpapiHostMsg_PPBCharSet_GetDefaultCharSet(
INTERFACE_ID_PPB_CHAR_SET, instance, &result));
- return result.Return(PluginDispatcher::Get());
+ return result.Return(dispatcher);
}
const PPB_CharSet_Dev ppb_charset_interface = {
diff --git a/ppapi/proxy/ppb_core_proxy.cc b/ppapi/proxy/ppb_core_proxy.cc
index 32cad67..b4afcb6 100644
--- a/ppapi/proxy/ppb_core_proxy.cc
+++ b/ppapi/proxy/ppb_core_proxy.cc
@@ -14,6 +14,7 @@
#include "ppapi/c/pp_resource.h"
#include "ppapi/c/ppb_core.h"
#include "ppapi/proxy/plugin_dispatcher.h"
+#include "ppapi/proxy/plugin_resource_tracker.h"
#include "ppapi/proxy/ppapi_messages.h"
namespace pp {
@@ -28,11 +29,11 @@ base::MessageLoopProxy* GetMainThreadMessageLoop() {
}
void AddRefResource(PP_Resource resource) {
- PluginDispatcher::Get()->plugin_resource_tracker()->AddRefResource(resource);
+ PluginResourceTracker::GetInstance()->AddRefResource(resource);
}
void ReleaseResource(PP_Resource resource) {
- PluginDispatcher::Get()->plugin_resource_tracker()->ReleaseResource(resource);
+ PluginResourceTracker::GetInstance()->ReleaseResource(resource);
}
void* MemAlloc(size_t num_bytes) {
diff --git a/ppapi/proxy/ppb_cursor_control_proxy.cc b/ppapi/proxy/ppb_cursor_control_proxy.cc
index f576ae0..75c3c3a 100644
--- a/ppapi/proxy/ppb_cursor_control_proxy.cc
+++ b/ppapi/proxy/ppb_cursor_control_proxy.cc
@@ -14,12 +14,16 @@ namespace proxy {
namespace {
PP_Bool SetCursor(PP_Instance instance_id,
- PP_CursorType_Dev type,
- PP_Resource custom_image_id,
- const PP_Point* hot_spot) {
+ PP_CursorType_Dev type,
+ PP_Resource custom_image_id,
+ const PP_Point* hot_spot) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
+ if (!dispatcher)
+ return PP_FALSE;
+
PP_Bool result = PP_FALSE;
PP_Point empty_point = { 0, 0 };
- PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBCursorControl_SetCursor(
+ dispatcher->Send(new PpapiHostMsg_PPBCursorControl_SetCursor(
INTERFACE_ID_PPB_CURSORCONTROL,
instance_id, static_cast<int32_t>(type), custom_image_id,
hot_spot ? *hot_spot : empty_point, &result));
@@ -27,29 +31,45 @@ PP_Bool SetCursor(PP_Instance instance_id,
}
PP_Bool LockCursor(PP_Instance instance_id) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
+ if (!dispatcher)
+ return PP_FALSE;
+
PP_Bool result = PP_FALSE;
- PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBCursorControl_LockCursor(
+ dispatcher->Send(new PpapiHostMsg_PPBCursorControl_LockCursor(
INTERFACE_ID_PPB_CURSORCONTROL, instance_id, &result));
return result;
}
PP_Bool UnlockCursor(PP_Instance instance_id) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
+ if (!dispatcher)
+ return PP_FALSE;
+
PP_Bool result = PP_FALSE;
- PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBCursorControl_UnlockCursor(
+ dispatcher->Send(new PpapiHostMsg_PPBCursorControl_UnlockCursor(
INTERFACE_ID_PPB_CURSORCONTROL, instance_id, &result));
return result;
}
PP_Bool HasCursorLock(PP_Instance instance_id) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
+ if (!dispatcher)
+ return PP_FALSE;
+
PP_Bool result = PP_FALSE;
- PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBCursorControl_HasCursorLock(
+ dispatcher->Send(new PpapiHostMsg_PPBCursorControl_HasCursorLock(
INTERFACE_ID_PPB_CURSORCONTROL, instance_id, &result));
return result;
}
PP_Bool CanLockCursor(PP_Instance instance_id) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
+ if (!dispatcher)
+ return PP_FALSE;
+
PP_Bool result = PP_FALSE;
- PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBCursorControl_CanLockCursor(
+ dispatcher->Send(new PpapiHostMsg_PPBCursorControl_CanLockCursor(
INTERFACE_ID_PPB_CURSORCONTROL, instance_id, &result));
return result;
}
diff --git a/ppapi/proxy/ppb_flash_proxy.cc b/ppapi/proxy/ppb_flash_proxy.cc
index 0cffa3c..014cea3 100644
--- a/ppapi/proxy/ppb_flash_proxy.cc
+++ b/ppapi/proxy/ppb_flash_proxy.cc
@@ -49,23 +49,27 @@ IPC::PlatformFileForTransit PlatformFileToPlatformFileForTransit(
#endif
}
-void SetInstanceAlwaysOnTop(PP_Instance pp_instance, bool on_top) {
- PluginDispatcher::Get()->Send(
- new PpapiHostMsg_PPBFlash_SetInstanceAlwaysOnTop(
- INTERFACE_ID_PPB_FLASH, pp_instance, on_top));
+void SetInstanceAlwaysOnTop(PP_Instance pp_instance, PP_Bool on_top) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(pp_instance);
+ if (dispatcher) {
+ dispatcher->Send(new PpapiHostMsg_PPBFlash_SetInstanceAlwaysOnTop(
+ INTERFACE_ID_PPB_FLASH, pp_instance, on_top));
+ }
}
-bool DrawGlyphs(PP_Instance instance,
- PP_Resource pp_image_data,
- const PP_FontDescription_Dev* font_desc,
- uint32_t color,
- PP_Point position,
- PP_Rect clip,
- const float transformation[3][3],
- uint32_t glyph_count,
- const uint16_t glyph_indices[],
- const PP_Point glyph_advances[]) {
- Dispatcher* dispatcher = PluginDispatcher::Get();
+PP_Bool DrawGlyphs(PP_Instance instance,
+ PP_Resource pp_image_data,
+ const PP_FontDescription_Dev* font_desc,
+ uint32_t color,
+ PP_Point position,
+ PP_Rect clip,
+ const float transformation[3][3],
+ uint32_t glyph_count,
+ const uint16_t glyph_indices[],
+ const PP_Point glyph_advances[]) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return PP_FALSE;
PPBFlash_DrawGlyphs_Params params;
params.instance = instance,
@@ -86,26 +90,34 @@ bool DrawGlyphs(PP_Instance instance,
&glyph_advances[0],
&glyph_advances[glyph_count]);
- bool result = false;
+ PP_Bool result = PP_FALSE;
dispatcher->Send(new PpapiHostMsg_PPBFlash_DrawGlyphs(
INTERFACE_ID_PPB_FLASH, params, &result));
return result;
}
PP_Var GetProxyForURL(PP_Instance instance, const char* url) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return PP_MakeUndefined();
+
ReceiveSerializedVarReturnValue result;
- PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBFlash_GetProxyForURL(
+ dispatcher->Send(new PpapiHostMsg_PPBFlash_GetProxyForURL(
INTERFACE_ID_PPB_FLASH, instance, url, &result));
- return result.Return(PluginDispatcher::Get());
+ return result.Return(dispatcher);
}
int32_t OpenModuleLocalFile(PP_Instance instance,
const char* path,
int32_t mode,
PP_FileHandle* file) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return PP_ERROR_BADARGUMENT;
+
int32_t result = PP_ERROR_FAILED;
IPC::PlatformFileForTransit transit;
- PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBFlash_OpenModuleLocalFile(
+ dispatcher->Send(new PpapiHostMsg_PPBFlash_OpenModuleLocalFile(
INTERFACE_ID_PPB_FLASH, instance, path, mode, &transit, &result));
*file = IPC::PlatformFileForTransitToPlatformFile(transit);
return result;
@@ -114,25 +126,36 @@ int32_t OpenModuleLocalFile(PP_Instance instance,
int32_t RenameModuleLocalFile(PP_Instance instance,
const char* path_from,
const char* path_to) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return PP_ERROR_BADARGUMENT;
+
int32_t result = PP_ERROR_FAILED;
- PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBFlash_RenameModuleLocalFile(
+ dispatcher->Send(new PpapiHostMsg_PPBFlash_RenameModuleLocalFile(
INTERFACE_ID_PPB_FLASH, instance, path_from, path_to, &result));
return result;
}
int32_t DeleteModuleLocalFileOrDir(PP_Instance instance,
const char* path,
- bool recursive) {
+ PP_Bool recursive) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return PP_ERROR_BADARGUMENT;
+
int32_t result = PP_ERROR_FAILED;
- PluginDispatcher::Get()->Send(
- new PpapiHostMsg_PPBFlash_DeleteModuleLocalFileOrDir(
- INTERFACE_ID_PPB_FLASH, instance, path, recursive, &result));
+ dispatcher->Send(new PpapiHostMsg_PPBFlash_DeleteModuleLocalFileOrDir(
+ INTERFACE_ID_PPB_FLASH, instance, path, recursive, &result));
return result;
}
int32_t CreateModuleLocalDir(PP_Instance instance, const char* path) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return PP_ERROR_BADARGUMENT;
+
int32_t result = PP_ERROR_FAILED;
- PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBFlash_CreateModuleLocalDir(
+ dispatcher->Send(new PpapiHostMsg_PPBFlash_CreateModuleLocalDir(
INTERFACE_ID_PPB_FLASH, instance, path, &result));
return result;
}
@@ -140,21 +163,27 @@ int32_t CreateModuleLocalDir(PP_Instance instance, const char* path) {
int32_t QueryModuleLocalFile(PP_Instance instance,
const char* path,
PP_FileInfo_Dev* info) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return PP_ERROR_BADARGUMENT;
+
int32_t result = PP_ERROR_FAILED;
- PluginDispatcher::Get()->Send(
- new PpapiHostMsg_PPBFlash_QueryModuleLocalFile(
- INTERFACE_ID_PPB_FLASH, instance, path, info, &result));
+ dispatcher->Send(new PpapiHostMsg_PPBFlash_QueryModuleLocalFile(
+ INTERFACE_ID_PPB_FLASH, instance, path, info, &result));
return result;
}
int32_t GetModuleLocalDirContents(PP_Instance instance,
const char* path,
PP_DirContents_Dev** contents) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return PP_ERROR_BADARGUMENT;
+
int32_t result = PP_ERROR_FAILED;
std::vector<SerializedDirEntry> entries;
- PluginDispatcher::Get()->Send(
- new PpapiHostMsg_PPBFlash_GetModuleLocalDirContents(
- INTERFACE_ID_PPB_FLASH, instance, path, &entries, &result));
+ dispatcher->Send(new PpapiHostMsg_PPBFlash_GetModuleLocalDirContents(
+ INTERFACE_ID_PPB_FLASH, instance, path, &entries, &result));
if (result != PP_OK)
return result;
@@ -170,13 +199,13 @@ int32_t GetModuleLocalDirContents(PP_Instance instance,
char* name_copy = new char[source.name.size() + 1];
memcpy(name_copy, source.name.c_str(), source.name.size() + 1);
dest->name = name_copy;
- dest->is_dir = source.is_dir;
+ dest->is_dir = BoolToPPBool(source.is_dir);
}
return result;
}
-void FreeModuleLocalDirContents(PP_Instance instance,
+void FreeModuleLocalDirContents(PP_Instance /* instance */,
PP_DirContents_Dev* contents) {
for (int32_t i = 0; i < contents->count; ++i)
delete[] contents->entries[i].name;
@@ -184,13 +213,16 @@ void FreeModuleLocalDirContents(PP_Instance instance,
delete contents;
}
-bool NavigateToURL(PP_Instance pp_instance,
- const char* url,
- const char* target) {
- bool result = false;
- PluginDispatcher::Get()->Send(
- new PpapiHostMsg_PPBFlash_NavigateToURL(
- INTERFACE_ID_PPB_FLASH, pp_instance, url, target, &result));
+PP_Bool NavigateToURL(PP_Instance instance,
+ const char* url,
+ const char* target) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return PP_FALSE;
+
+ PP_Bool result = PP_FALSE;
+ dispatcher->Send(new PpapiHostMsg_PPBFlash_NavigateToURL(
+ INTERFACE_ID_PPB_FLASH, instance, url, target, &result));
return result;
}
@@ -211,7 +243,7 @@ const PPB_Flash ppb_flash = {
} // namespace
PPB_Flash_Proxy::PPB_Flash_Proxy(Dispatcher* dispatcher,
- const void* target_interface)
+ const void* target_interface)
: InterfaceProxy(dispatcher, target_interface) {
}
@@ -256,14 +288,14 @@ bool PPB_Flash_Proxy::OnMessageReceived(const IPC::Message& msg) {
void PPB_Flash_Proxy::OnMsgSetInstanceAlwaysOnTop(
PP_Instance instance,
- bool on_top) {
+ PP_Bool on_top) {
ppb_flash_target()->SetInstanceAlwaysOnTop(instance, on_top);
}
void PPB_Flash_Proxy::OnMsgDrawGlyphs(
const pp::proxy::PPBFlash_DrawGlyphs_Params& params,
- bool* result) {
- *result = false;
+ PP_Bool* result) {
+ *result = PP_FALSE;
PP_FontDescription_Dev font_desc;
params.font_desc.SetToPPFontDescription(dispatcher(), &font_desc, false);
@@ -313,7 +345,7 @@ void PPB_Flash_Proxy::OnMsgRenameModuleLocalFile(
void PPB_Flash_Proxy::OnMsgDeleteModuleLocalFileOrDir(
PP_Instance instance,
const std::string& path,
- bool recursive,
+ PP_Bool recursive,
int32_t* result) {
*result = ppb_flash_target()->DeleteModuleLocalFileOrDir(instance,
path.c_str(),
@@ -350,7 +382,7 @@ void PPB_Flash_Proxy::OnMsgGetModuleLocalDirContents(
entries->resize(contents->count);
for (int32_t i = 0; i < contents->count; i++) {
(*entries)[i].name.assign(contents->entries[i].name);
- (*entries)[i].is_dir = contents->entries[i].is_dir;
+ (*entries)[i].is_dir = PPBoolToBool(contents->entries[i].is_dir);
}
ppb_flash_target()->FreeModuleLocalDirContents(instance, contents);
}
@@ -358,7 +390,7 @@ void PPB_Flash_Proxy::OnMsgGetModuleLocalDirContents(
void PPB_Flash_Proxy::OnMsgNavigateToURL(PP_Instance instance,
const std::string& url,
const std::string& target,
- bool* result) {
+ PP_Bool* result) {
*result = ppb_flash_target()->NavigateToURL(instance, url.c_str(),
target.c_str());
}
diff --git a/ppapi/proxy/ppb_flash_proxy.h b/ppapi/proxy/ppb_flash_proxy.h
index cbe30bd..797dae8 100644
--- a/ppapi/proxy/ppb_flash_proxy.h
+++ b/ppapi/proxy/ppb_flash_proxy.h
@@ -40,9 +40,9 @@ class PPB_Flash_Proxy : public InterfaceProxy {
private:
// Message handlers.
void OnMsgSetInstanceAlwaysOnTop(PP_Instance instance,
- bool on_top);
+ PP_Bool on_top);
void OnMsgDrawGlyphs(const pp::proxy::PPBFlash_DrawGlyphs_Params& params,
- bool* result);
+ PP_Bool* result);
void OnMsgGetProxyForURL(PP_Instance instance,
const std::string& url,
SerializedVarReturnValue result);
@@ -57,7 +57,7 @@ class PPB_Flash_Proxy : public InterfaceProxy {
int32_t* result);
void OnMsgDeleteModuleLocalFileOrDir(PP_Instance instance,
const std::string& path,
- bool recursive,
+ PP_Bool recursive,
int32_t* result);
void OnMsgCreateModuleLocalDir(PP_Instance instance,
const std::string& path,
@@ -74,7 +74,7 @@ class PPB_Flash_Proxy : public InterfaceProxy {
void OnMsgNavigateToURL(PP_Instance instance,
const std::string& url,
const std::string& target,
- bool* result);
+ PP_Bool* result);
};
} // namespace proxy
diff --git a/ppapi/proxy/ppb_font_proxy.cc b/ppapi/proxy/ppb_font_proxy.cc
index 2dc2744..5c9dfb9 100644
--- a/ppapi/proxy/ppb_font_proxy.cc
+++ b/ppapi/proxy/ppb_font_proxy.cc
@@ -14,7 +14,7 @@ namespace proxy {
class Font : public PluginResource {
public:
- Font();
+ Font(PP_Instance instance);
virtual ~Font();
// PluginResource overrides.
@@ -31,21 +31,23 @@ class Font : public PluginResource {
DISALLOW_COPY_AND_ASSIGN(Font);
};
-Font::Font() {
+Font::Font(PP_Instance instance) : PluginResource(instance) {
memset(&desc_, 0, sizeof(PP_FontDescription_Dev));
desc_.face.type = PP_VARTYPE_UNDEFINED;
memset(&metrics_, 0, sizeof(PP_FontMetrics_Dev));
}
Font::~Font() {
- PluginDispatcher::Get()->plugin_var_tracker()->Release(desc_.face);
+ PluginVarTracker::GetInstance()->Release(desc_.face);
}
namespace {
PP_Resource Create(PP_Instance instance,
const PP_FontDescription_Dev* description) {
- PluginDispatcher* dispatcher = PluginDispatcher::Get();
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return 0;
SerializedFontDescription in_description;
in_description.SetFromPPFontDescription(dispatcher, *description, true);
@@ -53,14 +55,14 @@ PP_Resource Create(PP_Instance instance,
PP_Resource result;
SerializedFontDescription out_description;
std::string out_metrics;
- PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBFont_Create(
+ dispatcher->Send(new PpapiHostMsg_PPBFont_Create(
INTERFACE_ID_PPB_FONT,
instance, in_description, &result, &out_description, &out_metrics));
if (!result)
return 0; // Failure creating font.
- linked_ptr<Font> object(new Font);
+ linked_ptr<Font> object(new Font(instance));
out_description.SetToPPFontDescription(dispatcher, object->desc_ptr(), true);
// Convert the metrics, this is just serialized as a string of bytes.
@@ -68,7 +70,7 @@ PP_Resource Create(PP_Instance instance,
return 0;
memcpy(&object->metrics(), out_metrics.data(), sizeof(PP_FontMetrics_Dev));
- dispatcher->plugin_resource_tracker()->AddResource(result, object);
+ PluginResourceTracker::GetInstance()->AddResource(result, object);
return result;
}
@@ -78,8 +80,8 @@ PP_Bool IsFont(PP_Resource resource) {
}
PP_Bool Describe(PP_Resource font_id,
- PP_FontDescription_Dev* description,
- PP_FontMetrics_Dev* metrics) {
+ PP_FontDescription_Dev* description,
+ PP_FontMetrics_Dev* metrics) {
Font* object = PluginResource::GetAs<Font>(font_id);
if (!object)
return PP_FALSE;
@@ -87,7 +89,7 @@ PP_Bool Describe(PP_Resource font_id,
// Copy the description, the caller expects its face PP_Var to have a ref
// added to it on its behalf.
memcpy(description, &object->desc(), sizeof(PP_FontDescription_Dev));
- PluginDispatcher::Get()->plugin_var_tracker()->AddRef(description->face);
+ PluginVarTracker::GetInstance()->AddRef(description->face);
memcpy(metrics, &object->metrics(), sizeof(PP_FontMetrics_Dev));
return PP_TRUE;
@@ -100,6 +102,10 @@ PP_Bool DrawTextAt(PP_Resource font_id,
uint32_t color,
const PP_Rect* clip,
PP_Bool image_data_is_opaque) {
+ Font* object = PluginResource::GetAs<Font>(font_id);
+ if (!object)
+ return PP_FALSE;
+
PPBFont_DrawTextAt_Params params;
params.font = font_id;
params.image_data = image_data;
@@ -116,17 +122,23 @@ PP_Bool DrawTextAt(PP_Resource font_id,
}
params.image_data_is_opaque = image_data_is_opaque;
- Dispatcher* dispatcher = PluginDispatcher::Get();
+ Dispatcher* dispatcher = PluginDispatcher::GetForInstance(object->instance());
PP_Bool result = PP_FALSE;
- dispatcher->Send(new PpapiHostMsg_PPBFont_DrawTextAt(
- INTERFACE_ID_PPB_FONT,
- SerializedVarSendInput(dispatcher, text->text),
- params, &result));
+ if (dispatcher) {
+ dispatcher->Send(new PpapiHostMsg_PPBFont_DrawTextAt(
+ INTERFACE_ID_PPB_FONT,
+ SerializedVarSendInput(dispatcher, text->text),
+ params, &result));
+ }
return result;
}
int32_t MeasureText(PP_Resource font_id, const PP_TextRun_Dev* text) {
- Dispatcher* dispatcher = PluginDispatcher::Get();
+ Font* object = PluginResource::GetAs<Font>(font_id);
+ if (!object)
+ return -1;
+
+ Dispatcher* dispatcher = PluginDispatcher::GetForInstance(object->instance());
int32_t result = 0;
dispatcher->Send(new PpapiHostMsg_PPBFont_MeasureText(
INTERFACE_ID_PPB_FONT, font_id,
@@ -138,7 +150,11 @@ int32_t MeasureText(PP_Resource font_id, const PP_TextRun_Dev* text) {
uint32_t CharacterOffsetForPixel(PP_Resource font_id,
const PP_TextRun_Dev* text,
int32_t pixel_position) {
- Dispatcher* dispatcher = PluginDispatcher::Get();
+ Font* object = PluginResource::GetAs<Font>(font_id);
+ if (!object)
+ return -1;
+
+ Dispatcher* dispatcher = PluginDispatcher::GetForInstance(object->instance());
uint32_t result = 0;
dispatcher->Send(new PpapiHostMsg_PPBFont_CharacterOffsetForPixel(
INTERFACE_ID_PPB_FONT, font_id,
@@ -150,7 +166,11 @@ uint32_t CharacterOffsetForPixel(PP_Resource font_id,
int32_t PixelOffsetForCharacter(PP_Resource font_id,
const PP_TextRun_Dev* text,
uint32_t char_offset) {
- Dispatcher* dispatcher = PluginDispatcher::Get();
+ Font* object = PluginResource::GetAs<Font>(font_id);
+ if (!object)
+ return -1;
+
+ Dispatcher* dispatcher = PluginDispatcher::GetForInstance(object->instance());
int32_t result = 0;
dispatcher->Send(new PpapiHostMsg_PPBFont_PixelOffsetForCharacter(
INTERFACE_ID_PPB_FONT, font_id,
diff --git a/ppapi/proxy/ppb_fullscreen_proxy.cc b/ppapi/proxy/ppb_fullscreen_proxy.cc
index ab537ea..6ae1dca 100644
--- a/ppapi/proxy/ppb_fullscreen_proxy.cc
+++ b/ppapi/proxy/ppb_fullscreen_proxy.cc
@@ -14,15 +14,23 @@ namespace proxy {
namespace {
PP_Bool IsFullscreen(PP_Instance instance) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return PP_FALSE;
+
PP_Bool result = PP_FALSE;
- PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBFullscreen_IsFullscreen(
+ dispatcher->Send(new PpapiHostMsg_PPBFullscreen_IsFullscreen(
INTERFACE_ID_PPB_FULLSCREEN, instance, &result));
return result;
}
PP_Bool SetFullscreen(PP_Instance instance, PP_Bool fullscreen) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return PP_FALSE;
+
PP_Bool result = PP_FALSE;
- PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBFullscreen_SetFullscreen(
+ dispatcher->Send(new PpapiHostMsg_PPBFullscreen_SetFullscreen(
INTERFACE_ID_PPB_FULLSCREEN, instance, fullscreen, &result));
return result;
}
diff --git a/ppapi/proxy/ppb_graphics_2d_proxy.cc b/ppapi/proxy/ppb_graphics_2d_proxy.cc
index 033f71c..143ec44 100644
--- a/ppapi/proxy/ppb_graphics_2d_proxy.cc
+++ b/ppapi/proxy/ppb_graphics_2d_proxy.cc
@@ -21,8 +21,11 @@ namespace proxy {
class Graphics2D : public PluginResource {
public:
- Graphics2D(const PP_Size& size, PP_Bool is_always_opaque)
- : size_(size),
+ Graphics2D(PP_Instance instance,
+ const PP_Size& size,
+ PP_Bool is_always_opaque)
+ : PluginResource(instance),
+ size_(size),
is_always_opaque_(is_always_opaque),
current_flush_callback_(PP_BlockUntilComplete()) {
}
@@ -58,14 +61,18 @@ namespace {
PP_Resource Create(PP_Instance instance,
const PP_Size* size,
PP_Bool is_always_opaque) {
- PluginDispatcher* dispatcher = PluginDispatcher::Get();
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return PP_ERROR_BADARGUMENT;
+
PP_Resource result = 0;
dispatcher->Send(new PpapiHostMsg_PPBGraphics2D_Create(
INTERFACE_ID_PPB_GRAPHICS_2D, instance, *size, is_always_opaque,
&result));
if (result) {
- linked_ptr<Graphics2D> graphics_2d(new Graphics2D(*size, is_always_opaque));
- dispatcher->plugin_resource_tracker()->AddResource(result, graphics_2d);
+ linked_ptr<Graphics2D> graphics_2d(new Graphics2D(instance, *size,
+ is_always_opaque));
+ PluginResourceTracker::GetInstance()->AddResource(result, graphics_2d);
}
return result;
}
@@ -95,9 +102,17 @@ void PaintImageData(PP_Resource graphics_2d,
PP_Resource image_data,
const PP_Point* top_left,
const PP_Rect* src_rect) {
+ Graphics2D* object = PluginResource::GetAs<Graphics2D>(graphics_2d);
+ if (!object)
+ return;
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(
+ object->instance());
+ if (!dispatcher)
+ return;
+
PP_Rect dummy;
memset(&dummy, 0, sizeof(PP_Rect));
- PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBGraphics2D_PaintImageData(
+ dispatcher->Send(new PpapiHostMsg_PPBGraphics2D_PaintImageData(
INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d, image_data, *top_left,
!!src_rect, src_rect ? *src_rect : dummy));
}
@@ -105,15 +120,31 @@ void PaintImageData(PP_Resource graphics_2d,
void Scroll(PP_Resource graphics_2d,
const PP_Rect* clip_rect,
const PP_Point* amount) {
+ Graphics2D* object = PluginResource::GetAs<Graphics2D>(graphics_2d);
+ if (!object)
+ return;
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(
+ object->instance());
+ if (!dispatcher)
+ return;
+
PP_Rect dummy;
memset(&dummy, 0, sizeof(PP_Rect));
- PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBGraphics2D_Scroll(
+ dispatcher->Send(new PpapiHostMsg_PPBGraphics2D_Scroll(
INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d, !!clip_rect,
clip_rect ? *clip_rect : dummy, *amount));
}
void ReplaceContents(PP_Resource graphics_2d, PP_Resource image_data) {
- PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBGraphics2D_ReplaceContents(
+ Graphics2D* object = PluginResource::GetAs<Graphics2D>(graphics_2d);
+ if (!object)
+ return;
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(
+ object->instance());
+ if (!dispatcher)
+ return;
+
+ dispatcher->Send(new PpapiHostMsg_PPBGraphics2D_ReplaceContents(
INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d, image_data));
}
@@ -122,6 +153,10 @@ int32_t Flush(PP_Resource graphics_2d,
Graphics2D* object = PluginResource::GetAs<Graphics2D>(graphics_2d);
if (!object)
return PP_ERROR_BADRESOURCE;
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(
+ object->instance());
+ if (!dispatcher)
+ return PP_ERROR_FAILED;
// For now, disallow blocking calls. We'll need to add support for other
// threads to this later.
@@ -132,7 +167,7 @@ int32_t Flush(PP_Resource graphics_2d,
return PP_ERROR_INPROGRESS; // Can't have >1 flush pending.
object->set_current_flush_callback(callback);
- PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBGraphics2D_Flush(
+ dispatcher->Send(new PpapiHostMsg_PPBGraphics2D_Flush(
INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d));
return PP_ERROR_WOULDBLOCK;
}
diff --git a/ppapi/proxy/ppb_image_data_proxy.cc b/ppapi/proxy/ppb_image_data_proxy.cc
index 9b8c2a2..386add9 100644
--- a/ppapi/proxy/ppb_image_data_proxy.cc
+++ b/ppapi/proxy/ppb_image_data_proxy.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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.
@@ -16,6 +16,7 @@
#include "ppapi/c/trusted/ppb_image_data_trusted.h"
#include "ppapi/proxy/image_data.h"
#include "ppapi/proxy/plugin_dispatcher.h"
+#include "ppapi/proxy/plugin_resource_tracker.h"
#include "ppapi/proxy/ppapi_messages.h"
namespace pp {
@@ -24,43 +25,35 @@ namespace proxy {
namespace {
PP_ImageDataFormat GetNativeImageDataFormat() {
- int32 format = 0;
- PluginDispatcher::Get()->Send(
- new PpapiHostMsg_PPBImageData_GetNativeImageDataFormat(
- INTERFACE_ID_PPB_IMAGE_DATA, &format));
- return static_cast<PP_ImageDataFormat>(format);
+ return ImageData::GetNativeImageDataFormat();
}
PP_Bool IsImageDataFormatSupported(PP_ImageDataFormat format) {
- PP_Bool supported = PP_FALSE;
- PluginDispatcher::Get()->Send(
- new PpapiHostMsg_PPBImageData_IsImageDataFormatSupported(
- INTERFACE_ID_PPB_IMAGE_DATA, static_cast<int32_t>(format),
- &supported));
- return supported;
+ return BoolToPPBool(ImageData::IsImageDataFormatSupported(format));
}
PP_Resource Create(PP_Instance instance,
PP_ImageDataFormat format,
const PP_Size* size,
PP_Bool init_to_zero) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return PP_ERROR_BADARGUMENT;
+
PP_Resource result = 0;
std::string image_data_desc;
ImageHandle image_handle = ImageData::NullHandle;
- PluginDispatcher::Get()->Send(
- new PpapiHostMsg_PPBImageData_Create(
- INTERFACE_ID_PPB_IMAGE_DATA, instance, format, *size, init_to_zero,
- &result, &image_data_desc, &image_handle));
+ dispatcher->Send(new PpapiHostMsg_PPBImageData_Create(
+ INTERFACE_ID_PPB_IMAGE_DATA, instance, format, *size, init_to_zero,
+ &result, &image_data_desc, &image_handle));
if (result && image_data_desc.size() == sizeof(PP_ImageDataDesc)) {
// We serialize the PP_ImageDataDesc just by copying to a string.
PP_ImageDataDesc desc;
memcpy(&desc, image_data_desc.data(), sizeof(PP_ImageDataDesc));
- linked_ptr<ImageData> object(
- new ImageData(desc, image_handle));
- PluginDispatcher::Get()->plugin_resource_tracker()->AddResource(
- result, object);
+ linked_ptr<ImageData> object(new ImageData(instance, desc, image_handle));
+ PluginResourceTracker::GetInstance()->AddResource(result, object);
}
return result;
}
@@ -122,10 +115,6 @@ InterfaceID PPB_ImageData_Proxy::GetInterfaceId() const {
bool PPB_ImageData_Proxy::OnMessageReceived(const IPC::Message& msg) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PPB_ImageData_Proxy, msg)
- IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBImageData_GetNativeImageDataFormat,
- OnMsgGetNativeImageDataFormat)
- IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBImageData_IsImageDataFormatSupported,
- OnMsgIsImageDataFormatSupported)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBImageData_Create, OnMsgCreate)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
@@ -133,16 +122,6 @@ bool PPB_ImageData_Proxy::OnMessageReceived(const IPC::Message& msg) {
return handled;
}
-void PPB_ImageData_Proxy::OnMsgGetNativeImageDataFormat(int32* result) {
- *result = ppb_image_data_target()->GetNativeImageDataFormat();
-}
-
-void PPB_ImageData_Proxy::OnMsgIsImageDataFormatSupported(int32 format,
- PP_Bool* result) {
- *result = ppb_image_data_target()->IsImageDataFormatSupported(
- static_cast<PP_ImageDataFormat>(format));
-}
-
void PPB_ImageData_Proxy::OnMsgCreate(PP_Instance instance,
int32_t format,
const PP_Size& size,
diff --git a/ppapi/proxy/ppb_instance_proxy.cc b/ppapi/proxy/ppb_instance_proxy.cc
index b26a028..8962292 100644
--- a/ppapi/proxy/ppb_instance_proxy.cc
+++ b/ppapi/proxy/ppb_instance_proxy.cc
@@ -16,7 +16,10 @@ namespace proxy {
namespace {
PP_Var GetWindowObject(PP_Instance instance) {
- Dispatcher* dispatcher = PluginDispatcher::Get();
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return PP_MakeUndefined();
+
ReceiveSerializedVarReturnValue result;
dispatcher->Send(new PpapiHostMsg_PPBInstance_GetWindowObject(
INTERFACE_ID_PPB_INSTANCE, instance, &result));
@@ -24,7 +27,10 @@ PP_Var GetWindowObject(PP_Instance instance) {
}
PP_Var GetOwnerElementObject(PP_Instance instance) {
- Dispatcher* dispatcher = PluginDispatcher::Get();
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return PP_MakeUndefined();
+
ReceiveSerializedVarReturnValue result;
dispatcher->Send(new PpapiHostMsg_PPBInstance_GetOwnerElementObject(
INTERFACE_ID_PPB_INSTANCE, instance, &result));
@@ -32,21 +38,32 @@ PP_Var GetOwnerElementObject(PP_Instance instance) {
}
PP_Bool BindGraphics(PP_Instance instance, PP_Resource device) {
- PP_Bool result;
- PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBInstance_BindGraphics(
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return PP_FALSE;
+
+ PP_Bool result = PP_FALSE;
+ dispatcher->Send(new PpapiHostMsg_PPBInstance_BindGraphics(
INTERFACE_ID_PPB_INSTANCE, instance, device, &result));
return result;
}
PP_Bool IsFullFrame(PP_Instance instance) {
- PP_Bool result;
- PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBInstance_IsFullFrame(
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return PP_FALSE;
+
+ PP_Bool result = PP_FALSE;
+ dispatcher->Send(new PpapiHostMsg_PPBInstance_IsFullFrame(
INTERFACE_ID_PPB_INSTANCE, instance, &result));
return result;
}
PP_Var ExecuteScript(PP_Instance instance, PP_Var script, PP_Var* exception) {
- Dispatcher* dispatcher = PluginDispatcher::Get();
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return PP_MakeUndefined();
+
ReceiveSerializedException se(dispatcher, exception);
if (se.IsThrown())
return PP_MakeUndefined();
diff --git a/ppapi/proxy/ppb_pdf_proxy.cc b/ppapi/proxy/ppb_pdf_proxy.cc
index 776a90a..7ad8326 100644
--- a/ppapi/proxy/ppb_pdf_proxy.cc
+++ b/ppapi/proxy/ppb_pdf_proxy.cc
@@ -14,6 +14,7 @@
#include "ppapi/c/private/ppb_pdf.h"
#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/plugin_resource.h"
+#include "ppapi/proxy/plugin_resource_tracker.h"
#include "ppapi/proxy/ppapi_messages.h"
namespace pp {
@@ -21,7 +22,7 @@ namespace proxy {
class PrivateFontFile : public PluginResource {
public:
- PrivateFontFile() {}
+ PrivateFontFile(PP_Instance instance) : PluginResource(instance) {}
virtual ~PrivateFontFile() {}
// Resource overrides.
@@ -60,7 +61,10 @@ PP_Resource GetFontFileWithFallback(
PP_Instance instance,
const PP_FontDescription_Dev* description,
PP_PrivateFontCharset charset) {
- PluginDispatcher* dispatcher = PluginDispatcher::Get();
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return 0;
+
SerializedFontDescription desc;
desc.SetFromPPFontDescription(dispatcher, *description, true);
@@ -70,8 +74,8 @@ PP_Resource GetFontFileWithFallback(
if (!result)
return 0;
- linked_ptr<PrivateFontFile> object(new PrivateFontFile);
- dispatcher->plugin_resource_tracker()->AddResource(result, object);
+ linked_ptr<PrivateFontFile> object(new PrivateFontFile(instance));
+ PluginResourceTracker::GetInstance()->AddResource(result, object);
return result;
}
@@ -82,13 +86,16 @@ bool GetFontTableForPrivateFontFile(PP_Resource font_file,
PrivateFontFile* object = PluginResource::GetAs<PrivateFontFile>(font_file);
if (!object)
return false;
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(
+ object->instance());
+ if (!dispatcher)
+ return false;
std::string* contents = object->GetFontTable(table);
if (!contents) {
std::string deserialized;
- PluginDispatcher::Get()->Send(
- new PpapiHostMsg_PPBPDF_GetFontTableForPrivateFontFile(
- INTERFACE_ID_PPB_PDF, font_file, table, &deserialized));
+ dispatcher->Send(new PpapiHostMsg_PPBPDF_GetFontTableForPrivateFontFile(
+ INTERFACE_ID_PPB_PDF, font_file, table, &deserialized));
if (deserialized.empty())
return false;
contents = object->AddFontTable(table, deserialized);
diff --git a/ppapi/proxy/ppb_testing_proxy.cc b/ppapi/proxy/ppb_testing_proxy.cc
index 946cecb..fc9b9b6 100644
--- a/ppapi/proxy/ppb_testing_proxy.cc
+++ b/ppapi/proxy/ppb_testing_proxy.cc
@@ -6,6 +6,7 @@
#include "base/message_loop.h"
#include "ppapi/c/dev/ppb_testing_dev.h"
+#include "ppapi/proxy/image_data.h"
#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/ppapi_messages.h"
@@ -17,8 +18,16 @@ namespace {
PP_Bool ReadImageData(PP_Resource device_context_2d,
PP_Resource image,
const PP_Point* top_left) {
+ ImageData* image_object = PluginResource::GetAs<ImageData>(image);
+ if (!image_object)
+ return PP_FALSE;
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(
+ image_object->instance());
+ if (!dispatcher)
+ return PP_FALSE;
+
PP_Bool result = PP_FALSE;
- PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBTesting_ReadImageData(
+ dispatcher->Send(new PpapiHostMsg_PPBTesting_ReadImageData(
INTERFACE_ID_PPB_TESTING, device_context_2d, image, *top_left, &result));
return result;
}
@@ -34,10 +43,14 @@ void QuitMessageLoop() {
MessageLoop::current()->QuitNow();
}
-uint32_t GetLiveObjectCount(PP_Module module_id) {
+uint32_t GetLiveObjectsForInstance(PP_Instance instance_id) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
+ if (!dispatcher)
+ return static_cast<uint32_t>(-1);
+
uint32_t result = 0;
- PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBTesting_GetLiveObjectCount(
- INTERFACE_ID_PPB_TESTING, module_id, &result));
+ dispatcher->Send(new PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance(
+ INTERFACE_ID_PPB_TESTING, instance_id, &result));
return result;
}
@@ -45,7 +58,7 @@ const PPB_Testing_Dev testing_interface = {
&ReadImageData,
&RunMessageLoop,
&QuitMessageLoop,
- &GetLiveObjectCount
+ &GetLiveObjectsForInstance
};
} // namespace
@@ -75,8 +88,8 @@ bool PPB_Testing_Proxy::OnMessageReceived(const IPC::Message& msg) {
OnMsgRunMessageLoop)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_QuitMessageLoop,
OnMsgQuitMessageLoop)
- IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_GetLiveObjectCount,
- OnMsgGetLiveObjectCount)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance,
+ OnMsgGetLiveObjectsForInstance)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
@@ -99,9 +112,9 @@ void PPB_Testing_Proxy::OnMsgQuitMessageLoop() {
ppb_testing_target()->QuitMessageLoop();
}
-void PPB_Testing_Proxy::OnMsgGetLiveObjectCount(PP_Module module_id,
+void PPB_Testing_Proxy::OnMsgGetLiveObjectsForInstance(PP_Instance instance,
uint32_t* result) {
- *result = ppb_testing_target()->GetLiveObjectCount(module_id);
+ *result = ppb_testing_target()->GetLiveObjectsForInstance(instance);
}
} // namespace proxy
diff --git a/ppapi/proxy/ppb_testing_proxy.h b/ppapi/proxy/ppb_testing_proxy.h
index 23314a8..a878329 100644
--- a/ppapi/proxy/ppb_testing_proxy.h
+++ b/ppapi/proxy/ppb_testing_proxy.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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.
@@ -6,7 +6,7 @@
#define PPAPI_PROXY_PPB_TESTING_PROXY_H_
#include "base/basictypes.h"
-#include "ppapi/c/pp_module.h"
+#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_resource.h"
#include "ppapi/proxy/interface_proxy.h"
@@ -38,7 +38,7 @@ class PPB_Testing_Proxy : public InterfaceProxy {
PP_Bool* result);
void OnMsgRunMessageLoop(bool* dummy);
void OnMsgQuitMessageLoop();
- void OnMsgGetLiveObjectCount(PP_Module module_id, uint32_t* result);
+ void OnMsgGetLiveObjectsForInstance(PP_Instance instance, uint32_t* result);
DISALLOW_COPY_AND_ASSIGN(PPB_Testing_Proxy);
};
diff --git a/ppapi/proxy/ppb_url_loader_proxy.cc b/ppapi/proxy/ppb_url_loader_proxy.cc
index e60afd1..24e327e 100644
--- a/ppapi/proxy/ppb_url_loader_proxy.cc
+++ b/ppapi/proxy/ppb_url_loader_proxy.cc
@@ -28,7 +28,7 @@ namespace proxy {
class URLLoader : public PluginResource {
public:
- URLLoader();
+ URLLoader(PP_Instance instance);
virtual ~URLLoader();
// Resource overrides.
@@ -50,8 +50,9 @@ class URLLoader : public PluginResource {
DISALLOW_COPY_AND_ASSIGN(URLLoader);
};
-URLLoader::URLLoader()
- : bytes_sent_(-1),
+URLLoader::URLLoader(PP_Instance instance)
+ : PluginResource(instance),
+ bytes_sent_(-1),
total_bytes_to_be_sent_(-1),
bytes_received_(-1),
total_bytes_to_be_received_(-1),
@@ -64,15 +65,27 @@ URLLoader::~URLLoader() {
namespace {
+// Converts the given loader ID to the dispatcher associated with it, or NULL
+// if it couldn't be found.
+PluginDispatcher* DispatcherFromURLLoader(PP_Resource loader_id) {
+ URLLoader* object = PluginResource::GetAs<URLLoader>(loader_id);
+ if (!object)
+ return NULL;
+ return PluginDispatcher::GetForInstance(object->instance());
+}
+
// Plugin PPB_URLLoader implmentation ------------------------------------------
PP_Resource Create(PP_Instance instance_id) {
- PluginDispatcher* dispatcher = PluginDispatcher::Get();
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
+ if (!dispatcher)
+ return 0;
+
PP_Resource result = 0;
dispatcher->Send(new PpapiHostMsg_PPBURLLoader_Create(
INTERFACE_ID_PPB_URL_LOADER, instance_id, &result));
if (result)
- PPB_URLLoader_Proxy::TrackPluginResource(result);
+ PPB_URLLoader_Proxy::TrackPluginResource(instance_id, result);
return result;
}
@@ -84,7 +97,10 @@ PP_Bool IsURLLoader(PP_Resource resource) {
int32_t Open(PP_Resource loader_id,
PP_Resource request_id,
PP_CompletionCallback callback) {
- Dispatcher* dispatcher = PluginDispatcher::Get();
+ PluginDispatcher* dispatcher = DispatcherFromURLLoader(loader_id);
+ if (!dispatcher)
+ return PP_ERROR_BADRESOURCE;
+
dispatcher->Send(new PpapiHostMsg_PPBURLLoader_Open(
INTERFACE_ID_PPB_URL_LOADER, loader_id, request_id,
dispatcher->callback_tracker().SendCallback(callback)));
@@ -93,7 +109,10 @@ int32_t Open(PP_Resource loader_id,
int32_t FollowRedirect(PP_Resource loader_id,
PP_CompletionCallback callback) {
- Dispatcher* dispatcher = PluginDispatcher::Get();
+ PluginDispatcher* dispatcher = DispatcherFromURLLoader(loader_id);
+ if (!dispatcher)
+ return PP_ERROR_BADRESOURCE;
+
dispatcher->Send(new PpapiHostMsg_PPBURLLoader_FollowRedirect(
INTERFACE_ID_PPB_URL_LOADER, loader_id,
dispatcher->callback_tracker().SendCallback(callback)));
@@ -129,6 +148,10 @@ PP_Bool GetDownloadProgress(PP_Resource loader_id,
}
PP_Resource GetResponseInfo(PP_Resource loader_id) {
+ URLLoader* object = PluginResource::GetAs<URLLoader>(loader_id);
+ if (!object)
+ return 0;
+
// If we find that plugins are frequently requesting the response info, we
// can improve performance by caching the PP_Resource in the URLLoader
// object. This way we only have to do IPC for the first request. However,
@@ -136,16 +159,20 @@ PP_Resource GetResponseInfo(PP_Resource loader_id) {
// optimizing this case.
PP_Resource result;
- PluginDispatcher* dispatcher = PluginDispatcher::Get();
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(
+ object->instance());
+ if (!dispatcher)
+ return PP_ERROR_BADRESOURCE;
+
dispatcher->Send(new PpapiHostMsg_PPBURLLoader_GetResponseInfo(
INTERFACE_ID_PPB_URL_LOADER, loader_id, &result));
- if (dispatcher->plugin_resource_tracker()->PreparePreviouslyTrackedResource(
- result))
+ if (PluginResourceTracker::GetInstance()->
+ PreparePreviouslyTrackedResource(result))
return result;
// Tell the response info to create a tracking object and add it to the
// resource tracker.
- PPB_URLResponseInfo_Proxy::TrackPluginResource(result);
+ PPB_URLResponseInfo_Proxy::TrackPluginResource(object->instance(), result);
return result;
}
@@ -156,6 +183,10 @@ int32_t ReadResponseBody(PP_Resource loader_id,
URLLoader* object = PluginResource::GetAs<URLLoader>(loader_id);
if (!object)
return PP_ERROR_BADRESOURCE;
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(
+ object->instance());
+ if (!dispatcher)
+ return PP_ERROR_BADRESOURCE;
if (!buffer)
return PP_ERROR_BADARGUMENT; // Must specify an output buffer.
@@ -170,14 +201,17 @@ int32_t ReadResponseBody(PP_Resource loader_id,
object->current_read_callback_ = callback;
object->current_read_buffer_ = buffer;
- PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBURLLoader_ReadResponseBody(
+ dispatcher->Send(new PpapiHostMsg_PPBURLLoader_ReadResponseBody(
INTERFACE_ID_PPB_URL_LOADER, loader_id, bytes_to_read));
return PP_ERROR_WOULDBLOCK;
}
int32_t FinishStreamingToFile(PP_Resource loader_id,
PP_CompletionCallback callback) {
- Dispatcher* dispatcher = PluginDispatcher::Get();
+ PluginDispatcher* dispatcher = DispatcherFromURLLoader(loader_id);
+ if (!dispatcher)
+ return PP_ERROR_BADRESOURCE;
+
dispatcher->Send(new PpapiHostMsg_PPBURLLoader_FinishStreamingToFile(
INTERFACE_ID_PPB_URL_LOADER, loader_id,
dispatcher->callback_tracker().SendCallback(callback)));
@@ -185,7 +219,11 @@ int32_t FinishStreamingToFile(PP_Resource loader_id,
}
void Close(PP_Resource loader_id) {
- PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBURLLoader_Close(
+ PluginDispatcher* dispatcher = DispatcherFromURLLoader(loader_id);
+ if (!dispatcher)
+ return;
+
+ dispatcher->Send(new PpapiHostMsg_PPBURLLoader_Close(
INTERFACE_ID_PPB_URL_LOADER, loader_id));
}
@@ -234,10 +272,11 @@ PPB_URLLoader_Proxy::~PPB_URLLoader_Proxy() {
}
// static
-void PPB_URLLoader_Proxy::TrackPluginResource(PP_Resource url_loader_resource) {
- linked_ptr<URLLoader> object(new URLLoader);
- PluginDispatcher::Get()->plugin_resource_tracker()->AddResource(
- url_loader_resource, object);
+void PPB_URLLoader_Proxy::TrackPluginResource(PP_Instance instance,
+ PP_Resource url_loader_resource) {
+ linked_ptr<URLLoader> object(new URLLoader(instance));
+ PluginResourceTracker::GetInstance()->AddResource(url_loader_resource,
+ object);
}
const void* PPB_URLLoader_Proxy::GetSourceInterface() const {
diff --git a/ppapi/proxy/ppb_url_loader_proxy.h b/ppapi/proxy/ppb_url_loader_proxy.h
index 3755d46..c05926a 100644
--- a/ppapi/proxy/ppb_url_loader_proxy.h
+++ b/ppapi/proxy/ppb_url_loader_proxy.h
@@ -30,7 +30,8 @@ class PPB_URLLoader_Proxy : public InterfaceProxy {
// they are also provided to PPP_Instance.OnMsgHandleDocumentLoad. This
// function allows the proxy for DocumentLoad to create the correct plugin
// proxied info for the given browser-supplied URLLoader resource ID.
- static void TrackPluginResource(PP_Resource url_loader_resource);
+ static void TrackPluginResource(PP_Instance instance,
+ PP_Resource url_loader_resource);
const PPB_URLLoader* ppb_url_loader_target() const {
return reinterpret_cast<const PPB_URLLoader*>(target_interface());
diff --git a/ppapi/proxy/ppb_url_request_info_proxy.cc b/ppapi/proxy/ppb_url_request_info_proxy.cc
index fdd5e5d..9c98cfe 100644
--- a/ppapi/proxy/ppb_url_request_info_proxy.cc
+++ b/ppapi/proxy/ppb_url_request_info_proxy.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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.
@@ -14,7 +14,7 @@ namespace proxy {
class URLRequestInfo : public PluginResource {
public:
- URLRequestInfo() {}
+ URLRequestInfo(PP_Instance instance) : PluginResource(instance) {}
virtual ~URLRequestInfo() {}
// Resource overrides.
@@ -26,14 +26,26 @@ class URLRequestInfo : public PluginResource {
namespace {
+// Returns the dispatcher associated with the given URLRequestInfo, or NULL if
+// none exists.
+PluginDispatcher* DispatcherFromURLRequestInfo(PP_Resource resource) {
+ URLRequestInfo* object = PluginResource::GetAs<URLRequestInfo>(resource);
+ if (!object)
+ return NULL;
+ return PluginDispatcher::GetForInstance(object->instance());
+}
+
PP_Resource Create(PP_Instance instance) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return 0;
+
PP_Resource result;
- PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBURLRequestInfo_Create(
+ dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_Create(
INTERFACE_ID_PPB_URL_REQUEST_INFO, instance, &result));
if (result) {
- linked_ptr<URLRequestInfo> object(new URLRequestInfo);
- PluginDispatcher::Get()->plugin_resource_tracker()->AddResource(
- result, object);
+ linked_ptr<URLRequestInfo> object(new URLRequestInfo(instance));
+ PluginResourceTracker::GetInstance()->AddResource(result, object);
}
return result;
}
@@ -46,7 +58,10 @@ PP_Bool IsURLRequestInfo(PP_Resource resource) {
PP_Bool SetProperty(PP_Resource request_id,
PP_URLRequestProperty property,
PP_Var var) {
- Dispatcher* dispatcher = PluginDispatcher::Get();
+ PluginDispatcher* dispatcher = DispatcherFromURLRequestInfo(request_id);
+ if (!dispatcher)
+ return PP_FALSE;
+
dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_SetProperty(
INTERFACE_ID_PPB_URL_REQUEST_INFO, request_id,
static_cast<int32_t>(property),
@@ -59,10 +74,12 @@ PP_Bool SetProperty(PP_Resource request_id,
PP_Bool AppendDataToBody(PP_Resource request_id,
const char* data, uint32_t len) {
- PluginDispatcher::Get()->Send(
- new PpapiHostMsg_PPBURLRequestInfo_AppendDataToBody(
- INTERFACE_ID_PPB_URL_REQUEST_INFO, request_id,
- std::string(data, len)));
+ PluginDispatcher* dispatcher = DispatcherFromURLRequestInfo(request_id);
+ if (!dispatcher)
+ return PP_FALSE;
+
+ dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_AppendDataToBody(
+ INTERFACE_ID_PPB_URL_REQUEST_INFO, request_id, std::string(data, len)));
// TODO(brettw) do some validation. We should be able to tell on the plugin
// side whether the request will succeed or fail in the renderer.
@@ -74,10 +91,13 @@ PP_Bool AppendFileToBody(PP_Resource request_id,
int64_t start_offset,
int64_t number_of_bytes,
PP_Time expected_last_modified_time) {
- PluginDispatcher::Get()->Send(
- new PpapiHostMsg_PPBURLRequestInfo_AppendFileToBody(
- INTERFACE_ID_PPB_URL_REQUEST_INFO, request_id, file_ref_id,
- start_offset, number_of_bytes, expected_last_modified_time));
+ PluginDispatcher* dispatcher = DispatcherFromURLRequestInfo(request_id);
+ if (!dispatcher)
+ return PP_FALSE;
+
+ dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_AppendFileToBody(
+ INTERFACE_ID_PPB_URL_REQUEST_INFO, request_id, file_ref_id,
+ start_offset, number_of_bytes, expected_last_modified_time));
// TODO(brettw) do some validation. We should be able to tell on the plugin
// side whether the request will succeed or fail in the renderer.
diff --git a/ppapi/proxy/ppb_url_response_info_proxy.cc b/ppapi/proxy/ppb_url_response_info_proxy.cc
index 01e1763..d9ddc20 100644
--- a/ppapi/proxy/ppb_url_response_info_proxy.cc
+++ b/ppapi/proxy/ppb_url_response_info_proxy.cc
@@ -15,7 +15,7 @@ namespace proxy {
class URLResponseInfo : public PluginResource {
public:
- URLResponseInfo() {}
+ URLResponseInfo(PP_Instance instance) : PluginResource(instance) {}
virtual ~URLResponseInfo() {}
// Resource overrides.
@@ -33,7 +33,14 @@ PP_Bool IsURLResponseInfo(PP_Resource resource) {
}
PP_Var GetProperty(PP_Resource response, PP_URLResponseProperty property) {
- Dispatcher* dispatcher = PluginDispatcher::Get();
+ URLResponseInfo* object = PluginResource::GetAs<URLResponseInfo>(response);
+ if (!object)
+ return PP_MakeUndefined();
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(
+ object->instance());
+ if (!dispatcher)
+ return PP_MakeUndefined();
+
ReceiveSerializedVarReturnValue result;
dispatcher->Send(new PpapiHostMsg_PPBURLResponseInfo_GetProperty(
INTERFACE_ID_PPB_URL_RESPONSE_INFO, response, property, &result));
@@ -43,7 +50,6 @@ PP_Var GetProperty(PP_Resource response, PP_URLResponseProperty property) {
PP_Resource GetBodyAsFileRef(PP_Resource response) {
PP_Resource result = 0;
/*
- Dispatcher* dispatcher = PluginDispatcher::Get();
dispatcher->Send(new PpapiHostMsg_PPBURLResponseInfo_GetBodyAsFileRef(
INTERFACE_ID_PPB_URL_RESPONSE_INFO, response, &result));
// TODO(brettw) when we have FileRef proxied, make an object from that
@@ -71,9 +77,10 @@ PPB_URLResponseInfo_Proxy::~PPB_URLResponseInfo_Proxy() {
// static
void PPB_URLResponseInfo_Proxy::TrackPluginResource(
+ PP_Instance instance,
PP_Resource response_resource) {
- linked_ptr<URLResponseInfo> object(new URLResponseInfo);
- PluginDispatcher::Get()->plugin_resource_tracker()->AddResource(
+ linked_ptr<URLResponseInfo> object(new URLResponseInfo(instance));
+ PluginResourceTracker::GetInstance()->AddResource(
response_resource, object);
}
diff --git a/ppapi/proxy/ppb_url_response_info_proxy.h b/ppapi/proxy/ppb_url_response_info_proxy.h
index c1de259..079f3b7 100644
--- a/ppapi/proxy/ppb_url_response_info_proxy.h
+++ b/ppapi/proxy/ppb_url_response_info_proxy.h
@@ -6,6 +6,7 @@
#define PPAPI_PROXY_PPB_URL_RESPONSE_INFO_PROXY_H_
#include "base/basictypes.h"
+#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_module.h"
#include "ppapi/c/pp_resource.h"
#include "ppapi/proxy/interface_proxy.h"
@@ -26,7 +27,8 @@ class PPB_URLResponseInfo_Proxy : public InterfaceProxy {
// URLResponseInfo objects are actually returned by the URLLoader class.
// This function allows the URLLoader proxy to start the tracking of
// a response info object in the plugin.
- static void TrackPluginResource(PP_Resource response_resource);
+ static void TrackPluginResource(PP_Instance instance,
+ PP_Resource response_resource);
const PPB_URLResponseInfo* ppb_url_response_info_target() const {
return static_cast<const PPB_URLResponseInfo*>(target_interface());
diff --git a/ppapi/proxy/ppb_var_deprecated_proxy.cc b/ppapi/proxy/ppb_var_deprecated_proxy.cc
index 0fcca7f..665f24d 100644
--- a/ppapi/proxy/ppb_var_deprecated_proxy.cc
+++ b/ppapi/proxy/ppb_var_deprecated_proxy.cc
@@ -23,24 +23,24 @@ namespace {
// PPP_Var_Deprecated plugin ---------------------------------------------------
void AddRefVar(PP_Var var) {
- PluginDispatcher::Get()->plugin_var_tracker()->AddRef(var);
+ PluginVarTracker::GetInstance()->AddRef(var);
}
void ReleaseVar(PP_Var var) {
- PluginDispatcher::Get()->plugin_var_tracker()->Release(var);
+ PluginVarTracker::GetInstance()->Release(var);
}
PP_Var VarFromUtf8(PP_Module module, const char* data, uint32_t len) {
PP_Var ret;
ret.type = PP_VARTYPE_STRING;
- ret.value.as_id = PluginDispatcher::Get()->plugin_var_tracker()->MakeString(
+ ret.value.as_id = PluginVarTracker::GetInstance()->MakeString(
data, len);
return ret;
}
const char* VarToUtf8(PP_Var var, uint32_t* len) {
const std::string* str =
- PluginDispatcher::Get()->plugin_var_tracker()->GetExistingString(var);
+ PluginVarTracker::GetInstance()->GetExistingString(var);
if (str) {
*len = static_cast<uint32_t>(str->size());
return str->c_str();
diff --git a/ppapi/proxy/ppp_instance_proxy.cc b/ppapi/proxy/ppp_instance_proxy.cc
index 886b7f1..3614c36 100644
--- a/ppapi/proxy/ppp_instance_proxy.cc
+++ b/ppapi/proxy/ppp_instance_proxy.cc
@@ -182,7 +182,7 @@ void PPP_Instance_Proxy::OnMsgHandleInputEvent(PP_Instance instance,
void PPP_Instance_Proxy::OnMsgHandleDocumentLoad(PP_Instance instance,
PP_Resource url_loader,
PP_Bool* result) {
- PPB_URLLoader_Proxy::TrackPluginResource(url_loader);
+ PPB_URLLoader_Proxy::TrackPluginResource(instance, url_loader);
*result = ppp_instance_target()->HandleDocumentLoad(
instance, url_loader);
}
diff --git a/ppapi/proxy/serialized_var.cc b/ppapi/proxy/serialized_var.cc
index a5356c5..5987ceb 100644
--- a/ppapi/proxy/serialized_var.cc
+++ b/ppapi/proxy/serialized_var.cc
@@ -225,9 +225,9 @@ SerializedVar::~SerializedVar() {
SerializedVarSendInput::SerializedVarSendInput(Dispatcher* dispatcher,
const PP_Var& var)
- : SerializedVar(dispatcher->serialization_rules(), var) {
- dispatcher->serialization_rules()->SendCallerOwned(var,
- inner_->GetStringPtr());
+ : SerializedVar(dispatcher->serialization_rules()) {
+ inner_->SetVar(dispatcher->serialization_rules()->SendCallerOwned(
+ var, inner_->GetStringPtr()));
}
// static
@@ -237,9 +237,10 @@ void SerializedVarSendInput::ConvertVector(Dispatcher* dispatcher,
std::vector<SerializedVar>* output) {
output->resize(input_count);
for (size_t i = 0; i < input_count; i++) {
- (*output)[i] = SerializedVar(dispatcher->serialization_rules(), input[i]);
- dispatcher->serialization_rules()->SendCallerOwned(
- input[i], (*output)[i].inner_->GetStringPtr());
+ SerializedVar& cur = (*output)[i];
+ cur = SerializedVar(dispatcher->serialization_rules());
+ cur.inner_->SetVar(dispatcher->serialization_rules()->SendCallerOwned(
+ input[i], cur.inner_->GetStringPtr()));
}
}
@@ -251,7 +252,7 @@ ReceiveSerializedVarReturnValue::ReceiveSerializedVarReturnValue() {
PP_Var ReceiveSerializedVarReturnValue::Return(Dispatcher* dispatcher) {
inner_->set_serialization_rules(dispatcher->serialization_rules());
inner_->SetVar(inner_->serialization_rules()->ReceivePassRef(
- inner_->GetIncompleteVar(), inner_->GetString()));
+ inner_->GetIncompleteVar(), inner_->GetString(), dispatcher));
return inner_->GetVar();
}
@@ -260,6 +261,7 @@ PP_Var ReceiveSerializedVarReturnValue::Return(Dispatcher* dispatcher) {
ReceiveSerializedException::ReceiveSerializedException(Dispatcher* dispatcher,
PP_Var* exception)
: SerializedVar(dispatcher->serialization_rules()),
+ dispatcher_(dispatcher),
exception_(exception) {
}
@@ -268,7 +270,7 @@ ReceiveSerializedException::~ReceiveSerializedException() {
// When an output exception is specified, it will take ownership of the
// reference.
inner_->SetVar(inner_->serialization_rules()->ReceivePassRef(
- inner_->GetIncompleteVar(), inner_->GetString()));
+ inner_->GetIncompleteVar(), inner_->GetString(), dispatcher_));
*exception_ = inner_->GetVar();
} else {
// When no output exception is specified, the browser thinks we have a ref
@@ -342,7 +344,8 @@ PP_Var SerializedVarReceiveInput::Get(Dispatcher* dispatcher) {
serialized_.inner_->SetVar(
serialized_.inner_->serialization_rules()->BeginReceiveCallerOwned(
serialized_.inner_->GetIncompleteVar(),
- serialized_.inner_->GetStringPtr()));
+ serialized_.inner_->GetStringPtr(),
+ dispatcher));
return serialized_.inner_->GetVar();
}
@@ -372,7 +375,8 @@ PP_Var* SerializedVarVectorReceiveInput::Get(Dispatcher* dispatcher,
serialized_[i].inner_->SetVar(
serialized_[i].inner_->serialization_rules()->BeginReceiveCallerOwned(
serialized_[i].inner_->GetIncompleteVar(),
- serialized_[i].inner_->GetStringPtr()));
+ serialized_[i].inner_->GetStringPtr(),
+ dispatcher));
deserialized_[i] = serialized_[i].inner_->GetVar();
}
@@ -390,14 +394,14 @@ void SerializedVarReturnValue::Return(Dispatcher* dispatcher,
const PP_Var& var) {
serialized_->inner_->set_serialization_rules(
dispatcher->serialization_rules());
- serialized_->inner_->SetVar(var);
// Var must clean up after our BeginSendPassRef call.
serialized_->inner_->set_cleanup_mode(SerializedVar::END_SEND_PASS_REF);
- dispatcher->serialization_rules()->BeginSendPassRef(
- serialized_->inner_->GetIncompleteVar(),
- serialized_->inner_->GetStringPtr());
+ serialized_->inner_->SetVar(
+ dispatcher->serialization_rules()->BeginSendPassRef(
+ var,
+ serialized_->inner_->GetStringPtr()));
}
// SerializedVarOutParam -------------------------------------------------------
@@ -411,9 +415,9 @@ SerializedVarOutParam::~SerializedVarOutParam() {
if (serialized_->inner_->serialization_rules()) {
// When unset, OutParam wasn't called. We'll just leave the var untouched
// in that case.
- serialized_->inner_->SetVar(writable_var_);
- serialized_->inner_->serialization_rules()->BeginSendPassRef(
- writable_var_, serialized_->inner_->GetStringPtr());
+ serialized_->inner_->SetVar(
+ serialized_->inner_->serialization_rules()->BeginSendPassRef(
+ writable_var_, serialized_->inner_->GetStringPtr()));
// Normally the current object will be created on the stack to wrap a
// SerializedVar and won't have a scope around the actual IPC send. So we
diff --git a/ppapi/proxy/serialized_var.h b/ppapi/proxy/serialized_var.h
index 21adfd0..cf2d4d4 100644
--- a/ppapi/proxy/serialized_var.h
+++ b/ppapi/proxy/serialized_var.h
@@ -228,6 +228,8 @@ class ReceiveSerializedException : public SerializedVar {
bool IsThrown() const;
private:
+ Dispatcher* dispatcher_;
+
// The input/output exception we're wrapping. May be NULL.
PP_Var* exception_;
diff --git a/ppapi/proxy/var_serialization_rules.h b/ppapi/proxy/var_serialization_rules.h
index a6741ee..f18b6f0 100644
--- a/ppapi/proxy/var_serialization_rules.h
+++ b/ppapi/proxy/var_serialization_rules.h
@@ -12,6 +12,8 @@
namespace pp {
namespace proxy {
+class Dispatcher;
+
// Encapsulates the rules for serializing and deserializing vars to and from
// the local process. The renderer and the plugin process each have separate
// bookkeeping rules.
@@ -27,8 +29,9 @@ class VarSerializationRules {
// Prepares the given var for sending to the callee. If the var is a string,
// the value of that string will be placed in *str_val. If the var is not
- // a string, str_val will be untouched and may be NULL.
- virtual void SendCallerOwned(const PP_Var& var, std::string* str_val) = 0;
+ // a string, str_val will be untouched and may be NULL. The return value will
+ // be the var valid for the host process.
+ virtual PP_Var SendCallerOwned(const PP_Var& var, std::string* str_val) = 0;
// When receiving a caller-owned variable, normally we don't have to do
// anything. However, in the case of strings, we need to deserialize the
@@ -39,13 +42,13 @@ class VarSerializationRules {
// BeginReceiveCallerOwned takes a var from IPC and an optional pointer to
// the deserialized string (which will be used only when var is a
// VARTYPE_STRING and may be NULL otherwise) and returns a new var
- // representing the input in the local process. The output will be the same
- // as the input except for strings.
+ // representing the input in the local process.
//
// EndReceiveCallerOwned destroys the string created by Begin* and does
// nothing otherwise. It should be called with the result of Begin*.
virtual PP_Var BeginReceiveCallerOwned(const PP_Var& var,
- const std::string* str_val) = 0;
+ const std::string* str_val,
+ Dispatcher* dispatcher) = 0;
virtual void EndReceiveCallerOwned(const PP_Var& var) = 0;
// Passinag refs -------------------------------------------------------------
@@ -61,14 +64,18 @@ class VarSerializationRules {
// Creates a var in the context of the local process from the given
// deserialized var and deserialized string (which will be used only when var
// is a VARTYPE_STRING and may be NULL otherwise). The input var/string
- // should be the result of calling SendPassRef in the remote process.
+ // should be the result of calling SendPassRef in the remote process. The
+ // return value is the var valid in the plugin process.
virtual PP_Var ReceivePassRef(const PP_Var& var,
- const std::string& str_val) = 0;
+ const std::string& str_val,
+ Dispatcher* dispatcher) = 0;
// Prepares a var to be sent to the remote side. One local reference will
// be passed to the remote side. Call Begin* before doing the send and End*
// after doing the send. See SendCallerOwned for a description of the string.
- virtual void BeginSendPassRef(const PP_Var& var, std::string* str_val) = 0;
+ // The return value from BeginSendPassRef will be the var valid for the host
+ // process.
+ virtual PP_Var BeginSendPassRef(const PP_Var& var, std::string* str_val) = 0;
virtual void EndSendPassRef(const PP_Var& var) = 0;
// ---------------------------------------------------------------------------
diff --git a/ppapi/shared_impl/DEPS b/ppapi/shared_impl/DEPS
index 578728a..ebb73ea 100644
--- a/ppapi/shared_impl/DEPS
+++ b/ppapi/shared_impl/DEPS
@@ -6,4 +6,8 @@ include_rules = [
"-ipc",
"-ppapi/cpp",
+
+ # The image data implementation depends on how we're building Skia. This isn't
+ # a link-time dependency, so it's OK.
+ "+skia/config/SkUserConfig.h"
]
diff --git a/ppapi/shared_impl/image_data_impl.cc b/ppapi/shared_impl/image_data_impl.cc
new file mode 100644
index 0000000..afdc512
--- /dev/null
+++ b/ppapi/shared_impl/image_data_impl.cc
@@ -0,0 +1,29 @@
+// 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/shared_impl/image_data_impl.h"
+
+#include "skia/config/SkUserConfig.h"
+
+namespace pp {
+namespace shared_impl {
+
+// static
+PP_ImageDataFormat ImageDataImpl::GetNativeImageDataFormat() {
+ if (SK_B32_SHIFT == 0)
+ return PP_IMAGEDATAFORMAT_BGRA_PREMUL;
+ else if (SK_R32_SHIFT == 0)
+ return PP_IMAGEDATAFORMAT_RGBA_PREMUL;
+ else
+ return PP_IMAGEDATAFORMAT_BGRA_PREMUL; // Default to something on failure.
+}
+
+// static
+bool ImageDataImpl::IsImageDataFormatSupported(PP_ImageDataFormat format) {
+ return format == PP_IMAGEDATAFORMAT_BGRA_PREMUL ||
+ format == PP_IMAGEDATAFORMAT_RGBA_PREMUL;
+}
+
+} // namespace shared_impl
+} // namespace pp
diff --git a/ppapi/shared_impl/image_data_impl.h b/ppapi/shared_impl/image_data_impl.h
new file mode 100644
index 0000000..6b8a7cc
--- /dev/null
+++ b/ppapi/shared_impl/image_data_impl.h
@@ -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.
+
+#ifndef PPAPI_SHARED_IMPL_IMAGE_DATA_IMPL_H_
+#define PPAPI_SHARED_IMPL_IMAGE_DATA_IMPL_H_
+
+#include "ppapi/c/pp_bool.h"
+#include "ppapi/c/ppb_image_data.h"
+
+namespace pp {
+namespace shared_impl {
+
+// Contains the implementation of some simple image data functions that are
+// shared between the proxy and Chrome's implementation. Since these functions
+// are just lists of what we support, it's much easier to just have the same
+// code run in the plugin process than to proxy it.
+//
+// It's possible the implementation will get more complex. In this case, it's
+// probably best to have some kind of "configuration" message that the renderer
+// sends to the plugin process on startup that contains all of these kind of
+// settings.
+class ImageDataImpl {
+ public:
+ static PP_ImageDataFormat GetNativeImageDataFormat();
+ static bool IsImageDataFormatSupported(PP_ImageDataFormat format);
+};
+
+} // namespace shared_impl
+} // namespace pp
+
+#endif // PPAPI_SHARED_IMPL_IMAGE_DATA_IMPL_H_
diff --git a/ppapi/tests/test_var_deprecated.cc b/ppapi/tests/test_var_deprecated.cc
index 724e914..48c223a 100644
--- a/ppapi/tests/test_var_deprecated.cc
+++ b/ppapi/tests/test_var_deprecated.cc
@@ -47,8 +47,8 @@ void TestVarDeprecated::RunTest() {
}
std::string TestVarDeprecated::TestBasicString() {
- uint32_t before_object = testing_interface_->GetLiveObjectCount(
- pp::Module::Get()->pp_module());
+ uint32_t before_object = testing_interface_->GetLiveObjectsForInstance(
+ instance_->pp_instance());
{
const uint32_t kStrLen = 5;
const char kStr[kStrLen + 1] = "Hello";
@@ -70,8 +70,8 @@ std::string TestVarDeprecated::TestBasicString() {
}
// Make sure nothing leaked.
- ASSERT_TRUE(testing_interface_->GetLiveObjectCount(
- pp::Module::Get()->pp_module()) == before_object);
+ ASSERT_TRUE(testing_interface_->GetLiveObjectsForInstance(
+ instance_->pp_instance()) == before_object);
PASS();
}
@@ -251,8 +251,8 @@ std::string TestVarDeprecated::TestVarToUtf8ForWrongType() {
}
std::string TestVarDeprecated::TestHasPropertyAndMethod() {
- uint32_t before_objects = testing_interface_->GetLiveObjectCount(
- pp::Module::Get()->pp_module());
+ uint32_t before_objects = testing_interface_->GetLiveObjectsForInstance(
+ instance_->pp_instance());
{
pp::Var window = instance_->GetWindowObject();
ASSERT_TRUE(window.is_object());
@@ -321,8 +321,8 @@ std::string TestVarDeprecated::TestHasPropertyAndMethod() {
}
// Make sure nothing leaked.
- ASSERT_TRUE(testing_interface_->GetLiveObjectCount(
- pp::Module::Get()->pp_module()) == before_objects);
+ ASSERT_TRUE(testing_interface_->GetLiveObjectsForInstance(
+ instance_->pp_instance()) == before_objects);
PASS();
}
diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc
index ea0188d..fdd9448 100644
--- a/webkit/plugins/ppapi/plugin_module.cc
+++ b/webkit/plugins/ppapi/plugin_module.cc
@@ -191,18 +191,15 @@ void QuitMessageLoop() {
MessageLoop::current()->QuitNow();
}
-uint32_t GetLiveObjectCount(PP_Module module_id) {
- PluginModule* module = ResourceTracker::Get()->GetModule(module_id);
- if (!module)
- return static_cast<uint32_t>(-1);
- return ResourceTracker::Get()->GetLiveObjectsForModule(module);
+uint32_t GetLiveObjectsForInstance(PP_Instance instance_id) {
+ return ResourceTracker::Get()->GetLiveObjectsForInstance(instance_id);
}
const PPB_Testing_Dev testing_interface = {
&ReadImageData,
&RunMessageLoop,
&QuitMessageLoop,
- &GetLiveObjectCount
+ &GetLiveObjectsForInstance
};
// GetInterface ----------------------------------------------------------------
diff --git a/webkit/plugins/ppapi/ppb_audio_impl.cc b/webkit/plugins/ppapi/ppb_audio_impl.cc
index 93561f8..1a36e70 100644
--- a/webkit/plugins/ppapi/ppb_audio_impl.cc
+++ b/webkit/plugins/ppapi/ppb_audio_impl.cc
@@ -49,6 +49,8 @@ uint32_t RecommendSampleFrameCount(PP_AudioSampleRate sample_rate,
uint32_t requested_sample_frame_count) {
// TODO(brettw) Currently we don't actually query to get a value from the
// hardware, so we always return the input for in-range values.
+ //
+ // Danger: this code is duplicated in the audio config proxy.
if (requested_sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT)
return PP_AUDIOMINSAMPLEFRAMECOUNT;
if (requested_sample_frame_count > PP_AUDIOMAXSAMPLEFRAMECOUNT)
@@ -219,8 +221,10 @@ PPB_Audio_Impl::PPB_Audio_Impl(PluginInstance* instance)
PPB_Audio_Impl::~PPB_Audio_Impl() {
// Calling ShutDown() makes sure StreamCreated cannot be called anymore.
- audio_->ShutDown();
- audio_ = NULL;
+ if (audio_) {
+ audio_->ShutDown();
+ audio_ = NULL;
+ }
// If the completion callback hasn't fired yet, do so here
// with an error condition.
@@ -263,6 +267,8 @@ PP_Resource PPB_Audio_Impl::GetCurrentConfig() {
}
bool PPB_Audio_Impl::StartPlayback() {
+ if (!audio_)
+ return false;
if (playing())
return true;
SetStartPlaybackState();
@@ -270,6 +276,8 @@ bool PPB_Audio_Impl::StartPlayback() {
}
bool PPB_Audio_Impl::StopPlayback() {
+ if (!audio_)
+ return false;
if (!playing())
return true;
if (!audio_->StopPlayback())
diff --git a/webkit/plugins/ppapi/ppb_flash_impl.cc b/webkit/plugins/ppapi/ppb_flash_impl.cc
index 386b24f..33e0d11 100644
--- a/webkit/plugins/ppapi/ppb_flash_impl.cc
+++ b/webkit/plugins/ppapi/ppb_flash_impl.cc
@@ -28,11 +28,11 @@ namespace ppapi {
namespace {
-void SetInstanceAlwaysOnTop(PP_Instance pp_instance, bool on_top) {
+void SetInstanceAlwaysOnTop(PP_Instance pp_instance, PP_Bool on_top) {
PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance);
if (!instance)
return;
- instance->set_always_on_top(on_top);
+ instance->set_always_on_top(PPBoolToBool(on_top));
}
PP_Var GetProxyForURL(PP_Instance pp_instance, const char* url) {
@@ -114,14 +114,15 @@ int32_t RenameModuleLocalFile(PP_Instance pp_instance,
int32_t DeleteModuleLocalFileOrDir(PP_Instance pp_instance,
const char* path,
- bool recursive) {
+ PP_Bool recursive) {
PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance);
if (!instance)
return PP_ERROR_FAILED;
base::PlatformFileError result =
instance->delegate()->DeleteModuleLocalFileOrDir(
- instance->module()->name(), GetFilePathFromUTF8(path), recursive);
+ instance->module()->name(), GetFilePathFromUTF8(path),
+ PPBoolToBool(recursive));
return PlatformFileErrorToPepperError(result);
}
@@ -192,7 +193,7 @@ int32_t GetModuleLocalDirContents(PP_Instance pp_instance,
char* name_copy = new char[size];
memcpy(name_copy, name.c_str(), size);
entry.name = name_copy;
- entry.is_dir = pepper_contents[i].is_dir;
+ entry.is_dir = BoolToPPBool(pepper_contents[i].is_dir);
}
return PP_OK;
}
@@ -207,13 +208,13 @@ void FreeModuleLocalDirContents(PP_Instance instance,
delete contents;
}
-bool NavigateToURL(PP_Instance pp_instance,
- const char* url,
- const char* target) {
+PP_Bool NavigateToURL(PP_Instance pp_instance,
+ const char* url,
+ const char* target) {
PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance);
if (!instance)
- return false;
- return instance->NavigateToURL(url, target);
+ return PP_FALSE;
+ return BoolToPPBool(instance->NavigateToURL(url, target));
}
const PPB_Flash ppb_flash = {
diff --git a/webkit/plugins/ppapi/ppb_flash_impl.h b/webkit/plugins/ppapi/ppb_flash_impl.h
index 7eb2e8b..8b02dee 100644
--- a/webkit/plugins/ppapi/ppb_flash_impl.h
+++ b/webkit/plugins/ppapi/ppb_flash_impl.h
@@ -23,20 +23,20 @@ class PPB_Flash_Impl {
// exposed to the plugin.
static const PPB_Flash* GetInterface();
- static bool DrawGlyphs(PP_Instance pp_instance,
- PP_Resource pp_image_data,
- const PP_FontDescription_Dev* font_desc,
- uint32_t color,
- PP_Point position,
- PP_Rect clip,
- const float transformation[3][3],
- uint32_t glyph_count,
- const uint16_t glyph_indices[],
- const PP_Point glyph_advances[])
+ static PP_Bool DrawGlyphs(PP_Instance pp_instance,
+ PP_Resource pp_image_data,
+ const PP_FontDescription_Dev* font_desc,
+ uint32_t color,
+ PP_Point position,
+ PP_Rect clip,
+ const float transformation[3][3],
+ uint32_t glyph_count,
+ const uint16_t glyph_indices[],
+ const PP_Point glyph_advances[])
#if defined(OS_LINUX)
;
#else
- { return false; }
+ { return PP_FALSE; }
#endif
private:
diff --git a/webkit/plugins/ppapi/ppb_flash_impl_linux.cc b/webkit/plugins/ppapi/ppb_flash_impl_linux.cc
index 50346b4..bd554c7b 100644
--- a/webkit/plugins/ppapi/ppb_flash_impl_linux.cc
+++ b/webkit/plugins/ppapi/ppb_flash_impl_linux.cc
@@ -20,28 +20,28 @@
namespace webkit {
namespace ppapi {
-bool PPB_Flash_Impl::DrawGlyphs(PP_Instance,
- PP_Resource pp_image_data,
- const PP_FontDescription_Dev* font_desc,
- uint32_t color,
- PP_Point position,
- PP_Rect clip,
- const float transformation[3][3],
- uint32_t glyph_count,
- const uint16_t glyph_indices[],
- const PP_Point glyph_advances[]) {
+PP_Bool PPB_Flash_Impl::DrawGlyphs(PP_Instance,
+ PP_Resource pp_image_data,
+ const PP_FontDescription_Dev* font_desc,
+ uint32_t color,
+ PP_Point position,
+ PP_Rect clip,
+ const float transformation[3][3],
+ uint32_t glyph_count,
+ const uint16_t glyph_indices[],
+ const PP_Point glyph_advances[]) {
scoped_refptr<PPB_ImageData_Impl> image_resource(
Resource::GetAs<PPB_ImageData_Impl>(pp_image_data));
if (!image_resource.get())
- return false;
+ return PP_FALSE;
ImageDataAutoMapper mapper(image_resource);
if (!mapper.is_valid())
- return false;
+ return PP_FALSE;
// Set up the typeface.
scoped_refptr<StringVar> face_name(StringVar::FromPPVar(font_desc->face));
if (!face_name)
- return false;
+ return PP_FALSE;
int style = SkTypeface::kNormal;
if (font_desc->weight >= PP_FONTWEIGHT_BOLD)
style |= SkTypeface::kBold;
@@ -51,7 +51,7 @@ bool PPB_Flash_Impl::DrawGlyphs(PP_Instance,
SkTypeface::CreateFromName(face_name->value().c_str(),
static_cast<SkTypeface::Style>(style));
if (!typeface)
- return false;
+ return PP_FALSE;
// Set up the canvas.
SkCanvas* canvas = image_resource->mapped_canvas();
@@ -105,7 +105,7 @@ bool PPB_Flash_Impl::DrawGlyphs(PP_Instance,
canvas->drawPosText(glyph_indices, glyph_count * 2, sk_positions, paint);
canvas->restore();
- return true;
+ return PP_TRUE;
}
} // namespace ppapi
diff --git a/webkit/plugins/ppapi/ppb_font_impl.cc b/webkit/plugins/ppapi/ppb_font_impl.cc
index 8f4b6fd..b0a99ada 100644
--- a/webkit/plugins/ppapi/ppb_font_impl.cc
+++ b/webkit/plugins/ppapi/ppb_font_impl.cc
@@ -161,7 +161,7 @@ uint32_t CharacterOffsetForPixel(PP_Resource font_id,
int32_t pixel_position) {
scoped_refptr<PPB_Font_Impl> font(Resource::GetAs<PPB_Font_Impl>(font_id));
if (!font.get())
- return false;
+ return -1;
return font->CharacterOffsetForPixel(text, pixel_position);
}
diff --git a/webkit/plugins/ppapi/ppb_image_data_impl.cc b/webkit/plugins/ppapi/ppb_image_data_impl.cc
index 042f38b..062e613 100644
--- a/webkit/plugins/ppapi/ppb_image_data_impl.cc
+++ b/webkit/plugins/ppapi/ppb_image_data_impl.cc
@@ -129,23 +129,6 @@ const PPB_ImageDataTrusted* PPB_ImageData_Impl::GetTrustedInterface() {
return &ppb_imagedata_trusted;
}
-// static
-PP_ImageDataFormat PPB_ImageData_Impl::GetNativeImageDataFormat() {
- if (SK_B32_SHIFT == 0)
- return PP_IMAGEDATAFORMAT_BGRA_PREMUL;
- else if (SK_R32_SHIFT == 0)
- return PP_IMAGEDATAFORMAT_RGBA_PREMUL;
- else
- return PP_IMAGEDATAFORMAT_BGRA_PREMUL; // Default to something on failure.
-}
-
-// static
-bool PPB_ImageData_Impl::IsImageDataFormatSupported(
- PP_ImageDataFormat format) {
- return format == PP_IMAGEDATAFORMAT_BGRA_PREMUL ||
- format == PP_IMAGEDATAFORMAT_RGBA_PREMUL;
-}
-
PPB_ImageData_Impl* PPB_ImageData_Impl::AsPPB_ImageData_Impl() {
return this;
}
diff --git a/webkit/plugins/ppapi/ppb_image_data_impl.h b/webkit/plugins/ppapi/ppb_image_data_impl.h
index 84b2bde..9260d98 100644
--- a/webkit/plugins/ppapi/ppb_image_data_impl.h
+++ b/webkit/plugins/ppapi/ppb_image_data_impl.h
@@ -8,6 +8,7 @@
#include "base/basictypes.h"
#include "base/scoped_ptr.h"
#include "ppapi/c/ppb_image_data.h"
+#include "ppapi/shared_impl/image_data_impl.h"
#include "webkit/plugins/ppapi/plugin_delegate.h"
#include "webkit/plugins/ppapi/resource.h"
@@ -21,7 +22,8 @@ class SkBitmap;
namespace webkit {
namespace ppapi {
-class PPB_ImageData_Impl : public Resource {
+class PPB_ImageData_Impl : public Resource,
+ public pp::shared_impl::ImageDataImpl {
public:
explicit PPB_ImageData_Impl(PluginInstance* instance);
virtual ~PPB_ImageData_Impl();
@@ -45,14 +47,6 @@ class PPB_ImageData_Impl : public Resource {
static const PPB_ImageData* GetInterface();
static const PPB_ImageDataTrusted* GetTrustedInterface();
- // Returns the image data format used by the browser. If the plugin uses the
- // same format, there is no conversion. Otherwise the browser will be in
- // charge of converting from a supported format to its native format.
- static PP_ImageDataFormat GetNativeImageDataFormat();
-
- // Returns true if the format is supported by the browser.
- static bool IsImageDataFormatSupported(PP_ImageDataFormat format);
-
// Resource overrides.
virtual PPB_ImageData_Impl* AsPPB_ImageData_Impl();
diff --git a/webkit/plugins/ppapi/resource_tracker.cc b/webkit/plugins/ppapi/resource_tracker.cc
index 730c36a..6507e2d 100644
--- a/webkit/plugins/ppapi/resource_tracker.cc
+++ b/webkit/plugins/ppapi/resource_tracker.cc
@@ -155,18 +155,13 @@ void ResourceTracker::ForceDeletePluginResourceRefs(PP_Resource res) {
live_resources_.erase(i);
}
-uint32 ResourceTracker::GetLiveObjectsForModule(PluginModule* module) const {
- // Since this is for testing only, we'll just go through all of them and
- // count.
- //
- // TODO(brettw) we will eventually need to implement more efficient
- // module->resource lookup to free resources when a module is unloaded. In
- // this case, this function can be implemented using that system.
- uint32 count = 0;
- for (ResourceMap::const_iterator i = live_resources_.begin();
- i != live_resources_.end(); ++i)
- count++;
- return count;
+uint32 ResourceTracker::GetLiveObjectsForInstance(
+ PP_Instance instance) const {
+ InstanceToResourceMap::const_iterator found =
+ instance_to_resources_.find(instance);
+ if (found == instance_to_resources_.end())
+ return 0;
+ return static_cast<uint32>(found->second.size());
}
scoped_refptr<Var> ResourceTracker::GetVar(int32 var_id) const {
diff --git a/webkit/plugins/ppapi/resource_tracker.h b/webkit/plugins/ppapi/resource_tracker.h
index 0b49ad8..ce577c3 100644
--- a/webkit/plugins/ppapi/resource_tracker.h
+++ b/webkit/plugins/ppapi/resource_tracker.h
@@ -63,9 +63,7 @@ class ResourceTracker {
void ForceDeletePluginResourceRefs(PP_Resource res);
// Returns the number of resources associated with this module.
- //
- // This is slow, use only for testing.
- uint32 GetLiveObjectsForModule(PluginModule* module) const;
+ uint32 GetLiveObjectsForInstance(PP_Instance instance) const;
// PP_Vars -------------------------------------------------------------------
diff --git a/webkit/plugins/ppapi/resource_tracker_unittest.cc b/webkit/plugins/ppapi/resource_tracker_unittest.cc
index bbcff1f..6e7b2a4 100644
--- a/webkit/plugins/ppapi/resource_tracker_unittest.cc
+++ b/webkit/plugins/ppapi/resource_tracker_unittest.cc
@@ -53,7 +53,8 @@ class ResourceTrackerTest : public PpapiUnittest {
TEST_F(ResourceTrackerTest, Ref) {
ASSERT_EQ(0, TrackedMockResource::tracked_objects_alive);
- EXPECT_EQ(0u, tracker().GetLiveObjectsForModule(module()));
+ EXPECT_EQ(0u,
+ tracker().GetLiveObjectsForInstance(instance()->pp_instance()));
{
scoped_refptr<TrackedMockResource> new_resource(
new TrackedMockResource(instance()));
@@ -61,7 +62,8 @@ TEST_F(ResourceTrackerTest, Ref) {
// Since we haven't gotten a PP_Resource, it's not associated with the
// module.
- EXPECT_EQ(0u, tracker().GetLiveObjectsForModule(module()));
+ EXPECT_EQ(0u,
+ tracker().GetLiveObjectsForInstance(instance()->pp_instance()));
}
ASSERT_EQ(0, TrackedMockResource::tracked_objects_alive);
@@ -72,7 +74,8 @@ TEST_F(ResourceTrackerTest, Ref) {
new TrackedMockResource(instance()));
ASSERT_EQ(1, TrackedMockResource::tracked_objects_alive);
resource_id = new_resource->GetReference();
- EXPECT_EQ(1u, tracker().GetLiveObjectsForModule(module()));
+ EXPECT_EQ(1u,
+ tracker().GetLiveObjectsForInstance(instance()->pp_instance()));
// Resource IDs should be consistent.
PP_Resource resource_id_2 = new_resource->GetReference();
@@ -96,6 +99,7 @@ TEST_F(ResourceTrackerTest, ForceDeleteWithInstance) {
new PluginInstance(delegate(), module(),
static_cast<const PPP_Instance*>(
GetMockInterface(PPP_INSTANCE_INTERFACE))));
+ PP_Instance pp_instance2 = instance2->pp_instance();
// Make two resources and take refs on behalf of the "plugin" for each.
scoped_refptr<TrackedMockResource> resource1(
@@ -110,11 +114,11 @@ TEST_F(ResourceTrackerTest, ForceDeleteWithInstance) {
resource2 = NULL;
ASSERT_EQ(2, TrackedMockResource::tracked_objects_alive);
- EXPECT_EQ(2u, tracker().GetLiveObjectsForModule(module()));
+ EXPECT_EQ(2u, tracker().GetLiveObjectsForInstance(pp_instance2));
// Free the instance, this should release both plugin refs.
instance2 = NULL;
- EXPECT_EQ(0u, tracker().GetLiveObjectsForModule(module()));
+ EXPECT_EQ(0u, tracker().GetLiveObjectsForInstance(pp_instance2));
// The resource we have a scoped_refptr to should still be alive, but it
// should have a NULL instance.