1 /* 2 * Copyright (C) 1999 Harri Porten (porten@kde.org) 3 * Copyright (C) 2001 Peter Kelly (pmk@post.com) 4 * Copyright (C) 2008 Apple Inc. All rights reserved. 5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 */ 21 22 #ifndef ScriptController_h 23 #define ScriptController_h 24 25 #include "JSDOMWindowShell.h" 26 #include "ScriptInstance.h" 27 #include <runtime/Protect.h> 28 #include <wtf/RefPtr.h> 29 30 #if PLATFORM(MAC) 31 #include <wtf/RetainPtr.h> 32 33 #ifdef __OBJC__ 34 @class WebScriptObject; 35 #else 36 class WebScriptObject; 37 #endif 38 #endif 39 40 struct NPObject; 41 42 namespace JSC { 43 class JSGlobalObject; 44 45 namespace Bindings { 46 class RootObject; 47 } 48 } 49 50 namespace WebCore { 51 52 class Event; 53 class EventListener; 54 class HTMLPlugInElement; 55 class Frame; 56 class Node; 57 class ScriptSourceCode; 58 class ScriptValue; 59 class String; 60 class Widget; 61 class XSSAuditor; 62 63 typedef HashMap<void*, RefPtr<JSC::Bindings::RootObject> > RootObjectMap; 64 65 class ScriptController { 66 public: 67 ScriptController(Frame*); 68 ~ScriptController(); 69 haveWindowShell()70 bool haveWindowShell() const { return m_windowShell; } windowShell()71 JSDOMWindowShell* windowShell() 72 { 73 initScriptIfNeeded(); 74 return m_windowShell; 75 } 76 globalObject()77 JSDOMWindow* globalObject() 78 { 79 initScriptIfNeeded(); 80 return m_windowShell->window(); 81 } 82 83 ScriptValue evaluate(const ScriptSourceCode&); 84 setEventHandlerLineNumber(int lineno)85 void setEventHandlerLineNumber(int lineno) { m_handlerLineNumber = lineno; } eventHandlerLineNumber()86 int eventHandlerLineNumber() { return m_handlerLineNumber; } 87 setProcessingTimerCallback(bool b)88 void setProcessingTimerCallback(bool b) { m_processingTimerCallback = b; } 89 bool processingUserGesture() const; 90 bool anyPageIsProcessingUserGesture() const; 91 92 bool isEnabled(); 93 94 void attachDebugger(JSC::Debugger*); 95 setPaused(bool b)96 void setPaused(bool b) { m_paused = b; } isPaused()97 bool isPaused() const { return m_paused; } 98 setAllowPopupsFromPlugin(bool allowPopupsFromPlugin)99 void setAllowPopupsFromPlugin(bool allowPopupsFromPlugin) { m_allowPopupsFromPlugin = allowPopupsFromPlugin; } allowPopupsFromPlugin()100 bool allowPopupsFromPlugin() const { return m_allowPopupsFromPlugin; } 101 sourceURL()102 const String* sourceURL() const { return m_sourceURL; } // 0 if we are not evaluating any script 103 104 void clearWindowShell(); 105 void updateDocument(); 106 107 // Notifies the ScriptController that the securityOrigin of the current 108 // document was modified. For example, this method is called when 109 // document.domain is set. This method is *not* called when a new document 110 // is attached to a frame because updateDocument() is called instead. 111 void updateSecurityOrigin(); 112 113 void clearScriptObjects(); 114 void cleanupScriptObjectsForPlugin(void*); 115 116 void updatePlatformScriptObjects(); 117 118 PassScriptInstance createScriptInstanceForWidget(Widget*); 119 JSC::Bindings::RootObject* bindingRootObject(); 120 121 PassRefPtr<JSC::Bindings::RootObject> createRootObject(void* nativeHandle); 122 123 #if PLATFORM(MAC) 124 #if ENABLE(MAC_JAVA_BRIDGE) 125 static void initJavaJSBindings(); 126 #endif 127 WebScriptObject* windowScriptObject(); 128 #endif 129 130 JSC::JSObject* jsObjectForPluginElement(HTMLPlugInElement*); 131 132 #if ENABLE(NETSCAPE_PLUGIN_API) 133 NPObject* createScriptObjectForPluginElement(HTMLPlugInElement*); 134 NPObject* windowScriptNPObject(); 135 #endif 136 xssAuditor()137 XSSAuditor* xssAuditor() { return m_XSSAuditor.get(); } 138 139 private: initScriptIfNeeded()140 void initScriptIfNeeded() 141 { 142 if (!m_windowShell) 143 initScript(); 144 } 145 void initScript(); 146 147 void disconnectPlatformScriptObjects(); 148 149 bool processingUserGestureEvent() const; 150 bool isJavaScriptAnchorNavigation() const; 151 152 JSC::ProtectedPtr<JSDOMWindowShell> m_windowShell; 153 Frame* m_frame; 154 int m_handlerLineNumber; 155 const String* m_sourceURL; 156 157 bool m_processingTimerCallback; 158 bool m_paused; 159 bool m_allowPopupsFromPlugin; 160 161 // The root object used for objects bound outside the context of a plugin. 162 RefPtr<JSC::Bindings::RootObject> m_bindingRootObject; 163 RootObjectMap m_rootObjects; 164 #if ENABLE(NETSCAPE_PLUGIN_API) 165 NPObject* m_windowScriptNPObject; 166 #endif 167 #if PLATFORM(MAC) 168 RetainPtr<WebScriptObject> m_windowScriptObject; 169 #endif 170 171 // The XSSAuditor associated with this ScriptController. 172 OwnPtr<XSSAuditor> m_XSSAuditor; 173 }; 174 175 } // namespace WebCore 176 177 #endif // ScriptController_h 178