Reviewed by Geoff.
Test case for <http://bugzilla.opendarwin.org/show_bug.cgi?id=9843>:
Give Netscape plug-ins access to their own DOM element
* plugins/netscape-dom-access-expected.checksum: Added.
* plugins/netscape-dom-access-expected.png: Added.
* plugins/netscape-dom-access-expected.txt: Added.
* plugins/netscape-dom-access.html: Added.
WebCore:
Reviewed by Anders.
<http://bugzilla.opendarwin.org/show_bug.cgi?id=9843>:
Give Netscape plug-ins access to their own DOM element
* html/HTMLPlugInElement.h:
Just import JSC headers on Mac. The NPObject and Bindings::Instance stuff is only used on Mac anyway.
Changed __APPLE__ to PLATFORM(MAC).
Added m_NPObject ivar.
* html/HTMLPlugInElement.cpp:
(WebCore::HTMLPlugInElement::HTMLPlugInElement):
Initialize the NPObject.
(WebCore::HTMLPlugInElement::~HTMLPlugInElement):
Release the NPObject when the element is destroyed.
(WebCore::HTMLPlugInElement::createNPObject):
Creates an NPObject for the element.
(WebCore::HTMLPlugInElement::getNPObject):
Returns the NPObject for the element, creating and caching it if necessary.
* html/HTMLAppletElement.h:
Changed __APPLE__ to PLATFORM(MAC).
* html/HTMLAppletElement.cpp:
ditto
* html/HTMLEmbedElement.h:
ditto
* html/HTMLEmbedElement.cpp:
ditto
* html/HTMLObjectElement.h:
ditto
* html/HTMLObjectElement.cpp:
ditto
* bindings/objc/DOMPrivate.h:
Added -[DOMElement _NPObject].
* bindings/objc/DOM.mm:
(-[DOMElement _NPObject]):
Returns the NPObject for the element. Since this is only needed by the Netscape plug-in API, you can only get
the NPObject for applet, embed, and object elements.
WebKit:
Reviewed by Geoff.
<http://bugzilla.opendarwin.org/show_bug.cgi?id=9843>:
Give Netscape plug-ins access to their own DOM element
* Plugins/WebBaseNetscapePluginView.h:
* Plugins/WebBaseNetscapePluginView.m:
(-[WebBaseNetscapePluginView dealloc]):
Release DOM element.
(-[WebBaseNetscapePluginView getVariable:value:]):
Return NPObject for plugin DOM element.
* Plugins/WebNetscapePluginEmbeddedView.h:
* Plugins/WebNetscapePluginEmbeddedView.m:
(-[WebNetscapePluginEmbeddedView initWithFrame:plugin:URL:baseURL:MIMEType:attributeKeys:attributeValues:loadManually:DOMElement:]):
Now takes a DOMElement, in much the same way that WebKit plug-in views take a DOMElement.
* WebCoreSupport/WebFrameBridge.m:
(-[WebFrameBridge viewForPluginWithURL:attributeNames:attributeValues:MIMEType:DOMElement:loadManually:]):
Pass DOMElement to Netscape plug-ins.
(-[WebFrameBridge viewForJavaAppletWithFrame:attributeNames:attributeValues:baseURL:DOMElement:]):
ditto
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@15360
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2006-07-11 Tim Omernick <timo@apple.com>
+
+ Reviewed by Geoff.
+
+ Test case for <http://bugzilla.opendarwin.org/show_bug.cgi?id=9843>:
+ Give Netscape plug-ins access to their own DOM element
+
+ * plugins/netscape-dom-access-expected.checksum: Added.
+ * plugins/netscape-dom-access-expected.png: Added.
+ * plugins/netscape-dom-access-expected.txt: Added.
+ * plugins/netscape-dom-access.html: Added.
+
2006-07-11 Adele Peterson <adele@apple.com>
Reviewed by Hyatt.
--- /dev/null
+f07bf2879eb8b90f23b099c313f09e77
\ No newline at end of file
--- /dev/null
+layer at (0,0) size 800x600
+ RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+ RenderBlock {HTML} at (0,0) size 800x600
+ RenderBody {BODY} at (8,8) size 784x584
+ RenderBlock {P} at (0,0) size 784x18
+ RenderText {#text} at (0,0) size 774x18
+ text run at (0,0) width 508: "This page tests whether Netscape plug-ins can access their own DOM elements. "
+ text run at (508,0) width 266: "The plug-in should have a 3px red border."
+ RenderBlock (anonymous) at (0,34) size 784x206
+ RenderPartObject {EMBED} at (0,0) size 206x206 [border: (3px solid #FF0000)]
+ RenderText {#text} at (0,0) size 0x0
+ RenderText {#text} at (0,0) size 0x0
+ RenderText {#text} at (0,0) size 0x0
--- /dev/null
+<html>
+<head>
+<script>
+function doTest()
+{
+ // Test DOM access
+ document.getElementById("testPlugin").testDOMAccess();
+}
+</script>
+</head>
+<body onload="doTest();">
+<p>This page tests whether Netscape plug-ins can access their own DOM elements. The plug-in should have a 3px red border.</p>
+<embed id="testPlugin" type="application/x-webkit-test-netscape" width="200" height="200"></embed>
+</body>
+</html>
+2006-07-11 Tim Omernick <timo@apple.com>
+
+ Reviewed by Anders.
+
+ <http://bugzilla.opendarwin.org/show_bug.cgi?id=9843>:
+ Give Netscape plug-ins access to their own DOM element
+
+ * html/HTMLPlugInElement.h:
+ Just import JSC headers on Mac. The NPObject and Bindings::Instance stuff is only used on Mac anyway.
+ Changed __APPLE__ to PLATFORM(MAC).
+ Added m_NPObject ivar.
+ * html/HTMLPlugInElement.cpp:
+ (WebCore::HTMLPlugInElement::HTMLPlugInElement):
+ Initialize the NPObject.
+ (WebCore::HTMLPlugInElement::~HTMLPlugInElement):
+ Release the NPObject when the element is destroyed.
+ (WebCore::HTMLPlugInElement::createNPObject):
+ Creates an NPObject for the element.
+ (WebCore::HTMLPlugInElement::getNPObject):
+ Returns the NPObject for the element, creating and caching it if necessary.
+
+ * html/HTMLAppletElement.h:
+ Changed __APPLE__ to PLATFORM(MAC).
+ * html/HTMLAppletElement.cpp:
+ ditto
+ * html/HTMLEmbedElement.h:
+ ditto
+ * html/HTMLEmbedElement.cpp:
+ ditto
+ * html/HTMLObjectElement.h:
+ ditto
+ * html/HTMLObjectElement.cpp:
+ ditto
+
+ * bindings/objc/DOMPrivate.h:
+ Added -[DOMElement _NPObject].
+
+ * bindings/objc/DOM.mm:
+ (-[DOMElement _NPObject]):
+ Returns the NPObject for the element. Since this is only needed by the Netscape plug-in API, you can only get
+ the NPObject for applet, embed, and object elements.
+
2006-07-11 Adele Peterson <adele@apple.com>
Reviewed by Hyatt.
#import "FrameMac.h"
#import "HTMLDocument.h"
#import "HTMLNames.h"
+#import "HTMLPlugInElement.h"
#import "NodeFilter.h"
#import "NodeFilterCondition.h"
#import "NodeIterator.h"
return KURL(e->document()->completeURL(parseURL(e->getAttribute(name)).deprecatedString())).getNSURL();
}
+- (NPObject *)_NPObject
+{
+ Element* element = [self _element];
+ if (element->hasTagName(appletTag) || element->hasTagName(embedTag) || element->hasTagName(objectTag))
+ return static_cast<WebCore::HTMLPlugInElement*>(element)->getNPObject();
+ else
+ return 0;
+}
+
@end
//------------------------------------------------------------------------------------------
#import <WebCore/DOMRange.h>
#import <WebCore/DOMEvents.h>
+@class NPObject;
+
@interface DOMRange (WebPrivate)
// uses same algorithm as innerText
- (NSString *)_text;
- (NSFont *)_font;
- (NSData *)_imageTIFFRepresentation;
- (NSURL *)_getURLAttribute:(NSString *)name;
+- (NPObject *)_NPObject; // For subclasses to implement; we only allow NPObjects to be created for certain element types
@end
@interface DOMCSSStyleDeclaration (WebPrivate)
HTMLAppletElement::~HTMLAppletElement()
{
-#if __APPLE__
+#if PLATFORM(MAC)
// m_instance should have been cleaned up in detach().
assert(!m_instance);
#endif
return new (document()->renderArena()) RenderInline(this);
}
-#if __APPLE__
+#if PLATFORM(MAC)
KJS::Bindings::Instance *HTMLAppletElement::getInstance() const
{
Frame *frame = document()->frame();
void HTMLAppletElement::detach()
{
-#if __APPLE__
+#if PLATFORM(MAC)
m_instance = 0;
#endif
HTMLPlugInElement::detach();
#include "HTMLPlugInElement.h"
-#if __APPLE__
+#if PLATFORM(MAC)
#include <JavaScriptCore/runtime.h>
#else
namespace KJS { namespace Bindings { class Instance; } }
virtual void closeRenderer();
virtual void detach();
-#if __APPLE__
+#if PLATFORM(MAC)
virtual KJS::Bindings::Instance* getInstance() const;
#endif
HTMLEmbedElement::~HTMLEmbedElement()
{
-#if __APPLE__
+#if PLATFORM(MAC)
// m_instance should have been cleaned up in detach().
assert(!m_instance);
#endif
}
-#if __APPLE__
+#if PLATFORM(MAC)
KJS::Bindings::Instance *HTMLEmbedElement::getInstance() const
{
Frame* frame = document()->frame();
void HTMLEmbedElement::detach()
{
-#if __APPLE__
+#if PLATFORM(MAC)
m_instance = 0;
#endif
HTMLPlugInElement::detach();
#include "HTMLPlugInElement.h"
-#if __APPLE__
+#if PLATFORM(MAC)
#include <JavaScriptCore/runtime.h>
#else
namespace KJS { namespace Bindings { class Instance; } }
virtual bool isURLAttribute(Attribute*) const;
-#if __APPLE__
+#if PLATFORM(MAC)
virtual KJS::Bindings::Instance* getInstance() const;
#endif
HTMLObjectElement::~HTMLObjectElement()
{
-#if __APPLE__
+#if PLATFORM(MAC)
// m_instance should have been cleaned up in detach().
assert(!m_instance);
#endif
delete m_imageLoader;
}
-#if __APPLE__
+#if PLATFORM(MAC)
KJS::Bindings::Instance *HTMLObjectElement::getInstance() const
{
Frame* frame = document()->frame();
needWidgetUpdate = true;
}
-#if __APPLE__
+#if PLATFORM(MAC)
m_instance = 0;
#endif
HTMLPlugInElement::detach();
#include "HTMLPlugInElement.h"
-#if __APPLE__
+#if PLATFORM(MAC)
#include <JavaScriptCore/runtime.h>
#else
namespace KJS { namespace Bindings { class Instance; } }
void renderFallbackContent();
-#if __APPLE__
+#if PLATFORM(MAC)
virtual KJS::Bindings::Instance* getInstance() const;
#endif
#include "Frame.h"
#include "FrameTree.h"
#include "HTMLNames.h"
+#include "kjs_dom.h"
+#include "kjs_proxy.h"
+
+#if PLATFORM(MAC)
+#include "FrameMac.h"
+#include <JavaScriptCore/npruntime_impl.h>
+#include <JavaScriptCore/NP_jsobject.h>
+#endif
+
+using KJS::ExecState;
+using KJS::JSLock;
+using KJS::JSValue;
+using KJS::Bindings::RootObject;
namespace WebCore {
HTMLPlugInElement::HTMLPlugInElement(const QualifiedName& tagName, Document* doc)
: HTMLElement(tagName, doc)
+#if PLATFORM(MAC)
+ , m_NPObject(0)
+#endif
+{
+}
+
+HTMLPlugInElement::~HTMLPlugInElement()
{
+#if PLATFORM(MAC)
+ if (m_NPObject) {
+ _NPN_ReleaseObject(m_NPObject);
+ m_NPObject = 0;
+ }
+#endif
}
String HTMLPlugInElement::align() const
HTMLElement::detach();
}
+#if PLATFORM(MAC)
+
+NPObject* HTMLPlugInElement::createNPObject()
+{
+ // This shouldn't ever happen, but might as well check anyway
+ if (!document() || !document()->frame())
+ return _NPN_CreateNoScriptObject();
+
+ // Can't create NPObjects when JavaScript is disabled
+ Frame* frame = document()->frame();
+ if (!frame->jScriptEnabled())
+ return _NPN_CreateNoScriptObject();
+
+ // Create a JSObject bound to this element
+ JSLock lock;
+ ExecState *exec = frame->jScript()->interpreter()->globalExec();
+ JSValue* jsElementValue = toJS(exec, this);
+ if (!jsElementValue || !jsElementValue->isObject())
+ return _NPN_CreateNoScriptObject();
+
+ // Wrap the JSObject in an NPObject
+ const RootObject *executionContext = Mac(frame)->bindingRootObject();
+ return _NPN_CreateScriptObject(0, jsElementValue->getObject(), executionContext, executionContext);
+}
+
+NPObject* HTMLPlugInElement::getNPObject()
+{
+ if (!m_NPObject)
+ m_NPObject = createNPObject();
+ return m_NPObject;
+}
+
+#endif /* PLATFORM(MAC) */
+
}
#define HTMLPlugInElement_H
#include "HTMLElement.h"
-
-#if __APPLE__
+#if PLATFORM(MAC)
#include <JavaScriptCore/runtime.h>
-#else
-namespace KJS { namespace Bindings { class Instance; } }
+#include <JavaScriptCore/npruntime.h>
#endif
namespace WebCore {
{
public:
HTMLPlugInElement(const QualifiedName& tagName, Document*);
+ HTMLPlugInElement::~HTMLPlugInElement();
virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const;
virtual void parseMappedAttribute(MappedAttribute*);
String width() const;
void setWidth(const String&);
-#if __APPLE__
+#if PLATFORM(MAC)
virtual KJS::Bindings::Instance* getInstance() const = 0;
+ virtual NPObject* getNPObject();
#endif
void setFrameName(const AtomicString& frameName) { m_frameName = frameName; }
+private:
+#if PLATFORM(MAC)
+ NPObject* createNPObject();
+#endif
+
protected:
String oldNameAttr;
-#if __APPLE__
+#if PLATFORM(MAC)
mutable RefPtr<KJS::Bindings::Instance> m_instance;
+ NPObject* m_NPObject;
#endif
private:
AtomicString m_frameName;
+2006-07-11 Tim Omernick <timo@apple.com>
+
+ Reviewed by Geoff.
+
+ <http://bugzilla.opendarwin.org/show_bug.cgi?id=9843>:
+ Give Netscape plug-ins access to their own DOM element
+
+ * Plugins/WebBaseNetscapePluginView.h:
+ * Plugins/WebBaseNetscapePluginView.m:
+ (-[WebBaseNetscapePluginView dealloc]):
+ Release DOM element.
+ (-[WebBaseNetscapePluginView getVariable:value:]):
+ Return NPObject for plugin DOM element.
+
+ * Plugins/WebNetscapePluginEmbeddedView.h:
+ * Plugins/WebNetscapePluginEmbeddedView.m:
+ (-[WebNetscapePluginEmbeddedView initWithFrame:plugin:URL:baseURL:MIMEType:attributeKeys:attributeValues:loadManually:DOMElement:]):
+ Now takes a DOMElement, in much the same way that WebKit plug-in views take a DOMElement.
+
+ * WebCoreSupport/WebFrameBridge.m:
+ (-[WebFrameBridge viewForPluginWithURL:attributeNames:attributeValues:MIMEType:DOMElement:loadManually:]):
+ Pass DOMElement to Netscape plug-ins.
+ (-[WebFrameBridge viewForJavaAppletWithFrame:attributeNames:attributeValues:baseURL:DOMElement:]):
+ ditto
+
2006-07-11 Justin Garcia <justin.garcia@apple.com>
Reviewed by levi & thatcher
#import <WebKit/npfunctions.h>
#import <WebKit/npapi.h>
+@class DOMElement;
@class WebDataSource;
@class WebFrame;
@class WebNetscapePluginPackage;
BOOL isTransparent;
BOOL isCompletelyObscured;
+ DOMElement *element;
+
int32 specifiedHeight;
int32 specifiedWidth;
#import <Accelerate/Accelerate.h>
#import <JavaScriptCore/Assertions.h>
+#import <WebKit/DOMPrivate.h>
#import <WebKit/WebFrameBridge.h>
#import <WebKit/WebDataSource.h>
#import <WebKit/WebDefaultUIDelegate.h>
[MIMEType release];
[baseURL release];
[pendingFrameLoads release];
+ [element release];
ASSERT(!aglWindow);
ASSERT(!aglContext);
return NPERR_NO_ERROR;
}
+
+ case NPNVPluginElementNPObject:
+ {
+ if (!element)
+ return NPERR_GENERIC_ERROR;
+
+ NPObject *plugInScriptObject = [element _NPObject];
+
+ // Return value is expected to be retained, as described here: <http://www.mozilla.org/projects/plugins/npruntime.html#browseraccess>
+ if (plugInScriptObject)
+ _NPN_RetainObject(plugInScriptObject);
+
+ void **v = (void **)value;
+ *v = plugInScriptObject;
+
+ return NPERR_NO_ERROR;
+ }
case NPNVpluginDrawingModel:
{
MIMEType:(NSString *)MIME
attributeKeys:(NSArray *)keys
attributeValues:(NSArray *)values
- loadManually:(BOOL)loadManually;
+ loadManually:(BOOL)loadManually
+ DOMElement:(DOMElement *)anElement;
- (void)setWebFrame:(WebFrame *)webFrame;
attributeKeys:(NSArray *)keys
attributeValues:(NSArray *)values
loadManually:(BOOL)loadManually
+ DOMElement:(DOMElement *)anElement
{
[super initWithFrame:frame];
return nil;
}
[self setPlugin:thePlugin];
+
+ element = [anElement retain];
URL = [theURL retain];
MIMEType:MIMEType
attributeKeys:attributeNames
attributeValues:attributeValues
- loadManually:loadManually] autorelease];
+ loadManually:loadManually
+ DOMElement:element] autorelease];
view = embeddedView;
[_frame _addPlugInView:embeddedView];
} else
MIMEType:MIMEType
attributeKeys:attributeNames
attributeValues:attributeValues
- loadManually:NO] autorelease];
+ loadManually:NO
+ DOMElement:element] autorelease];
} else {
ASSERT_NOT_REACHED();
}