Chromium Code Reviews| Index: content/renderer/pepper/message_channel.cc |
| diff --git a/content/renderer/pepper/message_channel.cc b/content/renderer/pepper/message_channel.cc |
| index 4e373ac2eabfc3d8c0c3de4fc7da8a428f0cb21d..7e1acb13231981bb20f76f5a4c4697e405fc67a3 100644 |
| --- a/content/renderer/pepper/message_channel.cc |
| +++ b/content/renderer/pepper/message_channel.cc |
| @@ -13,6 +13,7 @@ |
| #include "content/renderer/pepper/host_array_buffer_var.h" |
| #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| #include "content/renderer/pepper/pepper_try_catch.h" |
| +#include "content/renderer/pepper/plugin_instance_throttler_impl.h" |
| #include "content/renderer/pepper/plugin_module.h" |
| #include "content/renderer/pepper/plugin_object.h" |
| #include "gin/arguments.h" |
| @@ -20,6 +21,7 @@ |
| #include "gin/function_template.h" |
| #include "gin/object_template_builder.h" |
| #include "gin/public/gin_embedders.h" |
| +#include "ppapi/shared_impl/ppapi_constants.h" |
| #include "ppapi/shared_impl/ppapi_globals.h" |
| #include "ppapi/shared_impl/scoped_pp_var.h" |
| #include "ppapi/shared_impl/var.h" |
| @@ -49,6 +51,7 @@ namespace content { |
| namespace { |
| +const char kIsPeripheral[] = "isPeripheral"; |
| const char kPostMessage[] = "postMessage"; |
| const char kPostMessageAndAwaitResponse[] = "postMessageAndAwaitResponse"; |
| const char kV8ToVarConversionError[] = |
| @@ -225,6 +228,11 @@ v8::Local<v8::Value> MessageChannel::GetNamedProperty( |
| return GetFunctionTemplate(isolate, identifier, |
| &MessageChannel::PostBlockingMessageToNative) |
| ->GetFunction(); |
| + } else if (instance_->module()->name() == ppapi::kPpapiTestLibraryName && |
| + identifier == kIsPeripheral) { |
| + return GetFunctionTemplate(isolate, identifier, |
| + &MessageChannel::IsPeripheralToNative) |
| + ->GetFunction(); |
|
raymes
2015/04/16 02:27:57
We should avoid changing the MessageChannel just f
tommycli
2015/04/17 00:02:17
Done.
|
| } |
| std::map<std::string, ScopedPPVar>::const_iterator it = |
| @@ -248,6 +256,11 @@ bool MessageChannel::SetNamedProperty(v8::Isolate* isolate, |
| if (!instance_) |
| return false; |
| PepperTryCatchV8 try_catch(instance_, &var_converter_, isolate); |
| + if (instance_->module()->name() == ppapi::kPpapiTestLibraryName && |
| + identifier == kIsPeripheral) { |
| + try_catch.ThrowException("Cannot set property with the name isPeripheral"); |
| + return true; |
| + } |
| if (identifier == kPostMessage || |
| identifier == kPostMessageAndAwaitResponse) { |
| try_catch.ThrowException("Cannot set properties with the name postMessage" |
| @@ -270,6 +283,10 @@ std::vector<std::string> MessageChannel::EnumerateNamedProperties( |
| PluginObject* plugin_object = GetPluginObject(isolate); |
| if (plugin_object) |
| result = plugin_object->EnumerateNamedProperties(isolate); |
| + |
| + if (instance_->module()->name() == ppapi::kPpapiTestLibraryName) |
| + result.push_back(kIsPeripheral); |
| + |
| result.push_back(kPostMessage); |
| result.push_back(kPostMessageAndAwaitResponse); |
| return result; |
| @@ -352,6 +369,23 @@ void MessageChannel::PostBlockingMessageToNative(gin::Arguments* args) { |
| args->Return(v8_result); |
| } |
| +void MessageChannel::IsPeripheralToNative(gin::Arguments* args) { |
| + if (!instance_) |
| + return; |
| + PepperTryCatchV8 try_catch(instance_, &var_converter_, args->isolate()); |
| + if (args->Length() != 0) { |
| + try_catch.ThrowException("isPeripheral takes no arguments"); |
| + return; |
| + } |
| + |
| + bool is_peripheral = |
| + instance_->throttler() && instance_->throttler()->power_saver_enabled(); |
| + |
| + v8::Handle<v8::Value> v8_result = |
| + v8::Boolean::New(args->isolate(), is_peripheral); |
| + args->Return(v8_result); |
| +} |
| + |
| void MessageChannel::PostMessageToJavaScriptImpl( |
| const WebSerializedScriptValue& message_data) { |
| DCHECK(instance_); |