| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 NotAboutToExecuteScript | 66 NotAboutToExecuteScript |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 class ScriptController { | 69 class ScriptController { |
| 70 public: | 70 public: |
| 71 enum ExecuteScriptPolicy { | 71 enum ExecuteScriptPolicy { |
| 72 ExecuteScriptWhenScriptsDisabled, | 72 ExecuteScriptWhenScriptsDisabled, |
| 73 DoNotExecuteScriptWhenScriptsDisabled | 73 DoNotExecuteScriptWhenScriptsDisabled |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 ScriptController(LocalFrame*); | 76 static PassOwnPtr<ScriptController> create(LocalFrame* frame) |
| 77 { |
| 78 return adoptPtr(new ScriptController(frame)); |
| 79 } |
| 80 |
| 77 ~ScriptController(); | 81 ~ScriptController(); |
| 78 | 82 |
| 79 bool initializeMainWorld(); | 83 bool initializeMainWorld(); |
| 80 WindowProxy* windowProxy(DOMWrapperWorld&); | 84 WindowProxy* windowProxy(DOMWrapperWorld&); |
| 81 WindowProxy* existingWindowProxy(DOMWrapperWorld&); | 85 WindowProxy* existingWindowProxy(DOMWrapperWorld&); |
| 82 | 86 |
| 83 // Evaluate JavaScript in the main world. | 87 // Evaluate JavaScript in the main world. |
| 84 void executeScriptInMainWorld(const String&, ExecuteScriptPolicy = DoNotExec
uteScriptWhenScriptsDisabled); | 88 void executeScriptInMainWorld(const String&, ExecuteScriptPolicy = DoNotExec
uteScriptWhenScriptsDisabled); |
| 85 void executeScriptInMainWorld(const ScriptSourceCode&, AccessControlStatus =
NotSharableCrossOrigin, double* compilationFinishTime = 0); | 89 void executeScriptInMainWorld(const ScriptSourceCode&, AccessControlStatus =
NotSharableCrossOrigin, double* compilationFinishTime = 0); |
| 86 v8::Local<v8::Value> executeScriptInMainWorldAndReturnValue(const ScriptSour
ceCode&); | 90 v8::Local<v8::Value> executeScriptInMainWorldAndReturnValue(const ScriptSour
ceCode&); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 130 |
| 127 void clearWindowProxy(); | 131 void clearWindowProxy(); |
| 128 void updateDocument(); | 132 void updateDocument(); |
| 129 | 133 |
| 130 void namedItemAdded(HTMLDocument*, const AtomicString&); | 134 void namedItemAdded(HTMLDocument*, const AtomicString&); |
| 131 void namedItemRemoved(HTMLDocument*, const AtomicString&); | 135 void namedItemRemoved(HTMLDocument*, const AtomicString&); |
| 132 | 136 |
| 133 void updateSecurityOrigin(SecurityOrigin*); | 137 void updateSecurityOrigin(SecurityOrigin*); |
| 134 void clearScriptObjects(); | 138 void clearScriptObjects(); |
| 135 void cleanupScriptObjectsForPlugin(Widget*); | 139 void cleanupScriptObjectsForPlugin(Widget*); |
| 136 | |
| 137 void clearForClose(); | 140 void clearForClose(); |
| 138 | 141 |
| 139 NPObject* createScriptObjectForPluginElement(HTMLPlugInElement*); | 142 NPObject* createScriptObjectForPluginElement(HTMLPlugInElement*); |
| 140 NPObject* windowScriptNPObject(); | 143 NPObject* windowScriptNPObject(); |
| 141 | 144 |
| 142 // Registers a v8 extension to be available on webpages. Will only | 145 // Registers a v8 extension to be available on webpages. Will only |
| 143 // affect v8 contexts initialized after this call. Takes ownership of | 146 // affect v8 contexts initialized after this call. Takes ownership of |
| 144 // the v8::Extension object passed. | 147 // the v8::Extension object passed. |
| 145 static void registerExtensionIfNeeded(v8::Extension*); | 148 static void registerExtensionIfNeeded(v8::Extension*); |
| 146 static V8Extensions& registeredExtensions(); | 149 static V8Extensions& registeredExtensions(); |
| 147 | 150 |
| 148 void setWorldDebugId(int worldId, int debuggerId); | 151 void setWorldDebugId(int worldId, int debuggerId); |
| 149 | 152 |
| 150 v8::Isolate* isolate() const { return m_isolate; } | 153 v8::Isolate* isolate() const { return m_isolate; } |
| 151 | 154 |
| 152 private: | 155 private: |
| 156 explicit ScriptController(LocalFrame*); |
| 157 |
| 153 typedef HashMap<int, OwnPtr<WindowProxy> > IsolatedWorldMap; | 158 typedef HashMap<int, OwnPtr<WindowProxy> > IsolatedWorldMap; |
| 154 typedef HashMap<Widget*, NPObject*> PluginObjectMap; | 159 typedef HashMap<Widget*, NPObject*> PluginObjectMap; |
| 155 | 160 |
| 156 v8::Local<v8::Value> evaluateScriptInMainWorld(const ScriptSourceCode&, Acce
ssControlStatus, ExecuteScriptPolicy, double* compilationFinishTime = 0); | 161 v8::Local<v8::Value> evaluateScriptInMainWorld(const ScriptSourceCode&, Acce
ssControlStatus, ExecuteScriptPolicy, double* compilationFinishTime = 0); |
| 157 | 162 |
| 158 LocalFrame* m_frame; | 163 LocalFrame* m_frame; |
| 159 const String* m_sourceURL; | 164 const String* m_sourceURL; |
| 160 v8::Isolate* m_isolate; | 165 v8::Isolate* m_isolate; |
| 161 | 166 |
| 162 OwnPtr<WindowProxy> m_windowProxy; | 167 OwnPtr<WindowProxy> m_windowProxy; |
| 163 IsolatedWorldMap m_isolatedWorlds; | 168 IsolatedWorldMap m_isolatedWorlds; |
| 164 | 169 |
| 165 // A mapping between Widgets and their corresponding script object. | 170 // A mapping between Widgets and their corresponding script object. |
| 166 // This list is used so that when the plugin dies, we can immediately | 171 // This list is used so that when the plugin dies, we can immediately |
| 167 // invalidate all sub-objects which are associated with that plugin. | 172 // invalidate all sub-objects which are associated with that plugin. |
| 168 // The frame keeps a NPObject reference for each item on the list. | 173 // The frame keeps a NPObject reference for each item on the list. |
| 169 PluginObjectMap m_pluginObjects; | 174 PluginObjectMap m_pluginObjects; |
| 170 | 175 |
| 171 NPObject* m_windowScriptNPObject; | 176 NPObject* m_windowScriptNPObject; |
| 172 }; | 177 }; |
| 173 | 178 |
| 174 } // namespace blink | 179 } // namespace blink |
| 175 | 180 |
| 176 #endif // ScriptController_h | 181 #endif // ScriptController_h |
| OLD | NEW |