Chromium Code Reviews| 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/plugin_var_serialization_rules.h" | 5 #include "ppapi/proxy/plugin_var_serialization_rules.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ppapi/proxy/plugin_dispatcher.h" | 8 #include "ppapi/proxy/plugin_dispatcher.h" |
| 9 #include "ppapi/proxy/plugin_resource_tracker.h" | |
| 9 #include "ppapi/proxy/plugin_var_tracker.h" | 10 #include "ppapi/proxy/plugin_var_tracker.h" |
| 11 #include "ppapi/shared_impl/var.h" | |
| 12 | |
| 13 using ppapi::StringVar; | |
| 10 | 14 |
| 11 namespace pp { | 15 namespace pp { |
| 12 namespace proxy { | 16 namespace proxy { |
| 13 | 17 |
| 14 PluginVarSerializationRules::PluginVarSerializationRules() | 18 PluginVarSerializationRules::PluginVarSerializationRules() |
| 15 : var_tracker_(PluginVarTracker::GetInstance()) { | 19 : var_tracker_(&PluginResourceTracker::GetInstance()->var_tracker()) { |
| 16 } | 20 } |
| 17 | 21 |
| 18 PluginVarSerializationRules::~PluginVarSerializationRules() { | 22 PluginVarSerializationRules::~PluginVarSerializationRules() { |
| 19 } | 23 } |
| 20 | 24 |
| 21 PP_Var PluginVarSerializationRules::SendCallerOwned(const PP_Var& var, | 25 PP_Var PluginVarSerializationRules::SendCallerOwned(const PP_Var& var, |
| 22 std::string* str_val) { | 26 std::string* str_val) { |
| 23 // Objects need special translations to get the IDs valid in the host. | 27 // Objects need special translations to get the IDs valid in the host. |
| 24 if (var.type == PP_VARTYPE_OBJECT) | 28 if (var.type == PP_VARTYPE_OBJECT) |
| 25 return var_tracker_->GetHostObject(var); | 29 return var_tracker_->GetHostObject(var); |
| 26 | 30 |
| 27 // Retrieve the string to use for IPC. | 31 // Retrieve the string to use for IPC. |
| 28 if (var.type == PP_VARTYPE_STRING) { | 32 if (var.type == PP_VARTYPE_STRING) { |
| 29 const std::string* var_string = var_tracker_->GetExistingString(var); | 33 scoped_refptr<StringVar> string_var(StringVar::FromPPVar(var)); |
| 30 if (var_string) | 34 if (string_var.get()) |
| 31 *str_val = *var_string; | 35 *str_val = string_var->value(); |
| 32 else | 36 else |
| 33 NOTREACHED() << "Trying to send unknown string over IPC."; | 37 NOTREACHED() << "Trying to send unknown string over IPC."; |
| 34 } | 38 } |
| 35 return var; | 39 return var; |
| 36 } | 40 } |
| 37 | 41 |
| 38 PP_Var PluginVarSerializationRules::BeginReceiveCallerOwned( | 42 PP_Var PluginVarSerializationRules::BeginReceiveCallerOwned( |
| 39 const PP_Var& var, | 43 const PP_Var& var, |
| 40 const std::string* str_val, | 44 const std::string* str_val, |
| 41 Dispatcher* dispatcher) { | 45 Dispatcher* dispatcher) { |
| 42 if (var.type == PP_VARTYPE_STRING) { | 46 if (var.type == PP_VARTYPE_STRING) |
| 43 // Convert the string to the context of the current process. | 47 return StringVar::StringToPPVar(0, *str_val); |
|
dmichael (off chromium)
2011/08/08 22:13:59
The 0 for module is just because Module is irrelev
brettw
2011/08/09 17:08:09
Correct, I've been wanting to force people do to t
| |
| 44 PP_Var ret; | |
| 45 ret.type = PP_VARTYPE_STRING; | |
| 46 ret.value.as_id = var_tracker_->MakeString(*str_val); | |
| 47 return ret; | |
| 48 } | |
| 49 | 48 |
| 50 if (var.type == PP_VARTYPE_OBJECT) { | 49 if (var.type == PP_VARTYPE_OBJECT) { |
| 51 DCHECK(dispatcher->IsPlugin()); | 50 DCHECK(dispatcher->IsPlugin()); |
| 52 return var_tracker_->TrackObjectWithNoReference( | 51 return var_tracker_->TrackObjectWithNoReference( |
| 53 var, static_cast<PluginDispatcher*>(dispatcher)); | 52 var, static_cast<PluginDispatcher*>(dispatcher)); |
| 54 } | 53 } |
| 55 | 54 |
| 56 return var; | 55 return var; |
| 57 } | 56 } |
| 58 | 57 |
| 59 void PluginVarSerializationRules::EndReceiveCallerOwned(const PP_Var& var) { | 58 void PluginVarSerializationRules::EndReceiveCallerOwned(const PP_Var& var) { |
| 60 if (var.type == PP_VARTYPE_STRING) { | 59 if (var.type == PP_VARTYPE_STRING) { |
| 61 // Destroy the string BeginReceiveCallerOwned created above. | 60 // Destroy the string BeginReceiveCallerOwned created above. |
| 62 var_tracker_->Release(var); | 61 var_tracker_->ReleaseVar(var); |
| 63 } else if (var.type == PP_VARTYPE_OBJECT) { | 62 } else if (var.type == PP_VARTYPE_OBJECT) { |
| 64 var_tracker_->StopTrackingObjectWithNoReference(var); | 63 var_tracker_->StopTrackingObjectWithNoReference(var); |
| 65 } | 64 } |
| 66 } | 65 } |
| 67 | 66 |
| 68 PP_Var PluginVarSerializationRules::ReceivePassRef(const PP_Var& var, | 67 PP_Var PluginVarSerializationRules::ReceivePassRef(const PP_Var& var, |
| 69 const std::string& str_val, | 68 const std::string& str_val, |
| 70 Dispatcher* dispatcher) { | 69 Dispatcher* dispatcher) { |
| 71 if (var.type == PP_VARTYPE_STRING) { | 70 if (var.type == PP_VARTYPE_STRING) |
| 72 // Convert the string to the context of the current process. | 71 return StringVar::StringToPPVar(0, str_val); |
| 73 PP_Var ret; | |
| 74 ret.type = PP_VARTYPE_STRING; | |
| 75 ret.value.as_id = var_tracker_->MakeString(str_val); | |
| 76 return ret; | |
| 77 } | |
| 78 | 72 |
| 79 // Overview of sending an object with "pass ref" from the browser to the | 73 // Overview of sending an object with "pass ref" from the browser to the |
| 80 // plugin: | 74 // plugin: |
| 81 // Example 1 Example 2 | 75 // Example 1 Example 2 |
| 82 // Plugin Browser Plugin Browser | 76 // Plugin Browser Plugin Browser |
| 83 // Before send 3 2 0 1 | 77 // Before send 3 2 0 1 |
| 84 // Browser calls BeginSendPassRef 3 2 0 1 | 78 // Browser calls BeginSendPassRef 3 2 0 1 |
| 85 // Plugin calls ReceivePassRef 4 1 1 1 | 79 // Plugin calls ReceivePassRef 4 1 1 1 |
| 86 // Browser calls EndSendPassRef 4 1 1 1 | 80 // Browser calls EndSendPassRef 4 1 1 1 |
| 87 // | 81 // |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 117 // entire ref count in the plugin. When the plugin refcount goes to 0, it | 111 // entire ref count in the plugin. When the plugin refcount goes to 0, it |
| 118 // will call the browser to deref the object. This is why in example 2 | 112 // will call the browser to deref the object. This is why in example 2 |
| 119 // transferring the object ref to the browser involves no net change in the | 113 // transferring the object ref to the browser involves no net change in the |
| 120 // browser's refcount. | 114 // browser's refcount. |
| 121 | 115 |
| 122 // Objects need special translations to get the IDs valid in the host. | 116 // Objects need special translations to get the IDs valid in the host. |
| 123 if (var.type == PP_VARTYPE_OBJECT) | 117 if (var.type == PP_VARTYPE_OBJECT) |
| 124 return var_tracker_->GetHostObject(var); | 118 return var_tracker_->GetHostObject(var); |
| 125 | 119 |
| 126 if (var.type == PP_VARTYPE_STRING) { | 120 if (var.type == PP_VARTYPE_STRING) { |
| 127 const std::string* var_string = var_tracker_->GetExistingString(var); | 121 scoped_refptr<StringVar> string_var(StringVar::FromPPVar(var)); |
| 128 if (var_string) | 122 if (string_var.get()) |
| 129 *str_val = *var_string; | 123 *str_val = string_var->value(); |
| 130 else | 124 else |
| 131 NOTREACHED() << "Trying to send unknown string over IPC."; | 125 NOTREACHED() << "Trying to send unknown string over IPC."; |
| 132 } | 126 } |
| 133 return var; | 127 return var; |
| 134 } | 128 } |
| 135 | 129 |
| 136 void PluginVarSerializationRules::EndSendPassRef(const PP_Var& var, | 130 void PluginVarSerializationRules::EndSendPassRef(const PP_Var& var, |
| 137 Dispatcher* dispatcher) { | 131 Dispatcher* dispatcher) { |
| 138 // See BeginSendPassRef for an example of why we release our ref here. | 132 // See BeginSendPassRef for an example of why we release our ref here. |
| 139 // The var we have in our inner class has been converted to a host object | 133 // The var we have in our inner class has been converted to a host object |
| 140 // by BeginSendPassRef. This means it's not a normal var valid in the plugin, | 134 // by BeginSendPassRef. This means it's not a normal var valid in the plugin, |
| 141 // so we need to use the special ReleaseHostObject. | 135 // so we need to use the special ReleaseHostObject. |
| 142 if (var.type == PP_VARTYPE_OBJECT) { | 136 if (var.type == PP_VARTYPE_OBJECT) { |
| 143 var_tracker_->ReleaseHostObject( | 137 var_tracker_->ReleaseHostObject( |
| 144 static_cast<PluginDispatcher*>(dispatcher), var); | 138 static_cast<PluginDispatcher*>(dispatcher), var); |
| 145 } | 139 } |
| 146 } | 140 } |
| 147 | 141 |
| 148 void PluginVarSerializationRules::ReleaseObjectRef(const PP_Var& var) { | 142 void PluginVarSerializationRules::ReleaseObjectRef(const PP_Var& var) { |
| 149 var_tracker_->Release(var); | 143 var_tracker_->ReleaseVar(var); |
| 150 } | 144 } |
| 151 | 145 |
| 152 } // namespace proxy | 146 } // namespace proxy |
| 153 } // namespace pp | 147 } // namespace pp |
| OLD | NEW |