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

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

Issue 230813002: Make it possible to have <object>'s scriptableObject as a v8 object instead of NPObject. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased to current ToT (by raymes - fetched from https://codereview.chromium.org/426853002/) Created 6 years, 4 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
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 * 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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 m_isolatedWorlds.set(world.worldId(), isolatedWorldShell.release()); 229 m_isolatedWorlds.set(world.worldId(), isolatedWorldShell.release());
229 } 230 }
230 } 231 }
231 if (!shell->isContextInitialized() && shell->initializeIfNeeded() && world.i sMainWorld()) 232 if (!shell->isContextInitialized() && shell->initializeIfNeeded() && world.i sMainWorld())
232 m_frame->loader().dispatchDidClearWindowObjectInMainWorld(); 233 m_frame->loader().dispatchDidClearWindowObjectInMainWorld();
233 return shell; 234 return shell;
234 } 235 }
235 236
236 bool ScriptController::shouldBypassMainWorldCSP() 237 bool ScriptController::shouldBypassMainWorldCSP()
237 { 238 {
239 v8::HandleScope handleScope(m_isolate);
abarth-chromium 2014/07/29 17:34:21 Why is this handle scope needed?
Krzysztof Olczyk 2014/07/30 08:40:30 Hmm. It happened to appear in raymes' rebase. Have
238 v8::Handle<v8::Context> context = m_isolate->GetCurrentContext(); 240 v8::Handle<v8::Context> context = m_isolate->GetCurrentContext();
239 if (context.IsEmpty() || !toDOMWindow(context)) 241 if (context.IsEmpty() || !toDOMWindow(context))
240 return false; 242 return false;
241 DOMWrapperWorld& world = DOMWrapperWorld::current(m_isolate); 243 DOMWrapperWorld& world = DOMWrapperWorld::current(m_isolate);
242 return world.isIsolatedWorld() ? world.isolatedWorldHasContentSecurityPolicy () : false; 244 return world.isIsolatedWorld() ? world.isolatedWorldHasContentSecurityPolicy () : false;
243 } 245 }
244 246
245 TextPosition ScriptController::eventHandlerPosition() const 247 TextPosition ScriptController::eventHandlerPosition() const
246 { 248 {
247 ScriptableDocumentParser* parser = m_frame->document()->scriptableDocumentPa rser(); 249 ScriptableDocumentParser* parser = m_frame->document()->scriptableDocumentPa rser();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 v8Context->SetErrorMessageForCodeGenerationFromStrings(v8String(m_isolate, e rrorMessage)); 284 v8Context->SetErrorMessageForCodeGenerationFromStrings(v8String(m_isolate, e rrorMessage));
283 } 285 }
284 286
285 PassRefPtr<SharedPersistent<v8::Object> > ScriptController::createPluginWrapper( Widget* widget) 287 PassRefPtr<SharedPersistent<v8::Object> > ScriptController::createPluginWrapper( Widget* widget)
286 { 288 {
287 ASSERT(widget); 289 ASSERT(widget);
288 290
289 if (!widget->isPluginView()) 291 if (!widget->isPluginView())
290 return nullptr; 292 return nullptr;
291 293
292 NPObject* npObject = toPluginView(widget)->scriptableObject(); 294 v8::HandleScope handleScope(m_isolate);
293 if (!npObject) 295 v8::Local<v8::Object> scriptableObject;
296 toPluginView(widget)->getScriptableObject(m_isolate, &scriptableObject);
297
298 if (scriptableObject.IsEmpty())
294 return nullptr; 299 return nullptr;
295 300
296 // LocalFrame Memory Management for NPObjects 301 // LocalFrame Memory Management for NPObjects
297 // ------------------------------------- 302 // -------------------------------------
298 // NPObjects are treated differently than other objects wrapped by JS. 303 // NPObjects are treated differently than other objects wrapped by JS.
299 // NPObjects can be created either by the browser (e.g. the main 304 // NPObjects can be created either by the browser (e.g. the main
300 // window object) or by the plugin (the main plugin object 305 // window object) or by the plugin (the main plugin object
301 // for a HTMLEmbedElement). Further, unlike most DOM Objects, the frame 306 // for a HTMLEmbedElement). Further, unlike most DOM Objects, the frame
302 // is especially careful to ensure NPObjects terminate at frame teardown bec ause 307 // 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). 308 // if a plugin leaks a reference, it could leak its objects (or the browser' s objects).
304 // 309 //
305 // The LocalFrame maintains a list of plugin objects (m_pluginObjects) 310 // The LocalFrame maintains a list of plugin objects (m_pluginObjects)
306 // which it can use to quickly find the wrapped embed object. 311 // which it can use to quickly find the wrapped embed object.
307 // 312 //
308 // Inside the NPRuntime, we've added a few methods for registering 313 // Inside the NPRuntime, we've added a few methods for registering
309 // wrapped NPObjects. The purpose of the registration is because 314 // wrapped NPObjects. The purpose of the registration is because
310 // javascript garbage collection is non-deterministic, yet we need to 315 // javascript garbage collection is non-deterministic, yet we need to
311 // be able to tear down the plugin objects immediately. When an object 316 // be able to tear down the plugin objects immediately. When an object
312 // is registered, javascript can use it. When the object is destroyed, 317 // is registered, javascript can use it. When the object is destroyed,
313 // or when the object's "owning" object is destroyed, the object will 318 // or when the object's "owning" object is destroyed, the object will
314 // be un-registered, and the javascript engine must not use it. 319 // be un-registered, and the javascript engine must not use it.
315 // 320 //
316 // Inside the javascript engine, the engine can keep a reference to the 321 // Inside the javascript engine, the engine can keep a reference to the
317 // NPObject as part of its wrapper. However, before accessing the object 322 // NPObject as part of its wrapper. However, before accessing the object
318 // it must consult the _NPN_Registry. 323 // it must consult the _NPN_Registry.
319 324
320 v8::Local<v8::Object> wrapper = createV8ObjectForNPObject(npObject, 0, m_iso late); 325 if (isWrappedNPObject(scriptableObject)) {
326 // Track the plugin object. We've been given a reference to the object.
327 m_pluginObjects.set(widget, v8ObjectToNPObject(scriptableObject));
328 }
321 329
322 // Track the plugin object. We've been given a reference to the object. 330 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 } 331 }
327 332
328 void ScriptController::cleanupScriptObjectsForPlugin(Widget* nativeHandle) 333 void ScriptController::cleanupScriptObjectsForPlugin(Widget* nativeHandle)
329 { 334 {
330 PluginObjectMap::iterator it = m_pluginObjects.find(nativeHandle); 335 PluginObjectMap::iterator it = m_pluginObjects.find(nativeHandle);
331 if (it == m_pluginObjects.end()) 336 if (it == m_pluginObjects.end())
332 return; 337 return;
333 _NPN_UnregisterObject(it->value); 338 _NPN_UnregisterObject(it->value);
334 _NPN_ReleaseObject(it->value); 339 _NPN_ReleaseObject(it->value);
335 m_pluginObjects.remove(it); 340 m_pluginObjects.remove(it);
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 resultArray->Set(i, evaluationResult); 633 resultArray->Set(i, evaluationResult);
629 } 634 }
630 635
631 if (results) { 636 if (results) {
632 for (size_t i = 0; i < resultArray->Length(); ++i) 637 for (size_t i = 0; i < resultArray->Length(); ++i)
633 results->append(handleScope.Escape(resultArray->Get(i))); 638 results->append(handleScope.Escape(resultArray->Get(i)));
634 } 639 }
635 } 640 }
636 641
637 } // namespace blink 642 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698