• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
62 typedef HashMap<void*, RefPtr<JSC::Bindings::RootObject> > RootObjectMap;
63 
64 class ScriptController {
65 public:
66     ScriptController(Frame*);
67     ~ScriptController();
68 
haveWindowShell()69     bool haveWindowShell() const { return m_windowShell; }
windowShell()70     JSDOMWindowShell* windowShell()
71     {
72         initScriptIfNeeded();
73         return m_windowShell;
74     }
75 
globalObject()76     JSDOMWindow* globalObject()
77     {
78         initScriptIfNeeded();
79         return m_windowShell->window();
80     }
81 
82     ScriptValue evaluate(const ScriptSourceCode&);
83 
84     PassRefPtr<EventListener> createInlineEventListener(const String& functionName, const String& code, Node*);
85 #if ENABLE(SVG)
86     PassRefPtr<EventListener> createSVGEventHandler(const String& functionName, const String& code, Node*);
87 #endif
setEventHandlerLineno(int lineno)88     void setEventHandlerLineno(int lineno) { m_handlerLineno = lineno; }
89 
setProcessingTimerCallback(bool b)90     void setProcessingTimerCallback(bool b) { m_processingTimerCallback = b; }
91     bool processingUserGesture() const;
92     bool anyPageIsProcessingUserGesture() const;
93 
94     bool isEnabled();
95 
96     void attachDebugger(JSC::Debugger*);
97 
setPaused(bool b)98     void setPaused(bool b) { m_paused = b; }
isPaused()99     bool isPaused() const { return m_paused; }
100 
sourceURL()101     const String* sourceURL() const { return m_sourceURL; } // 0 if we are not evaluating any script
102 
103     void clearWindowShell();
104     void updateDocument();
105 
106     // Notifies the ScriptController that the securityOrigin of the current
107     // document was modified.  For example, this method is called when
108     // document.domain is set.  This method is *not* called when a new document
109     // is attached to a frame because updateDocument() is called instead.
110     void updateSecurityOrigin();
111 
112     void clearScriptObjects();
113     void cleanupScriptObjectsForPlugin(void*);
114 
115     void updatePlatformScriptObjects();
116 
117     PassScriptInstance createScriptInstanceForWidget(Widget*);
118     JSC::Bindings::RootObject* bindingRootObject();
119 
120     PassRefPtr<JSC::Bindings::RootObject> createRootObject(void* nativeHandle);
121 
122 #if PLATFORM(MAC)
123 #if ENABLE(MAC_JAVA_BRIDGE)
124     static void initJavaJSBindings();
125 #endif
126     WebScriptObject* windowScriptObject();
127 #endif
128 
129 #if ENABLE(NETSCAPE_PLUGIN_API)
130     NPObject* createScriptObjectForPluginElement(HTMLPlugInElement*);
131     NPObject* windowScriptNPObject();
132 #endif
133 
134 private:
initScriptIfNeeded()135     void initScriptIfNeeded()
136     {
137         if (!m_windowShell)
138             initScript();
139     }
140     void initScript();
141 
142     void disconnectPlatformScriptObjects();
143 
144     bool processingUserGestureEvent() const;
145     bool isJavaScriptAnchorNavigation() const;
146 
147     JSC::ProtectedPtr<JSDOMWindowShell> m_windowShell;
148     Frame* m_frame;
149     int m_handlerLineno;
150     const String* m_sourceURL;
151 
152     bool m_processingTimerCallback;
153     bool m_paused;
154 
155     // The root object used for objects bound outside the context of a plugin.
156     RefPtr<JSC::Bindings::RootObject> m_bindingRootObject;
157     RootObjectMap m_rootObjects;
158 #if ENABLE(NETSCAPE_PLUGIN_API)
159     NPObject* m_windowScriptNPObject;
160 #endif
161 #if PLATFORM(MAC)
162     RetainPtr<WebScriptObject> m_windowScriptObject;
163 #endif
164 };
165 
166 } // namespace WebCore
167 
168 #endif // ScriptController_h
169