| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved. |
| 3 * Copyright (C) 2007 Google, Inc. All rights reserved. | 3 * Copyright (C) 2007 Google, Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 #include "np_v8object.h" | 34 #include "np_v8object.h" |
| 35 #include "Frame.h" | 35 #include "Frame.h" |
| 36 #include "bindings/npruntime.h" | 36 #include "bindings/npruntime.h" |
| 37 #include "npruntime_priv.h" | 37 #include "npruntime_priv.h" |
| 38 #include "PlatformString.h" | 38 #include "PlatformString.h" |
| 39 #include "ScriptController.h" | 39 #include "ScriptController.h" |
| 40 #include "v8_helpers.h" | 40 #include "v8_helpers.h" |
| 41 #include "v8_np_utils.h" | 41 #include "v8_np_utils.h" |
| 42 #include "v8_proxy.h" | 42 #include "v8_proxy.h" |
| 43 #include "DOMWindow.h" | 43 #include "DOMWindow.h" |
| 44 #include "glue/plugins/plugin_instance.h" |
| 44 | 45 |
| 45 using WebCore::V8ClassIndex; | 46 using WebCore::V8ClassIndex; |
| 46 using WebCore::V8Proxy; | 47 using WebCore::V8Proxy; |
| 47 | 48 |
| 48 namespace { | 49 namespace { |
| 49 | 50 |
| 50 // TODO(mbelshe): comments on why use malloc and free. | 51 // TODO(mbelshe): comments on why use malloc and free. |
| 51 static NPObject* AllocV8NPObject(NPP, NPClass*) { | 52 static NPObject* AllocV8NPObject(NPP, NPClass*) { |
| 52 return static_cast<NPObject*>(malloc(sizeof(V8NPObject))); | 53 return static_cast<NPObject*>(malloc(sizeof(V8NPObject))); |
| 53 } | 54 } |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 | 236 |
| 236 if (npobj->_class->invokeDefault) | 237 if (npobj->_class->invokeDefault) |
| 237 return npobj->_class->invokeDefault(npobj, args, argCount, result); | 238 return npobj->_class->invokeDefault(npobj, args, argCount, result); |
| 238 | 239 |
| 239 VOID_TO_NPVARIANT(*result); | 240 VOID_TO_NPVARIANT(*result); |
| 240 return true; | 241 return true; |
| 241 } | 242 } |
| 242 | 243 |
| 243 bool NPN_Evaluate(NPP npp, NPObject *npobj, NPString *npscript, | 244 bool NPN_Evaluate(NPP npp, NPObject *npobj, NPString *npscript, |
| 244 NPVariant *result) { | 245 NPVariant *result) { |
| 246 bool popups_allowed = false; |
| 247 |
| 248 if (npp) { |
| 249 NPAPI::PluginInstance* plugin_instance = |
| 250 reinterpret_cast<NPAPI::PluginInstance*>(npp->ndata); |
| 251 if (plugin_instance) |
| 252 popups_allowed = plugin_instance->popups_allowed(); |
| 253 } |
| 254 |
| 255 return NPN_EvaluateHelper(npp, popups_allowed, npobj, npscript, result); |
| 256 } |
| 257 |
| 258 bool NPN_EvaluateHelper(NPP npp, bool popups_allowed, NPObject *npobj, |
| 259 NPString *npscript, NPVariant *result) { |
| 245 VOID_TO_NPVARIANT(*result); | 260 VOID_TO_NPVARIANT(*result); |
| 246 if (npobj == NULL) | 261 if (npobj == NULL) |
| 247 return false; | 262 return false; |
| 248 | 263 |
| 249 if (npobj->_class == NPScriptObjectClass) { | 264 if (npobj->_class == NPScriptObjectClass) { |
| 250 v8::HandleScope handle_scope; | 265 v8::HandleScope handle_scope; |
| 251 v8::Handle<v8::Context> context = GetV8Context(npp, npobj); | 266 v8::Handle<v8::Context> context = GetV8Context(npp, npobj); |
| 252 if (context.IsEmpty()) | 267 if (context.IsEmpty()) |
| 253 return false; | 268 return false; |
| 254 | 269 |
| 255 WebCore::V8Proxy* proxy = GetV8Proxy(npobj); | 270 WebCore::V8Proxy* proxy = GetV8Proxy(npobj); |
| 256 ASSERT(proxy); | 271 ASSERT(proxy); |
| 257 | 272 |
| 258 v8::Context::Scope scope(context); | 273 v8::Context::Scope scope(context); |
| 259 | 274 |
| 260 WebCore::String filename("npscript"); | 275 // Passing in a NULL filename is the trick used in V8 to indicate |
| 276 // user gesture. See the inline_code/setInlineCode functions in V8Proxy |
| 277 // for more information. |
| 278 WebCore::String filename; |
| 279 if (!popups_allowed) |
| 280 filename = "npscript"; |
| 281 |
| 261 // Convert UTF-8 stream to WebCore::String. | 282 // Convert UTF-8 stream to WebCore::String. |
| 262 WebCore::String script = WebCore::String::fromUTF8( | 283 WebCore::String script = WebCore::String::fromUTF8( |
| 263 npscript->UTF8Characters, npscript->UTF8Length); | 284 npscript->UTF8Characters, npscript->UTF8Length); |
| 264 v8::Local<v8::Value> v8result = | 285 v8::Local<v8::Value> v8result = |
| 265 proxy->Evaluate(filename, 0, script, NULL); | 286 proxy->Evaluate(filename, 0, script, NULL); |
| 266 | 287 |
| 267 // If we had an error, return false. | 288 // If we had an error, return false. |
| 268 if (v8result.IsEmpty()) return false; | 289 if (v8result.IsEmpty()) return false; |
| 269 | 290 |
| 270 ConvertV8ObjectToNPVariant(v8result, npobj, result); | 291 ConvertV8ObjectToNPVariant(v8result, npobj, result); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 return true; | 494 return true; |
| 474 } | 495 } |
| 475 | 496 |
| 476 if (NP_CLASS_STRUCT_VERSION_HAS_ENUM(npobj->_class) && | 497 if (NP_CLASS_STRUCT_VERSION_HAS_ENUM(npobj->_class) && |
| 477 npobj->_class->enumerate) { | 498 npobj->_class->enumerate) { |
| 478 return npobj->_class->enumerate(npobj, identifier, count); | 499 return npobj->_class->enumerate(npobj, identifier, count); |
| 479 } | 500 } |
| 480 | 501 |
| 481 return false; | 502 return false; |
| 482 } | 503 } |
| OLD | NEW |