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 17 matching lines...) Expand all Loading... |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef ScriptController_h | 31 #ifndef ScriptController_h |
32 #define ScriptController_h | 32 #define ScriptController_h |
33 | 33 |
34 #include "bindings/core/v8/SharedPersistent.h" | 34 #include "bindings/core/v8/SharedPersistent.h" |
35 #include "bindings/core/v8/WindowProxyManager.h" | 35 #include "bindings/core/v8/WindowProxyManager.h" |
36 #include "core/CoreExport.h" | 36 #include "core/CoreExport.h" |
37 #include "core/dom/ExecutionContext.h" | 37 #include "core/dom/ExecutionContext.h" |
38 #include "core/frame/LocalFrame.h" | |
39 #include "platform/heap/Handle.h" | 38 #include "platform/heap/Handle.h" |
40 #include "platform/loader/fetch/AccessControlStatus.h" | 39 #include "platform/loader/fetch/AccessControlStatus.h" |
41 #include "platform/loader/fetch/CrossOriginAccessControl.h" | 40 #include "platform/loader/fetch/CrossOriginAccessControl.h" |
42 #include "v8/include/v8.h" | 41 #include "v8/include/v8.h" |
43 #include "wtf/HashMap.h" | 42 #include "wtf/HashMap.h" |
44 #include "wtf/Noncopyable.h" | 43 #include "wtf/Noncopyable.h" |
45 #include "wtf/Vector.h" | 44 #include "wtf/Vector.h" |
46 #include "wtf/text/TextPosition.h" | 45 #include "wtf/text/TextPosition.h" |
47 | 46 |
48 namespace blink { | 47 namespace blink { |
49 | 48 |
50 class DOMWrapperWorld; | 49 class DOMWrapperWorld; |
51 class Element; | 50 class Element; |
52 class FrameViewBase; | 51 class FrameViewBase; |
53 class KURL; | 52 class KURL; |
| 53 class LocalFrame; |
54 class ScriptSourceCode; | 54 class ScriptSourceCode; |
55 class SecurityOrigin; | 55 class SecurityOrigin; |
56 | 56 |
57 typedef WTF::Vector<v8::Extension*> V8Extensions; | 57 typedef WTF::Vector<v8::Extension*> V8Extensions; |
58 | 58 |
59 | 59 |
60 class CORE_EXPORT ScriptController final | 60 class CORE_EXPORT ScriptController final |
61 : public GarbageCollected<ScriptController> { | 61 : public GarbageCollected<ScriptController> { |
62 WTF_MAKE_NONCOPYABLE(ScriptController); | 62 WTF_MAKE_NONCOPYABLE(ScriptController); |
63 | 63 |
64 public: | 64 public: |
65 enum ExecuteScriptPolicy { | 65 enum ExecuteScriptPolicy { |
66 ExecuteScriptWhenScriptsDisabled, | 66 ExecuteScriptWhenScriptsDisabled, |
67 DoNotExecuteScriptWhenScriptsDisabled | 67 DoNotExecuteScriptWhenScriptsDisabled |
68 }; | 68 }; |
69 | 69 |
70 static ScriptController* create(LocalFrame* frame) { | 70 static ScriptController* create(LocalFrame& frame, |
71 return new ScriptController(frame); | 71 LocalWindowProxyManager& windowProxyManager) { |
| 72 return new ScriptController(frame, windowProxyManager); |
72 } | 73 } |
73 | 74 |
74 DECLARE_TRACE(); | 75 DECLARE_TRACE(); |
75 | 76 |
76 // This returns an initialized window proxy. (If the window proxy is not | 77 // This returns an initialized window proxy. (If the window proxy is not |
77 // yet initialized, it's implicitly initialized at the first access.) | 78 // yet initialized, it's implicitly initialized at the first access.) |
78 LocalWindowProxy* windowProxy(DOMWrapperWorld&); | 79 LocalWindowProxy* windowProxy(DOMWrapperWorld& world) { |
| 80 return m_windowProxyManager->windowProxy(world); |
| 81 } |
79 | 82 |
80 // Evaluate JavaScript in the main world. | 83 // Evaluate JavaScript in the main world. |
81 void executeScriptInMainWorld( | 84 void executeScriptInMainWorld( |
82 const String&, | 85 const String&, |
83 ExecuteScriptPolicy = DoNotExecuteScriptWhenScriptsDisabled); | 86 ExecuteScriptPolicy = DoNotExecuteScriptWhenScriptsDisabled); |
84 void executeScriptInMainWorld(const ScriptSourceCode&, | 87 void executeScriptInMainWorld(const ScriptSourceCode&, |
85 AccessControlStatus = NotSharableCrossOrigin); | 88 AccessControlStatus = NotSharableCrossOrigin); |
86 v8::Local<v8::Value> executeScriptInMainWorldAndReturnValue( | 89 v8::Local<v8::Value> executeScriptInMainWorldAndReturnValue( |
87 const ScriptSourceCode&, | 90 const ScriptSourceCode&, |
88 ExecuteScriptPolicy = DoNotExecuteScriptWhenScriptsDisabled); | 91 ExecuteScriptPolicy = DoNotExecuteScriptWhenScriptsDisabled); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 void updateSecurityOrigin(SecurityOrigin*); | 127 void updateSecurityOrigin(SecurityOrigin*); |
125 | 128 |
126 void clearForClose(); | 129 void clearForClose(); |
127 | 130 |
128 // Registers a v8 extension to be available on webpages. Will only | 131 // Registers a v8 extension to be available on webpages. Will only |
129 // affect v8 contexts initialized after this call. Takes ownership of | 132 // affect v8 contexts initialized after this call. Takes ownership of |
130 // the v8::Extension object passed. | 133 // the v8::Extension object passed. |
131 static void registerExtensionIfNeeded(v8::Extension*); | 134 static void registerExtensionIfNeeded(v8::Extension*); |
132 static V8Extensions& registeredExtensions(); | 135 static V8Extensions& registeredExtensions(); |
133 | 136 |
| 137 private: |
| 138 ScriptController(LocalFrame& frame, |
| 139 LocalWindowProxyManager& windowProxyManager) |
| 140 : m_frame(&frame), m_windowProxyManager(&windowProxyManager) {} |
| 141 |
| 142 LocalFrame* frame() const { return m_frame; } |
134 v8::Isolate* isolate() const { return m_windowProxyManager->isolate(); } | 143 v8::Isolate* isolate() const { return m_windowProxyManager->isolate(); } |
135 | 144 |
136 LocalWindowProxyManager* getWindowProxyManager() const { | |
137 return m_windowProxyManager.get(); | |
138 } | |
139 | |
140 private: | |
141 explicit ScriptController(LocalFrame*); | |
142 | |
143 LocalFrame* frame() const { return m_windowProxyManager->frame(); } | |
144 | |
145 v8::Local<v8::Value> evaluateScriptInMainWorld(const ScriptSourceCode&, | 145 v8::Local<v8::Value> evaluateScriptInMainWorld(const ScriptSourceCode&, |
146 AccessControlStatus, | 146 AccessControlStatus, |
147 ExecuteScriptPolicy); | 147 ExecuteScriptPolicy); |
148 | 148 |
149 Member<LocalWindowProxyManager> m_windowProxyManager; | 149 const Member<LocalFrame> m_frame; |
| 150 const Member<LocalWindowProxyManager> m_windowProxyManager; |
150 }; | 151 }; |
151 | 152 |
152 } // namespace blink | 153 } // namespace blink |
153 | 154 |
154 #endif // ScriptController_h | 155 #endif // ScriptController_h |
OLD | NEW |