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