summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/renderer/DEPS1
-rw-r--r--chrome/renderer/chrome_ppb_pdf_impl.cc16
-rw-r--r--ppapi/ppapi_shared.gypi2
-rw-r--r--ppapi/proxy/plugin_resource_tracker.cc29
-rw-r--r--ppapi/proxy/plugin_resource_tracker.h8
-rw-r--r--ppapi/shared_impl/tracker_base.h14
-rw-r--r--ppapi/shared_impl/var.cc155
-rw-r--r--ppapi/shared_impl/var.h (renamed from webkit/plugins/ppapi/var.h)124
-rw-r--r--webkit/glue/webkit_glue.gypi4
-rw-r--r--webkit/plugins/ppapi/message_channel.cc3
-rw-r--r--webkit/plugins/ppapi/npapi_glue.cc71
-rw-r--r--webkit/plugins/ppapi/npapi_glue.h55
-rw-r--r--webkit/plugins/ppapi/npobject_var.cc65
-rw-r--r--webkit/plugins/ppapi/npobject_var.h71
-rw-r--r--webkit/plugins/ppapi/plugin_module.cc1
-rw-r--r--webkit/plugins/ppapi/plugin_object.cc4
-rw-r--r--webkit/plugins/ppapi/ppapi_plugin_instance.cc4
-rw-r--r--webkit/plugins/ppapi/ppapi_webplugin_impl.cc7
-rw-r--r--webkit/plugins/ppapi/ppb_char_set_impl.cc5
-rw-r--r--webkit/plugins/ppapi/ppb_console_impl.cc3
-rw-r--r--webkit/plugins/ppapi/ppb_file_ref_impl.cc5
-rw-r--r--webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc4
-rw-r--r--webkit/plugins/ppapi/ppb_flash_impl.cc3
-rw-r--r--webkit/plugins/ppapi/ppb_flash_impl_linux.cc3
-rw-r--r--webkit/plugins/ppapi/ppb_font_impl.cc3
-rw-r--r--webkit/plugins/ppapi/ppb_input_event_impl.cc3
-rw-r--r--webkit/plugins/ppapi/ppb_transport_impl.cc3
-rw-r--r--webkit/plugins/ppapi/ppb_uma_private_impl.cc4
-rw-r--r--webkit/plugins/ppapi/ppb_url_request_info_impl.cc3
-rw-r--r--webkit/plugins/ppapi/ppb_url_response_info_impl.cc3
-rw-r--r--webkit/plugins/ppapi/ppb_url_util_impl.cc7
-rw-r--r--webkit/plugins/ppapi/ppb_var_impl.cc15
-rw-r--r--webkit/plugins/ppapi/ppb_video_decoder_impl.cc1
-rw-r--r--webkit/plugins/ppapi/resource_creation_impl.cc3
-rw-r--r--webkit/plugins/ppapi/resource_tracker.cc75
-rw-r--r--webkit/plugins/ppapi/resource_tracker.h41
-rw-r--r--webkit/plugins/ppapi/resource_tracker_unittest.cc6
-rw-r--r--webkit/plugins/ppapi/var.cc255
38 files changed, 595 insertions, 484 deletions
diff --git a/chrome/renderer/DEPS b/chrome/renderer/DEPS
index 2f67b681..96e817a 100644
--- a/chrome/renderer/DEPS
+++ b/chrome/renderer/DEPS
@@ -5,6 +5,7 @@ include_rules = [
"+media/base", # For initializing media library and media switches.
"+ppapi/c",
"+ppapi/proxy",
+ "+ppapi/shared_impl",
"+sandbox/src",
"+skia",
"+webkit/extensions",
diff --git a/chrome/renderer/chrome_ppb_pdf_impl.cc b/chrome/renderer/chrome_ppb_pdf_impl.cc
index 5395e42..bd8b4c0 100644
--- a/chrome/renderer/chrome_ppb_pdf_impl.cc
+++ b/chrome/renderer/chrome_ppb_pdf_impl.cc
@@ -13,6 +13,7 @@
#include "grit/webkit_strings.h"
#include "ppapi/c/pp_resource.h"
#include "ppapi/c/private/ppb_pdf.h"
+#include "ppapi/shared_impl/var.h"
#include "skia/ext/platform_canvas.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/l10n/l10n_util.h"
@@ -23,7 +24,6 @@
#include "webkit/plugins/ppapi/plugin_module.h"
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "webkit/plugins/ppapi/ppb_image_data_impl.h"
-#include "webkit/plugins/ppapi/var.h"
namespace chrome {
@@ -128,8 +128,7 @@ PP_Var GetLocalizedString(PP_Instance instance_id,
NOTREACHED();
}
- return webkit::ppapi::StringVar::StringToPPVar(
- instance->module()->pp_module(), rv);
+ return ppapi::StringVar::StringToPPVar(instance->module()->pp_module(), rv);
}
PP_Resource GetResourceImage(PP_Instance instance_id,
@@ -181,8 +180,8 @@ PP_Resource GetFontFileWithFallback(
if (!instance)
return 0;
- scoped_refptr<webkit::ppapi::StringVar>
- face_name(webkit::ppapi::StringVar::FromPPVar(description->face));
+ scoped_refptr<ppapi::StringVar> face_name(ppapi::StringVar::FromPPVar(
+ description->face));
if (!face_name)
return 0;
@@ -302,11 +301,12 @@ void HistogramPDFPageCount(int count) {
}
void UserMetricsRecordAction(PP_Var action) {
- scoped_refptr<webkit::ppapi::StringVar>
- action_str(webkit::ppapi::StringVar::FromPPVar(action));
- if (action_str)
+ scoped_refptr<ppapi::StringVar> action_str(
+ ppapi::StringVar::FromPPVar(action));
+ if (action_str) {
RenderThread::current()->Send(
new ViewHostMsg_UserMetricsRecordAction(action_str->value()));
+ }
}
void HasUnsupportedFeature(PP_Instance instance_id) {
diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi
index 496a9dd..fea7e66 100644
--- a/ppapi/ppapi_shared.gypi
+++ b/ppapi/ppapi_shared.gypi
@@ -58,6 +58,8 @@
'shared_impl/tracker_base.h',
'shared_impl/url_util_impl.cc',
'shared_impl/url_util_impl.h',
+ 'shared_impl/var.cc',
+ 'shared_impl/var.h',
'shared_impl/webkit_forwarding.cc',
'shared_impl/webkit_forwarding.h',
diff --git a/ppapi/proxy/plugin_resource_tracker.cc b/ppapi/proxy/plugin_resource_tracker.cc
index e1726cf..85f8a7d 100644
--- a/ppapi/proxy/plugin_resource_tracker.cc
+++ b/ppapi/proxy/plugin_resource_tracker.cc
@@ -11,6 +11,7 @@
#include "ppapi/proxy/plugin_resource.h"
#include "ppapi/proxy/serialized_var.h"
#include "ppapi/shared_impl/tracker_base.h"
+#include "ppapi/shared_impl/var.h"
namespace pp {
namespace proxy {
@@ -147,6 +148,34 @@ PP_Instance PluginResourceTracker::GetInstanceForResource(
return found->second.resource->instance();
}
+int32 PluginResourceTracker::AddVar(ppapi::Var* var) {
+ // TODO(brettw) implement this when the proxy uses the Var object in the
+ // plugin process.
+ NOTREACHED();
+ return 0;
+}
+
+scoped_refptr<ppapi::Var> PluginResourceTracker::GetVar(int32 var_id) const {
+ // TODO(brettw) implement this when the proxy uses the Var object in the
+ // plugin process.
+ NOTREACHED();
+ return scoped_refptr<ppapi::Var>();
+}
+
+bool PluginResourceTracker::AddRefVar(int32 var_id) {
+ // TODO(brettw) implement this when the proxy uses the Var object in the
+ // plugin process.
+ NOTREACHED();
+ return false;
+}
+
+bool PluginResourceTracker::UnrefVar(int32 var_id) {
+ // TODO(brettw) implement this when the proxy uses the Var object in the
+ // plugin process.
+ NOTREACHED();
+ return false;
+}
+
void PluginResourceTracker::ReleasePluginResourceRef(
const PP_Resource& resource,
bool notify_browser_on_release) {
diff --git a/ppapi/proxy/plugin_resource_tracker.h b/ppapi/proxy/plugin_resource_tracker.h
index 83b7840..9da3902 100644
--- a/ppapi/proxy/plugin_resource_tracker.h
+++ b/ppapi/proxy/plugin_resource_tracker.h
@@ -20,6 +20,10 @@
template<typename T> struct DefaultSingletonTraits;
+namespace ppapi {
+class Var;
+}
+
namespace pp {
namespace proxy {
@@ -62,6 +66,10 @@ class PluginResourceTracker : public ::ppapi::TrackerBase {
PP_Instance inst,
pp::proxy::InterfaceID id) OVERRIDE;
virtual PP_Instance GetInstanceForResource(PP_Resource resource) OVERRIDE;
+ virtual int32 AddVar(ppapi::Var* var);
+ virtual scoped_refptr< ::ppapi::Var > GetVar(int32 var_id) const;
+ virtual bool AddRefVar(int32 var_id);
+ virtual bool UnrefVar(int32 var_id);
private:
friend struct DefaultSingletonTraits<PluginResourceTracker>;
diff --git a/ppapi/shared_impl/tracker_base.h b/ppapi/shared_impl/tracker_base.h
index 28cd442..7d4d9e8 100644
--- a/ppapi/shared_impl/tracker_base.h
+++ b/ppapi/shared_impl/tracker_base.h
@@ -5,6 +5,8 @@
#ifndef PPAPI_SHARED_IMPL_TRACKER_BASE_H_
#define PPAPI_SHARED_IMPL_TRACKER_BASE_H_
+#include "base/basictypes.h"
+#include "base/memory/ref_counted.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_resource.h"
#include "ppapi/proxy/interface_id.h"
@@ -13,6 +15,7 @@ namespace ppapi {
class FunctionGroupBase;
class ResourceObjectBase;
+class Var;
// Tracks resource and function APIs, providing a mapping between ID and
// object.
@@ -44,6 +47,17 @@ class TrackerBase {
// Returns the instance corresponding to the given resource, or 0 if the
// resource is invalid.
virtual PP_Instance GetInstanceForResource(PP_Resource resource) = 0;
+
+ // PP_Vars -------------------------------------------------------------------
+
+ // Adds a new var to the tracker, returning the new Var ID.
+ virtual int32 AddVar(Var* var) = 0;
+
+ // Retrieves a var from the tracker, returning an empty scoped ptr on failure.
+ virtual scoped_refptr<Var> GetVar(int32 var_id) const = 0;
+
+ virtual bool AddRefVar(int32 var_id) = 0;
+ virtual bool UnrefVar(int32 var_id) = 0;
};
} // namespace ppapi
diff --git a/ppapi/shared_impl/var.cc b/ppapi/shared_impl/var.cc
new file mode 100644
index 0000000..4148afe
--- /dev/null
+++ b/ppapi/shared_impl/var.cc
@@ -0,0 +1,155 @@
+// 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/var.h"
+
+#include <limits>
+
+#include "base/logging.h"
+#include "base/string_number_conversions.h"
+#include "base/string_util.h"
+#include "ppapi/c/pp_var.h"
+#include "ppapi/shared_impl/tracker_base.h"
+
+namespace ppapi {
+
+// Var -------------------------------------------------------------------------
+
+Var::Var(PP_Module module) : pp_module_(module), var_id_(0) {
+}
+
+Var::~Var() {
+}
+
+// static
+std::string Var::PPVarToLogString(PP_Var var) {
+ switch (var.type) {
+ case PP_VARTYPE_UNDEFINED:
+ return "[Undefined]";
+ case PP_VARTYPE_NULL:
+ return "[Null]";
+ case PP_VARTYPE_BOOL:
+ return var.value.as_bool ? "[True]" : "[False]";
+ case PP_VARTYPE_INT32:
+ return base::IntToString(var.value.as_int);
+ case PP_VARTYPE_DOUBLE:
+ return base::DoubleToString(var.value.as_double);
+ case PP_VARTYPE_STRING: {
+ scoped_refptr<StringVar> string(StringVar::FromPPVar(var));
+ if (!string)
+ return "[Invalid string]";
+
+ // Since this is for logging, escape NULLs, truncate length.
+ std::string result;
+ const size_t kTruncateAboveLength = 128;
+ if (string->value().size() > kTruncateAboveLength)
+ result = string->value().substr(0, kTruncateAboveLength) + "...";
+ else
+ result = string->value();
+
+ std::string null;
+ null.push_back(0);
+ ReplaceSubstringsAfterOffset(&result, 0, null, "\\0");
+ return result;
+ }
+ case PP_VARTYPE_OBJECT:
+ return "[Object]";
+ default:
+ return "[Invalid var]";
+ }
+}
+
+// static
+void Var::PluginAddRefPPVar(PP_Var var) {
+ if (var.type == PP_VARTYPE_STRING || var.type == PP_VARTYPE_OBJECT) {
+ if (!TrackerBase::Get()->AddRefVar(static_cast<int32>(var.value.as_id)))
+ DLOG(WARNING) << "AddRefVar()ing a nonexistent string/object var.";
+ }
+}
+
+// static
+void Var::PluginReleasePPVar(PP_Var var) {
+ if (var.type == PP_VARTYPE_STRING || var.type == PP_VARTYPE_OBJECT) {
+ if (!TrackerBase::Get()->UnrefVar(static_cast<int32>(var.value.as_id)))
+ DLOG(WARNING) << "ReleaseVar()ing a nonexistent string/object var.";
+ }
+}
+
+StringVar* Var::AsStringVar() {
+ return NULL;
+}
+
+NPObjectVar* Var::AsNPObjectVar() {
+ return NULL;
+}
+
+int32 Var::GetExistingVarID() const {
+ return var_id_;
+}
+
+int32 Var::GetOrCreateVarID() {
+ TrackerBase* tracker = TrackerBase::Get();
+ 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(PP_Module module, const char* str, uint32 len)
+ : Var(module),
+ value_(str, len) {
+}
+
+StringVar::~StringVar() {
+}
+
+StringVar* StringVar::AsStringVar() {
+ return this;
+}
+
+PP_Var StringVar::GetPPVar() {
+ int32 id = GetOrCreateVarID();
+ 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(PP_Module module, const std::string& var) {
+ return StringToPPVar(module, var.c_str(), var.size());
+}
+
+// static
+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();
+ return str->GetPPVar();
+}
+
+// static
+scoped_refptr<StringVar> StringVar::FromPPVar(PP_Var var) {
+ if (var.type != PP_VARTYPE_STRING)
+ return scoped_refptr<StringVar>();
+ scoped_refptr<Var> var_object(
+ TrackerBase::Get()->GetVar(static_cast<int32>(var.value.as_id)));
+ if (!var_object)
+ return scoped_refptr<StringVar>();
+ return scoped_refptr<StringVar>(var_object->AsStringVar());
+}
+
+} // namespace ppapi
+
diff --git a/webkit/plugins/ppapi/var.h b/ppapi/shared_impl/var.h
index edbcec7..e03e286 100644
--- a/webkit/plugins/ppapi/var.h
+++ b/ppapi/shared_impl/var.h
@@ -2,27 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef WEBKIT_PLUGINS_PPAPI_VAR_H_
-#define WEBKIT_PLUGINS_PPAPI_VAR_H_
+#ifndef PPAPI_SHARED_IMPL_VAR_H_
+#define PPAPI_SHARED_IMPL_VAR_H_
#include <string>
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
-#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_module.h"
struct PP_Var;
-struct PPB_Var;
-struct PPB_Var_Deprecated;
-typedef struct NPObject NPObject;
-typedef struct _NPVariant NPVariant;
-typedef void* NPIdentifier;
-namespace webkit {
namespace ppapi {
-class ObjectVar;
+class NPObjectVar;
class StringVar;
// Var -------------------------------------------------------------------------
@@ -68,7 +61,7 @@ class Var : public base::RefCounted<Var> {
static void PluginReleasePPVar(PP_Var var);
virtual StringVar* AsStringVar();
- virtual ObjectVar* AsObjectVar();
+ virtual NPObjectVar* AsNPObjectVar();
// Creates a PP_Var corresponding to this object. The return value will have
// one reference addrefed on behalf of the caller.
@@ -148,113 +141,6 @@ class StringVar : public Var {
DISALLOW_COPY_AND_ASSIGN(StringVar);
};
-// ObjectVar -------------------------------------------------------------------
-
-// Represents a JavaScript object Var. By itself, this represents random
-// NPObjects that a given plugin (identified by the resource's module) wants to
-// reference. If two different modules reference the same NPObject (like the
-// "window" object), then there will be different ObjectVar's (and hence PP_Var
-// IDs) for each module. This allows us to track all references owned by a
-// given module and free them when the plugin exits independently of other
-// plugins that may be running at the same time.
-//
-// See StringVar for examples, except obviously using NPObjects instead of
-// strings.
-class ObjectVar : public Var {
- public:
- // You should always use FromNPObject to create an ObjectVar. This function
- // guarantees that we maintain the 1:1 mapping between NPObject and
- // ObjectVar.
- ObjectVar(PP_Module module, PP_Instance instance, NPObject* np_object);
-
- virtual ~ObjectVar();
-
- // Var overrides.
- virtual ObjectVar* AsObjectVar() OVERRIDE;
- virtual PP_Var GetPPVar() OVERRIDE;
-
- // Returns the underlying NPObject corresponding to this ObjectVar.
- // Guaranteed non-NULL.
- NPObject* np_object() const { return np_object_; }
-
- // Notification that the instance was deleted, the internal reference will be
- // zeroed out.
- void InstanceDeleted();
-
- // Possibly 0 if the object has outlived its instance.
- PP_Instance pp_instance() const { return pp_instance_; }
-
- // Helper function that converts a PP_Var to an object. This will return NULL
- // if the PP_Var is not of object type or the object is invalid.
- static scoped_refptr<ObjectVar> FromPPVar(PP_Var var);
-
- private:
- // Possibly 0 if the object has outlived its instance.
- PP_Instance pp_instance_;
-
- // Guaranteed non-NULL, this is the underlying object used by WebKit. We
- // hold a reference to this object.
- NPObject* np_object_;
-
- DISALLOW_COPY_AND_ASSIGN(ObjectVar);
-};
-
-// TryCatch --------------------------------------------------------------------
-
-// Instantiate this object on the stack to catch V8 exceptions and pass them
-// to an optional out parameter supplied by the plugin.
-class TryCatch {
- public:
- // The given exception may be NULL if the consumer isn't interested in
- // catching exceptions. If non-NULL, the given var will be updated if any
- // exception is thrown (so it must outlive the TryCatch object).
- //
- // The module associated with the exception is passed so we know which module
- // to associate any exception string with. It may be NULL if you don't know
- // the module at construction time, in which case you should set it later
- // by calling set_module().
- //
- // If an exception is thrown when the module is NULL, setting *any* exception
- // will result in using the InvalidObjectException.
- TryCatch(PP_Module module, PP_Var* exception);
- ~TryCatch();
-
- // Get and set the module. This may be NULL (see the constructor).
- 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.
- bool has_exception() const { return has_exception_; }
-
- // Sets the given exception. If no module has been set yet, the message will
- // be ignored (since we have no module to associate the string with) and the
- // SetInvalidObjectException() will be used instead.
- //
- // If an exception has been previously set, this function will do nothing
- // (normally you want only the first exception).
- void SetException(const char* message);
-
- // Sets the exception to be a generic message contained in a magic string
- // not associated with any module.
- void SetInvalidObjectException();
-
- private:
- static void Catch(void* self, const char* message);
-
- 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
- // always indicate if SetException has been called, regardless of whether
- // the exception itself has been stored.
- bool has_exception_;
-
- // May be null if the consumer isn't interesting in catching exceptions.
- PP_Var* exception_;
-};
-
} // namespace ppapi
-} // namespace webkit
-#endif // WEBKIT_PLUGINS_PPAPI_VAR_H_
+#endif // PPAPI_SHARED_IMPL_VAR_H_
diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi
index 5578051..076d6f6 100644
--- a/webkit/glue/webkit_glue.gypi
+++ b/webkit/glue/webkit_glue.gypi
@@ -214,6 +214,8 @@
'../plugins/ppapi/message_channel.h',
'../plugins/ppapi/npapi_glue.cc',
'../plugins/ppapi/npapi_glue.h',
+ '../plugins/ppapi/npobject_var.cc',
+ '../plugins/ppapi/npobject_var.h',
'../plugins/ppapi/plugin_delegate.h',
'../plugins/ppapi/plugin_module.cc',
'../plugins/ppapi/plugin_module.h',
@@ -316,8 +318,6 @@
'../plugins/ppapi/resource_tracker.h',
'../plugins/ppapi/string.cc',
'../plugins/ppapi/string.h',
- '../plugins/ppapi/var.cc',
- '../plugins/ppapi/var.h',
'../plugins/ppapi/webkit_forwarding_impl.cc',
'../plugins/ppapi/webkit_forwarding_impl.h',
'../plugins/sad_plugin.cc',
diff --git a/webkit/plugins/ppapi/message_channel.cc b/webkit/plugins/ppapi/message_channel.cc
index 2edfe13..71368a6 100644
--- a/webkit/plugins/ppapi/message_channel.cc
+++ b/webkit/plugins/ppapi/message_channel.cc
@@ -14,10 +14,11 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
+#include "ppapi/shared_impl/var.h"
#include "webkit/plugins/ppapi/npapi_glue.h"
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
-#include "webkit/plugins/ppapi/var.h"
+using ppapi::StringVar;
using WebKit::WebBindings;
namespace webkit {
diff --git a/webkit/plugins/ppapi/npapi_glue.cc b/webkit/plugins/ppapi/npapi_glue.cc
index 2d2c342..93c57ed 100644
--- a/webkit/plugins/ppapi/npapi_glue.cc
+++ b/webkit/plugins/ppapi/npapi_glue.cc
@@ -7,15 +7,18 @@
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/string_util.h"
+#include "webkit/plugins/ppapi/npobject_var.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/resource_tracker.h"
-#include "webkit/plugins/ppapi/var.h"
#include "third_party/npapi/bindings/npapi.h"
#include "third_party/npapi/bindings/npruntime.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
+using ppapi::NPObjectVar;
+using ppapi::StringVar;
+using ppapi::Var;
using WebKit::WebBindings;
namespace webkit {
@@ -59,7 +62,7 @@ bool PPVarToNPVariant(PP_Var var, NPVariant* result) {
break;
}
case PP_VARTYPE_OBJECT: {
- scoped_refptr<ObjectVar> object(ObjectVar::FromPPVar(var));
+ scoped_refptr<NPObjectVar> object(NPObjectVar::FromPPVar(var));
if (!object) {
VOID_TO_NPVARIANT(*result);
return false;
@@ -128,12 +131,12 @@ PP_Var NPIdentifierToPPVar(PP_Module module, NPIdentifier id) {
PP_Var NPObjectToPPVar(PluginInstance* instance, NPObject* object) {
DCHECK(object);
- scoped_refptr<ObjectVar> object_var(
- ResourceTracker::Get()->ObjectVarForNPObject(instance->pp_instance(),
- object));
+ scoped_refptr<NPObjectVar> object_var(
+ ResourceTracker::Get()->NPObjectVarForNPObject(instance->pp_instance(),
+ object));
if (!object_var) { // No object for this module yet, make a new one.
- object_var = new ObjectVar(instance->module()->pp_module(),
- instance->pp_instance(), object);
+ object_var = new NPObjectVar(instance->module()->pp_module(),
+ instance->pp_instance(), object);
}
return object_var->GetPPVar();
}
@@ -156,7 +159,7 @@ PPResultAndExceptionToNPResult::~PPResultAndExceptionToNPResult() {
// been lost.
DCHECK(checked_exception_);
- ObjectVar::PluginReleasePPVar(exception_);
+ NPObjectVar::PluginReleasePPVar(exception_);
}
// Call this with the return value of the PPAPI function. It will convert
@@ -181,7 +184,7 @@ bool PPResultAndExceptionToNPResult::SetResult(PP_Var result) {
// No matter what happened, we need to release the reference to the
// value passed in. On success, a reference to this value will be in
// the np_result_.
- Var::PluginReleasePPVar(result);
+ ::ppapi::Var::PluginReleasePPVar(result);
return success_;
}
@@ -235,7 +238,7 @@ PPVarArrayFromNPVariantArray::PPVarArrayFromNPVariantArray(
PPVarArrayFromNPVariantArray::~PPVarArrayFromNPVariantArray() {
for (size_t i = 0; i < size_; i++)
- Var::PluginReleasePPVar(array_[i]);
+ ::ppapi::Var::PluginReleasePPVar(array_[i]);
}
// PPVarFromNPObject -----------------------------------------------------------
@@ -245,7 +248,7 @@ PPVarFromNPObject::PPVarFromNPObject(PluginInstance* instance, NPObject* object)
}
PPVarFromNPObject::~PPVarFromNPObject() {
- Var::PluginReleasePPVar(var_);
+ ::ppapi::Var::PluginReleasePPVar(var_);
}
// NPObjectAccessorWithIdentifier ----------------------------------------------
@@ -265,7 +268,51 @@ NPObjectAccessorWithIdentifier::NPObjectAccessorWithIdentifier(
}
NPObjectAccessorWithIdentifier::~NPObjectAccessorWithIdentifier() {
- Var::PluginReleasePPVar(identifier_);
+ ::ppapi::Var::PluginReleasePPVar(identifier_);
+}
+
+// TryCatch --------------------------------------------------------------------
+
+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);
+}
+
+TryCatch::~TryCatch() {
+ WebBindings::popExceptionHandler();
+}
+
+void TryCatch::SetException(const char* message) {
+ if (!pp_module_) {
+ // Don't have a module to make the string.
+ SetInvalidObjectException();
+ return;
+ }
+
+ if (!has_exception()) {
+ has_exception_ = true;
+ if (exception_) {
+ *exception_ = ::ppapi::StringVar::StringToPPVar(pp_module_,
+ message, strlen(message));
+ }
+ }
+}
+
+void TryCatch::SetInvalidObjectException() {
+ if (!has_exception()) {
+ has_exception_ = true;
+ // TODO(brettw) bug 54504: Have a global singleton string that can hold
+ // a generic error message.
+ if (exception_)
+ *exception_ = PP_MakeInt32(1);
+ }
+}
+
+// static
+void TryCatch::Catch(void* self, const char* message) {
+ static_cast<TryCatch*>(self)->SetException(message);
}
} // namespace ppapi
diff --git a/webkit/plugins/ppapi/npapi_glue.h b/webkit/plugins/ppapi/npapi_glue.h
index ced0fe6..2ca7772 100644
--- a/webkit/plugins/ppapi/npapi_glue.h
+++ b/webkit/plugins/ppapi/npapi_glue.h
@@ -220,6 +220,61 @@ class NPObjectAccessorWithIdentifier {
DISALLOW_COPY_AND_ASSIGN(NPObjectAccessorWithIdentifier);
};
+// TryCatch --------------------------------------------------------------------
+
+// Instantiate this object on the stack to catch V8 exceptions and pass them
+// to an optional out parameter supplied by the plugin.
+class TryCatch {
+ public:
+ // The given exception may be NULL if the consumer isn't interested in
+ // catching exceptions. If non-NULL, the given var will be updated if any
+ // exception is thrown (so it must outlive the TryCatch object).
+ //
+ // The module associated with the exception is passed so we know which module
+ // to associate any exception string with. It may be NULL if you don't know
+ // the module at construction time, in which case you should set it later
+ // by calling set_module().
+ //
+ // If an exception is thrown when the module is NULL, setting *any* exception
+ // will result in using the InvalidObjectException.
+ TryCatch(PP_Module module, PP_Var* exception);
+ ~TryCatch();
+
+ // Get and set the module. This may be NULL (see the constructor).
+ 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.
+ bool has_exception() const { return has_exception_; }
+
+ // Sets the given exception. If no module has been set yet, the message will
+ // be ignored (since we have no module to associate the string with) and the
+ // SetInvalidObjectException() will be used instead.
+ //
+ // If an exception has been previously set, this function will do nothing
+ // (normally you want only the first exception).
+ void SetException(const char* message);
+
+ // Sets the exception to be a generic message contained in a magic string
+ // not associated with any module.
+ void SetInvalidObjectException();
+
+ private:
+ static void Catch(void* self, const char* message);
+
+ 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
+ // always indicate if SetException has been called, regardless of whether
+ // the exception itself has been stored.
+ bool has_exception_;
+
+ // May be null if the consumer isn't interesting in catching exceptions.
+ PP_Var* exception_;
+};
+
} // namespace ppapi
} // namespace webkit
diff --git a/webkit/plugins/ppapi/npobject_var.cc b/webkit/plugins/ppapi/npobject_var.cc
new file mode 100644
index 0000000..b951cde
--- /dev/null
+++ b/webkit/plugins/ppapi/npobject_var.cc
@@ -0,0 +1,65 @@
+// 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 "webkit/plugins/ppapi/npobject_var.h"
+
+#include "base/logging.h"
+#include "ppapi/c/pp_var.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
+#include "webkit/plugins/ppapi/resource_tracker.h"
+
+using WebKit::WebBindings;
+
+namespace ppapi {
+
+// NPObjectVar -----------------------------------------------------------------
+
+NPObjectVar::NPObjectVar(PP_Module module,
+ PP_Instance instance,
+ NPObject* np_object)
+ : Var(module),
+ pp_instance_(instance),
+ np_object_(np_object) {
+ WebBindings::retainObject(np_object_);
+ webkit::ppapi::ResourceTracker::Get()->AddNPObjectVar(this);
+}
+
+NPObjectVar::~NPObjectVar() {
+ if (pp_instance())
+ webkit::ppapi::ResourceTracker::Get()->RemoveNPObjectVar(this);
+ WebBindings::releaseObject(np_object_);
+}
+
+NPObjectVar* NPObjectVar::AsNPObjectVar() {
+ return this;
+}
+
+PP_Var NPObjectVar::GetPPVar() {
+ int32 id = GetOrCreateVarID();
+ if (!id)
+ return PP_MakeNull();
+
+ PP_Var result;
+ result.type = PP_VARTYPE_OBJECT;
+ result.value.as_id = id;
+ return result;
+}
+
+void NPObjectVar::InstanceDeleted() {
+ DCHECK(pp_instance_);
+ pp_instance_ = 0;
+}
+
+// static
+scoped_refptr<NPObjectVar> NPObjectVar::FromPPVar(PP_Var var) {
+ if (var.type != PP_VARTYPE_OBJECT)
+ return scoped_refptr<NPObjectVar>(NULL);
+ scoped_refptr<Var> var_object(webkit::ppapi::ResourceTracker::Get()->GetVar(
+ static_cast<int32>(var.value.as_id)));
+ if (!var_object)
+ return scoped_refptr<NPObjectVar>();
+ return scoped_refptr<NPObjectVar>(var_object->AsNPObjectVar());
+}
+
+} // namespace ppapi
diff --git a/webkit/plugins/ppapi/npobject_var.h b/webkit/plugins/ppapi/npobject_var.h
new file mode 100644
index 0000000..d0ba122
--- /dev/null
+++ b/webkit/plugins/ppapi/npobject_var.h
@@ -0,0 +1,71 @@
+// 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 WEBKIT_PLUGINS_PPAPI_NPOBJECT_VAR_H_
+#define WEBKIT_PLUGINS_PPAPI_NPOBJECT_VAR_H_
+
+#include <string>
+
+#include "base/compiler_specific.h"
+#include "ppapi/c/pp_instance.h"
+#include "ppapi/c/pp_module.h"
+#include "ppapi/shared_impl/var.h"
+
+typedef struct NPObject NPObject;
+typedef struct _NPVariant NPVariant;
+typedef void* NPIdentifier;
+
+namespace ppapi {
+
+// NPObjectVar -----------------------------------------------------------------
+
+// Represents a JavaScript object Var. By itself, this represents random
+// NPObjects that a given plugin (identified by the resource's module) wants to
+// reference. If two different modules reference the same NPObject (like the
+// "window" object), then there will be different NPObjectVar's (and hence
+// PP_Var IDs) for each module. This allows us to track all references owned by
+// a given module and free them when the plugin exits independently of other
+// plugins that may be running at the same time.
+class NPObjectVar : public Var {
+ public:
+ // You should always use FromNPObject to create an NPObjectVar. This function
+ // guarantees that we maintain the 1:1 mapping between NPObject and
+ // NPObjectVar.
+ NPObjectVar(PP_Module module, PP_Instance instance, NPObject* np_object);
+
+ virtual ~NPObjectVar();
+
+ // Var overrides.
+ virtual NPObjectVar* AsNPObjectVar() OVERRIDE;
+ virtual PP_Var GetPPVar() OVERRIDE;
+
+ // Returns the underlying NPObject corresponding to this NPObjectVar.
+ // Guaranteed non-NULL.
+ NPObject* np_object() const { return np_object_; }
+
+ // Notification that the instance was deleted, the internal reference will be
+ // zeroed out.
+ void InstanceDeleted();
+
+ // Possibly 0 if the object has outlived its instance.
+ PP_Instance pp_instance() const { return pp_instance_; }
+
+ // Helper function that converts a PP_Var to an object. This will return NULL
+ // if the PP_Var is not of object type or the object is invalid.
+ static scoped_refptr<NPObjectVar> FromPPVar(PP_Var var);
+
+ private:
+ // Possibly 0 if the object has outlived its instance.
+ PP_Instance pp_instance_;
+
+ // Guaranteed non-NULL, this is the underlying object used by WebKit. We
+ // hold a reference to this object.
+ NPObject* np_object_;
+
+ DISALLOW_COPY_AND_ASSIGN(NPObjectVar);
+};
+
+} // namespace
+
+#endif // WEBKIT_PLUGINS_PPAPI_NPOBJECT_VAR_H_
diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc
index 3c77a6e..145ba4d 100644
--- a/webkit/plugins/ppapi/plugin_module.cc
+++ b/webkit/plugins/ppapi/plugin_module.cc
@@ -105,7 +105,6 @@
#include "webkit/plugins/ppapi/ppb_video_decoder_impl.h"
#include "webkit/plugins/ppapi/ppb_video_layer_impl.h"
#include "webkit/plugins/ppapi/resource_tracker.h"
-#include "webkit/plugins/ppapi/var.h"
#include "webkit/plugins/ppapi/webkit_forwarding_impl.h"
using ppapi::TimeTicksToPPTimeTicks;
diff --git a/webkit/plugins/ppapi/plugin_object.cc b/webkit/plugins/ppapi/plugin_object.cc
index b20b9ff..95d8fba 100644
--- a/webkit/plugins/ppapi/plugin_object.cc
+++ b/webkit/plugins/ppapi/plugin_object.cc
@@ -15,14 +15,16 @@
#include "ppapi/c/dev/ppp_class_deprecated.h"
#include "ppapi/c/pp_resource.h"
#include "ppapi/c/pp_var.h"
+#include "ppapi/shared_impl/var.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
#include "webkit/plugins/ppapi/npapi_glue.h"
#include "webkit/plugins/ppapi/plugin_module.h"
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "webkit/plugins/ppapi/resource.h"
#include "webkit/plugins/ppapi/string.h"
-#include "webkit/plugins/ppapi/var.h"
+using ppapi::StringVar;
+using ppapi::Var;
using WebKit::WebBindings;
namespace webkit {
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
index 08b1d16..5770ca8 100644
--- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc
+++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
@@ -29,6 +29,7 @@
#include "ppapi/c/ppp_messaging.h"
#include "ppapi/c/private/ppb_instance_private.h"
#include "ppapi/c/private/ppp_instance_private.h"
+#include "ppapi/shared_impl/var.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_buffer_api.h"
#include "printing/units.h"
@@ -65,7 +66,6 @@
#include "webkit/plugins/ppapi/ppb_url_request_info_impl.h"
#include "webkit/plugins/ppapi/ppp_pdf.h"
#include "webkit/plugins/ppapi/string.h"
-#include "webkit/plugins/ppapi/var.h"
#include "webkit/plugins/sad_plugin.h"
#if defined(OS_MACOSX)
@@ -89,6 +89,7 @@
#include "skia/ext/skia_utils_mac.h"
#endif
+using ppapi::StringVar;
using ppapi::thunk::EnterResourceNoLock;
using ppapi::thunk::PPB_Buffer_API;
using ppapi::thunk::PPB_Graphics2D_API;
@@ -96,6 +97,7 @@ using ppapi::thunk::PPB_Graphics3D_API;
using ppapi::thunk::PPB_ImageData_API;
using ppapi::thunk::PPB_Instance_FunctionAPI;
using ppapi::thunk::PPB_Surface3D_API;
+using ppapi::Var;
using WebKit::WebBindings;
using WebKit::WebCanvas;
using WebKit::WebCursorInfo;
diff --git a/webkit/plugins/ppapi/ppapi_webplugin_impl.cc b/webkit/plugins/ppapi/ppapi_webplugin_impl.cc
index 80328ff..e302fc6 100644
--- a/webkit/plugins/ppapi/ppapi_webplugin_impl.cc
+++ b/webkit/plugins/ppapi/ppapi_webplugin_impl.cc
@@ -15,11 +15,12 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
#include "webkit/plugins/ppapi/message_channel.h"
+#include "webkit/plugins/ppapi/npobject_var.h"
#include "webkit/plugins/ppapi/plugin_module.h"
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "webkit/plugins/ppapi/ppb_url_loader_impl.h"
-#include "webkit/plugins/ppapi/var.h"
+using ppapi::NPObjectVar;
using WebKit::WebCanvas;
using WebKit::WebPluginContainer;
using WebKit::WebPluginParams;
@@ -94,8 +95,8 @@ void WebPluginImpl::destroy() {
}
NPObject* WebPluginImpl::scriptableObject() {
- scoped_refptr<ObjectVar> object(
- ObjectVar::FromPPVar(instance_->GetInstanceObject()));
+ scoped_refptr<NPObjectVar> object(
+ NPObjectVar::FromPPVar(instance_->GetInstanceObject()));
// GetInstanceObject talked to the plugin which may have removed the instance
// from the DOM, in which case instance_ would be NULL now.
if (!instance_)
diff --git a/webkit/plugins/ppapi/ppb_char_set_impl.cc b/webkit/plugins/ppapi/ppb_char_set_impl.cc
index 28d9101..a21b221 100644
--- a/webkit/plugins/ppapi/ppb_char_set_impl.cc
+++ b/webkit/plugins/ppapi/ppb_char_set_impl.cc
@@ -7,13 +7,14 @@
#include "ppapi/c/dev/ppb_char_set_dev.h"
#include "ppapi/c/dev/ppb_memory_dev.h"
#include "ppapi/shared_impl/char_set_impl.h"
+#include "ppapi/shared_impl/var.h"
#include "webkit/plugins/ppapi/plugin_delegate.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"
-using ::ppapi::thunk::PPB_CharSet_FunctionAPI;
+using ppapi::StringVar;
+using ppapi::thunk::PPB_CharSet_FunctionAPI;
namespace webkit {
namespace ppapi {
diff --git a/webkit/plugins/ppapi/ppb_console_impl.cc b/webkit/plugins/ppapi/ppb_console_impl.cc
index 3ca773c..1b08ebf 100644
--- a/webkit/plugins/ppapi/ppb_console_impl.cc
+++ b/webkit/plugins/ppapi/ppb_console_impl.cc
@@ -7,6 +7,7 @@
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "ppapi/c/dev/ppb_console_dev.h"
+#include "ppapi/shared_impl/var.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
@@ -15,8 +16,8 @@
#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"
+using ppapi::Var;
using WebKit::WebConsoleMessage;
using WebKit::WebString;
diff --git a/webkit/plugins/ppapi/ppb_file_ref_impl.cc b/webkit/plugins/ppapi/ppb_file_ref_impl.cc
index 4581d42..1db9a22 100644
--- a/webkit/plugins/ppapi/ppb_file_ref_impl.cc
+++ b/webkit/plugins/ppapi/ppb_file_ref_impl.cc
@@ -8,9 +8,10 @@
#include "base/utf_string_conversions.h"
#include "googleurl/src/gurl.h"
#include "ppapi/c/pp_errors.h"
-#include "ppapi/shared_impl/time_conversion.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_file_system_api.h"
+#include "ppapi/shared_impl/time_conversion.h"
+#include "ppapi/shared_impl/var.h"
#include "webkit/plugins/ppapi/common.h"
#include "webkit/plugins/ppapi/file_callbacks.h"
#include "webkit/plugins/ppapi/plugin_delegate.h"
@@ -18,9 +19,9 @@
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "webkit/plugins/ppapi/ppb_directory_reader_impl.h"
#include "webkit/plugins/ppapi/ppb_file_system_impl.h"
-#include "webkit/plugins/ppapi/var.h"
using ppapi::PPTimeToTime;
+using ppapi::StringVar;
using ppapi::thunk::EnterResourceNoLock;
using ppapi::thunk::PPB_FileRef_API;
using ppapi::thunk::PPB_FileSystem_API;
diff --git a/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc b/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc
index 404260f..b35391a 100644
--- a/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc
+++ b/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc
@@ -11,6 +11,7 @@
#include "base/memory/ref_counted.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/private/ppb_flash_clipboard.h"
+#include "ppapi/shared_impl/var.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebClipboard.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
@@ -20,7 +21,8 @@
#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"
+
+using ppapi::StringVar;
namespace webkit {
namespace ppapi {
diff --git a/webkit/plugins/ppapi/ppb_flash_impl.cc b/webkit/plugins/ppapi/ppb_flash_impl.cc
index 82d1656..b38932d 100644
--- a/webkit/plugins/ppapi/ppb_flash_impl.cc
+++ b/webkit/plugins/ppapi/ppb_flash_impl.cc
@@ -11,6 +11,7 @@
#include "googleurl/src/gurl.h"
#include "ppapi/c/private/ppb_flash.h"
#include "ppapi/shared_impl/time_conversion.h"
+#include "ppapi/shared_impl/var.h"
#include "ppapi/thunk/enter.h"
#include "webkit/plugins/ppapi/common.h"
#include "webkit/plugins/ppapi/plugin_delegate.h"
@@ -18,9 +19,9 @@
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "webkit/plugins/ppapi/ppb_url_request_info_impl.h"
#include "webkit/plugins/ppapi/resource_tracker.h"
-#include "webkit/plugins/ppapi/var.h"
using ppapi::PPTimeToTime;
+using ppapi::StringVar;
using ppapi::thunk::EnterResource;
using ppapi::thunk::PPB_URLRequestInfo_API;
diff --git a/webkit/plugins/ppapi/ppb_flash_impl_linux.cc b/webkit/plugins/ppapi/ppb_flash_impl_linux.cc
index c698620..55b7d79 100644
--- a/webkit/plugins/ppapi/ppb_flash_impl_linux.cc
+++ b/webkit/plugins/ppapi/ppb_flash_impl_linux.cc
@@ -8,6 +8,7 @@
#include "ppapi/c/pp_point.h"
#include "ppapi/c/pp_rect.h"
#include "ppapi/c/dev/ppb_font_dev.h"
+#include "ppapi/shared_impl/var.h"
#include "ppapi/thunk/enter.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkMatrix.h"
@@ -16,8 +17,8 @@
#include "third_party/skia/include/core/SkTemplates.h"
#include "third_party/skia/include/core/SkTypeface.h"
#include "webkit/plugins/ppapi/ppb_image_data_impl.h"
-#include "webkit/plugins/ppapi/var.h"
+using ppapi::StringVar;
using ppapi::thunk::EnterResource;
using ppapi::thunk::PPB_ImageData_API;
diff --git a/webkit/plugins/ppapi/ppb_font_impl.cc b/webkit/plugins/ppapi/ppb_font_impl.cc
index 8ad95b5..0173dea 100644
--- a/webkit/plugins/ppapi/ppb_font_impl.cc
+++ b/webkit/plugins/ppapi/ppb_font_impl.cc
@@ -7,6 +7,7 @@
#include "ppapi/c/dev/ppb_font_dev.h"
#include "ppapi/shared_impl/font_impl.h"
#include "ppapi/shared_impl/ppapi_preferences.h"
+#include "ppapi/shared_impl/var.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/thunk.h"
#include "webkit/plugins/ppapi/common.h"
@@ -14,8 +15,8 @@
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "webkit/plugins/ppapi/ppb_image_data_impl.h"
#include "webkit/plugins/ppapi/string.h"
-#include "webkit/plugins/ppapi/var.h"
+using ppapi::StringVar;
using ppapi::thunk::EnterResource;
using ppapi::thunk::PPB_ImageData_API;
using ppapi::WebKitForwarding;
diff --git a/webkit/plugins/ppapi/ppb_input_event_impl.cc b/webkit/plugins/ppapi/ppb_input_event_impl.cc
index 5139704..ffb6cba 100644
--- a/webkit/plugins/ppapi/ppb_input_event_impl.cc
+++ b/webkit/plugins/ppapi/ppb_input_event_impl.cc
@@ -4,12 +4,13 @@
#include "webkit/plugins/ppapi/ppb_input_event_impl.h"
+#include "ppapi/shared_impl/var.h"
#include "webkit/plugins/ppapi/plugin_module.h"
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
-#include "webkit/plugins/ppapi/var.h"
using ppapi::InputEventData;
using ppapi::InputEventImpl;
+using ppapi::StringVar;
using ppapi::thunk::PPB_InputEvent_API;
namespace webkit {
diff --git a/webkit/plugins/ppapi/ppb_transport_impl.cc b/webkit/plugins/ppapi/ppb_transport_impl.cc
index 968bbdb..0e68931 100644
--- a/webkit/plugins/ppapi/ppb_transport_impl.cc
+++ b/webkit/plugins/ppapi/ppb_transport_impl.cc
@@ -12,11 +12,12 @@
#include "ppapi/c/dev/ppb_transport_dev.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_errors.h"
+#include "ppapi/shared_impl/var.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/var.h"
+using ppapi::StringVar;
using ppapi::thunk::PPB_Transport_API;
using webkit_glue::P2PTransport;
diff --git a/webkit/plugins/ppapi/ppb_uma_private_impl.cc b/webkit/plugins/ppapi/ppb_uma_private_impl.cc
index f08e1df..10807cb 100644
--- a/webkit/plugins/ppapi/ppb_uma_private_impl.cc
+++ b/webkit/plugins/ppapi/ppb_uma_private_impl.cc
@@ -7,8 +7,10 @@
#include "base/metrics/histogram.h"
#include "ppapi/c/pp_var.h"
#include "ppapi/c/private/ppb_uma_private.h"
+#include "ppapi/shared_impl/var.h"
#include "webkit/glue/webkit_glue.h"
-#include "webkit/plugins/ppapi/var.h"
+
+using ppapi::StringVar;
namespace webkit {
namespace ppapi {
diff --git a/webkit/plugins/ppapi/ppb_url_request_info_impl.cc b/webkit/plugins/ppapi/ppb_url_request_info_impl.cc
index 617e9a7..44aa161 100644
--- a/webkit/plugins/ppapi/ppb_url_request_info_impl.cc
+++ b/webkit/plugins/ppapi/ppb_url_request_info_impl.cc
@@ -10,6 +10,7 @@
#include "googleurl/src/url_util.h"
#include "net/http/http_util.h"
#include "ppapi/c/pp_var.h"
+#include "ppapi/shared_impl/var.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_file_ref_api.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebData.h"
@@ -22,9 +23,9 @@
#include "webkit/plugins/ppapi/plugin_module.h"
#include "webkit/plugins/ppapi/ppb_file_ref_impl.h"
#include "webkit/plugins/ppapi/string.h"
-#include "webkit/plugins/ppapi/var.h"
#include "webkit/glue/webkit_glue.h"
+using ppapi::StringVar;
using ppapi::thunk::EnterResourceNoLock;
using ppapi::thunk::PPB_FileRef_API;
using ppapi::thunk::PPB_URLRequestInfo_API;
diff --git a/webkit/plugins/ppapi/ppb_url_response_info_impl.cc b/webkit/plugins/ppapi/ppb_url_response_info_impl.cc
index 286ecb2..b1ec1fd 100644
--- a/webkit/plugins/ppapi/ppb_url_response_info_impl.cc
+++ b/webkit/plugins/ppapi/ppb_url_response_info_impl.cc
@@ -6,6 +6,7 @@
#include "base/logging.h"
#include "ppapi/c/pp_var.h"
+#include "ppapi/shared_impl/var.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebHTTPHeaderVisitor.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
@@ -14,9 +15,9 @@
#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"
#include "webkit/glue/webkit_glue.h"
+using ppapi::StringVar;
using ppapi::thunk::PPB_URLResponseInfo_API;
using WebKit::WebHTTPHeaderVisitor;
using WebKit::WebString;
diff --git a/webkit/plugins/ppapi/ppb_url_util_impl.cc b/webkit/plugins/ppapi/ppb_url_util_impl.cc
index 6791de1..ebd8921 100644
--- a/webkit/plugins/ppapi/ppb_url_util_impl.cc
+++ b/webkit/plugins/ppapi/ppb_url_util_impl.cc
@@ -8,6 +8,7 @@
#include "ppapi/c/dev/ppb_url_util_dev.h"
#include "ppapi/c/ppb_var.h"
#include "ppapi/shared_impl/url_util_impl.h"
+#include "ppapi/shared_impl/var.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
@@ -21,13 +22,13 @@
#include "webkit/plugins/ppapi/ppb_var_impl.h"
#include "webkit/plugins/ppapi/resource_tracker.h"
#include "webkit/plugins/ppapi/string.h"
-#include "webkit/plugins/ppapi/var.h"
+
+using ppapi::StringVar;
+using ppapi::URLUtilImpl;
namespace webkit {
namespace ppapi {
-using ::ppapi::URLUtilImpl;
-
namespace {
// Returns the PP_Module associated with the given string, or 0 on failure.
diff --git a/webkit/plugins/ppapi/ppb_var_impl.cc b/webkit/plugins/ppapi/ppb_var_impl.cc
index a3cf3d5d..49576b3 100644
--- a/webkit/plugins/ppapi/ppb_var_impl.cc
+++ b/webkit/plugins/ppapi/ppb_var_impl.cc
@@ -12,13 +12,16 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
#include "webkit/plugins/ppapi/common.h"
#include "webkit/plugins/ppapi/npapi_glue.h"
+#include "webkit/plugins/ppapi/npobject_var.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/resource_tracker.h"
-#include "webkit/plugins/ppapi/var.h"
#include "v8/include/v8.h"
+using ppapi::NPObjectVar;
+using ppapi::StringVar;
+using ppapi::Var;
using WebKit::WebBindings;
namespace webkit {
@@ -75,7 +78,7 @@ bool PPVarToNPVariantNoCopy(PP_Var var, NPVariant* result) {
break;
}
case PP_VARTYPE_OBJECT: {
- scoped_refptr<ObjectVar> object(ObjectVar::FromPPVar(var));
+ scoped_refptr<NPObjectVar> object(NPObjectVar::FromPPVar(var));
if (!object) {
VOID_TO_NPVARIANT(*result);
return false;
@@ -106,7 +109,7 @@ class ObjectAccessorTryCatch : public TryCatch {
public:
ObjectAccessorTryCatch(PP_Var object, PP_Var* exception)
: TryCatch(0, exception),
- object_(ObjectVar::FromPPVar(object)) {
+ object_(NPObjectVar::FromPPVar(object)) {
if (!object_) {
// No object or an invalid object was given. This means we have no module
// to associated with the exception text, so use the magic invalid object
@@ -118,14 +121,14 @@ class ObjectAccessorTryCatch : public TryCatch {
}
}
- ObjectVar* object() { return object_.get(); }
+ NPObjectVar* object() { return object_.get(); }
PluginInstance* GetPluginInstance() {
return ResourceTracker::Get()->GetInstance(object()->pp_instance());
}
protected:
- scoped_refptr<ObjectVar> object_;
+ scoped_refptr<NPObjectVar> object_;
DISALLOW_COPY_AND_ASSIGN(ObjectAccessorTryCatch);
};
@@ -385,7 +388,7 @@ PP_Var Construct(PP_Var var,
bool IsInstanceOfDeprecated(PP_Var var,
const PPP_Class_Deprecated* ppp_class,
void** ppp_class_data) {
- scoped_refptr<ObjectVar> object(ObjectVar::FromPPVar(var));
+ scoped_refptr<NPObjectVar> object(NPObjectVar::FromPPVar(var));
if (!object)
return false; // Not an object at all.
diff --git a/webkit/plugins/ppapi/ppb_video_decoder_impl.cc b/webkit/plugins/ppapi/ppb_video_decoder_impl.cc
index 562fe3e..bb25863 100644
--- a/webkit/plugins/ppapi/ppb_video_decoder_impl.cc
+++ b/webkit/plugins/ppapi/ppb_video_decoder_impl.cc
@@ -22,7 +22,6 @@
#include "webkit/plugins/ppapi/ppb_buffer_impl.h"
#include "webkit/plugins/ppapi/ppb_context_3d_impl.h"
#include "webkit/plugins/ppapi/resource_tracker.h"
-#include "webkit/plugins/ppapi/var.h"
using ppapi::thunk::EnterResourceNoLock;
using ppapi::thunk::PPB_Buffer_API;
diff --git a/webkit/plugins/ppapi/resource_creation_impl.cc b/webkit/plugins/ppapi/resource_creation_impl.cc
index e68d167..354e62c 100644
--- a/webkit/plugins/ppapi/resource_creation_impl.cc
+++ b/webkit/plugins/ppapi/resource_creation_impl.cc
@@ -6,6 +6,7 @@
#include "ppapi/c/pp_size.h"
#include "ppapi/shared_impl/input_event_impl.h"
+#include "ppapi/shared_impl/var.h"
#include "webkit/plugins/ppapi/common.h"
#include "webkit/plugins/ppapi/ppb_audio_impl.h"
#include "webkit/plugins/ppapi/ppb_broker_impl.h"
@@ -30,9 +31,9 @@
#include "webkit/plugins/ppapi/ppb_url_request_info_impl.h"
#include "webkit/plugins/ppapi/ppb_video_decoder_impl.h"
#include "webkit/plugins/ppapi/ppb_video_layer_impl.h"
-#include "webkit/plugins/ppapi/var.h"
using ppapi::InputEventData;
+using ppapi::StringVar;
namespace webkit {
namespace ppapi {
diff --git a/webkit/plugins/ppapi/resource_tracker.cc b/webkit/plugins/ppapi/resource_tracker.cc
index 7e75fe9..3d050a5 100644
--- a/webkit/plugins/ppapi/resource_tracker.cc
+++ b/webkit/plugins/ppapi/resource_tracker.cc
@@ -13,6 +13,7 @@
#include "ppapi/c/pp_var.h"
#include "ppapi/shared_impl/function_group_base.h"
#include "ppapi/shared_impl/tracker_base.h"
+#include "webkit/plugins/ppapi/npobject_var.h"
#include "webkit/plugins/ppapi/plugin_module.h"
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "webkit/plugins/ppapi/ppb_char_set_impl.h"
@@ -21,7 +22,9 @@
#include "webkit/plugins/ppapi/ppb_font_impl.h"
#include "webkit/plugins/ppapi/resource.h"
#include "webkit/plugins/ppapi/resource_creation_impl.h"
-#include "webkit/plugins/ppapi/var.h"
+
+using ppapi::NPObjectVar;
+using ppapi::Var;
enum PPIdType {
PP_ID_TYPE_MODULE,
@@ -35,6 +38,9 @@ static const unsigned int kPPIdTypeBits = 2;
COMPILE_ASSERT(PP_ID_TYPE_COUNT <= (1<<kPPIdTypeBits),
kPPIdTypeBits_is_too_small_for_all_id_types);
+static const int32 kMaxPPIdType =
+ std::numeric_limits<int32>::max() >> kPPIdTypeBits;
+
template <typename T> static inline T MakeTypedId(T value, PPIdType type) {
return (value << kPPIdTypeBits) | static_cast<T>(type);
}
@@ -58,7 +64,7 @@ namespace {
} // namespace
-typedef std::map<NPObject*, ObjectVar*> NPObjectToObjectVarMap;
+typedef std::map<NPObject*, NPObjectVar*> NPObjectToNPObjectVarMap;
struct ResourceTracker::InstanceData {
InstanceData() : instance(0) {}
@@ -71,10 +77,11 @@ struct ResourceTracker::InstanceData {
ResourceSet ref_resources;
std::set<Resource*> assoc_resources;
- // Tracks all live ObjectVars used by this module so we can map NPObjects to
- // the corresponding object, and also release these properly if the instance
- // goes away when there are still refs. These are non-owning references.
- NPObjectToObjectVarMap np_object_to_object_var;
+ // Tracks all live NPObjectVars used by this module so we can map NPObjects
+ // to the corresponding object, and also release these properly if the
+ // instance goes away when there are still refs. These are non-owning
+ // references.
+ NPObjectToNPObjectVarMap np_object_to_object_var;
// Lazily allocated function proxies for the different interfaces.
scoped_ptr< ::ppapi::FunctionGroupBase >
@@ -152,22 +159,6 @@ PP_Resource ResourceTracker::AddResource(Resource* resource) {
return new_id;
}
-int32 ResourceTracker::AddVar(Var* var) {
- // If the plugin manages to create 1B strings...
- 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)));
-
- return new_id;
-}
-
bool ResourceTracker::AddRefResource(PP_Resource res) {
DLOG_IF(ERROR, !CheckIdType(res, PP_ID_TYPE_RESOURCE))
<< res << " is not a PP_Resource.";
@@ -241,11 +232,11 @@ void ResourceTracker::CleanupInstanceData(PP_Instance instance,
// Force delete all var references. Need to make a copy so we can iterate over
// the map while deleting stuff from it.
- NPObjectToObjectVarMap np_object_map_copy = data.np_object_to_object_var;
- NPObjectToObjectVarMap::iterator cur_var =
+ NPObjectToNPObjectVarMap np_object_map_copy = data.np_object_to_object_var;
+ NPObjectToNPObjectVarMap::iterator cur_var =
np_object_map_copy.begin();
while (cur_var != np_object_map_copy.end()) {
- NPObjectToObjectVarMap::iterator current = cur_var++;
+ NPObjectToNPObjectVarMap::iterator current = cur_var++;
// Clear the object from the var mapping and the live instance object list.
int32 var_id = current->second->GetExistingVarID();
@@ -336,6 +327,22 @@ PP_Instance ResourceTracker::GetInstanceForResource(PP_Resource pp_resource) {
return resource->instance()->pp_instance();
}
+int32 ResourceTracker::AddVar(Var* var) {
+ // If the plugin manages to create 1B strings...
+ if (last_var_id_ == kMaxPPIdType)
+ 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)));
+
+ return new_id;
+}
+
scoped_refptr<Var> ResourceTracker::GetVar(int32 var_id) const {
DLOG_IF(ERROR, !CheckIdType(var_id, PP_ID_TYPE_VAR))
<< var_id << " is not a PP_Var ID.";
@@ -371,38 +378,38 @@ bool ResourceTracker::UnrefVar(int32 var_id) {
return false;
}
-void ResourceTracker::AddNPObjectVar(ObjectVar* object_var) {
+void ResourceTracker::AddNPObjectVar(NPObjectVar* object_var) {
DCHECK(instance_map_.find(object_var->pp_instance()) != instance_map_.end());
InstanceData& data = *instance_map_[object_var->pp_instance()].get();
DCHECK(data.np_object_to_object_var.find(object_var->np_object()) ==
- data.np_object_to_object_var.end()) << "ObjectVar already in map";
+ data.np_object_to_object_var.end()) << "NPObjectVar already in map";
data.np_object_to_object_var[object_var->np_object()] = object_var;
}
-void ResourceTracker::RemoveNPObjectVar(ObjectVar* object_var) {
+void ResourceTracker::RemoveNPObjectVar(NPObjectVar* object_var) {
DCHECK(instance_map_.find(object_var->pp_instance()) != instance_map_.end());
InstanceData& data = *instance_map_[object_var->pp_instance()].get();
- NPObjectToObjectVarMap::iterator found =
+ NPObjectToNPObjectVarMap::iterator found =
data.np_object_to_object_var.find(object_var->np_object());
if (found == data.np_object_to_object_var.end()) {
- NOTREACHED() << "ObjectVar not registered.";
+ NOTREACHED() << "NPObjectVar not registered.";
return;
}
if (found->second != object_var) {
- NOTREACHED() << "ObjectVar doesn't match.";
+ NOTREACHED() << "NPObjectVar doesn't match.";
return;
}
data.np_object_to_object_var.erase(found);
}
-ObjectVar* ResourceTracker::ObjectVarForNPObject(PP_Instance instance,
- NPObject* np_object) {
+NPObjectVar* ResourceTracker::NPObjectVarForNPObject(PP_Instance instance,
+ NPObject* np_object) {
DCHECK(instance_map_.find(instance) != instance_map_.end());
InstanceData& data = *instance_map_[instance].get();
- NPObjectToObjectVarMap::iterator found =
+ NPObjectToNPObjectVarMap::iterator found =
data.np_object_to_object_var.find(np_object);
if (found == data.np_object_to_object_var.end())
return NULL;
diff --git a/webkit/plugins/ppapi/resource_tracker.h b/webkit/plugins/ppapi/resource_tracker.h
index a079c02..faf5aec 100644
--- a/webkit/plugins/ppapi/resource_tracker.h
+++ b/webkit/plugins/ppapi/resource_tracker.h
@@ -24,15 +24,18 @@
typedef struct NPObject NPObject;
+namespace ppapi {
+class NPObjectVar;
+class Var;
+}
+
namespace webkit {
namespace ppapi {
-class ObjectVar;
class PluginInstance;
class PluginModule;
class Resource;
class ResourceTrackerTest;
-class Var;
// This class maintains a global list of all live pepper resources. It allows
// us to check resource ID validity and to map them to a specific module.
@@ -70,22 +73,24 @@ class ResourceTracker : public ::ppapi::TrackerBase {
// PP_Vars -------------------------------------------------------------------
- scoped_refptr<Var> GetVar(int32 var_id) const;
-
- bool AddRefVar(int32 var_id);
- bool UnrefVar(int32 var_id);
+ // TrackerBase implementation.
+ virtual int32 AddVar(::ppapi::Var* var) OVERRIDE;
+ virtual scoped_refptr< ::ppapi::Var > GetVar(int32 var_id) const OVERRIDE;
+ virtual bool AddRefVar(int32 var_id) OVERRIDE;
+ virtual bool UnrefVar(int32 var_id) OVERRIDE;
- // Tracks all live ObjectVar. This is so we can map between instance +
- // NPObject and get the ObjectVar corresponding to it. This Add/Remove
- // function is called by the ObjectVar when it is created and
+ // Tracks all live NPObjectVar. This is so we can map between instance +
+ // NPObject and get the NPObjectVar corresponding to it. This Add/Remove
+ // function is called by the NPObjectVar when it is created and
// destroyed.
- void AddNPObjectVar(ObjectVar* object_var);
- void RemoveNPObjectVar(ObjectVar* object_var);
+ void AddNPObjectVar(::ppapi::NPObjectVar* object_var);
+ void RemoveNPObjectVar(::ppapi::NPObjectVar* object_var);
- // Looks up a previously registered ObjectVar for the given NPObject and
- // instance. Returns NULL if there is no ObjectVar corresponding to the given
- // NPObject for the given instance. See AddNPObjectVar above.
- ObjectVar* ObjectVarForNPObject(PP_Instance instance, NPObject* np_object);
+ // Looks up a previously registered NPObjectVar for the given NPObject and
+ // instance. Returns NULL if there is no NPObjectVar corresponding to the
+ // given NPObject for the given instance. See AddNPObjectVar above.
+ ::ppapi::NPObjectVar* NPObjectVarForNPObject(PP_Instance instance,
+ NPObject* np_object);
// PP_Modules ----------------------------------------------------------------
@@ -121,7 +126,6 @@ class ResourceTracker : public ::ppapi::TrackerBase {
private:
friend class Resource;
friend class ResourceTrackerTest;
- friend class Var;
typedef std::set<PP_Resource> ResourceSet;
@@ -144,9 +148,6 @@ class ResourceTracker : public ::ppapi::TrackerBase {
// Resource class.
PP_Resource AddResource(Resource* resource);
- // The same as AddResource but for Var, and returns the new Var ID.
- int32 AddVar(Var* var);
-
// Force frees all vars and resources associated with the given instance.
// If delete_instance is true, the instance tracking information will also
// be deleted.
@@ -197,7 +198,7 @@ class ResourceTracker : public ::ppapi::TrackerBase {
ResourceMap live_resources_;
// Like ResourceAndRefCount but for vars, which are associated with modules.
- typedef std::pair<scoped_refptr<Var>, size_t> VarAndRefCount;
+ typedef std::pair<scoped_refptr< ::ppapi::Var>, size_t> VarAndRefCount;
typedef base::hash_map<int32, VarAndRefCount> VarMap;
VarMap live_vars_;
diff --git a/webkit/plugins/ppapi/resource_tracker_unittest.cc b/webkit/plugins/ppapi/resource_tracker_unittest.cc
index c1199dd..89590e8 100644
--- a/webkit/plugins/ppapi/resource_tracker_unittest.cc
+++ b/webkit/plugins/ppapi/resource_tracker_unittest.cc
@@ -11,9 +11,11 @@
#include "webkit/plugins/ppapi/mock_plugin_delegate.h"
#include "webkit/plugins/ppapi/mock_resource.h"
#include "webkit/plugins/ppapi/npapi_glue.h"
+#include "webkit/plugins/ppapi/npobject_var.h"
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "webkit/plugins/ppapi/resource_tracker.h"
-#include "webkit/plugins/ppapi/var.h"
+
+using ppapi::NPObjectVar;
namespace webkit {
namespace ppapi {
@@ -207,7 +209,7 @@ TEST_F(ResourceTrackerTest, ReuseVar) {
// This ObjectVar must be released before we do NPObjectToPPVar again
// below so it gets freed and we get a new identifier.
{
- scoped_refptr<ObjectVar> check_object(ObjectVar::FromPPVar(pp_object1));
+ scoped_refptr<NPObjectVar> check_object(NPObjectVar::FromPPVar(pp_object1));
ASSERT_TRUE(check_object.get());
EXPECT_EQ(instance()->pp_instance(), check_object->pp_instance());
EXPECT_EQ(npobject.get(), check_object->np_object());
diff --git a/webkit/plugins/ppapi/var.cc b/webkit/plugins/ppapi/var.cc
deleted file mode 100644
index 914cdaf..0000000
--- a/webkit/plugins/ppapi/var.cc
+++ /dev/null
@@ -1,255 +0,0 @@
-// 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 "webkit/plugins/ppapi/var.h"
-
-#include <limits>
-
-#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/string_number_conversions.h"
-#include "base/string_util.h"
-#include "ppapi/c/dev/ppb_var_deprecated.h"
-#include "ppapi/c/ppb_var.h"
-#include "ppapi/c/pp_var.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
-#include "webkit/plugins/ppapi/common.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/resource_tracker.h"
-
-using WebKit::WebBindings;
-
-namespace webkit {
-namespace ppapi {
-
-// Var -------------------------------------------------------------------------
-
-Var::Var(PP_Module module) : pp_module_(module), var_id_(0) {
-}
-
-Var::~Var() {
-}
-
-// static
-std::string Var::PPVarToLogString(PP_Var var) {
- switch (var.type) {
- case PP_VARTYPE_UNDEFINED:
- return "[Undefined]";
- case PP_VARTYPE_NULL:
- return "[Null]";
- case PP_VARTYPE_BOOL:
- return var.value.as_bool ? "[True]" : "[False]";
- case PP_VARTYPE_INT32:
- return base::IntToString(var.value.as_int);
- case PP_VARTYPE_DOUBLE:
- return base::DoubleToString(var.value.as_double);
- case PP_VARTYPE_STRING: {
- scoped_refptr<StringVar> string(StringVar::FromPPVar(var));
- if (!string)
- return "[Invalid string]";
-
- // Since this is for logging, escape NULLs.
- std::string result = string->value();
- std::string null;
- null.push_back(0);
- ReplaceSubstringsAfterOffset(&result, 0, null, "\\0");
- return result;
- }
- case PP_VARTYPE_OBJECT:
- return "[Object]";
- default:
- return "[Invalid var]";
- }
-}
-
-// static
-void Var::PluginAddRefPPVar(PP_Var var) {
- if (var.type == PP_VARTYPE_STRING || var.type == PP_VARTYPE_OBJECT) {
- if (!ResourceTracker::Get()->AddRefVar(static_cast<int32>(var.value.as_id)))
- DLOG(WARNING) << "AddRefVar()ing a nonexistent string/object var.";
- }
-}
-
-// static
-void Var::PluginReleasePPVar(PP_Var var) {
- if (var.type == PP_VARTYPE_STRING || var.type == PP_VARTYPE_OBJECT) {
- if (!ResourceTracker::Get()->UnrefVar(static_cast<int32>(var.value.as_id)))
- DLOG(WARNING) << "ReleaseVar()ing a nonexistent string/object var.";
- }
-}
-
-StringVar* Var::AsStringVar() {
- return NULL;
-}
-
-ObjectVar* Var::AsObjectVar() {
- return NULL;
-}
-
-int32 Var::GetExistingVarID() const {
- return var_id_;
-}
-
-int32 Var::GetOrCreateVarID() {
- ResourceTracker *tracker = ResourceTracker::Get();
- 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(PP_Module module, const char* str, uint32 len)
- : Var(module),
- value_(str, len) {
-}
-
-StringVar::~StringVar() {
-}
-
-StringVar* StringVar::AsStringVar() {
- return this;
-}
-
-PP_Var StringVar::GetPPVar() {
- int32 id = GetOrCreateVarID();
- 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(PP_Module module, const std::string& var) {
- return StringToPPVar(module, var.c_str(), var.size());
-}
-
-// static
-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();
- return str->GetPPVar();
-}
-
-// static
-scoped_refptr<StringVar> StringVar::FromPPVar(PP_Var var) {
- if (var.type != PP_VARTYPE_STRING)
- return scoped_refptr<StringVar>();
- scoped_refptr<Var> var_object(
- ResourceTracker::Get()->GetVar(static_cast<int32>(var.value.as_id)));
- if (!var_object)
- return scoped_refptr<StringVar>();
- return scoped_refptr<StringVar>(var_object->AsStringVar());
-}
-
-// ObjectVar -------------------------------------------------------------------
-
-ObjectVar::ObjectVar(PP_Module module,
- PP_Instance instance,
- NPObject* np_object)
- : Var(module),
- pp_instance_(instance),
- np_object_(np_object) {
- WebBindings::retainObject(np_object_);
- ResourceTracker::Get()->AddNPObjectVar(this);
-}
-
-ObjectVar::~ObjectVar() {
- if (pp_instance_)
- ResourceTracker::Get()->RemoveNPObjectVar(this);
-
- WebBindings::releaseObject(np_object_);
-}
-
-ObjectVar* ObjectVar::AsObjectVar() {
- return this;
-}
-
-PP_Var ObjectVar::GetPPVar() {
- int32 id = GetOrCreateVarID();
- if (!id)
- return PP_MakeNull();
-
- PP_Var result;
- result.type = PP_VARTYPE_OBJECT;
- result.value.as_id = id;
- return result;
-}
-
-void ObjectVar::InstanceDeleted() {
- DCHECK(pp_instance_);
- pp_instance_ = 0;
-}
-
-// static
-scoped_refptr<ObjectVar> ObjectVar::FromPPVar(PP_Var var) {
- if (var.type != PP_VARTYPE_OBJECT)
- return scoped_refptr<ObjectVar>(NULL);
- scoped_refptr<Var> var_object(
- ResourceTracker::Get()->GetVar(static_cast<int32>(var.value.as_id)));
- if (!var_object)
- return scoped_refptr<ObjectVar>();
- return scoped_refptr<ObjectVar>(var_object->AsObjectVar());
-}
-
-// TryCatch --------------------------------------------------------------------
-
-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);
-}
-
-TryCatch::~TryCatch() {
- WebBindings::popExceptionHandler();
-}
-
-void TryCatch::SetException(const char* message) {
- if (!pp_module_) {
- // Don't have a module to make the string.
- SetInvalidObjectException();
- return;
- }
-
- if (!has_exception()) {
- has_exception_ = true;
- if (exception_) {
- *exception_ = StringVar::StringToPPVar(pp_module_,
- message, strlen(message));
- }
- }
-}
-
-void TryCatch::SetInvalidObjectException() {
- if (!has_exception()) {
- has_exception_ = true;
- // TODO(brettw) bug 54504: Have a global singleton string that can hold
- // a generic error message.
- if (exception_)
- *exception_ = PP_MakeInt32(1);
- }
-}
-
-// static
-void TryCatch::Catch(void* self, const char* message) {
- static_cast<TryCatch*>(self)->SetException(message);
-}
-
-} // namespace ppapi
-} // namespace webkit
-