diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-12 22:58:40 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-12 22:58:40 +0000 |
commit | 0127a0957c66d925c55de0921fa0a81964e019ec (patch) | |
tree | 3c7bceeb40fd38df46774971963f7cf710fb3fcd /webkit | |
parent | c999ae2b2daeb6a0e7f7446ddff39b6691590062 (diff) | |
download | chromium_src-0127a0957c66d925c55de0921fa0a81964e019ec.zip chromium_src-0127a0957c66d925c55de0921fa0a81964e019ec.tar.gz chromium_src-0127a0957c66d925c55de0921fa0a81964e019ec.tar.bz2 |
Make the Var object use a PP_Module ID rather than a PluginModule object.
This is a first step to moving the Var implementation and tracking into
shared_impl so we don't have to have to have a duplicate implementation in
the proxy. This means we can't depend on _impl-specific objects like
PluginModule from the Var objects.
TEST=ppapi tests
Review URL: http://codereview.chromium.org/7345016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92255 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/plugins/ppapi/message_channel.cc | 2 | ||||
-rw-r--r-- | webkit/plugins/ppapi/npapi_glue.cc | 7 | ||||
-rw-r--r-- | webkit/plugins/ppapi/plugin_object.cc | 2 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.cc | 2 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_char_set_impl.cc | 2 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_file_ref_impl.cc | 5 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc | 3 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_flash_impl.cc | 4 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_font_impl.cc | 3 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_input_event_impl.cc | 3 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_transport_impl.cc | 2 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_url_response_info_impl.cc | 12 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_url_util_impl.cc | 2 | ||||
-rw-r--r-- | webkit/plugins/ppapi/resource_tracker.cc | 4 | ||||
-rw-r--r-- | webkit/plugins/ppapi/var.cc | 90 | ||||
-rw-r--r-- | webkit/plugins/ppapi/var.h | 41 |
16 files changed, 106 insertions, 78 deletions
diff --git a/webkit/plugins/ppapi/message_channel.cc b/webkit/plugins/ppapi/message_channel.cc index 78a5729..759f8175 100644 --- a/webkit/plugins/ppapi/message_channel.cc +++ b/webkit/plugins/ppapi/message_channel.cc @@ -104,7 +104,7 @@ PP_Var CopyPPVar(const PP_Var& var) { scoped_refptr<StringVar> string(StringVar::FromPPVar(var)); if (!string) return PP_MakeUndefined(); - return StringVar::StringToPPVar(string->module(), string->value()); + return StringVar::StringToPPVar(string->pp_module(), string->value()); } else { return var; } diff --git a/webkit/plugins/ppapi/npapi_glue.cc b/webkit/plugins/ppapi/npapi_glue.cc index b2eacb4..ad9f248 100644 --- a/webkit/plugins/ppapi/npapi_glue.cc +++ b/webkit/plugins/ppapi/npapi_glue.cc @@ -7,8 +7,9 @@ #include "base/logging.h" #include "base/memory/ref_counted.h" #include "base/string_util.h" -#include "webkit/plugins/ppapi/ppapi_plugin_instance.h" +#include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/plugin_object.h" +#include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/var.h" #include "third_party/npapi/bindings/npapi.h" #include "third_party/npapi/bindings/npruntime.h" @@ -193,8 +194,8 @@ NPObjectAccessorWithIdentifier::NPObjectAccessorWithIdentifier( : object_(PluginObject::FromNPObject(object)), identifier_(PP_MakeUndefined()) { if (object_) { - identifier_ = Var::NPIdentifierToPPVar(object_->instance()->module(), - identifier); + identifier_ = Var::NPIdentifierToPPVar( + object_->instance()->module()->pp_module(), identifier); if (identifier_.type == PP_VARTYPE_INT32 && !allow_integer_identifier) identifier_.type = PP_VARTYPE_UNDEFINED; // Mark it invalid. } diff --git a/webkit/plugins/ppapi/plugin_object.cc b/webkit/plugins/ppapi/plugin_object.cc index d5b9865..e24e1b2 100644 --- a/webkit/plugins/ppapi/plugin_object.cc +++ b/webkit/plugins/ppapi/plugin_object.cc @@ -178,7 +178,7 @@ bool WrapperClass_Enumerate(NPObject* object, NPIdentifier** values, if (!((*values)[i] = Var::PPVarToNPIdentifier(properties[i]))) { // Throw an exception for the failed convertion. *result_converter.exception() = StringVar::StringToPPVar( - obj->instance()->module(), kInvalidValueException); + obj->instance()->module()->pp_module(), kInvalidValueException); break; } (*count)++; diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc index 8ebb10cd..6ed2ea8 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc @@ -1431,7 +1431,7 @@ PP_Var PluginInstance::GetOwnerElementObject(PP_Instance instance) { PP_Var PluginInstance::ExecuteScript(PP_Instance instance, PP_Var script, PP_Var* exception) { - TryCatch try_catch(module(), exception); + TryCatch try_catch(module()->pp_module(), exception); if (try_catch.has_exception()) return PP_MakeUndefined(); diff --git a/webkit/plugins/ppapi/ppb_char_set_impl.cc b/webkit/plugins/ppapi/ppb_char_set_impl.cc index 496e339..47197fe 100644 --- a/webkit/plugins/ppapi/ppb_char_set_impl.cc +++ b/webkit/plugins/ppapi/ppb_char_set_impl.cc @@ -52,7 +52,7 @@ uint16_t* PPB_CharSet_Impl::CharSetToUTF16(PP_Instance instance, PP_Var PPB_CharSet_Impl::GetDefaultCharSet(PP_Instance instance) { std::string encoding = instance_->delegate()->GetDefaultEncoding(); - return StringVar::StringToPPVar(instance_->module(), encoding); + return StringVar::StringToPPVar(instance_->module()->pp_module(), encoding); } } // namespace ppapi diff --git a/webkit/plugins/ppapi/ppb_file_ref_impl.cc b/webkit/plugins/ppapi/ppb_file_ref_impl.cc index aa0f2ed..245ab8d 100644 --- a/webkit/plugins/ppapi/ppb_file_ref_impl.cc +++ b/webkit/plugins/ppapi/ppb_file_ref_impl.cc @@ -136,13 +136,14 @@ PP_Var PPB_FileRef_Impl::GetName() const { result = virtual_path_.substr(pos + 1); } - return StringVar::StringToPPVar(instance()->module(), result); + return StringVar::StringToPPVar(instance()->module()->pp_module(), result); } PP_Var PPB_FileRef_Impl::GetPath() const { if (GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) return PP_MakeUndefined(); - return StringVar::StringToPPVar(instance()->module(), virtual_path_); + return StringVar::StringToPPVar(instance()->module()->pp_module(), + virtual_path_); } PP_Resource PPB_FileRef_Impl::GetParent() { diff --git a/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc b/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc index 4954862..404260f 100644 --- a/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc +++ b/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc @@ -17,6 +17,7 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebKitClient.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" #include "webkit/plugins/ppapi/common.h" +#include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/resource_tracker.h" #include "webkit/plugins/ppapi/var.h" @@ -90,7 +91,7 @@ PP_Var ReadPlainText(PP_Instance instance_id, WebKit::WebCString s = web_clipboard->readPlainText(ConvertClipboardType(clipboard_type)).utf8(); - return StringVar::StringToPPVar(instance->module(), s); + return StringVar::StringToPPVar(instance->module()->pp_module(), s); } int32_t WritePlainText(PP_Instance instance_id, diff --git a/webkit/plugins/ppapi/ppb_flash_impl.cc b/webkit/plugins/ppapi/ppb_flash_impl.cc index ffd519d..82d1656 100644 --- a/webkit/plugins/ppapi/ppb_flash_impl.cc +++ b/webkit/plugins/ppapi/ppb_flash_impl.cc @@ -48,7 +48,7 @@ PP_Var GetProxyForURL(PP_Instance pp_instance, const char* url) { std::string proxy_host = instance->delegate()->ResolveProxy(gurl); if (proxy_host.empty()) return PP_MakeUndefined(); // No proxy. - return StringVar::StringToPPVar(instance->module(), proxy_host); + return StringVar::StringToPPVar(instance->module()->pp_module(), proxy_host); } int32_t Navigate(PP_Resource request_id, @@ -109,7 +109,7 @@ PP_Var GetCommandLineArgs(PP_Module pp_module) { return PP_MakeUndefined(); std::string args = instance->delegate()->GetFlashCommandLineArgs(); - return StringVar::StringToPPVar(module, args); + return StringVar::StringToPPVar(pp_module, args); } const PPB_Flash ppb_flash = { diff --git a/webkit/plugins/ppapi/ppb_font_impl.cc b/webkit/plugins/ppapi/ppb_font_impl.cc index 2616325..8ad95b5 100644 --- a/webkit/plugins/ppapi/ppb_font_impl.cc +++ b/webkit/plugins/ppapi/ppb_font_impl.cc @@ -78,7 +78,8 @@ PP_Bool PPB_Font_Impl::Describe(PP_FontDescription_Dev* description, return PP_FALSE; // Convert the string. - description->face = StringVar::StringToPPVar(instance()->module(), face); + description->face = StringVar::StringToPPVar( + instance()->module()->pp_module(), face); return PP_TRUE; } diff --git a/webkit/plugins/ppapi/ppb_input_event_impl.cc b/webkit/plugins/ppapi/ppb_input_event_impl.cc index 92be3a7..5139704 100644 --- a/webkit/plugins/ppapi/ppb_input_event_impl.cc +++ b/webkit/plugins/ppapi/ppb_input_event_impl.cc @@ -4,6 +4,7 @@ #include "webkit/plugins/ppapi/ppb_input_event_impl.h" +#include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/var.h" @@ -33,7 +34,7 @@ PPB_InputEvent_API* PPB_InputEvent_Impl::AsPPB_InputEvent_API() { } PP_Var PPB_InputEvent_Impl::StringToPPVar(const std::string& str) { - return StringVar::StringToPPVar(instance()->module(), str); + return StringVar::StringToPPVar(instance()->module()->pp_module(), str); } } // namespace ppapi diff --git a/webkit/plugins/ppapi/ppb_transport_impl.cc b/webkit/plugins/ppapi/ppb_transport_impl.cc index 54e0adf..968bbdb 100644 --- a/webkit/plugins/ppapi/ppb_transport_impl.cc +++ b/webkit/plugins/ppapi/ppb_transport_impl.cc @@ -128,7 +128,7 @@ int32_t PPB_Transport_Impl::GetNextAddress(PP_Var* address, return PP_ERROR_INPROGRESS; if (!local_candidates_.empty()) { - *address = StringVar::StringToPPVar(instance()->module(), + *address = StringVar::StringToPPVar(instance()->module()->pp_module(), local_candidates_.front()); local_candidates_.pop_front(); return PP_OK; diff --git a/webkit/plugins/ppapi/ppb_url_response_info_impl.cc b/webkit/plugins/ppapi/ppb_url_response_info_impl.cc index 4160e6b..286ecb2 100644 --- a/webkit/plugins/ppapi/ppb_url_response_info_impl.cc +++ b/webkit/plugins/ppapi/ppb_url_response_info_impl.cc @@ -11,6 +11,7 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" #include "webkit/plugins/ppapi/common.h" +#include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" #include "webkit/plugins/ppapi/var.h" @@ -82,23 +83,24 @@ PPB_URLResponseInfo_API* PPB_URLResponseInfo_Impl::AsPPB_URLResponseInfo_API() { } PP_Var PPB_URLResponseInfo_Impl::GetProperty(PP_URLResponseProperty property) { + PP_Module pp_module = instance()->module()->pp_module(); switch (property) { case PP_URLRESPONSEPROPERTY_URL: - return StringVar::StringToPPVar(instance()->module(), url_); + return StringVar::StringToPPVar(pp_module, url_); case PP_URLRESPONSEPROPERTY_REDIRECTURL: if (IsRedirect(status_code_)) - return StringVar::StringToPPVar(instance()->module(), redirect_url_); + return StringVar::StringToPPVar(pp_module, redirect_url_); break; case PP_URLRESPONSEPROPERTY_REDIRECTMETHOD: if (IsRedirect(status_code_)) - return StringVar::StringToPPVar(instance()->module(), status_text_); + return StringVar::StringToPPVar(pp_module, status_text_); break; case PP_URLRESPONSEPROPERTY_STATUSCODE: return PP_MakeInt32(status_code_); case PP_URLRESPONSEPROPERTY_STATUSLINE: - return StringVar::StringToPPVar(instance()->module(), status_text_); + return StringVar::StringToPPVar(pp_module, status_text_); case PP_URLRESPONSEPROPERTY_HEADERS: - return StringVar::StringToPPVar(instance()->module(), headers_); + return StringVar::StringToPPVar(pp_module, headers_); } // The default is to return an undefined PP_Var. return PP_MakeUndefined(); diff --git a/webkit/plugins/ppapi/ppb_url_util_impl.cc b/webkit/plugins/ppapi/ppb_url_util_impl.cc index 048c26e..64625f4 100644 --- a/webkit/plugins/ppapi/ppb_url_util_impl.cc +++ b/webkit/plugins/ppapi/ppb_url_util_impl.cc @@ -34,7 +34,7 @@ PP_Module GetModuleFromVar(PP_Var string_var) { scoped_refptr<StringVar> str(StringVar::FromPPVar(string_var)); if (!str) return 0; - return str->module()->pp_module(); + return str->pp_module(); } const std::string* StringFromVar(PP_Var var) { diff --git a/webkit/plugins/ppapi/resource_tracker.cc b/webkit/plugins/ppapi/resource_tracker.cc index ed65a2a..edd103b 100644 --- a/webkit/plugins/ppapi/resource_tracker.cc +++ b/webkit/plugins/ppapi/resource_tracker.cc @@ -151,6 +151,10 @@ int32 ResourceTracker::AddVar(Var* var) { if (last_var_id_ == std::numeric_limits<int32>::max() >> kPPIdTypeBits) return 0; + // Validate the module. + if (!GetModule(var->pp_module())) + return 0; + // Add the resource with plugin use-count 1. int32 new_id = MakeTypedId(++last_var_id_, PP_ID_TYPE_VAR); live_vars_.insert(std::make_pair(new_id, std::make_pair(var, 1))); diff --git a/webkit/plugins/ppapi/var.cc b/webkit/plugins/ppapi/var.cc index 5d392fc..90092e0 100644 --- a/webkit/plugins/ppapi/var.cc +++ b/webkit/plugins/ppapi/var.cc @@ -102,7 +102,7 @@ bool PPVarToNPVariantNoCopy(PP_Var var, NPVariant* result) { // an exception if it's invalid. At the end of construction, if there is no // exception, you know that there is no previously set exception, that the // object passed in is valid and ready to use (via the object() getter), and -// that the TryCatch's module() getter is also set up properly and ready to +// that the TryCatch's pp_module() getter is also set up properly and ready to // use. class ObjectAccessorTryCatch : public TryCatch { public: @@ -116,7 +116,7 @@ class ObjectAccessorTryCatch : public TryCatch { SetInvalidObjectException(); } else { // When the object is valid, we have a valid module to associate - set_module(object_->module()); + set_pp_module(object_->pp_module()); } } @@ -138,7 +138,7 @@ class ObjectAccessorTryCatch : public TryCatch { // At the end of construction, if there is no exception, you know that there is // no previously set exception, that the object passed in is valid and ready to // use (via the object() getter), that the identifier is valid and ready to -// use (via the identifier() getter), and that the TryCatch's module() getter +// use (via the identifier() getter), and that the TryCatch's pp_module() getter // is also set up properly and ready to use. class ObjectAccessorWithIdentifierTryCatch : public ObjectAccessorTryCatch { public: @@ -164,10 +164,7 @@ class ObjectAccessorWithIdentifierTryCatch : public ObjectAccessorTryCatch { // PPB_Var methods ------------------------------------------------------------- -PP_Var VarFromUtf8(PP_Module module_id, const char* data, uint32_t len) { - PluginModule* module = ResourceTracker::Get()->GetModule(module_id); - if (!module) - return PP_MakeNull(); +PP_Var VarFromUtf8(PP_Module module, const char* data, uint32_t len) { return StringVar::StringToPPVar(module, data, len); } @@ -260,7 +257,7 @@ void EnumerateProperties(PP_Var var, *properties = static_cast<PP_Var*>(malloc(sizeof(PP_Var) * count)); for (uint32_t i = 0; i < count; ++i) { (*properties)[i] = Var::NPIdentifierToPPVar( - accessor.object()->instance()->module(), + accessor.object()->instance()->module()->pp_module(), identifiers[i]); } free(identifiers); @@ -449,7 +446,7 @@ const PPB_Var var_interface = { // Var ------------------------------------------------------------------------- -Var::Var(PluginModule* module) : module_(module), var_id_(0) { +Var::Var(PP_Module module) : pp_module_(module), var_id_(0) { } Var::~Var() { @@ -471,7 +468,7 @@ PP_Var Var::NPVariantToPPVar(PluginInstance* instance, return PP_MakeDouble(NPVARIANT_TO_DOUBLE(*variant)); case NPVariantType_String: return StringVar::StringToPPVar( - instance->module(), + instance->module()->pp_module(), NPVARIANT_TO_STRING(*variant).UTF8Characters, NPVARIANT_TO_STRING(*variant).UTF8Length); case NPVariantType_Object: @@ -499,7 +496,7 @@ NPIdentifier Var::PPVarToNPIdentifier(PP_Var var) { } // static -PP_Var Var::NPIdentifierToPPVar(PluginModule* module, NPIdentifier id) { +PP_Var Var::NPIdentifierToPPVar(PP_Module module, NPIdentifier id) { const NPUTF8* string_value = NULL; int32_t int_value = 0; bool is_string = false; @@ -576,21 +573,21 @@ ObjectVar* Var::AsObjectVar() { } int32 Var::GetID() { - // This should only be called for objects and strings. POD vars like integers - // have no identifiers. - DCHECK(AsStringVar() || AsObjectVar()); - ResourceTracker *tracker = ResourceTracker::Get(); - if (var_id_) - tracker->AddRefVar(var_id_); - else + if (var_id_) { + if (!tracker->AddRefVar(var_id_)) + return 0; + } else { var_id_ = tracker->AddVar(this); + if (!var_id_) + return 0; + } return var_id_; } // StringVar ------------------------------------------------------------------- -StringVar::StringVar(PluginModule* module, const char* str, uint32 len) +StringVar::StringVar(PP_Module module, const char* str, uint32 len) : Var(module), value_(str, len) { } @@ -602,24 +599,29 @@ StringVar* StringVar::AsStringVar() { return this; } +PP_Var StringVar::GetPPVar() { + int32 id = GetID(); + if (!id) + return PP_MakeNull(); + + PP_Var result; + result.type = PP_VARTYPE_STRING; + result.value.as_id = id; + return result; +} + // static -PP_Var StringVar::StringToPPVar(PluginModule* module, const std::string& var) { +PP_Var StringVar::StringToPPVar(PP_Module module, const std::string& var) { return StringToPPVar(module, var.c_str(), var.size()); } // static -PP_Var StringVar::StringToPPVar(PluginModule* module, +PP_Var StringVar::StringToPPVar(PP_Module module, const char* data, uint32 len) { scoped_refptr<StringVar> str(new StringVar(module, data, len)); if (!str || !IsStringUTF8(str->value())) return PP_MakeNull(); - - PP_Var ret; - ret.type = PP_VARTYPE_STRING; - - // The caller takes ownership now. - ret.value.as_id = str->GetID(); - return ret; + return str->GetPPVar(); } // static @@ -636,7 +638,7 @@ scoped_refptr<StringVar> StringVar::FromPPVar(PP_Var var) { // ObjectVar ------------------------------------------------------------- ObjectVar::ObjectVar(PluginInstance* instance, NPObject* np_object) - : Var(instance->module()), + : Var(instance->module()->pp_module()), instance_(instance), np_object_(np_object) { WebBindings::retainObject(np_object_); @@ -653,6 +655,17 @@ ObjectVar* ObjectVar::AsObjectVar() { return this; } +PP_Var ObjectVar::GetPPVar() { + int32 id = GetID(); + if (!id) + return PP_MakeNull(); + + PP_Var result; + result.type = PP_VARTYPE_OBJECT; + result.value.as_id = id; + return result; +} + void ObjectVar::InstanceDeleted() { DCHECK(instance_); instance_ = NULL; @@ -667,12 +680,7 @@ PP_Var ObjectVar::NPObjectToPPVar(PluginInstance* instance, NPObject* object) { if (!object_var) return PP_MakeUndefined(); - - // Convert to a PP_Var, GetID will AddRef for us. - PP_Var result; - result.type = PP_VARTYPE_OBJECT; - result.value.as_id = object_var->GetID(); - return result; + return object_var->GetPPVar(); } // static @@ -688,8 +696,8 @@ scoped_refptr<ObjectVar> ObjectVar::FromPPVar(PP_Var var) { // TryCatch -------------------------------------------------------------------- -TryCatch::TryCatch(PluginModule* module, PP_Var* exception) - : module_(module), +TryCatch::TryCatch(PP_Module module, PP_Var* exception) + : pp_module_(module), has_exception_(exception && exception->type != PP_VARTYPE_UNDEFINED), exception_(exception) { WebBindings::pushExceptionHandler(&TryCatch::Catch, this); @@ -700,7 +708,7 @@ TryCatch::~TryCatch() { } void TryCatch::SetException(const char* message) { - if (!module_) { + if (!pp_module_) { // Don't have a module to make the string. SetInvalidObjectException(); return; @@ -708,8 +716,10 @@ void TryCatch::SetException(const char* message) { if (!has_exception()) { has_exception_ = true; - if (exception_) - *exception_ = StringVar::StringToPPVar(module_, message, strlen(message)); + if (exception_) { + *exception_ = StringVar::StringToPPVar(pp_module_, + message, strlen(message)); + } } } diff --git a/webkit/plugins/ppapi/var.h b/webkit/plugins/ppapi/var.h index 4210e28..730d87e 100644 --- a/webkit/plugins/ppapi/var.h +++ b/webkit/plugins/ppapi/var.h @@ -9,6 +9,7 @@ #include "base/compiler_specific.h" #include "base/memory/ref_counted.h" +#include "ppapi/c/pp_module.h" struct PP_Var; struct PPB_Var; @@ -22,7 +23,6 @@ namespace ppapi { class ObjectVar; class PluginInstance; -class PluginModule; class StringVar; // Var ------------------------------------------------------------------------- @@ -52,7 +52,7 @@ class Var : public base::RefCounted<Var> { // Returns a PP_Var corresponding to the given identifier. In the case of // a string identifier, the string will be allocated associated with the // given module. A returned string will have a reference count of 1. - static PP_Var NPIdentifierToPPVar(PluginModule* module, NPIdentifier id); + static PP_Var NPIdentifierToPPVar(PP_Module module, NPIdentifier id); // Returns a string representing the given var for logging purposes. static std::string PPVarToLogString(PP_Var var); @@ -96,19 +96,25 @@ class Var : public base::RefCounted<Var> { virtual StringVar* AsStringVar(); virtual ObjectVar* AsObjectVar(); - PluginModule* module() const { return module_; } + // Creates a PP_Var corresponding to this object. The return value will have + // one reference addrefed on behalf of the caller. + virtual PP_Var GetPPVar() = 0; - // Returns the unique ID associated with this string or object. The object - // must be a string or an object var, and the return value is guaranteed - // nonzero. - int32 GetID(); + PP_Module pp_module() const { return pp_module_; } protected: // This can only be constructed as a StringVar or an ObjectVar. - explicit Var(PluginModule* module); + explicit Var(PP_Module module); + + // Returns the unique ID associated with this string or object. The return + // value will be 0 if the string or object is invalid. + // + // This function will take a reference to the var that will be passed to the + // caller. + int32 GetID(); private: - PluginModule* module_; + PP_Module pp_module_; // This will be 0 if no ID has been assigned (this happens lazily). int32 var_id_; @@ -130,13 +136,14 @@ class Var : public base::RefCounted<Var> { // DoSomethingWithTheString(string->value()); class StringVar : public Var { public: - StringVar(PluginModule* module, const char* str, uint32 len); + StringVar(PP_Module module, const char* str, uint32 len); virtual ~StringVar(); const std::string& value() const { return value_; } // Var override. virtual StringVar* AsStringVar() OVERRIDE; + virtual PP_Var GetPPVar() OVERRIDE; // Helper function to create a PP_Var of type string that contains a copy of // the given string. The input data must be valid UTF-8 encoded text, if it @@ -145,9 +152,8 @@ class StringVar : public Var { // The return value will have a reference count of 1. Internally, this will // create a StringVar, associate it with a module, and return the reference // to it in the var. - static PP_Var StringToPPVar(PluginModule* module, const std::string& str); - static PP_Var StringToPPVar(PluginModule* module, - const char* str, uint32 len); + static PP_Var StringToPPVar(PP_Module module, const std::string& str); + static PP_Var StringToPPVar(PP_Module module, const char* str, uint32 len); // Helper function that converts a PP_Var to a string. This will return NULL // if the PP_Var is not of string type or the string is invalid. @@ -177,6 +183,7 @@ class ObjectVar : public Var { // Var overrides. virtual ObjectVar* AsObjectVar() OVERRIDE; + virtual PP_Var GetPPVar() OVERRIDE; // Returns the underlying NPObject corresponding to this ObjectVar. // Guaranteed non-NULL. @@ -240,12 +247,12 @@ class TryCatch { // // If an exception is thrown when the module is NULL, setting *any* exception // will result in using the InvalidObjectException. - TryCatch(PluginModule* module, PP_Var* exception); + TryCatch(PP_Module module, PP_Var* exception); ~TryCatch(); // Get and set the module. This may be NULL (see the constructor). - PluginModule* module() { return module_; } - void set_module(PluginModule* module) { module_ = module; } + PP_Module pp_module() { return pp_module_; } + void set_pp_module(PP_Module module) { pp_module_ = module; } // Returns true is an exception has been thrown. This can be true immediately // after construction if the var passed to the constructor is non-void. @@ -266,7 +273,7 @@ class TryCatch { private: static void Catch(void* self, const char* message); - PluginModule* module_; + PP_Module pp_module_; // True if an exception has been thrown. Since the exception itself may be // NULL if the plugin isn't interested in getting the exception, this will |