Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Side by Side Diff: Source/bindings/v8/ScriptController.cpp

Issue 147333004: Revert of Limit the usage of SharedPersistent to ScriptValue only (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/bindings/v8/ScriptController.h ('k') | Source/bindings/v8/ScriptValue.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 * 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 are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 void ScriptController::disableEval(const String& errorMessage) 338 void ScriptController::disableEval(const String& errorMessage)
339 { 339 {
340 if (!m_windowShell->isContextInitialized()) 340 if (!m_windowShell->isContextInitialized())
341 return; 341 return;
342 v8::HandleScope handleScope(m_isolate); 342 v8::HandleScope handleScope(m_isolate);
343 v8::Local<v8::Context> v8Context = m_windowShell->context(); 343 v8::Local<v8::Context> v8Context = m_windowShell->context();
344 v8Context->AllowCodeGenerationFromStrings(false); 344 v8Context->AllowCodeGenerationFromStrings(false);
345 v8Context->SetErrorMessageForCodeGenerationFromStrings(v8String(m_isolate, e rrorMessage)); 345 v8Context->SetErrorMessageForCodeGenerationFromStrings(v8String(m_isolate, e rrorMessage));
346 } 346 }
347 347
348 ScriptValue ScriptController::createPluginWrapper(Widget* widget) 348 PassRefPtr<SharedPersistent<v8::Object> > ScriptController::createPluginWrapper( Widget* widget)
349 { 349 {
350 ASSERT(widget); 350 ASSERT(widget);
351 351
352 if (!widget->isPluginView()) 352 if (!widget->isPluginView())
353 return ScriptValue(); 353 return 0;
354 354
355 NPObject* npObject = toPluginView(widget)->scriptableObject(); 355 NPObject* npObject = toPluginView(widget)->scriptableObject();
356 if (!npObject) 356 if (!npObject)
357 return ScriptValue(); 357 return 0;
358 358
359 // Frame Memory Management for NPObjects 359 // Frame Memory Management for NPObjects
360 // ------------------------------------- 360 // -------------------------------------
361 // NPObjects are treated differently than other objects wrapped by JS. 361 // NPObjects are treated differently than other objects wrapped by JS.
362 // NPObjects can be created either by the browser (e.g. the main 362 // NPObjects can be created either by the browser (e.g. the main
363 // window object) or by the plugin (the main plugin object 363 // window object) or by the plugin (the main plugin object
364 // for a HTMLEmbedElement). Further, unlike most DOM Objects, the frame 364 // for a HTMLEmbedElement). Further, unlike most DOM Objects, the frame
365 // is especially careful to ensure NPObjects terminate at frame teardown bec ause 365 // is especially careful to ensure NPObjects terminate at frame teardown bec ause
366 // if a plugin leaks a reference, it could leak its objects (or the browser' s objects). 366 // if a plugin leaks a reference, it could leak its objects (or the browser' s objects).
367 // 367 //
368 // The Frame maintains a list of plugin objects (m_pluginObjects) 368 // The Frame maintains a list of plugin objects (m_pluginObjects)
369 // which it can use to quickly find the wrapped embed object. 369 // which it can use to quickly find the wrapped embed object.
370 // 370 //
371 // Inside the NPRuntime, we've added a few methods for registering 371 // Inside the NPRuntime, we've added a few methods for registering
372 // wrapped NPObjects. The purpose of the registration is because 372 // wrapped NPObjects. The purpose of the registration is because
373 // javascript garbage collection is non-deterministic, yet we need to 373 // javascript garbage collection is non-deterministic, yet we need to
374 // be able to tear down the plugin objects immediately. When an object 374 // be able to tear down the plugin objects immediately. When an object
375 // is registered, javascript can use it. When the object is destroyed, 375 // is registered, javascript can use it. When the object is destroyed,
376 // or when the object's "owning" object is destroyed, the object will 376 // or when the object's "owning" object is destroyed, the object will
377 // be un-registered, and the javascript engine must not use it. 377 // be un-registered, and the javascript engine must not use it.
378 // 378 //
379 // Inside the javascript engine, the engine can keep a reference to the 379 // Inside the javascript engine, the engine can keep a reference to the
380 // NPObject as part of its wrapper. However, before accessing the object 380 // NPObject as part of its wrapper. However, before accessing the object
381 // it must consult the _NPN_Registry. 381 // it must consult the _NPN_Registry.
382 382
383 v8::Handle<v8::Object> wrapper = createV8ObjectForNPObject(npObject, 0, m_is olate); 383 v8::Local<v8::Object> wrapper = createV8ObjectForNPObject(npObject, 0, m_iso late);
384 384
385 // Track the plugin object. We've been given a reference to the object. 385 // Track the plugin object. We've been given a reference to the object.
386 m_pluginObjects.set(widget, npObject); 386 m_pluginObjects.set(widget, npObject);
387 387
388 return ScriptValue(wrapper, m_isolate); 388 return SharedPersistent<v8::Object>::create(wrapper, m_isolate);
389 } 389 }
390 390
391 void ScriptController::cleanupScriptObjectsForPlugin(Widget* nativeHandle) 391 void ScriptController::cleanupScriptObjectsForPlugin(Widget* nativeHandle)
392 { 392 {
393 PluginObjectMap::iterator it = m_pluginObjects.find(nativeHandle); 393 PluginObjectMap::iterator it = m_pluginObjects.find(nativeHandle);
394 if (it == m_pluginObjects.end()) 394 if (it == m_pluginObjects.end())
395 return; 395 return;
396 _NPN_UnregisterObject(it->value); 396 _NPN_UnregisterObject(it->value);
397 _NPN_ReleaseObject(it->value); 397 _NPN_ReleaseObject(it->value);
398 m_pluginObjects.remove(it); 398 m_pluginObjects.remove(it);
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 v8Results = evaluateHandleScope.Escape(resultArray); 683 v8Results = evaluateHandleScope.Escape(resultArray);
684 } 684 }
685 685
686 if (results && !v8Results.IsEmpty()) { 686 if (results && !v8Results.IsEmpty()) {
687 for (size_t i = 0; i < v8Results->Length(); ++i) 687 for (size_t i = 0; i < v8Results->Length(); ++i)
688 results->append(ScriptValue(v8Results->Get(i), m_isolate)); 688 results->append(ScriptValue(v8Results->Get(i), m_isolate));
689 } 689 }
690 } 690 }
691 691
692 } // namespace WebCore 692 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/ScriptController.h ('k') | Source/bindings/v8/ScriptValue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698