Chromium Code Reviews| 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 29 matching lines...) Expand all Loading... | |
| 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 blink { | 47 namespace blink { |
| 48 | 48 |
| 49 class CompiledScript; | 49 class CompiledScript; |
| 50 class DOMWrapperWorld; | |
| 51 class Element; | 50 class Element; |
| 52 class KURL; | 51 class KURL; |
| 53 class ScriptSourceCode; | 52 class ScriptSourceCode; |
| 54 class SecurityOrigin; | 53 class SecurityOrigin; |
| 55 class Widget; | 54 class Widget; |
| 56 | 55 |
| 57 typedef WTF::Vector<v8::Extension*> V8Extensions; | 56 typedef WTF::Vector<v8::Extension*> V8Extensions; |
| 58 | 57 |
| 59 enum ReasonForCallingCanExecuteScripts { | 58 enum ReasonForCallingCanExecuteScripts { |
| 60 AboutToExecuteScript, | 59 AboutToExecuteScript, |
| 61 NotAboutToExecuteScript | 60 NotAboutToExecuteScript |
| 62 }; | 61 }; |
| 63 | 62 |
| 64 class CORE_EXPORT ScriptController final | 63 class CORE_EXPORT ScriptController final : public LocalWindowProxyManager { |
|
Yuki
2017/01/13 10:42:00
If possible, could you elaborate what ScriptContro
dcheng
2017/01/13 18:57:30
Done.
| |
| 65 : public GarbageCollected<ScriptController> { | |
| 66 WTF_MAKE_NONCOPYABLE(ScriptController); | 64 WTF_MAKE_NONCOPYABLE(ScriptController); |
| 67 | 65 |
| 68 public: | 66 public: |
| 69 enum ExecuteScriptPolicy { | 67 enum ExecuteScriptPolicy { |
| 70 ExecuteScriptWhenScriptsDisabled, | 68 ExecuteScriptWhenScriptsDisabled, |
| 71 DoNotExecuteScriptWhenScriptsDisabled | 69 DoNotExecuteScriptWhenScriptsDisabled |
| 72 }; | 70 }; |
| 73 | 71 |
| 74 static ScriptController* create(LocalFrame* frame) { | 72 static ScriptController* create(LocalFrame& frame) { |
| 75 return new ScriptController(frame); | 73 return new ScriptController(frame); |
| 76 } | 74 } |
| 77 | 75 |
| 78 DECLARE_TRACE(); | |
| 79 | |
| 80 // This returns an initialized window proxy. (If the window proxy is not | |
| 81 // yet initialized, it's implicitly initialized at the first access.) | |
| 82 LocalWindowProxy* windowProxy(DOMWrapperWorld&); | |
| 83 | |
| 84 // Evaluate JavaScript in the main world. | 76 // Evaluate JavaScript in the main world. |
| 85 void executeScriptInMainWorld( | 77 void executeScriptInMainWorld( |
| 86 const String&, | 78 const String&, |
| 87 ExecuteScriptPolicy = DoNotExecuteScriptWhenScriptsDisabled); | 79 ExecuteScriptPolicy = DoNotExecuteScriptWhenScriptsDisabled); |
| 88 void executeScriptInMainWorld(const ScriptSourceCode&, | 80 void executeScriptInMainWorld(const ScriptSourceCode&, |
| 89 AccessControlStatus = NotSharableCrossOrigin); | 81 AccessControlStatus = NotSharableCrossOrigin); |
| 90 v8::Local<v8::Value> executeScriptInMainWorldAndReturnValue( | 82 v8::Local<v8::Value> executeScriptInMainWorldAndReturnValue( |
| 91 const ScriptSourceCode&, | 83 const ScriptSourceCode&, |
| 92 ExecuteScriptPolicy = DoNotExecuteScriptWhenScriptsDisabled); | 84 ExecuteScriptPolicy = DoNotExecuteScriptWhenScriptsDisabled); |
| 93 v8::Local<v8::Value> executeScriptAndReturnValue( | 85 v8::Local<v8::Value> executeScriptAndReturnValue( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 | 117 |
| 126 PassRefPtr<SharedPersistent<v8::Object>> createPluginWrapper(Widget*); | 118 PassRefPtr<SharedPersistent<v8::Object>> createPluginWrapper(Widget*); |
| 127 | 119 |
| 128 void enableEval(); | 120 void enableEval(); |
| 129 void disableEval(const String& errorMessage); | 121 void disableEval(const String& errorMessage); |
| 130 | 122 |
| 131 bool canExecuteScripts(ReasonForCallingCanExecuteScripts); | 123 bool canExecuteScripts(ReasonForCallingCanExecuteScripts); |
| 132 | 124 |
| 133 TextPosition eventHandlerPosition() const; | 125 TextPosition eventHandlerPosition() const; |
| 134 | 126 |
| 135 void clearWindowProxy(); | 127 void clearForClose(); |
| 128 void clearForNavigation(); | |
| 136 void updateDocument(); | 129 void updateDocument(); |
| 137 | |
| 138 void updateSecurityOrigin(SecurityOrigin*); | 130 void updateSecurityOrigin(SecurityOrigin*); |
| 139 | 131 |
| 140 void clearForClose(); | |
| 141 | |
| 142 // Registers a v8 extension to be available on webpages. Will only | 132 // Registers a v8 extension to be available on webpages. Will only |
| 143 // affect v8 contexts initialized after this call. Takes ownership of | 133 // affect v8 contexts initialized after this call. Takes ownership of |
| 144 // the v8::Extension object passed. | 134 // the v8::Extension object passed. |
| 145 static void registerExtensionIfNeeded(v8::Extension*); | 135 static void registerExtensionIfNeeded(v8::Extension*); |
| 146 static V8Extensions& registeredExtensions(); | 136 static V8Extensions& registeredExtensions(); |
| 147 | 137 |
| 148 v8::Isolate* isolate() const { return m_windowProxyManager->isolate(); } | |
| 149 | |
| 150 LocalWindowProxyManager* getWindowProxyManager() const { | |
| 151 return m_windowProxyManager.get(); | |
| 152 } | |
| 153 | |
| 154 private: | 138 private: |
| 155 explicit ScriptController(LocalFrame*); | 139 explicit ScriptController(LocalFrame&); |
| 156 | |
| 157 LocalFrame* frame() const { return m_windowProxyManager->frame(); } | |
| 158 | 140 |
| 159 v8::Local<v8::Value> evaluateScriptInMainWorld(const ScriptSourceCode&, | 141 v8::Local<v8::Value> evaluateScriptInMainWorld(const ScriptSourceCode&, |
| 160 AccessControlStatus, | 142 AccessControlStatus, |
| 161 ExecuteScriptPolicy); | 143 ExecuteScriptPolicy); |
| 162 | |
| 163 Member<LocalWindowProxyManager> m_windowProxyManager; | |
| 164 }; | 144 }; |
| 165 | 145 |
| 166 } // namespace blink | 146 } // namespace blink |
| 167 | 147 |
| 168 #endif // ScriptController_h | 148 #endif // ScriptController_h |
| OLD | NEW |