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_var_tracker.h" | 9 #include "ppapi/proxy/plugin_var_tracker.h" |
10 | 10 |
11 namespace pp { | 11 namespace pp { |
12 namespace proxy { | 12 namespace proxy { |
13 | 13 |
14 PluginVarSerializationRules::PluginVarSerializationRules() | 14 PluginVarSerializationRules::PluginVarSerializationRules() |
15 : var_tracker_(PluginVarTracker::GetInstance()) { | 15 : var_tracker_(PluginVarTracker::GetInstance()) { |
16 } | 16 } |
17 | 17 |
18 PluginVarSerializationRules::~PluginVarSerializationRules() { | 18 PluginVarSerializationRules::~PluginVarSerializationRules() { |
19 } | 19 } |
20 | 20 |
21 PP_Var PluginVarSerializationRules::SendCallerOwned(const PP_Var& var, | 21 PP_Var PluginVarSerializationRules::SendCallerOwned(const PP_Var& var, |
22 std::string* str_val) { | 22 std::string* str_val) { |
23 // Objects need special translations to get the IDs valid in the host. | 23 // Objects need special translations to get the IDs valid in the host. |
24 if (var.type == PP_VARTYPE_OBJECT) | 24 if (var.type == PP_VARTYPE_OBJECT) |
25 return var_tracker_->GetHostObject(var); | 25 return var_tracker_->GetHostObject(var); |
26 | 26 |
27 // Nothing to do since we manage the refcount, other than retrieve the string | 27 // Retrieve the string to use for IPC. |
28 // to use for IPC. | 28 if (var.type == PP_VARTYPE_STRING) { |
29 if (var.type == PP_VARTYPE_STRING) | 29 const std::string* var_string = var_tracker_->GetExistingString(var); |
30 *str_val = var_tracker_->GetString(var); | 30 if (var_string) |
| 31 *str_val = *var_string; |
| 32 else |
| 33 NOTREACHED() << "Trying to send unknown string over IPC."; |
| 34 } |
31 return var; | 35 return var; |
32 } | 36 } |
33 | 37 |
34 PP_Var PluginVarSerializationRules::BeginReceiveCallerOwned( | 38 PP_Var PluginVarSerializationRules::BeginReceiveCallerOwned( |
35 const PP_Var& var, | 39 const PP_Var& var, |
36 const std::string* str_val, | 40 const std::string* str_val, |
37 Dispatcher* dispatcher) { | 41 Dispatcher* dispatcher) { |
38 if (var.type == PP_VARTYPE_STRING) { | 42 if (var.type == PP_VARTYPE_STRING) { |
39 // Convert the string to the context of the current process. | 43 // Convert the string to the context of the current process. |
40 PP_Var ret; | 44 PP_Var ret; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 // The plugin maintains one ref count in the browser on behalf of the | 116 // The plugin maintains one ref count in the browser on behalf of the |
113 // entire ref count in the plugin. When the plugin refcount goes to 0, it | 117 // entire ref count in the plugin. When the plugin refcount goes to 0, it |
114 // will call the browser to deref the object. This is why in example 2 | 118 // will call the browser to deref the object. This is why in example 2 |
115 // transferring the object ref to the browser involves no net change in the | 119 // transferring the object ref to the browser involves no net change in the |
116 // browser's refcount. | 120 // browser's refcount. |
117 | 121 |
118 // Objects need special translations to get the IDs valid in the host. | 122 // Objects need special translations to get the IDs valid in the host. |
119 if (var.type == PP_VARTYPE_OBJECT) | 123 if (var.type == PP_VARTYPE_OBJECT) |
120 return var_tracker_->GetHostObject(var); | 124 return var_tracker_->GetHostObject(var); |
121 | 125 |
122 if (var.type == PP_VARTYPE_STRING) | 126 if (var.type == PP_VARTYPE_STRING) { |
123 *str_val = var_tracker_->GetString(var); | 127 const std::string* var_string = var_tracker_->GetExistingString(var); |
| 128 if (var_string) |
| 129 *str_val = *var_string; |
| 130 else |
| 131 NOTREACHED() << "Trying to send unknown string over IPC."; |
| 132 } |
124 return var; | 133 return var; |
125 } | 134 } |
126 | 135 |
127 void PluginVarSerializationRules::EndSendPassRef(const PP_Var& var, | 136 void PluginVarSerializationRules::EndSendPassRef(const PP_Var& var, |
128 Dispatcher* dispatcher) { | 137 Dispatcher* dispatcher) { |
129 // See BeginSendPassRef for an example of why we release our ref here. | 138 // See BeginSendPassRef for an example of why we release our ref here. |
130 // The var we have in our inner class has been converted to a host object | 139 // The var we have in our inner class has been converted to a host object |
131 // by BeginSendPassRef. This means it's not a normal var valid in the plugin, | 140 // by BeginSendPassRef. This means it's not a normal var valid in the plugin, |
132 // so we need to use the special ReleaseHostObject. | 141 // so we need to use the special ReleaseHostObject. |
133 if (var.type == PP_VARTYPE_OBJECT) { | 142 if (var.type == PP_VARTYPE_OBJECT) { |
134 var_tracker_->ReleaseHostObject( | 143 var_tracker_->ReleaseHostObject( |
135 static_cast<PluginDispatcher*>(dispatcher), var); | 144 static_cast<PluginDispatcher*>(dispatcher), var); |
136 } | 145 } |
137 } | 146 } |
138 | 147 |
139 void PluginVarSerializationRules::ReleaseObjectRef(const PP_Var& var) { | 148 void PluginVarSerializationRules::ReleaseObjectRef(const PP_Var& var) { |
140 var_tracker_->Release(var); | 149 var_tracker_->Release(var); |
141 } | 150 } |
142 | 151 |
143 } // namespace proxy | 152 } // namespace proxy |
144 } // namespace pp | 153 } // namespace pp |
OLD | NEW |