Commit 0683d949 authored by eric@webkit.org's avatar eric@webkit.org

Reviewed by Cameron Zwarich.

        Move more methods from Frame into ScriptController
        https://bugs.webkit.org/show_bug.cgi?id=20294

        Finally finish more of the work which Darin started long ago
        Move a few more Frame methods into ScriptController.
        I also took this opportunity to clean up some of the plugin
        code as well, and moved some of that into ScriptController.

        I removed Frame::clearScriptController() and ScriptController::clear() is now clearWindowShell()

        No functional changes, thus no test cases.

        * GNUmakefile.am:
        * WebCore.NPAPI.exp:
        * WebCore.base.exp:
        * WebCore.pro:
        * WebCore.vcproj/WebCore.vcproj:
        * WebCore.xcodeproj/project.pbxproj:
        * bindings/js/ScriptController.cpp:
        (WebCore::ScriptController::ScriptController):
        (WebCore::ScriptController::~ScriptController):
        (WebCore::ScriptController::bindingRootObject):
        (WebCore::ScriptController::createRootObject):
        (WebCore::ScriptController::windowScriptNPObject):
        (WebCore::ScriptController::createScriptObjectForPluginElement): New method.
        (WebCore::ScriptController::clearPlatformScriptObjects):
        (WebCore::ScriptController::disconnectPlatformScriptObjects):
        (WebCore::ScriptController::cleanupScriptObjectsForPlugin):
        (WebCore::ScriptController::clearScriptObjects):
        * bindings/js/ScriptController.h:
        (WebCore::ScriptController::sourceURL):
        (WebCore::ScriptController::clearFormerWindow):
        * bindings/js/ScriptControllerGtk.cpp: Copied from WebCore/page/gtk/FrameGtk.cpp.
        (WebCore::Frame::createScriptInstanceForWidget):
        * bindings/js/ScriptControllerMac.mm: Added.
        (WebCore::ScriptController::createScriptInstanceForWidget):
        (WebCore::ScriptController::windowScriptObject):
        (WebCore::ScriptController::clearPlatformScriptObjects):
        (WebCore::ScriptController::disconnectPlatformScriptObjects):
        (WebCore::updateRenderingForBindings):
        (WebCore::ScriptController::initJavaJSBindings):
        * bindings/js/ScriptControllerQt.cpp: Copied from WebCore/page/gtk/FrameGtk.cpp.
        (WebCore::ScriptController::createScriptInstanceForWidget):
        * bindings/js/ScriptControllerWin.cpp: Copied from WebCore/svg/graphics/cg/SVGResourceMaskerCg.cpp.
        (WebCore::ScriptController::createScriptInstanceForWidget):
        * bindings/objc/DOM.mm:
        (-[DOMNode KJS::Bindings::]):
        * bindings/objc/DOMInternal.mm:
        (-[WebScriptObject _initializeScriptDOMNodeImp]):
        * bridge/jni/jni_jsobject.mm:
        (createRootObject):
        * html/HTMLAppletElement.cpp:
        (WebCore::HTMLAppletElement::renderWidgetForJSBindings):
        * html/HTMLAppletElement.h:
        * html/HTMLEmbedElement.cpp:
        (WebCore::findWidgetRenderer):
        (WebCore::HTMLEmbedElement::renderWidgetForJSBindings):
        * html/HTMLEmbedElement.h:
        * html/HTMLObjectElement.cpp:
        (WebCore::HTMLObjectElement::~HTMLObjectElement):
        (WebCore::HTMLObjectElement::renderWidgetForJSBindings):
        (WebCore::HTMLObjectElement::detach):
        * html/HTMLObjectElement.h:
        * html/HTMLPlugInElement.cpp:
        (WebCore::HTMLPlugInElement::~HTMLPlugInElement):
        (WebCore::HTMLPlugInElement::detach):
        (WebCore::HTMLPlugInElement::getInstance):
        (WebCore::HTMLPlugInElement::parseMappedAttribute):
        (WebCore::HTMLPlugInElement::getNPObject):
        * html/HTMLPlugInElement.h:
        * loader/FrameLoader.cpp:
        (WebCore::FrameLoader::clear):
        * page/Frame.cpp:
        (WebCore::Frame::Frame):
        (WebCore::Frame::~Frame):
        (WebCore::Frame::pageDestroyed):
        (WebCore::FramePrivate::FramePrivate):
        * page/Frame.h:
        * page/FramePrivate.h:
        * page/gtk/FrameGtk.cpp:
        * page/mac/FrameMac.mm:
        * page/qt/FrameQt.cpp:
        * page/win/FrameWin.cpp:
        (WebCore::computePageRectsForFrame):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@35590 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 61f8e9a0
2008-08-06 Eric Seidel <eric@webkit.org>
Reviewed by Cameron Zwarich.
Move more methods from Frame into ScriptController
https://bugs.webkit.org/show_bug.cgi?id=20294
Finally finish more of the work which Darin started long ago
Move a few more Frame methods into ScriptController.
I also took this opportunity to clean up some of the plugin
code as well, and moved some of that into ScriptController.
I removed Frame::clearScriptController() and ScriptController::clear() is now clearWindowShell()
No functional changes, thus no test cases.
* GNUmakefile.am:
* WebCore.NPAPI.exp:
* WebCore.base.exp:
* WebCore.pro:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/ScriptController.cpp:
(WebCore::ScriptController::ScriptController):
(WebCore::ScriptController::~ScriptController):
(WebCore::ScriptController::bindingRootObject):
(WebCore::ScriptController::createRootObject):
(WebCore::ScriptController::windowScriptNPObject):
(WebCore::ScriptController::createScriptObjectForPluginElement): New method.
(WebCore::ScriptController::clearPlatformScriptObjects):
(WebCore::ScriptController::disconnectPlatformScriptObjects):
(WebCore::ScriptController::cleanupScriptObjectsForPlugin):
(WebCore::ScriptController::clearScriptObjects):
* bindings/js/ScriptController.h:
(WebCore::ScriptController::sourceURL):
(WebCore::ScriptController::clearFormerWindow):
* bindings/js/ScriptControllerGtk.cpp: Copied from WebCore/page/gtk/FrameGtk.cpp.
(WebCore::Frame::createScriptInstanceForWidget):
* bindings/js/ScriptControllerMac.mm: Added.
(WebCore::ScriptController::createScriptInstanceForWidget):
(WebCore::ScriptController::windowScriptObject):
(WebCore::ScriptController::clearPlatformScriptObjects):
(WebCore::ScriptController::disconnectPlatformScriptObjects):
(WebCore::updateRenderingForBindings):
(WebCore::ScriptController::initJavaJSBindings):
* bindings/js/ScriptControllerQt.cpp: Copied from WebCore/page/gtk/FrameGtk.cpp.
(WebCore::ScriptController::createScriptInstanceForWidget):
* bindings/js/ScriptControllerWin.cpp: Copied from WebCore/svg/graphics/cg/SVGResourceMaskerCg.cpp.
(WebCore::ScriptController::createScriptInstanceForWidget):
* bindings/objc/DOM.mm:
(-[DOMNode KJS::Bindings::]):
* bindings/objc/DOMInternal.mm:
(-[WebScriptObject _initializeScriptDOMNodeImp]):
* bridge/jni/jni_jsobject.mm:
(createRootObject):
* html/HTMLAppletElement.cpp:
(WebCore::HTMLAppletElement::renderWidgetForJSBindings):
* html/HTMLAppletElement.h:
* html/HTMLEmbedElement.cpp:
(WebCore::findWidgetRenderer):
(WebCore::HTMLEmbedElement::renderWidgetForJSBindings):
* html/HTMLEmbedElement.h:
* html/HTMLObjectElement.cpp:
(WebCore::HTMLObjectElement::~HTMLObjectElement):
(WebCore::HTMLObjectElement::renderWidgetForJSBindings):
(WebCore::HTMLObjectElement::detach):
* html/HTMLObjectElement.h:
* html/HTMLPlugInElement.cpp:
(WebCore::HTMLPlugInElement::~HTMLPlugInElement):
(WebCore::HTMLPlugInElement::detach):
(WebCore::HTMLPlugInElement::getInstance):
(WebCore::HTMLPlugInElement::parseMappedAttribute):
(WebCore::HTMLPlugInElement::getNPObject):
* html/HTMLPlugInElement.h:
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::clear):
* page/Frame.cpp:
(WebCore::Frame::Frame):
(WebCore::Frame::~Frame):
(WebCore::Frame::pageDestroyed):
(WebCore::FramePrivate::FramePrivate):
* page/Frame.h:
* page/FramePrivate.h:
* page/gtk/FrameGtk.cpp:
* page/mac/FrameMac.mm:
* page/qt/FrameQt.cpp:
* page/win/FrameWin.cpp:
(WebCore::computePageRectsForFrame):
2008-08-05 Steve Falkenburg <sfalken@apple.com>
Fix last timer fix.
......@@ -1050,6 +1050,7 @@ webcore_sources += \
WebCore/xml/XMLSerializer.cpp
webcoregtk_sources += \
WebCore/bindings/js/ScriptControllerGtk.cpp \
WebCore/plugins/gtk/PluginDataGtk.cpp \
WebCore/plugins/gtk/PluginPackageGtk.cpp \
WebCore/plugins/gtk/PluginViewGtk.cpp
......
......@@ -16,4 +16,5 @@ __NPN_RetainObject
__NPN_SetException
__NPN_SetProperty
__NPN_UTF8FromIdentifier
__ZN7WebCore5Frame20windowScriptNPObjectEv
__ZN7WebCore16ScriptController20windowScriptNPObjectEv
__ZN7WebCore16ScriptController29cleanupScriptObjectsForPluginEPv
......@@ -167,7 +167,6 @@ __ZN7WebCore11FrameLoader4loadEPNS_14DocumentLoaderE
__ZN7WebCore11FrameLoader4loadERKNS_15ResourceRequestE
__ZN7WebCore11FrameLoader4loadERKNS_15ResourceRequestERKNS_14SubstituteDataE
__ZN7WebCore11FrameLoader4loadERKNS_15ResourceRequestERKNS_6StringE
__ZN7WebCore11FrameLoader5clearEbb
__ZN7WebCore11FrameLoader6reloadEv
__ZN7WebCore11FrameLoader7addDataEPKci
__ZN7WebCore11FrameLoader7canLoadERKNS_4KURLERKNS_6StringEPKNS_8DocumentE
......@@ -362,6 +361,7 @@ __ZN7WebCore16NavigationActionC1ERKNS_4KURLENS_13FrameLoadTypeEb
__ZN7WebCore16NavigationActionC1ERKNS_4KURLENS_14NavigationTypeE
__ZN7WebCore16NavigationActionC1Ev
__ZN7WebCore16ScriptController10initScriptEv
__ZN7WebCore16ScriptController18windowScriptObjectEv
__ZN7WebCore16colorFromNSColorEP7NSColor
__ZN7WebCore16createFullMarkupEPKNS_4NodeE
__ZN7WebCore16createFullMarkupEPKNS_5RangeE
......@@ -461,16 +461,13 @@ __ZN7WebCore5Frame13setZoomFactorEfb
__ZN7WebCore5Frame14frameForWidgetEPKNS_6WidgetE
__ZN7WebCore5Frame15sendScrollEventEv
__ZN7WebCore5Frame16adjustPageHeightEPffff
__ZN7WebCore5Frame17bindingRootObjectEv
__ZN7WebCore5Frame17setIsDisconnectedEb
__ZN7WebCore5Frame18windowScriptObjectEv
__ZN7WebCore5Frame20setSelectionFromNoneEv
__ZN7WebCore5Frame21markAllMatchesForTextERKNS_6StringEbj
__ZN7WebCore5Frame21setProhibitsScrollingEb
__ZN7WebCore5Frame24computeAndSetTypingStyleEPNS_19CSSStyleDeclarationENS_10EditActionE
__ZN7WebCore5Frame25matchLabelsAgainstElementEP7NSArrayPNS_7ElementE
__ZN7WebCore5Frame28searchForLabelsBeforeElementEP7NSArrayPNS_7ElementE
__ZN7WebCore5Frame29cleanupScriptObjectsForPluginEPv
__ZN7WebCore5Frame29forceLayoutWithPageWidthRangeEffb
__ZN7WebCore5Frame34setMarkedTextMatchesAreHighlightedEb
__ZN7WebCore5Frame4initEv
......@@ -561,6 +558,7 @@ __ZN7WebCore8FormDataD1Ev
__ZN7WebCore8IntPointC1ERK8_NSPoint
__ZN7WebCore8Settings14setJavaEnabledEb
__ZN7WebCore8Settings16setUsesPageCacheEb
__ZN7WebCore8Settings16setZoomsTextOnlyEb
__ZN7WebCore8Settings17setPluginsEnabledEb
__ZN7WebCore8Settings18setDOMPasteAllowedEb
__ZN7WebCore8Settings18setDefaultFontSizeEi
......@@ -576,7 +574,6 @@ __ZN7WebCore8Settings22setShowsURLsInToolTipsEb
__ZN7WebCore8Settings23setDefaultFixedFontSizeEi
__ZN7WebCore8Settings23setEditableLinkBehaviorENS_20EditableLinkBehaviorE
__ZN7WebCore8Settings23setUpdatesWhenOffscreenEb
__ZN7WebCore8Settings16setZoomsTextOnlyEb
__ZN7WebCore8Settings24setTextAreasAreResizableEb
__ZN7WebCore8Settings25setDeveloperExtrasEnabledEb
__ZN7WebCore8Settings25setMinimumLogicalFontSizeEi
......
......@@ -922,6 +922,7 @@ HEADERS += \
$$PWD/platform/network/qt/QNetworkReplyHandler.h
SOURCES += \
bindings/js/ScriptControllerQt.cpp \
bridge/qt/qt_class.cpp \
bridge/qt/qt_instance.cpp \
bridge/qt/qt_runtime.cpp \
......
......@@ -14182,6 +14182,10 @@
RelativePath="..\bindings\js\ScriptController.h"
>
</File>
<File
RelativePath="..\bindings\js\ScriptControllerWin.cpp"
>
</File>
<File
RelativePath="..\bindings\js\StringSourceProvider.h"
>
......
......@@ -2186,6 +2186,7 @@
A83B79550CCB0125000B0825 /* DOMSVGFontFaceElementInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = A83B79460CCB0125000B0825 /* DOMSVGFontFaceElementInternal.h */; };
A83B79560CCB0125000B0825 /* DOMSVGFontFaceElement.mm in Sources */ = {isa = PBXBuildFile; fileRef = A83B79470CCB0125000B0825 /* DOMSVGFontFaceElement.mm */; };
A83B79570CCB0125000B0825 /* DOMSVGFontFaceElement.h in Headers */ = {isa = PBXBuildFile; fileRef = A83B79480CCB0125000B0825 /* DOMSVGFontFaceElement.h */; };
A83E1C740E49042C00140B9C /* ScriptControllerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = A83E1C720E49042B00140B9C /* ScriptControllerMac.mm */; };
A84EBD780CB8C89200079609 /* JSStyleSheetListCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A84EBD770CB8C89200079609 /* JSStyleSheetListCustom.cpp */; };
A84EBD830CB8C97700079609 /* JSStyleSheetList.h in Headers */ = {isa = PBXBuildFile; fileRef = A84EBD810CB8C97700079609 /* JSStyleSheetList.h */; };
A84EBD840CB8C97700079609 /* JSStyleSheetList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A84EBD820CB8C97700079609 /* JSStyleSheetList.cpp */; };
......@@ -6520,6 +6521,7 @@
A83B79460CCB0125000B0825 /* DOMSVGFontFaceElementInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMSVGFontFaceElementInternal.h; sourceTree = "<group>"; };
A83B79470CCB0125000B0825 /* DOMSVGFontFaceElement.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMSVGFontFaceElement.mm; sourceTree = "<group>"; };
A83B79480CCB0125000B0825 /* DOMSVGFontFaceElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMSVGFontFaceElement.h; sourceTree = "<group>"; };
A83E1C720E49042B00140B9C /* ScriptControllerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ScriptControllerMac.mm; sourceTree = "<group>"; };
A84EBD770CB8C89200079609 /* JSStyleSheetListCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSStyleSheetListCustom.cpp; sourceTree = "<group>"; };
A84EBD810CB8C97700079609 /* JSStyleSheetList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSStyleSheetList.h; sourceTree = "<group>"; };
A84EBD820CB8C97700079609 /* JSStyleSheetList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSStyleSheetList.cpp; sourceTree = "<group>"; };
......@@ -12323,6 +12325,7 @@
BCA378BA0D15F64200B793D6 /* ScheduledAction.cpp */,
BCA378BB0D15F64200B793D6 /* ScheduledAction.h */,
93B70D5309EB0C7C009D8468 /* ScriptController.cpp */,
A83E1C720E49042B00140B9C /* ScriptControllerMac.mm */,
93B70D5409EB0C7C009D8468 /* ScriptController.h */,
65488D6A0DD5A83D009D83B2 /* StringSourceProvider.h */,
);
......@@ -17088,6 +17091,7 @@
BCDFD4950E30592F009D10AD /* JSXMLHttpRequestUpload.cpp in Sources */,
31288E720E3005D6003619AE /* WebKitCSSKeyframeRule.cpp in Sources */,
31288E740E3005D6003619AE /* WebKitCSSKeyframesRule.cpp in Sources */,
A83E1C740E49042C00140B9C /* ScriptControllerMac.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -29,16 +29,24 @@
#include "Frame.h"
#include "FrameLoader.h"
#include "GCController.h"
#include "JSDocument.h"
#include "JSDOMWindow.h"
#include "JSDocument.h"
#include "JSEventListener.h"
#include "npruntime_impl.h"
#include "NP_jsobject.h"
#include "Page.h"
#include "PageGroup.h"
#include "runtime_root.h"
#include "Settings.h"
#include "StringSourceProvider.h"
#include "JSEventListener.h"
#include <kjs/completion.h>
#include <kjs/debugger.h>
#if ENABLE(NETSCAPE_PLUGIN_API)
#include "HTMLPlugInElement.h"
#endif
#if ENABLE(SVG)
#include "JSSVGLazyEventListener.h"
#endif
......@@ -54,7 +62,20 @@ ScriptController::ScriptController(Frame* frame)
, m_sourceURL(0)
, m_processingTimerCallback(false)
, m_paused(false)
#if ENABLE(NETSCAPE_PLUGIN_API)
, m_windowScriptNPObject(0)
#endif
#if PLATFORM(MAC)
, m_windowScriptObject(0)
#endif
{
#if PLATFORM(MAC) && ENABLE(MAC_JAVA_BRIDGE)
static bool initializedJavaJSBindings;
if (!initializedJavaJSBindings) {
initializedJavaJSBindings = true;
initJavaJSBindings();
}
#endif
}
ScriptController::~ScriptController()
......@@ -65,6 +86,8 @@ ScriptController::~ScriptController()
// It's likely that releasing the global object has created a lot of garbage.
gcController().garbageCollectSoon();
}
disconnectPlatformScriptObjects();
}
JSValue* ScriptController::evaluate(const String& sourceURL, int baseLine, const String& str)
......@@ -101,7 +124,7 @@ JSValue* ScriptController::evaluate(const String& sourceURL, int baseLine, const
return 0;
}
void ScriptController::clear()
void ScriptController::clearWindowShell()
{
if (!m_windowShell)
return;
......@@ -215,4 +238,111 @@ void ScriptController::updateDocument()
}
Bindings::RootObject* ScriptController::bindingRootObject()
{
if (!isEnabled())
return 0;
if (!m_bindingRootObject)
m_bindingRootObject = Bindings::RootObject::create(0, globalObject());
return m_bindingRootObject.get();
}
PassRefPtr<Bindings::RootObject> ScriptController::createRootObject(void* nativeHandle)
{
RootObjectMap::iterator it = m_rootObjects.find(nativeHandle);
if (it != m_rootObjects.end())
return it->second;
RefPtr<Bindings::RootObject> rootObject = Bindings::RootObject::create(nativeHandle, globalObject());
m_rootObjects.set(nativeHandle, rootObject);
return rootObject.release();
}
#if ENABLE(NETSCAPE_PLUGIN_API)
NPObject* ScriptController::windowScriptNPObject()
{
if (!m_windowScriptNPObject) {
if (isEnabled()) {
// JavaScript is enabled, so there is a JavaScript window object.
// Return an NPObject bound to the window object.
JSObject* win = windowShell()->window();
ASSERT(win);
Bindings::RootObject* root = bindingRootObject();
m_windowScriptNPObject = _NPN_CreateScriptObject(0, win, root);
} else {
// JavaScript is not enabled, so we cannot bind the NPObject to the JavaScript window object.
// Instead, we create an NPObject of a different class, one which is not bound to a JavaScript object.
m_windowScriptNPObject = _NPN_CreateNoScriptObject();
}
}
return m_windowScriptNPObject;
}
NPObject* ScriptController::createScriptObjectForPluginElement(HTMLPlugInElement* plugin)
{
// Can't create NPObjects when JavaScript is disabled
if (!isEnabled())
return _NPN_CreateNoScriptObject();
// Create a JSObject bound to this element
ExecState* exec = globalObject()->globalExec();
JSValue* jsElementValue = toJS(exec, plugin);
if (!jsElementValue || !jsElementValue->isObject())
return _NPN_CreateNoScriptObject();
// Wrap the JSObject in an NPObject
return _NPN_CreateScriptObject(0, jsElementValue->getObject(), bindingRootObject());
}
#endif
#if !PLATFORM(MAC)
void ScriptController::clearPlatformScriptObjects()
{
}
void ScriptController::disconnectPlatformScriptObjects()
{
}
#endif
void ScriptController::cleanupScriptObjectsForPlugin(void* nativeHandle)
{
RootObjectMap::iterator it = m_rootObjects.find(nativeHandle);
if (it == m_rootObjects.end())
return;
it->second->invalidate();
m_rootObjects.remove(it);
}
void ScriptController::clearScriptObjects()
{
RootObjectMap::const_iterator end = m_rootObjects.end();
for (RootObjectMap::const_iterator it = m_rootObjects.begin(); it != end; ++it)
it->second->invalidate();
m_rootObjects.clear();
if (m_bindingRootObject) {
m_bindingRootObject->invalidate();
m_bindingRootObject = 0;
}
#if ENABLE(NETSCAPE_PLUGIN_API)
if (m_windowScriptNPObject) {
// Call _NPN_DeallocateObject() instead of _NPN_ReleaseObject() so that we don't leak if a plugin fails to release the window
// script object properly.
// This shouldn't cause any problems for plugins since they should have already been stopped and destroyed at this point.
_NPN_DeallocateObject(m_windowScriptNPObject);
m_windowScriptNPObject = 0;
}
#endif
clearPlatformScriptObjects();
}
} // namespace WebCore
......@@ -2,6 +2,7 @@
* 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
......@@ -24,19 +25,39 @@
#include "JSDOMWindowShell.h"
#include <kjs/protect.h>
#include <wtf/RefPtr.h>
#include <wtf/RetainPtr.h>
#if PLATFORM(MAC)
#ifdef __OBJC__
@class WebScriptObject;
#else
class WebScriptObject;
#endif
#endif
struct NPObject;
namespace KJS {
class JSGlobalObject;
class JSValue;
namespace Bindings {
class Instance;
class RootObject;
}
}
namespace WebCore {
class Event;
class EventListener;
class HTMLPlugInElement;
class Frame;
class Node;
class String;
class Widget;
typedef HashMap<void*, RefPtr<KJS::Bindings::RootObject> > RootObjectMap;
class ScriptController {
public:
......@@ -57,7 +78,7 @@ public:
}
KJS::JSValue* evaluate(const String& sourceURL, int baseLine, const String& code);
void clear();
PassRefPtr<EventListener> createHTMLEventHandler(const String& functionName, const String& code, Node*);
#if ENABLE(SVG)
PassRefPtr<EventListener> createSVGEventHandler(const String& functionName, const String& code, Node*);
......@@ -75,10 +96,31 @@ public:
void setPaused(bool b) { m_paused = b; }
bool isPaused() const { return m_paused; }
const String* sourceURL() const { return m_sourceURL; } // 0 if we are not evaluating any script
void clearWindowShell();
void clearFormerWindow(JSDOMWindow* window) { m_liveFormerWindows.remove(window); }
void updateDocument();
const String* sourceURL() const { return m_sourceURL; } // 0 if we are not evaluating any script
void clearScriptObjects();
void cleanupScriptObjectsForPlugin(void*);
PassRefPtr<KJS::Bindings::Instance> createScriptInstanceForWidget(Widget*);
KJS::Bindings::RootObject* bindingRootObject();
PassRefPtr<KJS::Bindings::RootObject> createRootObject(void* nativeHandle);
#if PLATFORM(MAC)
#if ENABLE(MAC_JAVA_BRIDGE)
static void initJavaJSBindings();
#endif
WebScriptObject* windowScriptObject();
#endif
#if ENABLE(NETSCAPE_PLUGIN_API)
NPObject* createScriptObjectForPluginElement(HTMLPlugInElement*);
NPObject* windowScriptNPObject();
#endif
private:
void initScriptIfNeeded()
......@@ -88,6 +130,9 @@ private:
}
void initScript();
void clearPlatformScriptObjects();
void disconnectPlatformScriptObjects();
KJS::ProtectedPtr<JSDOMWindowShell> m_windowShell;
HashSet<JSDOMWindow*> m_liveFormerWindows;
Frame* m_frame;
......@@ -96,6 +141,16 @@ private:
bool m_processingTimerCallback;
bool m_paused;
// The root object used for objects bound outside the context of a plugin.
RefPtr<KJS::Bindings::RootObject> m_bindingRootObject;
RootObjectMap m_rootObjects;
#if ENABLE(NETSCAPE_PLUGIN_API)
NPObject* m_windowScriptNPObject;
#endif
#if PLATFORM(MAC)
RetainPtr<WebScriptObject> m_windowScriptObject;
#endif
};
} // namespace WebCore
......
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
* Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com
* Copyright (C) 2007 Holger Hans Peter Freyther
* Copyright (C) 2008 Collabora Ltd. All rights reserved.
* Copyright (C) 2008 Eric Seidel <eric@webkit.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "ScriptController.h"
#include "PluginView.h"
#include "runtime_root.h"
#include "runtime.h"
namespace WebCore {
PassRefPtr<KJS::Bindings::Instance> Frame::createScriptInstanceForWidget(Widget* widget)
{
if (widget->isPluginView())
return 0;
return static_cast<PluginView*>(widget)->bindingInstance();
}
}
/*
* Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
* Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
* Copyright (C) 2007 Trolltech ASA
* Copyright (C) 2008 Eric Seidel <eric@webkit.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import "config.h"
#import "ScriptController.h"
#import "DOMAbstractViewFrame.h"
#import "DOMWindow.h"
#import "Frame.h"
#import "FrameLoader.h"
#import "FrameLoaderClient.h"
#import "JSDOMWindow.h"
#import "WebScriptObjectPrivate.h"
#import "Widget.h"
#import <JavaScriptCore/APICast.h>
#if ENABLE(NETSCAPE_PLUGIN_API)
#import "c_instance.h"
#import "NP_jsobject.h"
#import "npruntime_impl.h"
#endif
#import "objc_instance.h"
#import "runtime_root.h"
#import "runtime.h"
#if ENABLE(MAC_JAVA_BRIDGE)
#import "jni_instance.h"
#endif
@interface NSObject (WebPlugin)
- (id)objectForWebScript;
- (NPObject *)createPluginScriptableObject;
@end
using namespace KJS::Bindings;
namespace WebCore {
PassRefPtr<KJS::Bindings::Instance> ScriptController::createScriptInstanceForWidget(Widget* widget)
{
NSView* widgetView = widget->getView();
if (!widgetView)
return 0;
RefPtr<RootObject> rootObject = createRootObject(widgetView);
if ([widgetView respondsToSelector:@selector(objectForWebScript)]) {
id objectForWebScript = [widgetView objectForWebScript];
if (!objectForWebScript)
return 0;
return KJS::Bindings::ObjcInstance::create(objectForWebScript, rootObject.release());
}
if ([widgetView respondsToSelector:@selector(createPluginScriptableObject)]) {
#if !ENABLE(NETSCAPE_PLUGIN_API)
return 0;
#else
NPObject* npObject = [widgetView createPluginScriptableObject];
if (!npObject)
return 0;
RefPtr<Instance> instance = KJS::Bindings::CInstance::create(npObject, rootObject.release());
// -createPluginScriptableObject returns a retained NPObject. The caller is expected to release it.
_NPN_ReleaseObject(npObject);
return instance.release();
#endif
}
#if ENABLE(MAC_JAVA_BRIDGE)
jobject applet = m_frame->loader()->client()->javaApplet(widgetView);
if (!applet)
return 0;
return KJS::Bindings::JavaInstance::create(applet, rootObject.release());
#else
return 0;
#endif
}
WebScriptObject* ScriptController::windowScriptObject()
{
if (!isEnabled())
return 0;
if (!m_windowScriptObject) {
KJS::Bindings::RootObject* root = bindingRootObject();
m_windowScriptObject = [WebScriptObject scriptObjectForJSObject:toRef(windowShell()) originRootObject:root rootObject:root];
}
ASSERT([m_windowScriptObject.get() isKindOfClass:[DOMAbstractView class]]);
return m_windowScriptObject.get();
}
void ScriptController::clearPlatformScriptObjects()
{
if (m_windowScriptObject) {
KJS::Bindings::RootObject* root = bindingRootObject();
[m_windowScriptObject.get() _setOriginRootObject:root andRootObject:root];
}
}
void ScriptController::disconnectPlatformScriptObjects()
{
if (m_windowScriptObject) {
ASSERT([m_windowScriptObject.get() isKindOfClass:[DOMAbstractView class]]);
[(DOMAbstractView *)m_windowScriptObject.get() _disconnectFrame];