[email protected] | 99800f2a | 2012-07-10 23:41:40 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 20790a22 | 2013-07-25 02:23:05 | [diff] [blame] | 5 | #include "content/renderer/pepper/ppb_var_deprecated_impl.h" |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 6 | |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | #include <stdint.h> |
| 9 | |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 10 | #include <limits> |
| 11 | |
[email protected] | 20790a22 | 2013-07-25 02:23:05 | [diff] [blame] | 12 | #include "content/renderer/pepper/host_globals.h" |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 13 | #include "content/renderer/pepper/message_channel.h" |
[email protected] | adab233 | 2013-07-25 18:04:32 | [diff] [blame] | 14 | #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 15 | #include "content/renderer/pepper/pepper_try_catch.h" |
[email protected] | 20790a22 | 2013-07-25 02:23:05 | [diff] [blame] | 16 | #include "content/renderer/pepper/plugin_module.h" |
| 17 | #include "content/renderer/pepper/plugin_object.h" |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 18 | #include "content/renderer/pepper/v8object_var.h" |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 19 | #include "ppapi/c/dev/ppb_var_deprecated.h" |
| 20 | #include "ppapi/c/ppb_var.h" |
[email protected] | d989cce | 2011-12-08 04:51:14 | [diff] [blame] | 21 | #include "ppapi/shared_impl/ppb_var_shared.h" |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 22 | #include "third_party/WebKit/public/web/WebDocument.h" |
| 23 | #include "third_party/WebKit/public/web/WebElement.h" |
| 24 | #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 25 | #include "third_party/WebKit/public/web/WebPluginContainer.h" |
dcheng | 16be73c | 2015-06-11 22:02:41 | [diff] [blame] | 26 | #include "third_party/WebKit/public/web/WebPluginScriptForbiddenScope.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 27 | #include "third_party/WebKit/public/web/WebScopedUserGesture.h" |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 28 | |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 29 | using ppapi::V8ObjectVar; |
[email protected] | 794d83cd | 2011-10-20 19:09:20 | [diff] [blame] | 30 | using ppapi::PpapiGlobals; |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 31 | using ppapi::ScopedPPVar; |
| 32 | using ppapi::ScopedPPVarArray; |
[email protected] | ce701cd | 2011-08-01 21:47:04 | [diff] [blame] | 33 | using ppapi::StringVar; |
| 34 | using ppapi::Var; |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 35 | |
[email protected] | adab233 | 2013-07-25 18:04:32 | [diff] [blame] | 36 | namespace content { |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 37 | |
| 38 | namespace { |
| 39 | |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 40 | const char kInvalidIdentifierException[] = "Error: Invalid identifier."; |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 41 | const char kInvalidObjectException[] = "Error: Invalid object"; |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 42 | const char kUnableToCallMethodException[] = "Error: Unable to call method"; |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 43 | |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 44 | class ObjectAccessor { |
| 45 | public: |
| 46 | ObjectAccessor(PP_Var var) |
Daniel Cheng | 99adf74 | 2014-09-05 06:26:50 | [diff] [blame] | 47 | : object_var_(V8ObjectVar::FromPPVar(var).get()), |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 48 | instance_(object_var_ ? object_var_->instance() : NULL) { |
dmichael | e1705472 | 2014-10-10 20:03:19 | [diff] [blame] | 49 | if (instance_) { |
| 50 | converter_.reset(new V8VarConverter(instance_->pp_instance(), |
| 51 | V8VarConverter::kAllowObjectVars)); |
| 52 | } |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 53 | } |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 54 | |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 55 | // Check if the object is valid. If it isn't, set an exception and return |
| 56 | // false. |
| 57 | bool IsValid(PP_Var* exception) { |
| 58 | // If we already have an exception, then the call is invalid according to |
| 59 | // the unittests. |
| 60 | if (exception && exception->type != PP_VARTYPE_UNDEFINED) |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 61 | return false; |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 62 | if (instance_) |
dcheng | 16be73c | 2015-06-11 22:02:41 | [diff] [blame] | 63 | return !instance_->is_deleted() || |
| 64 | !blink::WebPluginScriptForbiddenScope::isForbidden(); |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 65 | if (exception) |
| 66 | *exception = ppapi::StringVar::StringToPPVar(kInvalidObjectException); |
| 67 | return false; |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 68 | } |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 69 | // Lazily grab the object so that the handle is created in the current handle |
| 70 | // scope. |
deepak.s | 750d68f | 2015-04-30 07:32:41 | [diff] [blame] | 71 | v8::Local<v8::Object> GetObject() { return object_var_->GetHandle(); } |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 72 | PepperPluginInstanceImpl* instance() { return instance_; } |
dmichael | e1705472 | 2014-10-10 20:03:19 | [diff] [blame] | 73 | V8VarConverter* converter() { return converter_.get(); } |
raymes | dc463a9 | 2014-09-03 05:51:04 | [diff] [blame] | 74 | |
| 75 | private: |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 76 | V8ObjectVar* object_var_; |
| 77 | PepperPluginInstanceImpl* instance_; |
dmichael | e1705472 | 2014-10-10 20:03:19 | [diff] [blame] | 78 | scoped_ptr<V8VarConverter> converter_; |
raymes | dc463a9 | 2014-09-03 05:51:04 | [diff] [blame] | 79 | }; |
| 80 | |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 81 | bool IsValidIdentifer(PP_Var identifier, PP_Var* exception) { |
| 82 | if (identifier.type == PP_VARTYPE_INT32 || |
| 83 | identifier.type == PP_VARTYPE_STRING) { |
| 84 | return true; |
| 85 | } |
| 86 | if (exception) |
| 87 | *exception = ppapi::StringVar::StringToPPVar(kInvalidIdentifierException); |
| 88 | return false; |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 89 | } |
| 90 | |
[email protected] | ad63b5c | 2014-04-11 21:12:36 | [diff] [blame] | 91 | bool HasPropertyDeprecated(PP_Var var, PP_Var name, PP_Var* exception) { |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 92 | ObjectAccessor accessor(var); |
| 93 | if (!accessor.IsValid(exception) || !IsValidIdentifer(name, exception)) |
| 94 | return false; |
| 95 | |
dmichael | e1705472 | 2014-10-10 20:03:19 | [diff] [blame] | 96 | PepperTryCatchVar try_catch(accessor.instance(), accessor.converter(), |
| 97 | exception); |
deepak.s | 750d68f | 2015-04-30 07:32:41 | [diff] [blame] | 98 | v8::Local<v8::Value> v8_name = try_catch.ToV8(name); |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 99 | if (try_catch.HasException()) |
| 100 | return false; |
| 101 | |
| 102 | bool result = accessor.GetObject()->Has(v8_name); |
| 103 | if (try_catch.HasException()) |
| 104 | return false; |
| 105 | return result; |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 106 | } |
| 107 | |
[email protected] | ad63b5c | 2014-04-11 21:12:36 | [diff] [blame] | 108 | bool HasMethodDeprecated(PP_Var var, PP_Var name, PP_Var* exception) { |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 109 | ObjectAccessor accessor(var); |
| 110 | if (!accessor.IsValid(exception) || !IsValidIdentifer(name, exception)) |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 111 | return false; |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 112 | |
dmichael | e1705472 | 2014-10-10 20:03:19 | [diff] [blame] | 113 | PepperTryCatchVar try_catch(accessor.instance(), accessor.converter(), |
| 114 | exception); |
deepak.s | 750d68f | 2015-04-30 07:32:41 | [diff] [blame] | 115 | v8::Local<v8::Value> v8_name = try_catch.ToV8(name); |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 116 | if (try_catch.HasException()) |
| 117 | return false; |
| 118 | |
| 119 | bool result = accessor.GetObject()->Has(v8_name) && |
| 120 | accessor.GetObject()->Get(v8_name)->IsFunction(); |
| 121 | if (try_catch.HasException()) |
| 122 | return false; |
| 123 | return result; |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 124 | } |
| 125 | |
[email protected] | ad63b5c | 2014-04-11 21:12:36 | [diff] [blame] | 126 | PP_Var GetProperty(PP_Var var, PP_Var name, PP_Var* exception) { |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 127 | ObjectAccessor accessor(var); |
| 128 | if (!accessor.IsValid(exception) || !IsValidIdentifer(name, exception)) |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 129 | return PP_MakeUndefined(); |
| 130 | |
dmichael | e1705472 | 2014-10-10 20:03:19 | [diff] [blame] | 131 | PepperTryCatchVar try_catch(accessor.instance(), accessor.converter(), |
| 132 | exception); |
deepak.s | 750d68f | 2015-04-30 07:32:41 | [diff] [blame] | 133 | v8::Local<v8::Value> v8_name = try_catch.ToV8(name); |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 134 | if (try_catch.HasException()) |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 135 | return PP_MakeUndefined(); |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 136 | |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 137 | ScopedPPVar result_var = try_catch.FromV8(accessor.GetObject()->Get(v8_name)); |
| 138 | if (try_catch.HasException()) |
| 139 | return PP_MakeUndefined(); |
| 140 | |
| 141 | return result_var.Release(); |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | void EnumerateProperties(PP_Var var, |
| 145 | uint32_t* property_count, |
| 146 | PP_Var** properties, |
| 147 | PP_Var* exception) { |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 148 | ObjectAccessor accessor(var); |
| 149 | if (!accessor.IsValid(exception)) |
| 150 | return; |
| 151 | |
dmichael | e1705472 | 2014-10-10 20:03:19 | [diff] [blame] | 152 | PepperTryCatchVar try_catch(accessor.instance(), accessor.converter(), |
| 153 | exception); |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 154 | |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 155 | *properties = NULL; |
| 156 | *property_count = 0; |
| 157 | |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 158 | v8::Local<v8::Array> identifiers = accessor.GetObject()->GetPropertyNames(); |
| 159 | if (try_catch.HasException()) |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 160 | return; |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 161 | ScopedPPVarArray identifier_vars(identifiers->Length()); |
| 162 | for (uint32_t i = 0; i < identifiers->Length(); ++i) { |
| 163 | ScopedPPVar var = try_catch.FromV8(identifiers->Get(i)); |
| 164 | if (try_catch.HasException()) |
| 165 | return; |
| 166 | identifier_vars.Set(i, var); |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 167 | } |
| 168 | |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 169 | size_t size = identifier_vars.size(); |
| 170 | *properties = identifier_vars.Release( |
| 171 | ScopedPPVarArray::PassPPBMemoryAllocatedArray()); |
| 172 | *property_count = size; |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | void SetPropertyDeprecated(PP_Var var, |
| 176 | PP_Var name, |
| 177 | PP_Var value, |
| 178 | PP_Var* exception) { |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 179 | ObjectAccessor accessor(var); |
| 180 | if (!accessor.IsValid(exception) || !IsValidIdentifer(name, exception)) |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 181 | return; |
| 182 | |
dmichael | e1705472 | 2014-10-10 20:03:19 | [diff] [blame] | 183 | PepperTryCatchVar try_catch(accessor.instance(), accessor.converter(), |
| 184 | exception); |
deepak.s | 750d68f | 2015-04-30 07:32:41 | [diff] [blame] | 185 | v8::Local<v8::Value> v8_name = try_catch.ToV8(name); |
| 186 | v8::Local<v8::Value> v8_value = try_catch.ToV8(value); |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 187 | |
| 188 | if (try_catch.HasException()) |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 189 | return; |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 190 | |
| 191 | accessor.GetObject()->Set(v8_name, v8_value); |
| 192 | try_catch.HasException(); // Ensure an exception gets set if one occured. |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 193 | } |
| 194 | |
[email protected] | ad63b5c | 2014-04-11 21:12:36 | [diff] [blame] | 195 | void DeletePropertyDeprecated(PP_Var var, PP_Var name, PP_Var* exception) { |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 196 | ObjectAccessor accessor(var); |
| 197 | if (!accessor.IsValid(exception) || !IsValidIdentifer(name, exception)) |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 198 | return; |
| 199 | |
dmichael | e1705472 | 2014-10-10 20:03:19 | [diff] [blame] | 200 | PepperTryCatchVar try_catch(accessor.instance(), accessor.converter(), |
| 201 | exception); |
deepak.s | 750d68f | 2015-04-30 07:32:41 | [diff] [blame] | 202 | v8::Local<v8::Value> v8_name = try_catch.ToV8(name); |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 203 | |
| 204 | if (try_catch.HasException()) |
| 205 | return; |
| 206 | |
| 207 | accessor.GetObject()->Delete(v8_name); |
| 208 | try_catch.HasException(); // Ensure an exception gets set if one occured. |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 209 | } |
| 210 | |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 211 | PP_Var CallDeprecatedInternal(PP_Var var, |
[email protected] | 99800f2a | 2012-07-10 23:41:40 | [diff] [blame] | 212 | PP_Var method_name, |
| 213 | uint32_t argc, |
| 214 | PP_Var* argv, |
| 215 | PP_Var* exception) { |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 216 | ObjectAccessor accessor(var); |
| 217 | if (!accessor.IsValid(exception)) |
| 218 | return PP_MakeUndefined(); |
| 219 | |
| 220 | // If the method name is undefined, set it to the empty string to trigger |
| 221 | // calling |var| as a function. |
| 222 | ScopedPPVar scoped_name(method_name); |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 223 | if (method_name.type == PP_VARTYPE_UNDEFINED) { |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 224 | scoped_name = ScopedPPVar(ScopedPPVar::PassRef(), |
| 225 | StringVar::StringToPPVar("")); |
| 226 | } |
| 227 | |
dmichael | e1705472 | 2014-10-10 20:03:19 | [diff] [blame] | 228 | PepperTryCatchVar try_catch(accessor.instance(), accessor.converter(), |
| 229 | exception); |
deepak.s | 750d68f | 2015-04-30 07:32:41 | [diff] [blame] | 230 | v8::Local<v8::Value> v8_method_name = try_catch.ToV8(scoped_name.get()); |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 231 | if (try_catch.HasException()) |
| 232 | return PP_MakeUndefined(); |
| 233 | |
| 234 | if (!v8_method_name->IsString()) { |
| 235 | try_catch.SetException(kUnableToCallMethodException); |
| 236 | return PP_MakeUndefined(); |
| 237 | } |
| 238 | |
deepak.s | 750d68f | 2015-04-30 07:32:41 | [diff] [blame] | 239 | v8::Local<v8::Object> function = accessor.GetObject(); |
| 240 | v8::Local<v8::Object> recv = |
raymes | 816f98b | 2014-09-29 04:14:38 | [diff] [blame] | 241 | accessor.instance()->GetMainWorldContext()->Global(); |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 242 | if (v8_method_name.As<v8::String>()->Length() != 0) { |
dcarney | 04cd964 | 2014-11-21 13:58:11 | [diff] [blame] | 243 | function = function->Get(v8_method_name) |
| 244 | ->ToObject(accessor.instance()->GetIsolate()); |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 245 | recv = accessor.GetObject(); |
| 246 | } |
| 247 | |
| 248 | if (try_catch.HasException()) |
| 249 | return PP_MakeUndefined(); |
| 250 | |
| 251 | if (!function->IsFunction()) { |
| 252 | try_catch.SetException(kUnableToCallMethodException); |
| 253 | return PP_MakeUndefined(); |
| 254 | } |
| 255 | |
deepak.s | 750d68f | 2015-04-30 07:32:41 | [diff] [blame] | 256 | scoped_ptr<v8::Local<v8::Value>[] > converted_args( |
| 257 | new v8::Local<v8::Value>[argc]); |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 258 | for (uint32_t i = 0; i < argc; ++i) { |
| 259 | converted_args[i] = try_catch.ToV8(argv[i]); |
| 260 | if (try_catch.HasException()) |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 261 | return PP_MakeUndefined(); |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | blink::WebPluginContainer* container = accessor.instance()->container(); |
| 265 | blink::WebLocalFrame* frame = NULL; |
| 266 | if (container) |
| 267 | frame = container->element().document().frame(); |
| 268 | |
| 269 | if (!frame) { |
| 270 | try_catch.SetException("No frame to execute script in."); |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 271 | return PP_MakeUndefined(); |
| 272 | } |
| 273 | |
deepak.s | 750d68f | 2015-04-30 07:32:41 | [diff] [blame] | 274 | v8::Local<v8::Value> result = frame->callFunctionEvenIfScriptDisabled( |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 275 | function.As<v8::Function>(), recv, argc, converted_args.get()); |
| 276 | ScopedPPVar result_var = try_catch.FromV8(result); |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 277 | |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 278 | if (try_catch.HasException()) |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 279 | return PP_MakeUndefined(); |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 280 | |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 281 | return result_var.Release(); |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 282 | } |
| 283 | |
[email protected] | 99800f2a | 2012-07-10 23:41:40 | [diff] [blame] | 284 | PP_Var CallDeprecated(PP_Var var, |
| 285 | PP_Var method_name, |
| 286 | uint32_t argc, |
| 287 | PP_Var* argv, |
| 288 | PP_Var* exception) { |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 289 | ObjectAccessor accessor(var); |
| 290 | if (accessor.instance() && accessor.instance()->IsProcessingUserGesture()) { |
| 291 | blink::WebScopedUserGesture user_gesture( |
| 292 | accessor.instance()->CurrentUserGestureToken()); |
| 293 | return CallDeprecatedInternal(var, method_name, argc, argv, exception); |
[email protected] | 99800f2a | 2012-07-10 23:41:40 | [diff] [blame] | 294 | } |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 295 | return CallDeprecatedInternal(var, method_name, argc, argv, exception); |
[email protected] | 99800f2a | 2012-07-10 23:41:40 | [diff] [blame] | 296 | } |
| 297 | |
[email protected] | ad63b5c | 2014-04-11 21:12:36 | [diff] [blame] | 298 | PP_Var Construct(PP_Var var, uint32_t argc, PP_Var* argv, PP_Var* exception) { |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 299 | // Deprecated. |
| 300 | NOTREACHED(); |
| 301 | return PP_MakeUndefined(); |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | bool IsInstanceOfDeprecated(PP_Var var, |
| 305 | const PPP_Class_Deprecated* ppp_class, |
| 306 | void** ppp_class_data) { |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 307 | scoped_refptr<V8ObjectVar> object(V8ObjectVar::FromPPVar(var)); |
[email protected] | ff875be5 | 2013-06-02 23:47:38 | [diff] [blame] | 308 | if (!object.get()) |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 309 | return false; // Not an object at all. |
| 310 | |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 311 | v8::HandleScope handle_scope(object->instance()->GetIsolate()); |
deepak.s | 750d68f | 2015-04-30 07:32:41 | [diff] [blame] | 312 | v8::Local<v8::Context> context = object->instance()->GetMainWorldContext(); |
raymes | 9db73d2 | 2014-10-20 23:45:31 | [diff] [blame] | 313 | if (context.IsEmpty()) |
| 314 | return false; |
| 315 | v8::Context::Scope context_scope(context); |
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 316 | PluginObject* plugin_object = PluginObject::FromV8Object( |
| 317 | object->instance()->GetIsolate(), object->GetHandle()); |
| 318 | if (plugin_object && plugin_object->ppp_class() == ppp_class) { |
| 319 | if (ppp_class_data) |
| 320 | *ppp_class_data = plugin_object->ppp_class_data(); |
| 321 | return true; |
| 322 | } |
| 323 | |
| 324 | return false; |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 325 | } |
| 326 | |
[email protected] | 794d83cd | 2011-10-20 19:09:20 | [diff] [blame] | 327 | PP_Var CreateObjectDeprecated(PP_Instance pp_instance, |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 328 | const PPP_Class_Deprecated* ppp_class, |
| 329 | void* ppp_class_data) { |
[email protected] | adab233 | 2013-07-25 18:04:32 | [diff] [blame] | 330 | PepperPluginInstanceImpl* instance = |
| 331 | HostGlobals::Get()->GetInstance(pp_instance); |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 332 | if (!instance) { |
| 333 | DLOG(ERROR) << "Create object passed an invalid instance."; |
| 334 | return PP_MakeNull(); |
| 335 | } |
| 336 | return PluginObject::Create(instance, ppp_class, ppp_class_data); |
| 337 | } |
| 338 | |
[email protected] | 794d83cd | 2011-10-20 19:09:20 | [diff] [blame] | 339 | PP_Var CreateObjectWithModuleDeprecated(PP_Module pp_module, |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 340 | const PPP_Class_Deprecated* ppp_class, |
| 341 | void* ppp_class_data) { |
[email protected] | 2f59e38 | 2011-10-20 22:51:01 | [diff] [blame] | 342 | PluginModule* module = HostGlobals::Get()->GetModule(pp_module); |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 343 | if (!module) |
| 344 | return PP_MakeNull(); |
[email protected] | ad63b5c | 2014-04-11 21:12:36 | [diff] [blame] | 345 | return PluginObject::Create( |
| 346 | module->GetSomeInstance(), ppp_class, ppp_class_data); |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 347 | } |
| 348 | |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 349 | } // namespace |
| 350 | |
| 351 | // static |
[email protected] | 872caf56 | 2011-12-07 22:50:43 | [diff] [blame] | 352 | const PPB_Var_Deprecated* PPB_Var_Deprecated_Impl::GetVarDeprecatedInterface() { |
| 353 | static const PPB_Var_Deprecated var_deprecated_interface = { |
[email protected] | ad63b5c | 2014-04-11 21:12:36 | [diff] [blame] | 354 | ppapi::PPB_Var_Shared::GetVarInterface1_0()->AddRef, |
| 355 | ppapi::PPB_Var_Shared::GetVarInterface1_0()->Release, |
| 356 | ppapi::PPB_Var_Shared::GetVarInterface1_0()->VarFromUtf8, |
| 357 | ppapi::PPB_Var_Shared::GetVarInterface1_0()->VarToUtf8, |
| 358 | &HasPropertyDeprecated, |
| 359 | &HasMethodDeprecated, |
| 360 | &GetProperty, |
| 361 | &EnumerateProperties, |
| 362 | &SetPropertyDeprecated, |
| 363 | &DeletePropertyDeprecated, |
| 364 | &CallDeprecated, |
| 365 | &Construct, |
| 366 | &IsInstanceOfDeprecated, |
| 367 | &CreateObjectDeprecated, |
| 368 | &CreateObjectWithModuleDeprecated, }; |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 369 | |
[email protected] | aaa72e7 | 2011-07-28 16:12:04 | [diff] [blame] | 370 | return &var_deprecated_interface; |
| 371 | } |
| 372 | |
[email protected] | adab233 | 2013-07-25 18:04:32 | [diff] [blame] | 373 | } // namespace content |