| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2009 Apple Inc. All rights reserved. | 3 * Copyright (C) 2009 Apple Inc. All rights reserved. |
| 4 * Copyright (C) 2014 Opera Software ASA. All rights reserved. |
| 4 * | 5 * |
| 5 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 7 * modification, are permitted provided that the following conditions are |
| 7 * met: | 8 * met: |
| 8 * | 9 * |
| 9 * * Redistributions of source code must retain the above copyright | 10 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 11 * notice, this list of conditions and the following disclaimer. |
| 11 * * Redistributions in binary form must reproduce the above | 12 * * Redistributions in binary form must reproduce the above |
| 12 * copyright notice, this list of conditions and the following disclaimer | 13 * copyright notice, this list of conditions and the following disclaimer |
| 13 * in the documentation and/or other materials provided with the | 14 * in the documentation and/or other materials provided with the |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 v8Context->SetErrorMessageForCodeGenerationFromStrings(v8String(m_isolate, e
rrorMessage)); | 283 v8Context->SetErrorMessageForCodeGenerationFromStrings(v8String(m_isolate, e
rrorMessage)); |
| 283 } | 284 } |
| 284 | 285 |
| 285 PassRefPtr<SharedPersistent<v8::Object> > ScriptController::createPluginWrapper(
Widget* widget) | 286 PassRefPtr<SharedPersistent<v8::Object> > ScriptController::createPluginWrapper(
Widget* widget) |
| 286 { | 287 { |
| 287 ASSERT(widget); | 288 ASSERT(widget); |
| 288 | 289 |
| 289 if (!widget->isPluginView()) | 290 if (!widget->isPluginView()) |
| 290 return nullptr; | 291 return nullptr; |
| 291 | 292 |
| 292 NPObject* npObject = toPluginView(widget)->scriptableObject(); | 293 v8::HandleScope handleScope(m_isolate); |
| 293 if (!npObject) | 294 v8::Local<v8::Object> scriptableObject = toPluginView(widget)->scriptableObj
ect(m_isolate); |
| 295 |
| 296 if (scriptableObject.IsEmpty()) |
| 294 return nullptr; | 297 return nullptr; |
| 295 | 298 |
| 296 // LocalFrame Memory Management for NPObjects | 299 // LocalFrame Memory Management for NPObjects |
| 297 // ------------------------------------- | 300 // ------------------------------------- |
| 298 // NPObjects are treated differently than other objects wrapped by JS. | 301 // NPObjects are treated differently than other objects wrapped by JS. |
| 299 // NPObjects can be created either by the browser (e.g. the main | 302 // NPObjects can be created either by the browser (e.g. the main |
| 300 // window object) or by the plugin (the main plugin object | 303 // window object) or by the plugin (the main plugin object |
| 301 // for a HTMLEmbedElement). Further, unlike most DOM Objects, the frame | 304 // for a HTMLEmbedElement). Further, unlike most DOM Objects, the frame |
| 302 // is especially careful to ensure NPObjects terminate at frame teardown bec
ause | 305 // is especially careful to ensure NPObjects terminate at frame teardown bec
ause |
| 303 // if a plugin leaks a reference, it could leak its objects (or the browser'
s objects). | 306 // if a plugin leaks a reference, it could leak its objects (or the browser'
s objects). |
| 304 // | 307 // |
| 305 // The LocalFrame maintains a list of plugin objects (m_pluginObjects) | 308 // The LocalFrame maintains a list of plugin objects (m_pluginObjects) |
| 306 // which it can use to quickly find the wrapped embed object. | 309 // which it can use to quickly find the wrapped embed object. |
| 307 // | 310 // |
| 308 // Inside the NPRuntime, we've added a few methods for registering | 311 // Inside the NPRuntime, we've added a few methods for registering |
| 309 // wrapped NPObjects. The purpose of the registration is because | 312 // wrapped NPObjects. The purpose of the registration is because |
| 310 // javascript garbage collection is non-deterministic, yet we need to | 313 // javascript garbage collection is non-deterministic, yet we need to |
| 311 // be able to tear down the plugin objects immediately. When an object | 314 // be able to tear down the plugin objects immediately. When an object |
| 312 // is registered, javascript can use it. When the object is destroyed, | 315 // is registered, javascript can use it. When the object is destroyed, |
| 313 // or when the object's "owning" object is destroyed, the object will | 316 // or when the object's "owning" object is destroyed, the object will |
| 314 // be un-registered, and the javascript engine must not use it. | 317 // be un-registered, and the javascript engine must not use it. |
| 315 // | 318 // |
| 316 // Inside the javascript engine, the engine can keep a reference to the | 319 // Inside the javascript engine, the engine can keep a reference to the |
| 317 // NPObject as part of its wrapper. However, before accessing the object | 320 // NPObject as part of its wrapper. However, before accessing the object |
| 318 // it must consult the _NPN_Registry. | 321 // it must consult the _NPN_Registry. |
| 319 | 322 |
| 320 v8::Local<v8::Object> wrapper = createV8ObjectForNPObject(npObject, 0, m_iso
late); | 323 if (isWrappedNPObject(scriptableObject)) { |
| 324 // Track the plugin object. We've been given a reference to the object. |
| 325 m_pluginObjects.set(widget, v8ObjectToNPObject(scriptableObject)); |
| 326 } |
| 321 | 327 |
| 322 // Track the plugin object. We've been given a reference to the object. | 328 return SharedPersistent<v8::Object>::create(scriptableObject, m_isolate); |
| 323 m_pluginObjects.set(widget, npObject); | |
| 324 | |
| 325 return SharedPersistent<v8::Object>::create(wrapper, m_isolate); | |
| 326 } | 329 } |
| 327 | 330 |
| 328 void ScriptController::cleanupScriptObjectsForPlugin(Widget* nativeHandle) | 331 void ScriptController::cleanupScriptObjectsForPlugin(Widget* nativeHandle) |
| 329 { | 332 { |
| 330 PluginObjectMap::iterator it = m_pluginObjects.find(nativeHandle); | 333 PluginObjectMap::iterator it = m_pluginObjects.find(nativeHandle); |
| 331 if (it == m_pluginObjects.end()) | 334 if (it == m_pluginObjects.end()) |
| 332 return; | 335 return; |
| 333 _NPN_UnregisterObject(it->value); | 336 _NPN_UnregisterObject(it->value); |
| 334 _NPN_ReleaseObject(it->value); | 337 _NPN_ReleaseObject(it->value); |
| 335 m_pluginObjects.remove(it); | 338 m_pluginObjects.remove(it); |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 resultArray->Set(i, evaluationResult); | 631 resultArray->Set(i, evaluationResult); |
| 629 } | 632 } |
| 630 | 633 |
| 631 if (results) { | 634 if (results) { |
| 632 for (size_t i = 0; i < resultArray->Length(); ++i) | 635 for (size_t i = 0; i < resultArray->Length(); ++i) |
| 633 results->append(handleScope.Escape(resultArray->Get(i))); | 636 results->append(handleScope.Escape(resultArray->Get(i))); |
| 634 } | 637 } |
| 635 } | 638 } |
| 636 | 639 |
| 637 } // namespace blink | 640 } // namespace blink |
| OLD | NEW |