| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/proxy/ppb_var_deprecated_proxy.h" | 5 #include "ppapi/proxy/ppb_var_deprecated_proxy.h" |
| 6 | 6 |
| 7 #include <stdlib.h> // For malloc | 7 #include <stdlib.h> // For malloc |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/task.h" | 11 #include "base/task.h" |
| 12 #include "ppapi/c/dev/ppb_var_deprecated.h" | 12 #include "ppapi/c/dev/ppb_var_deprecated.h" |
| 13 #include "ppapi/c/pp_var.h" | 13 #include "ppapi/c/pp_var.h" |
| 14 #include "ppapi/c/ppb_core.h" | 14 #include "ppapi/c/ppb_core.h" |
| 15 #include "ppapi/proxy/host_dispatcher.h" | 15 #include "ppapi/proxy/host_dispatcher.h" |
| 16 #include "ppapi/proxy/plugin_dispatcher.h" | 16 #include "ppapi/proxy/plugin_dispatcher.h" |
| 17 #include "ppapi/proxy/plugin_resource_tracker.h" |
| 17 #include "ppapi/proxy/plugin_var_tracker.h" | 18 #include "ppapi/proxy/plugin_var_tracker.h" |
| 18 #include "ppapi/proxy/ppapi_messages.h" | 19 #include "ppapi/proxy/ppapi_messages.h" |
| 19 #include "ppapi/proxy/ppp_class_proxy.h" | 20 #include "ppapi/proxy/ppp_class_proxy.h" |
| 20 #include "ppapi/proxy/serialized_var.h" | 21 #include "ppapi/proxy/serialized_var.h" |
| 22 #include "ppapi/shared_impl/var.h" |
| 23 |
| 24 using ppapi::StringVar; |
| 21 | 25 |
| 22 namespace pp { | 26 namespace pp { |
| 23 namespace proxy { | 27 namespace proxy { |
| 24 | 28 |
| 25 namespace { | 29 namespace { |
| 26 | 30 |
| 27 // Used to do get the set-up information for calling a var object. If the | 31 // Used to do get the set-up information for calling a var object. If the |
| 28 // exception is set, returns NULL. Otherwise, computes the dispatcher for the | 32 // exception is set, returns NULL. Otherwise, computes the dispatcher for the |
| 29 // given var object. If the var is not a valid object, returns NULL and sets | 33 // given var object. If the var is not a valid object, returns NULL and sets |
| 30 // the exception. | 34 // the exception. |
| 31 PluginDispatcher* CheckExceptionAndGetDispatcher(const PP_Var& object, | 35 PluginDispatcher* CheckExceptionAndGetDispatcher(const PP_Var& object, |
| 32 PP_Var* exception) { | 36 PP_Var* exception) { |
| 33 // If an exception is already set, we don't need to do anything, just return | 37 // If an exception is already set, we don't need to do anything, just return |
| 34 // an error to the caller. | 38 // an error to the caller. |
| 35 if (exception && exception->type != PP_VARTYPE_UNDEFINED) | 39 if (exception && exception->type != PP_VARTYPE_UNDEFINED) |
| 36 return NULL; | 40 return NULL; |
| 37 | 41 |
| 38 PluginVarTracker* tracker = PluginVarTracker::GetInstance(); | 42 |
| 39 PluginDispatcher* dispatcher = tracker->DispatcherForPluginObject(object); | 43 if (object.type == PP_VARTYPE_OBJECT) { |
| 40 if (dispatcher) | 44 // Get the dispatcher for the object. |
| 41 return dispatcher; | 45 PluginDispatcher* dispatcher = PluginResourceTracker::GetInstance()-> |
| 46 var_tracker().DispatcherForPluginObject(object); |
| 47 if (dispatcher) |
| 48 return dispatcher; |
| 49 } |
| 42 | 50 |
| 43 // The object is invalid. This means we can't figure out which dispatcher | 51 // The object is invalid. This means we can't figure out which dispatcher |
| 44 // to use, which is OK because the call will fail anyway. Set the exception. | 52 // to use, which is OK because the call will fail anyway. Set the exception. |
| 45 if (exception) { | 53 if (exception) { |
| 46 exception->type = PP_VARTYPE_STRING; | 54 *exception = StringVar::StringToPPVar(0, |
| 47 exception->value.as_id = | 55 std::string("Attempting to use an invalid object")); |
| 48 tracker->MakeString("Attempting to use an invalid object"); | |
| 49 } | 56 } |
| 50 return NULL; | 57 return NULL; |
| 51 } | 58 } |
| 52 | 59 |
| 53 // PPP_Var_Deprecated plugin --------------------------------------------------- | 60 // PPP_Var_Deprecated plugin --------------------------------------------------- |
| 54 | 61 |
| 55 void AddRefVar(PP_Var var) { | 62 void AddRefVar(PP_Var var) { |
| 56 PluginVarTracker::GetInstance()->AddRef(var); | 63 PluginResourceTracker::GetInstance()->var_tracker().AddRefVar(var); |
| 57 } | 64 } |
| 58 | 65 |
| 59 void ReleaseVar(PP_Var var) { | 66 void ReleaseVar(PP_Var var) { |
| 60 PluginVarTracker::GetInstance()->Release(var); | 67 PluginResourceTracker::GetInstance()->var_tracker().ReleaseVar(var); |
| 61 } | 68 } |
| 62 | 69 |
| 63 PP_Var VarFromUtf8(PP_Module module, const char* data, uint32_t len) { | 70 PP_Var VarFromUtf8(PP_Module module, const char* data, uint32_t len) { |
| 64 PP_Var ret = {}; | 71 return StringVar::StringToPPVar(module, data, len); |
| 65 ret.type = PP_VARTYPE_STRING; | |
| 66 ret.value.as_id = PluginVarTracker::GetInstance()->MakeString( | |
| 67 data, len); | |
| 68 return ret; | |
| 69 } | 72 } |
| 70 | 73 |
| 71 const char* VarToUtf8(PP_Var var, uint32_t* len) { | 74 const char* VarToUtf8(PP_Var var, uint32_t* len) { |
| 72 const std::string* str = | 75 scoped_refptr<StringVar> str(StringVar::FromPPVar(var)); |
| 73 PluginVarTracker::GetInstance()->GetExistingString(var); | |
| 74 if (str) { | 76 if (str) { |
| 75 *len = static_cast<uint32_t>(str->size()); | 77 *len = static_cast<uint32_t>(str->value().size()); |
| 76 return str->c_str(); | 78 return str->value().c_str(); |
| 77 } | 79 } |
| 78 *len = 0; | 80 *len = 0; |
| 79 return NULL; | 81 return NULL; |
| 80 } | 82 } |
| 81 | 83 |
| 82 bool HasProperty(PP_Var var, | 84 bool HasProperty(PP_Var var, |
| 83 PP_Var name, | 85 PP_Var name, |
| 84 PP_Var* exception) { | 86 PP_Var* exception) { |
| 85 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, exception); | 87 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, exception); |
| 86 if (!dispatcher) | 88 if (!dispatcher) |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 | 516 |
| 515 void PPB_Var_Deprecated_Proxy::DoReleaseObject(int64 object_id) { | 517 void PPB_Var_Deprecated_Proxy::DoReleaseObject(int64 object_id) { |
| 516 PP_Var var; | 518 PP_Var var; |
| 517 var.type = PP_VARTYPE_OBJECT; | 519 var.type = PP_VARTYPE_OBJECT; |
| 518 var.value.as_id = object_id; | 520 var.value.as_id = object_id; |
| 519 ppb_var_target()->Release(var); | 521 ppb_var_target()->Release(var); |
| 520 } | 522 } |
| 521 | 523 |
| 522 } // namespace proxy | 524 } // namespace proxy |
| 523 } // namespace pp | 525 } // namespace pp |
| OLD | NEW |