| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/pepper/message_channel.h" | 5 #include "content/renderer/pepper/message_channel.h" |
| 6 | 6 |
| 7 #include <cstdlib> | 7 #include <cstdlib> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "content/public/common/content_client.h" | |
| 14 #include "content/public/renderer/content_renderer_client.h" | |
| 15 #include "content/renderer/pepper/host_array_buffer_var.h" | 13 #include "content/renderer/pepper/host_array_buffer_var.h" |
| 16 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 14 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| 17 #include "content/renderer/pepper/pepper_try_catch.h" | 15 #include "content/renderer/pepper/pepper_try_catch.h" |
| 18 #include "content/renderer/pepper/plugin_module.h" | 16 #include "content/renderer/pepper/plugin_module.h" |
| 19 #include "content/renderer/pepper/plugin_object.h" | 17 #include "content/renderer/pepper/plugin_object.h" |
| 20 #include "content/renderer/pepper/v8_var_converter.h" | 18 #include "content/renderer/pepper/v8_var_converter.h" |
| 21 #include "gin/arguments.h" | 19 #include "gin/arguments.h" |
| 22 #include "gin/converter.h" | 20 #include "gin/converter.h" |
| 23 #include "gin/function_template.h" | 21 #include "gin/function_template.h" |
| 24 #include "gin/object_template_builder.h" | 22 #include "gin/object_template_builder.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 const char kPostMessageAndAwaitResponse[] = "postMessageAndAwaitResponse"; | 54 const char kPostMessageAndAwaitResponse[] = "postMessageAndAwaitResponse"; |
| 57 const char kV8ToVarConversionError[] = | 55 const char kV8ToVarConversionError[] = |
| 58 "Failed to convert a PostMessage " | 56 "Failed to convert a PostMessage " |
| 59 "argument from a JavaScript value to a PP_Var. It may have cycles or be of " | 57 "argument from a JavaScript value to a PP_Var. It may have cycles or be of " |
| 60 "an unsupported type."; | 58 "an unsupported type."; |
| 61 const char kVarToV8ConversionError[] = | 59 const char kVarToV8ConversionError[] = |
| 62 "Failed to convert a PostMessage " | 60 "Failed to convert a PostMessage " |
| 63 "argument from a PP_Var to a Javascript value. It may have cycles or be of " | 61 "argument from a PP_Var to a Javascript value. It may have cycles or be of " |
| 64 "an unsupported type."; | 62 "an unsupported type."; |
| 65 | 63 |
| 66 bool HasDevPermission() { | |
| 67 return GetContentClient()->renderer()->IsPluginAllowedToUseDevChannelAPIs(); | |
| 68 } | |
| 69 | |
| 70 } // namespace | 64 } // namespace |
| 71 | 65 |
| 72 // MessageChannel -------------------------------------------------------------- | 66 // MessageChannel -------------------------------------------------------------- |
| 73 struct MessageChannel::VarConversionResult { | 67 struct MessageChannel::VarConversionResult { |
| 74 VarConversionResult() : success_(false), conversion_completed_(false) {} | 68 VarConversionResult() : success_(false), conversion_completed_(false) {} |
| 75 void ConversionCompleted(const ScopedPPVar& var, | 69 void ConversionCompleted(const ScopedPPVar& var, |
| 76 bool success) { | 70 bool success) { |
| 77 conversion_completed_ = true; | 71 conversion_completed_ = true; |
| 78 var_ = var; | 72 var_ = var; |
| 79 success_ = success; | 73 success_ = success; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 const std::string& identifier) { | 214 const std::string& identifier) { |
| 221 if (!instance_) | 215 if (!instance_) |
| 222 return v8::Local<v8::Value>(); | 216 return v8::Local<v8::Value>(); |
| 223 | 217 |
| 224 PepperTryCatchV8 try_catch(instance_, V8VarConverter::kDisallowObjectVars, | 218 PepperTryCatchV8 try_catch(instance_, V8VarConverter::kDisallowObjectVars, |
| 225 isolate); | 219 isolate); |
| 226 if (identifier == kPostMessage) { | 220 if (identifier == kPostMessage) { |
| 227 return gin::CreateFunctionTemplate(isolate, | 221 return gin::CreateFunctionTemplate(isolate, |
| 228 base::Bind(&MessageChannel::PostMessageToNative, | 222 base::Bind(&MessageChannel::PostMessageToNative, |
| 229 weak_ptr_factory_.GetWeakPtr()))->GetFunction(); | 223 weak_ptr_factory_.GetWeakPtr()))->GetFunction(); |
| 230 } else if (identifier == kPostMessageAndAwaitResponse && HasDevPermission()) { | 224 } else if (identifier == kPostMessageAndAwaitResponse) { |
| 231 return gin::CreateFunctionTemplate(isolate, | 225 return gin::CreateFunctionTemplate(isolate, |
| 232 base::Bind(&MessageChannel::PostBlockingMessageToNative, | 226 base::Bind(&MessageChannel::PostBlockingMessageToNative, |
| 233 weak_ptr_factory_.GetWeakPtr()))->GetFunction(); | 227 weak_ptr_factory_.GetWeakPtr()))->GetFunction(); |
| 234 } | 228 } |
| 235 | 229 |
| 236 std::map<std::string, ScopedPPVar>::const_iterator it = | 230 std::map<std::string, ScopedPPVar>::const_iterator it = |
| 237 internal_named_properties_.find(identifier); | 231 internal_named_properties_.find(identifier); |
| 238 if (it != internal_named_properties_.end()) { | 232 if (it != internal_named_properties_.end()) { |
| 239 v8::Handle<v8::Value> result = try_catch.ToV8(it->second.get()); | 233 v8::Handle<v8::Value> result = try_catch.ToV8(it->second.get()); |
| 240 if (try_catch.ThrowException()) | 234 if (try_catch.ThrowException()) |
| 241 return v8::Local<v8::Value>(); | 235 return v8::Local<v8::Value>(); |
| 242 return result; | 236 return result; |
| 243 } | 237 } |
| 244 | 238 |
| 245 PluginObject* plugin_object = GetPluginObject(isolate); | 239 PluginObject* plugin_object = GetPluginObject(isolate); |
| 246 if (plugin_object) | 240 if (plugin_object) |
| 247 return plugin_object->GetNamedProperty(isolate, identifier); | 241 return plugin_object->GetNamedProperty(isolate, identifier); |
| 248 return v8::Local<v8::Value>(); | 242 return v8::Local<v8::Value>(); |
| 249 } | 243 } |
| 250 | 244 |
| 251 bool MessageChannel::SetNamedProperty(v8::Isolate* isolate, | 245 bool MessageChannel::SetNamedProperty(v8::Isolate* isolate, |
| 252 const std::string& identifier, | 246 const std::string& identifier, |
| 253 v8::Local<v8::Value> value) { | 247 v8::Local<v8::Value> value) { |
| 254 if (!instance_) | 248 if (!instance_) |
| 255 return false; | 249 return false; |
| 256 PepperTryCatchV8 try_catch(instance_, V8VarConverter::kDisallowObjectVars, | 250 PepperTryCatchV8 try_catch(instance_, V8VarConverter::kDisallowObjectVars, |
| 257 isolate); | 251 isolate); |
| 258 if (identifier == kPostMessage || | 252 if (identifier == kPostMessage || |
| 259 (identifier == kPostMessageAndAwaitResponse && HasDevPermission())) { | 253 (identifier == kPostMessageAndAwaitResponse)) { |
| 260 try_catch.ThrowException("Cannot set properties with the name postMessage" | 254 try_catch.ThrowException("Cannot set properties with the name postMessage" |
| 261 "or postMessageAndAwaitResponse"); | 255 "or postMessageAndAwaitResponse"); |
| 262 return true; | 256 return true; |
| 263 } | 257 } |
| 264 | 258 |
| 265 // We don't forward this to the passthrough object; no plugins use that | 259 // We don't forward this to the passthrough object; no plugins use that |
| 266 // feature. | 260 // feature. |
| 267 // TODO(raymes): Remove SetProperty support from PPP_Class. | 261 // TODO(raymes): Remove SetProperty support from PPP_Class. |
| 268 | 262 |
| 269 return false; | 263 return false; |
| 270 } | 264 } |
| 271 | 265 |
| 272 std::vector<std::string> MessageChannel::EnumerateNamedProperties( | 266 std::vector<std::string> MessageChannel::EnumerateNamedProperties( |
| 273 v8::Isolate* isolate) { | 267 v8::Isolate* isolate) { |
| 274 std::vector<std::string> result; | 268 std::vector<std::string> result; |
| 275 PluginObject* plugin_object = GetPluginObject(isolate); | 269 PluginObject* plugin_object = GetPluginObject(isolate); |
| 276 if (plugin_object) | 270 if (plugin_object) |
| 277 result = plugin_object->EnumerateNamedProperties(isolate); | 271 result = plugin_object->EnumerateNamedProperties(isolate); |
| 278 result.push_back(kPostMessage); | 272 result.push_back(kPostMessage); |
| 279 if (HasDevPermission()) | 273 result.push_back(kPostMessageAndAwaitResponse); |
| 280 result.push_back(kPostMessageAndAwaitResponse); | |
| 281 return result; | 274 return result; |
| 282 } | 275 } |
| 283 | 276 |
| 284 void MessageChannel::PostMessageToNative(gin::Arguments* args) { | 277 void MessageChannel::PostMessageToNative(gin::Arguments* args) { |
| 285 if (!instance_) | 278 if (!instance_) |
| 286 return; | 279 return; |
| 287 if (args->Length() != 1) { | 280 if (args->Length() != 1) { |
| 288 // TODO(raymes): Consider throwing an exception here. We don't now for | 281 // TODO(raymes): Consider throwing an exception here. We don't now for |
| 289 // backward compatibility. | 282 // backward compatibility. |
| 290 return; | 283 return; |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 if (!instance_) | 467 if (!instance_) |
| 475 return; | 468 return; |
| 476 ppapi::proxy::HostDispatcher* dispatcher = | 469 ppapi::proxy::HostDispatcher* dispatcher = |
| 477 ppapi::proxy::HostDispatcher::GetForInstance(instance_->pp_instance()); | 470 ppapi::proxy::HostDispatcher::GetForInstance(instance_->pp_instance()); |
| 478 // The dispatcher is NULL for in-process. | 471 // The dispatcher is NULL for in-process. |
| 479 if (dispatcher) | 472 if (dispatcher) |
| 480 dispatcher->RemoveSyncMessageStatusObserver(this); | 473 dispatcher->RemoveSyncMessageStatusObserver(this); |
| 481 } | 474 } |
| 482 | 475 |
| 483 } // namespace content | 476 } // namespace content |
| OLD | NEW |