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 * Copyright (C) 2014 Opera Software ASA. All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions are | 7 * modification, are permitted provided that the following conditions are |
8 * met: | 8 * met: |
9 * | 9 * |
10 * * Redistributions of source code must retain the above copyright | 10 * * Redistributions of source code must retain the above copyright |
(...skipping 28 matching lines...) Expand all Loading... |
39 #include "bindings/core/v8/ScriptSourceCode.h" | 39 #include "bindings/core/v8/ScriptSourceCode.h" |
40 #include "bindings/core/v8/ScriptValue.h" | 40 #include "bindings/core/v8/ScriptValue.h" |
41 #include "bindings/core/v8/V8Binding.h" | 41 #include "bindings/core/v8/V8Binding.h" |
42 #include "bindings/core/v8/V8Event.h" | 42 #include "bindings/core/v8/V8Event.h" |
43 #include "bindings/core/v8/V8GCController.h" | 43 #include "bindings/core/v8/V8GCController.h" |
44 #include "bindings/core/v8/V8HTMLElement.h" | 44 #include "bindings/core/v8/V8HTMLElement.h" |
45 #include "bindings/core/v8/V8NPObject.h" | 45 #include "bindings/core/v8/V8NPObject.h" |
46 #include "bindings/core/v8/V8PerContextData.h" | 46 #include "bindings/core/v8/V8PerContextData.h" |
47 #include "bindings/core/v8/V8ScriptRunner.h" | 47 #include "bindings/core/v8/V8ScriptRunner.h" |
48 #include "bindings/core/v8/V8Window.h" | 48 #include "bindings/core/v8/V8Window.h" |
49 #include "bindings/core/v8/V8WindowShell.h" | 49 #include "bindings/core/v8/WindowProxy.h" |
50 #include "bindings/core/v8/npruntime_impl.h" | 50 #include "bindings/core/v8/npruntime_impl.h" |
51 #include "bindings/core/v8/npruntime_priv.h" | 51 #include "bindings/core/v8/npruntime_priv.h" |
52 #include "core/dom/Document.h" | 52 #include "core/dom/Document.h" |
53 #include "core/dom/Node.h" | 53 #include "core/dom/Node.h" |
54 #include "core/dom/ScriptableDocumentParser.h" | 54 #include "core/dom/ScriptableDocumentParser.h" |
55 #include "core/events/Event.h" | 55 #include "core/events/Event.h" |
56 #include "core/events/EventListener.h" | 56 #include "core/events/EventListener.h" |
57 #include "core/frame/LocalDOMWindow.h" | 57 #include "core/frame/LocalDOMWindow.h" |
58 #include "core/frame/LocalFrame.h" | 58 #include "core/frame/LocalFrame.h" |
59 #include "core/frame/Settings.h" | 59 #include "core/frame/Settings.h" |
(...skipping 27 matching lines...) Expand all Loading... |
87 if (!frame) | 87 if (!frame) |
88 return false; | 88 return false; |
89 v8::Isolate* isolate = toIsolate(frame); | 89 v8::Isolate* isolate = toIsolate(frame); |
90 return !isolate->InContext() || BindingSecurity::shouldAllowAccessToFrame(is
olate, frame); | 90 return !isolate->InContext() || BindingSecurity::shouldAllowAccessToFrame(is
olate, frame); |
91 } | 91 } |
92 | 92 |
93 ScriptController::ScriptController(LocalFrame* frame) | 93 ScriptController::ScriptController(LocalFrame* frame) |
94 : m_frame(frame) | 94 : m_frame(frame) |
95 , m_sourceURL(0) | 95 , m_sourceURL(0) |
96 , m_isolate(v8::Isolate::GetCurrent()) | 96 , m_isolate(v8::Isolate::GetCurrent()) |
97 , m_windowShell(V8WindowShell::create(frame, DOMWrapperWorld::mainWorld(), m
_isolate)) | 97 , m_windowShell(WindowProxy::create(frame, DOMWrapperWorld::mainWorld(), m_i
solate)) |
98 , m_windowScriptNPObject(0) | 98 , m_windowScriptNPObject(0) |
99 { | 99 { |
100 } | 100 } |
101 | 101 |
102 ScriptController::~ScriptController() | 102 ScriptController::~ScriptController() |
103 { | 103 { |
104 // V8WindowShell::clearForClose() must be invoked before destruction starts. | 104 // WindowProxy::clearForClose() must be invoked before destruction starts. |
105 ASSERT(!m_windowShell->isContextInitialized()); | 105 ASSERT(!m_windowShell->isContextInitialized()); |
106 } | 106 } |
107 | 107 |
108 void ScriptController::clearScriptObjects() | 108 void ScriptController::clearScriptObjects() |
109 { | 109 { |
110 PluginObjectMap::iterator it = m_pluginObjects.begin(); | 110 PluginObjectMap::iterator it = m_pluginObjects.begin(); |
111 for (; it != m_pluginObjects.end(); ++it) { | 111 for (; it != m_pluginObjects.end(); ++it) { |
112 _NPN_UnregisterObject(it->value); | 112 _NPN_UnregisterObject(it->value); |
113 _NPN_ReleaseObject(it->value); | 113 _NPN_ReleaseObject(it->value); |
114 } | 114 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 return result; | 200 return result; |
201 } | 201 } |
202 | 202 |
203 bool ScriptController::initializeMainWorld() | 203 bool ScriptController::initializeMainWorld() |
204 { | 204 { |
205 if (m_windowShell->isContextInitialized()) | 205 if (m_windowShell->isContextInitialized()) |
206 return false; | 206 return false; |
207 return windowShell(DOMWrapperWorld::mainWorld())->isContextInitialized(); | 207 return windowShell(DOMWrapperWorld::mainWorld())->isContextInitialized(); |
208 } | 208 } |
209 | 209 |
210 V8WindowShell* ScriptController::existingWindowShell(DOMWrapperWorld& world) | 210 WindowProxy* ScriptController::existingWindowShell(DOMWrapperWorld& world) |
211 { | 211 { |
212 if (world.isMainWorld()) | 212 if (world.isMainWorld()) |
213 return m_windowShell->isContextInitialized() ? m_windowShell.get() : 0; | 213 return m_windowShell->isContextInitialized() ? m_windowShell.get() : 0; |
214 | 214 |
215 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world.worldId()); | 215 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world.worldId()); |
216 if (iter == m_isolatedWorlds.end()) | 216 if (iter == m_isolatedWorlds.end()) |
217 return 0; | 217 return 0; |
218 return iter->value->isContextInitialized() ? iter->value.get() : 0; | 218 return iter->value->isContextInitialized() ? iter->value.get() : 0; |
219 } | 219 } |
220 | 220 |
221 V8WindowShell* ScriptController::windowShell(DOMWrapperWorld& world) | 221 WindowProxy* ScriptController::windowShell(DOMWrapperWorld& world) |
222 { | 222 { |
223 V8WindowShell* shell = 0; | 223 WindowProxy* shell = 0; |
224 if (world.isMainWorld()) { | 224 if (world.isMainWorld()) { |
225 shell = m_windowShell.get(); | 225 shell = m_windowShell.get(); |
226 } else { | 226 } else { |
227 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world.worldId())
; | 227 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world.worldId())
; |
228 if (iter != m_isolatedWorlds.end()) { | 228 if (iter != m_isolatedWorlds.end()) { |
229 shell = iter->value.get(); | 229 shell = iter->value.get(); |
230 } else { | 230 } else { |
231 OwnPtr<V8WindowShell> isolatedWorldShell = V8WindowShell::create(m_f
rame, world, m_isolate); | 231 OwnPtr<WindowProxy> isolatedWorldShell = WindowProxy::create(m_frame
, world, m_isolate); |
232 shell = isolatedWorldShell.get(); | 232 shell = isolatedWorldShell.get(); |
233 m_isolatedWorlds.set(world.worldId(), isolatedWorldShell.release()); | 233 m_isolatedWorlds.set(world.worldId(), isolatedWorldShell.release()); |
234 } | 234 } |
235 } | 235 } |
236 if (!shell->isContextInitialized() && shell->initializeIfNeeded() && world.i
sMainWorld()) | 236 if (!shell->isContextInitialized() && shell->initializeIfNeeded() && world.i
sMainWorld()) |
237 m_frame->loader().dispatchDidClearWindowObjectInMainWorld(); | 237 m_frame->loader().dispatchDidClearWindowObjectInMainWorld(); |
238 return shell; | 238 return shell; |
239 } | 239 } |
240 | 240 |
241 bool ScriptController::shouldBypassMainWorldCSP() | 241 bool ScriptController::shouldBypassMainWorldCSP() |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 } | 429 } |
430 | 430 |
431 void ScriptController::setCaptureCallStackForUncaughtExceptions(bool value) | 431 void ScriptController::setCaptureCallStackForUncaughtExceptions(bool value) |
432 { | 432 { |
433 v8::V8::SetCaptureStackTraceForUncaughtExceptions(value, ScriptCallStack::ma
xCallStackSizeToCapture, stackTraceOptions); | 433 v8::V8::SetCaptureStackTraceForUncaughtExceptions(value, ScriptCallStack::ma
xCallStackSizeToCapture, stackTraceOptions); |
434 } | 434 } |
435 | 435 |
436 void ScriptController::collectIsolatedContexts(Vector<std::pair<ScriptState*, Se
curityOrigin*> >& result) | 436 void ScriptController::collectIsolatedContexts(Vector<std::pair<ScriptState*, Se
curityOrigin*> >& result) |
437 { | 437 { |
438 for (IsolatedWorldMap::iterator it = m_isolatedWorlds.begin(); it != m_isola
tedWorlds.end(); ++it) { | 438 for (IsolatedWorldMap::iterator it = m_isolatedWorlds.begin(); it != m_isola
tedWorlds.end(); ++it) { |
439 V8WindowShell* isolatedWorldShell = it->value.get(); | 439 WindowProxy* isolatedWorldShell = it->value.get(); |
440 SecurityOrigin* origin = isolatedWorldShell->world().isolatedWorldSecuri
tyOrigin(); | 440 SecurityOrigin* origin = isolatedWorldShell->world().isolatedWorldSecuri
tyOrigin(); |
441 if (!origin) | 441 if (!origin) |
442 continue; | 442 continue; |
443 if (!isolatedWorldShell->isContextInitialized()) | 443 if (!isolatedWorldShell->isContextInitialized()) |
444 continue; | 444 continue; |
445 result.append(std::pair<ScriptState*, SecurityOrigin*>(isolatedWorldShel
l->scriptState(), origin)); | 445 result.append(std::pair<ScriptState*, SecurityOrigin*>(isolatedWorldShel
l->scriptState(), origin)); |
446 } | 446 } |
447 } | 447 } |
448 | 448 |
449 void ScriptController::setWorldDebugId(int worldId, int debuggerId) | 449 void ScriptController::setWorldDebugId(int worldId, int debuggerId) |
450 { | 450 { |
451 ASSERT(debuggerId > 0); | 451 ASSERT(debuggerId > 0); |
452 bool isMainWorld = worldId == MainWorldId; | 452 bool isMainWorld = worldId == MainWorldId; |
453 V8WindowShell* shell = 0; | 453 WindowProxy* shell = 0; |
454 if (isMainWorld) { | 454 if (isMainWorld) { |
455 shell = m_windowShell.get(); | 455 shell = m_windowShell.get(); |
456 } else { | 456 } else { |
457 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(worldId); | 457 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(worldId); |
458 if (iter != m_isolatedWorlds.end()) | 458 if (iter != m_isolatedWorlds.end()) |
459 shell = iter->value.get(); | 459 shell = iter->value.get(); |
460 } | 460 } |
461 if (!shell || !shell->isContextInitialized()) | 461 if (!shell || !shell->isContextInitialized()) |
462 return; | 462 return; |
463 v8::HandleScope scope(m_isolate); | 463 v8::HandleScope scope(m_isolate); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 return v8::Local<v8::Value>(); | 612 return v8::Local<v8::Value>(); |
613 | 613 |
614 return handleScope.Escape(object); | 614 return handleScope.Escape(object); |
615 } | 615 } |
616 | 616 |
617 void ScriptController::executeScriptInIsolatedWorld(int worldID, const Vector<Sc
riptSourceCode>& sources, int extensionGroup, Vector<v8::Local<v8::Value> >* res
ults) | 617 void ScriptController::executeScriptInIsolatedWorld(int worldID, const Vector<Sc
riptSourceCode>& sources, int extensionGroup, Vector<v8::Local<v8::Value> >* res
ults) |
618 { | 618 { |
619 ASSERT(worldID > 0); | 619 ASSERT(worldID > 0); |
620 | 620 |
621 RefPtr<DOMWrapperWorld> world = DOMWrapperWorld::ensureIsolatedWorld(worldID
, extensionGroup); | 621 RefPtr<DOMWrapperWorld> world = DOMWrapperWorld::ensureIsolatedWorld(worldID
, extensionGroup); |
622 V8WindowShell* isolatedWorldShell = windowShell(*world); | 622 WindowProxy* isolatedWorldShell = windowShell(*world); |
623 if (!isolatedWorldShell->isContextInitialized()) | 623 if (!isolatedWorldShell->isContextInitialized()) |
624 return; | 624 return; |
625 | 625 |
626 ScriptState* scriptState = isolatedWorldShell->scriptState(); | 626 ScriptState* scriptState = isolatedWorldShell->scriptState(); |
627 v8::EscapableHandleScope handleScope(scriptState->isolate()); | 627 v8::EscapableHandleScope handleScope(scriptState->isolate()); |
628 ScriptState::Scope scope(scriptState); | 628 ScriptState::Scope scope(scriptState); |
629 v8::Local<v8::Array> resultArray = v8::Array::New(m_isolate, sources.size())
; | 629 v8::Local<v8::Array> resultArray = v8::Array::New(m_isolate, sources.size())
; |
630 | 630 |
631 for (size_t i = 0; i < sources.size(); ++i) { | 631 for (size_t i = 0; i < sources.size(); ++i) { |
632 v8::Local<v8::Value> evaluationResult = executeScriptAndReturnValue(scri
ptState->context(), sources[i]); | 632 v8::Local<v8::Value> evaluationResult = executeScriptAndReturnValue(scri
ptState->context(), sources[i]); |
633 if (evaluationResult.IsEmpty()) | 633 if (evaluationResult.IsEmpty()) |
634 evaluationResult = v8::Local<v8::Value>::New(m_isolate, v8::Undefine
d(m_isolate)); | 634 evaluationResult = v8::Local<v8::Value>::New(m_isolate, v8::Undefine
d(m_isolate)); |
635 resultArray->Set(i, evaluationResult); | 635 resultArray->Set(i, evaluationResult); |
636 } | 636 } |
637 | 637 |
638 if (results) { | 638 if (results) { |
639 for (size_t i = 0; i < resultArray->Length(); ++i) | 639 for (size_t i = 0; i < resultArray->Length(); ++i) |
640 results->append(handleScope.Escape(resultArray->Get(i))); | 640 results->append(handleScope.Escape(resultArray->Get(i))); |
641 } | 641 } |
642 } | 642 } |
643 | 643 |
644 } // namespace blink | 644 } // namespace blink |
OLD | NEW |