| 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 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 class WindowProxy; | 59 class WindowProxy; |
| 60 class Widget; | 60 class Widget; |
| 61 | 61 |
| 62 typedef WTF::Vector<v8::Extension*> V8Extensions; | 62 typedef WTF::Vector<v8::Extension*> V8Extensions; |
| 63 | 63 |
| 64 enum ReasonForCallingCanExecuteScripts { | 64 enum ReasonForCallingCanExecuteScripts { |
| 65 AboutToExecuteScript, | 65 AboutToExecuteScript, |
| 66 NotAboutToExecuteScript | 66 NotAboutToExecuteScript |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 class CORE_EXPORT ScriptController final : public NoBaseWillBeGarbageCollectedFi
nalized<ScriptController> { | 69 class CORE_EXPORT ScriptController final : public GarbageCollectedFinalized<Scri
ptController> { |
| 70 WTF_MAKE_NONCOPYABLE(ScriptController); | 70 WTF_MAKE_NONCOPYABLE(ScriptController); |
| 71 USING_FAST_MALLOC_WILL_BE_REMOVED(ScriptController); | |
| 72 public: | 71 public: |
| 73 enum ExecuteScriptPolicy { | 72 enum ExecuteScriptPolicy { |
| 74 ExecuteScriptWhenScriptsDisabled, | 73 ExecuteScriptWhenScriptsDisabled, |
| 75 DoNotExecuteScriptWhenScriptsDisabled | 74 DoNotExecuteScriptWhenScriptsDisabled |
| 76 }; | 75 }; |
| 77 | 76 |
| 78 static PassOwnPtrWillBeRawPtr<ScriptController> create(LocalFrame* frame) | 77 static RawPtr<ScriptController> create(LocalFrame* frame) |
| 79 { | 78 { |
| 80 return adoptPtrWillBeNoop(new ScriptController(frame)); | 79 return (new ScriptController(frame)); |
| 81 } | 80 } |
| 82 | 81 |
| 83 ~ScriptController(); | 82 ~ScriptController(); |
| 84 DECLARE_TRACE(); | 83 DECLARE_TRACE(); |
| 85 | 84 |
| 86 bool initializeMainWorld(); | 85 bool initializeMainWorld(); |
| 87 WindowProxy* windowProxy(DOMWrapperWorld&); | 86 WindowProxy* windowProxy(DOMWrapperWorld&); |
| 88 WindowProxy* existingWindowProxy(DOMWrapperWorld&); | 87 WindowProxy* existingWindowProxy(DOMWrapperWorld&); |
| 89 | 88 |
| 90 // Evaluate JavaScript in the main world. | 89 // Evaluate JavaScript in the main world. |
| 91 void executeScriptInMainWorld(const String&, ExecuteScriptPolicy = DoNotExec
uteScriptWhenScriptsDisabled); | 90 void executeScriptInMainWorld(const String&, ExecuteScriptPolicy = DoNotExec
uteScriptWhenScriptsDisabled); |
| 92 void executeScriptInMainWorld(const ScriptSourceCode&, AccessControlStatus =
NotSharableCrossOrigin, double* compilationFinishTime = 0); | 91 void executeScriptInMainWorld(const ScriptSourceCode&, AccessControlStatus =
NotSharableCrossOrigin, double* compilationFinishTime = 0); |
| 93 v8::Local<v8::Value> executeScriptInMainWorldAndReturnValue(const ScriptSour
ceCode&, ExecuteScriptPolicy = DoNotExecuteScriptWhenScriptsDisabled); | 92 v8::Local<v8::Value> executeScriptInMainWorldAndReturnValue(const ScriptSour
ceCode&, ExecuteScriptPolicy = DoNotExecuteScriptWhenScriptsDisabled); |
| 94 v8::Local<v8::Value> executeScriptAndReturnValue(v8::Local<v8::Context>, con
st ScriptSourceCode&, AccessControlStatus = NotSharableCrossOrigin, double* comp
ilationFinishTime = 0); | 93 v8::Local<v8::Value> executeScriptAndReturnValue(v8::Local<v8::Context>, con
st ScriptSourceCode&, AccessControlStatus = NotSharableCrossOrigin, double* comp
ilationFinishTime = 0); |
| 95 | 94 |
| 96 // Executes JavaScript in an isolated world. The script gets its own global
scope, | 95 // Executes JavaScript in an isolated world. The script gets its own global
scope, |
| 97 // its own prototypes for intrinsic JavaScript objects (String, Array, and s
o-on), | 96 // its own prototypes for intrinsic JavaScript objects (String, Array, and s
o-on), |
| 98 // and its own wrappers for all DOM nodes and DOM constructors. | 97 // and its own wrappers for all DOM nodes and DOM constructors. |
| 99 // | 98 // |
| 100 // If an isolated world with the specified ID already exists, it is reused. | 99 // If an isolated world with the specified ID already exists, it is reused. |
| 101 // Otherwise, a new world is created. | 100 // Otherwise, a new world is created. |
| 102 // | 101 // |
| 103 // FIXME: Get rid of extensionGroup here. | 102 // FIXME: Get rid of extensionGroup here. |
| 104 // FIXME: We don't want to support multiple scripts. | 103 // FIXME: We don't want to support multiple scripts. |
| 105 void executeScriptInIsolatedWorld(int worldID, const WillBeHeapVector<Script
SourceCode>& sources, int extensionGroup, Vector<v8::Local<v8::Value>>* results)
; | 104 void executeScriptInIsolatedWorld(int worldID, const HeapVector<ScriptSource
Code>& sources, int extensionGroup, Vector<v8::Local<v8::Value>>* results); |
| 106 | 105 |
| 107 // Returns true if argument is a JavaScript URL. | 106 // Returns true if argument is a JavaScript URL. |
| 108 bool executeScriptIfJavaScriptURL(const KURL&); | 107 bool executeScriptIfJavaScriptURL(const KURL&); |
| 109 | 108 |
| 110 v8::MaybeLocal<v8::Value> callFunction(v8::Local<v8::Function>, v8::Local<v8
::Value>, int argc, v8::Local<v8::Value> argv[]); | 109 v8::MaybeLocal<v8::Value> callFunction(v8::Local<v8::Function>, v8::Local<v8
::Value>, int argc, v8::Local<v8::Value> argv[]); |
| 111 static v8::MaybeLocal<v8::Value> callFunction(ExecutionContext*, v8::Local<v
8::Function>, v8::Local<v8::Value> receiver, int argc, v8::Local<v8::Value> info
[], v8::Isolate*); | 110 static v8::MaybeLocal<v8::Value> callFunction(ExecutionContext*, v8::Local<v
8::Function>, v8::Local<v8::Value> receiver, int argc, v8::Local<v8::Value> info
[], v8::Isolate*); |
| 112 | 111 |
| 113 // Returns true if the current world is isolated, and has its own Content | 112 // Returns true if the current world is isolated, and has its own Content |
| 114 // Security Policy. In this case, the policy of the main world should be | 113 // Security Policy. In this case, the policy of the main world should be |
| 115 // ignored when evaluating resources injected into the DOM. | 114 // ignored when evaluating resources injected into the DOM. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 154 |
| 156 v8::Isolate* isolate() const { return m_windowProxyManager->isolate(); } | 155 v8::Isolate* isolate() const { return m_windowProxyManager->isolate(); } |
| 157 | 156 |
| 158 WindowProxyManager* windowProxyManager() const { return m_windowProxyManager
.get(); } | 157 WindowProxyManager* windowProxyManager() const { return m_windowProxyManager
.get(); } |
| 159 | 158 |
| 160 private: | 159 private: |
| 161 explicit ScriptController(LocalFrame*); | 160 explicit ScriptController(LocalFrame*); |
| 162 | 161 |
| 163 LocalFrame* frame() const { return toLocalFrame(m_windowProxyManager->frame(
)); } | 162 LocalFrame* frame() const { return toLocalFrame(m_windowProxyManager->frame(
)); } |
| 164 | 163 |
| 165 typedef WillBeHeapHashMap<RawPtrWillBeMember<Widget>, NPObject*> PluginObjec
tMap; | 164 typedef HeapHashMap<Member<Widget>, NPObject*> PluginObjectMap; |
| 166 | 165 |
| 167 v8::Local<v8::Value> evaluateScriptInMainWorld(const ScriptSourceCode&, Acce
ssControlStatus, ExecuteScriptPolicy, double* compilationFinishTime = 0); | 166 v8::Local<v8::Value> evaluateScriptInMainWorld(const ScriptSourceCode&, Acce
ssControlStatus, ExecuteScriptPolicy, double* compilationFinishTime = 0); |
| 168 | 167 |
| 169 OwnPtrWillBeMember<WindowProxyManager> m_windowProxyManager; | 168 Member<WindowProxyManager> m_windowProxyManager; |
| 170 const String* m_sourceURL; | 169 const String* m_sourceURL; |
| 171 | 170 |
| 172 // A mapping between Widgets and their corresponding script object. | 171 // A mapping between Widgets and their corresponding script object. |
| 173 // This list is used so that when the plugin dies, we can immediately | 172 // This list is used so that when the plugin dies, we can immediately |
| 174 // invalidate all sub-objects which are associated with that plugin. | 173 // invalidate all sub-objects which are associated with that plugin. |
| 175 // The frame keeps a NPObject reference for each item on the list. | 174 // The frame keeps a NPObject reference for each item on the list. |
| 176 PluginObjectMap m_pluginObjects; | 175 PluginObjectMap m_pluginObjects; |
| 177 | 176 |
| 178 NPObject* m_windowScriptNPObject; | 177 NPObject* m_windowScriptNPObject; |
| 179 }; | 178 }; |
| 180 | 179 |
| 181 } // namespace blink | 180 } // namespace blink |
| 182 | 181 |
| 183 #endif // ScriptController_h | 182 #endif // ScriptController_h |
| OLD | NEW |