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 26 matching lines...) Expand all Loading... |
37 #include "core/fetch/AccessControlStatus.h" | 37 #include "core/fetch/AccessControlStatus.h" |
38 #include "core/fetch/CrossOriginAccessControl.h" | 38 #include "core/fetch/CrossOriginAccessControl.h" |
39 #include "core/frame/LocalFrame.h" | 39 #include "core/frame/LocalFrame.h" |
40 #include "platform/heap/Handle.h" | 40 #include "platform/heap/Handle.h" |
41 #include "wtf/HashMap.h" | 41 #include "wtf/HashMap.h" |
42 #include "wtf/Noncopyable.h" | 42 #include "wtf/Noncopyable.h" |
43 #include "wtf/Vector.h" | 43 #include "wtf/Vector.h" |
44 #include "wtf/text/TextPosition.h" | 44 #include "wtf/text/TextPosition.h" |
45 #include <v8.h> | 45 #include <v8.h> |
46 | 46 |
| 47 namespace WTF { |
| 48 class AtomicString; |
| 49 } // namespace WTF |
| 50 |
47 namespace blink { | 51 namespace blink { |
48 | 52 |
49 class DOMWrapperWorld; | 53 class DOMWrapperWorld; |
50 class Element; | 54 class Element; |
| 55 class HTMLDocument; |
51 class KURL; | 56 class KURL; |
52 class ScriptSourceCode; | 57 class ScriptSourceCode; |
53 class SecurityOrigin; | 58 class SecurityOrigin; |
54 class Widget; | 59 class Widget; |
55 | 60 |
56 typedef WTF::Vector<v8::Extension*> V8Extensions; | 61 typedef WTF::Vector<v8::Extension*> V8Extensions; |
57 | 62 |
58 enum ReasonForCallingCanExecuteScripts { | 63 enum ReasonForCallingCanExecuteScripts { |
59 AboutToExecuteScript, | 64 AboutToExecuteScript, |
60 NotAboutToExecuteScript | 65 NotAboutToExecuteScript |
61 }; | 66 }; |
62 | 67 |
63 class CORE_EXPORT ScriptController final | 68 // LocalWindowProxyManager is just a template specialization for the local |
64 : public GarbageCollected<ScriptController> { | 69 // version of a WindowProxyManager. It contains only the core logic of mapping a |
| 70 // DOMWrapperWorld to its corresponding WindowProxy. |
| 71 // ScriptController adds functionality for executing scripts and other |
| 72 // LocalWindowProxy-specific management logic, such as updating the security |
| 73 // origin. |
| 74 class CORE_EXPORT ScriptController final : public LocalWindowProxyManager { |
65 WTF_MAKE_NONCOPYABLE(ScriptController); | 75 WTF_MAKE_NONCOPYABLE(ScriptController); |
66 | 76 |
67 public: | 77 public: |
68 enum ExecuteScriptPolicy { | 78 enum ExecuteScriptPolicy { |
69 ExecuteScriptWhenScriptsDisabled, | 79 ExecuteScriptWhenScriptsDisabled, |
70 DoNotExecuteScriptWhenScriptsDisabled | 80 DoNotExecuteScriptWhenScriptsDisabled |
71 }; | 81 }; |
72 | 82 |
73 static ScriptController* create(LocalFrame* frame) { | 83 static ScriptController* create(LocalFrame& frame) { |
74 return new ScriptController(frame); | 84 return new ScriptController(frame); |
75 } | 85 } |
76 | 86 |
77 DECLARE_TRACE(); | |
78 | |
79 // This returns an initialized window proxy. (If the window proxy is not | |
80 // yet initialized, it's implicitly initialized at the first access.) | |
81 LocalWindowProxy* windowProxy(DOMWrapperWorld&); | |
82 | |
83 // Evaluate JavaScript in the main world. | 87 // Evaluate JavaScript in the main world. |
84 void executeScriptInMainWorld( | 88 void executeScriptInMainWorld( |
85 const String&, | 89 const String&, |
86 ExecuteScriptPolicy = DoNotExecuteScriptWhenScriptsDisabled); | 90 ExecuteScriptPolicy = DoNotExecuteScriptWhenScriptsDisabled); |
87 void executeScriptInMainWorld(const ScriptSourceCode&, | 91 void executeScriptInMainWorld(const ScriptSourceCode&, |
88 AccessControlStatus = NotSharableCrossOrigin); | 92 AccessControlStatus = NotSharableCrossOrigin); |
89 v8::Local<v8::Value> executeScriptInMainWorldAndReturnValue( | 93 v8::Local<v8::Value> executeScriptInMainWorldAndReturnValue( |
90 const ScriptSourceCode&, | 94 const ScriptSourceCode&, |
91 ExecuteScriptPolicy = DoNotExecuteScriptWhenScriptsDisabled); | 95 ExecuteScriptPolicy = DoNotExecuteScriptWhenScriptsDisabled); |
92 v8::Local<v8::Value> executeScriptAndReturnValue( | 96 v8::Local<v8::Value> executeScriptAndReturnValue( |
(...skipping 23 matching lines...) Expand all Loading... |
116 | 120 |
117 PassRefPtr<SharedPersistent<v8::Object>> createPluginWrapper(Widget*); | 121 PassRefPtr<SharedPersistent<v8::Object>> createPluginWrapper(Widget*); |
118 | 122 |
119 void enableEval(); | 123 void enableEval(); |
120 void disableEval(const String& errorMessage); | 124 void disableEval(const String& errorMessage); |
121 | 125 |
122 bool canExecuteScripts(ReasonForCallingCanExecuteScripts); | 126 bool canExecuteScripts(ReasonForCallingCanExecuteScripts); |
123 | 127 |
124 TextPosition eventHandlerPosition() const; | 128 TextPosition eventHandlerPosition() const; |
125 | 129 |
126 void clearWindowProxy(); | 130 void namedItemAdded(HTMLDocument*, const AtomicString&); |
| 131 void namedItemRemoved(HTMLDocument*, const AtomicString&); |
| 132 |
| 133 void clearForClose(); |
| 134 void clearForNavigation(); |
127 void updateDocument(); | 135 void updateDocument(); |
128 | |
129 void updateSecurityOrigin(SecurityOrigin*); | 136 void updateSecurityOrigin(SecurityOrigin*); |
130 | 137 |
131 void clearForClose(); | 138 void initializeMainWorld(); |
132 | 139 |
133 // Registers a v8 extension to be available on webpages. Will only | 140 // Registers a v8 extension to be available on webpages. Will only |
134 // affect v8 contexts initialized after this call. Takes ownership of | 141 // affect v8 contexts initialized after this call. Takes ownership of |
135 // the v8::Extension object passed. | 142 // the v8::Extension object passed. |
136 static void registerExtensionIfNeeded(v8::Extension*); | 143 static void registerExtensionIfNeeded(v8::Extension*); |
137 static V8Extensions& registeredExtensions(); | 144 static V8Extensions& registeredExtensions(); |
138 | 145 |
139 v8::Isolate* isolate() const { return m_windowProxyManager->isolate(); } | |
140 | |
141 LocalWindowProxyManager* getWindowProxyManager() const { | |
142 return m_windowProxyManager.get(); | |
143 } | |
144 | |
145 private: | 146 private: |
146 explicit ScriptController(LocalFrame*); | 147 explicit ScriptController(LocalFrame&); |
147 | |
148 LocalFrame* frame() const { return m_windowProxyManager->frame(); } | |
149 | 148 |
150 v8::Local<v8::Value> evaluateScriptInMainWorld(const ScriptSourceCode&, | 149 v8::Local<v8::Value> evaluateScriptInMainWorld(const ScriptSourceCode&, |
151 AccessControlStatus, | 150 AccessControlStatus, |
152 ExecuteScriptPolicy); | 151 ExecuteScriptPolicy); |
153 | |
154 Member<LocalWindowProxyManager> m_windowProxyManager; | |
155 }; | 152 }; |
156 | 153 |
157 } // namespace blink | 154 } // namespace blink |
158 | 155 |
159 #endif // ScriptController_h | 156 #endif // ScriptController_h |
OLD | NEW |