Fixed 3695730: Added support for document.embeds[], much like
authorrjw <rjw@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Jun 2004 18:09:53 +0000 (18:09 +0000)
committerrjw <rjw@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Jun 2004 18:09:53 +0000 (18:09 +0000)
document.applets[], to allow access to a plugin's exported interface.

        Reviewed by Chris.

        * khtml/dom/html_document.cpp:
        (HTMLDocument::embeds):
        * khtml/dom/html_document.h:
        * khtml/ecma/kjs_dom.cpp:
        (KJS::getRuntimeObject):
        * khtml/ecma/kjs_html.cpp:
        (KJS::HTMLDocument::tryGet):
        (KJS::HTMLElement::tryGet):
        (KJS::HTMLCollection::tryGet):
        (KJS::HTMLCollection::getNamedItems):
        * khtml/ecma/kjs_html.h:
        (KJS::HTMLDocument::):
        * khtml/ecma/kjs_html.lut.h:
        (KJS::):
        * khtml/html/html_miscimpl.cpp:
        (HTMLCollectionImpl::calcLength):
        (HTMLCollectionImpl::getItem):
        (HTMLCollectionImpl::getNamedItem):
        * khtml/html/html_miscimpl.h:
        (DOM::HTMLCollectionImpl::):
        * khtml/html/html_objectimpl.cpp:
        (HTMLEmbedElementImpl::getEmbedInstance):
        * khtml/html/html_objectimpl.h:
        * kwq/KWQKHTMLPart.h:
        * kwq/KWQKHTMLPart.mm:
        (KWQKHTMLPart::getEmbedInstanceForView):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@6864 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
WebCore/ChangeLog-2005-08-23
WebCore/khtml/dom/html_document.cpp
WebCore/khtml/dom/html_document.h
WebCore/khtml/ecma/kjs_dom.cpp
WebCore/khtml/ecma/kjs_html.cpp
WebCore/khtml/ecma/kjs_html.h
WebCore/khtml/ecma/kjs_html.lut.h
WebCore/khtml/html/html_miscimpl.cpp
WebCore/khtml/html/html_miscimpl.h
WebCore/khtml/html/html_objectimpl.cpp
WebCore/khtml/html/html_objectimpl.h
WebCore/kwq/KWQKHTMLPart.h
WebCore/kwq/KWQKHTMLPart.mm

index 024267e..d94c738 100644 (file)
@@ -1,3 +1,37 @@
+2004-06-16  Richard Williamson   <rjw@apple.com>
+
+       Fixed 3695730:  Added support for embeds[], much like
+       applets[], to allow access to a plugin's exported interface.
+
+        Reviewed by Chris.
+
+        * khtml/dom/html_document.cpp:
+        (HTMLDocument::embeds):
+        * khtml/dom/html_document.h:
+        * khtml/ecma/kjs_dom.cpp:
+        (KJS::getRuntimeObject):
+        * khtml/ecma/kjs_html.cpp:
+        (KJS::HTMLDocument::tryGet):
+        (KJS::HTMLElement::tryGet):
+        (KJS::HTMLCollection::tryGet):
+        (KJS::HTMLCollection::getNamedItems):
+        * khtml/ecma/kjs_html.h:
+        (KJS::HTMLDocument::):
+        * khtml/ecma/kjs_html.lut.h:
+        (KJS::):
+        * khtml/html/html_miscimpl.cpp:
+        (HTMLCollectionImpl::calcLength):
+        (HTMLCollectionImpl::getItem):
+        (HTMLCollectionImpl::getNamedItem):
+        * khtml/html/html_miscimpl.h:
+        (DOM::HTMLCollectionImpl::):
+        * khtml/html/html_objectimpl.cpp:
+        (HTMLEmbedElementImpl::getEmbedInstance):
+        * khtml/html/html_objectimpl.h:
+        * kwq/KWQKHTMLPart.h:
+        * kwq/KWQKHTMLPart.mm:
+        (KWQKHTMLPart::getEmbedInstanceForView):
+
 2004-06-15  Maciej Stachowiak  <mjs@apple.com>
 
         Reviewed by Dave.
index d97c258..3e4a057 100644 (file)
@@ -160,6 +160,12 @@ HTMLCollection HTMLDocument::applets() const
     return HTMLCollection(impl, HTMLCollectionImpl::DOC_APPLETS);
 }
 
+HTMLCollection HTMLDocument::embeds() const
+{
+    if(!impl) return HTMLCollection();
+    return HTMLCollection(impl, HTMLCollectionImpl::DOC_EMBEDS);
+}
+
 HTMLCollection HTMLDocument::links() const
 {
     if(!impl) return HTMLCollection();
index 81c7841..870381f 100644 (file)
@@ -157,6 +157,13 @@ public:
     HTMLCollection applets() const;
 
     /**
+     * A collection of all the <embed> OBJECT </embed> elements that
+     * include embedded elements in a document.
+     *
+     */
+    HTMLCollection embeds() const;
+
+    /**
      * A collection of all <code> AREA </code> elements and anchor (
      * <code> A </code> ) elements in a document with a value for the
      * <code> href </code> attribute.
index 13f93b6..b65e4d9 100644 (file)
@@ -41,6 +41,8 @@
 
 #include "html_objectimpl.h"
 
+#include "misc/htmltags.h"
+
 #if APPLE_CHANGES
 #include <JavaScriptCore/runtime_object.h>
 #endif
@@ -1523,12 +1525,25 @@ Value KJS::getDOMNamedNodeMap(ExecState *exec, const DOM::NamedNodeMap &m)
 Value KJS::getRuntimeObject(ExecState *exec, const DOM::Node &node)
 {
     DOM::HTMLElement element = static_cast<DOM::HTMLElement>(node);
-    DOM::HTMLAppletElementImpl *appletElement = static_cast<DOM::HTMLAppletElementImpl *>(element.handle());
-    
-    if (appletElement->getAppletInstance()) {
-        // The instance is owned by the applet element.
-        RuntimeObjectImp *appletImp = new RuntimeObjectImp(appletElement->getAppletInstance(), false);
-        return Value(appletImp);
+
+    if (!node.isNull()) {
+        if (node.handle()->id() == ID_APPLET) {
+            DOM::HTMLAppletElementImpl *appletElement = static_cast<DOM::HTMLAppletElementImpl *>(element.handle());
+            
+            if (appletElement->getAppletInstance()) {
+                // The instance is owned by the applet element.
+                RuntimeObjectImp *appletImp = new RuntimeObjectImp(appletElement->getAppletInstance(), false);
+                return Value(appletImp);
+            }
+        }
+        else if (node.handle()->id() == ID_EMBED) {
+            DOM::HTMLEmbedElementImpl *embedElement = static_cast<DOM::HTMLEmbedElementImpl *>(element.handle());
+            
+            if (embedElement->getEmbedInstance()) {
+                RuntimeObjectImp *runtimeImp = new RuntimeObjectImp(embedElement->getEmbedInstance(), false);
+                return Value(runtimeImp);
+            }
+        }
     }
     return Undefined();
 }
index d35d762..f306ed8 100644 (file)
@@ -139,6 +139,7 @@ const ClassInfo KJS::HTMLDocument::info =
   location             HTMLDocument::Location          DontDelete
   cookie               HTMLDocument::Cookie            DontDelete
   images               HTMLDocument::Images            DontDelete|ReadOnly
+  embeds               HTMLDocument::Embeds            DontDelete|ReadOnly
   applets              HTMLDocument::Applets           DontDelete|ReadOnly
   links                        HTMLDocument::Links             DontDelete|ReadOnly
   forms                        HTMLDocument::Forms             DontDelete|ReadOnly
@@ -225,6 +226,8 @@ Value KJS::HTMLDocument::tryGet(ExecState *exec, const Identifier &propertyName)
       return String(doc.cookie());
     case Images:
       return getHTMLCollection(exec,doc.images());
+    case Embeds:
+      return getHTMLCollection(exec,doc.embeds());
     case Applets:
       return getHTMLCollection(exec,doc.applets());
     case Links:
@@ -284,6 +287,7 @@ Value KJS::HTMLDocument::tryGet(ExecState *exec, const Identifier &propertyName)
       return String(body.dir());
     }
   }
+
   if (DOMDocument::hasProperty(exec, propertyName))
     return DOMDocument::tryGet(exec, propertyName);
 
@@ -299,6 +303,12 @@ Value KJS::HTMLDocument::tryGet(ExecState *exec, const Identifier &propertyName)
     if (!anApplet.isNull()) {
         return getRuntimeObject(exec,anApplet);
     }
+
+    DOM::HTMLCollection embeds = doc.embeds();
+    DOM::HTMLElement anEmbed = embeds.namedItem (propertyName.string());
+    if (!anEmbed.isNull()) {
+        return getRuntimeObject(exec,anEmbed);
+    }
 #endif
 
   DOM::HTMLDocumentImpl *docImpl = static_cast<DOM::HTMLDocumentImpl*>(node.handle());
@@ -1139,6 +1149,7 @@ Value KJS::HTMLElement::tryGet(ExecState *exec, const Identifier &propertyName)
     }
       break;
 #if APPLE_CHANGES
+    case ID_EMBED:
     case ID_APPLET: {
         return getRuntimeObject(exec,element);
     }
@@ -2962,7 +2973,7 @@ Value KJS::HTMLCollection::tryGet(ExecState *exec, const Identifier &propertyNam
       DOM::Node node = collection.item(u);
 
 #if APPLE_CHANGES
-        if (!node.isNull() && node.handle()->id() == ID_APPLET) {
+        if (!node.isNull() && (node.handle()->id() == ID_APPLET || node.handle()->id() == ID_EMBED)) {
             return getRuntimeObject(exec,node);
         }
 #endif
@@ -3049,7 +3060,7 @@ Value KJS::HTMLCollection::getNamedItems(ExecState *exec, const Identifier &prop
       kdDebug(6070) << "returning single node" << endl;
 #endif
 #if APPLE_CHANGES
-         if (!node.isNull() && node.handle()->id() == ID_APPLET) {
+         if (!node.isNull() && (node.handle()->id() == ID_APPLET || node.handle()->id() == ID_EMBED)) {
            return getRuntimeObject(exec,node);
          }
 #endif
index 62c70f9..5f29d52 100644 (file)
@@ -47,7 +47,7 @@ namespace KJS {
     virtual const ClassInfo* classInfo() const { return &info; }
     static const ClassInfo info;
     enum { Title, Referrer, Domain, URL, Body, Location, Cookie,
-           Images, Applets, Links, Forms, Anchors, Scripts, All, Clear, Open, Close,
+           Images, Applets, Embeds, Links, Forms, Anchors, Scripts, All, Clear, Open, Close,
            Write, WriteLn, GetElementsByName, CaptureEvents, ReleaseEvents,
            BgColor, FgColor, AlinkColor, LinkColor, VlinkColor, LastModified, Height, Width, Dir, DesignMode };
     DOM::Document toDocument() const { return static_cast<DOM::Document>( node ); }
index 216bfc5..7ec6f8a 100644 (file)
@@ -6,13 +6,13 @@ const struct HashEntry HTMLDocumentTableEntries[] = {
    { "images", HTMLDocument::Images, DontDelete|ReadOnly, 0, &HTMLDocumentTableEntries[31] },
    { 0, 0, 0, 0, 0 },
    { "domain", HTMLDocument::Domain, DontDelete, 0, 0 },
-   { "URL", HTMLDocument::URL, DontDelete|ReadOnly, 0, &HTMLDocumentTableEntries[37] },
-   { "cookie", HTMLDocument::Cookie, DontDelete, 0, &HTMLDocumentTableEntries[38] },
-   { "links", HTMLDocument::Links, DontDelete|ReadOnly, 0, &HTMLDocumentTableEntries[33] },
+   { "URL", HTMLDocument::URL, DontDelete|ReadOnly, 0, &HTMLDocumentTableEntries[38] },
+   { "cookie", HTMLDocument::Cookie, DontDelete, 0, &HTMLDocumentTableEntries[39] },
+   { "links", HTMLDocument::Links, DontDelete|ReadOnly, 0, &HTMLDocumentTableEntries[34] },
    { "title", HTMLDocument::Title, DontDelete, 0, 0 },
    { "lastModified", HTMLDocument::LastModified, DontDelete|ReadOnly, 0, 0 },
    { 0, 0, 0, 0, 0 },
-   { "clear", HTMLDocument::Clear, DontDelete|Function, 0, &HTMLDocumentTableEntries[36] },
+   { "clear", HTMLDocument::Clear, DontDelete|Function, 0, &HTMLDocumentTableEntries[37] },
    { "body", HTMLDocument::Body, DontDelete, 0, 0 },
    { "applets", HTMLDocument::Applets, DontDelete|ReadOnly, 0, &HTMLDocumentTableEntries[30] },
    { 0, 0, 0, 0, 0 },
@@ -27,15 +27,16 @@ const struct HashEntry HTMLDocumentTableEntries[] = {
    { "referrer", HTMLDocument::Referrer, DontDelete|ReadOnly, 0, 0 },
    { "bgColor", HTMLDocument::BgColor, DontDelete, 0, 0 },
    { "writeln", HTMLDocument::WriteLn, DontDelete|Function, 1, 0 },
-   { "close", HTMLDocument::Close, DontDelete|Function, 0, 0 },
+   { "embeds", HTMLDocument::Embeds, DontDelete|ReadOnly, 0, &HTMLDocumentTableEntries[32] },
    { 0, 0, 0, 0, 0 },
-   { "scripts", HTMLDocument::Scripts, DontDelete|ReadOnly, 0, &HTMLDocumentTableEntries[34] },
+   { "scripts", HTMLDocument::Scripts, DontDelete|ReadOnly, 0, &HTMLDocumentTableEntries[35] },
    { 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0 },
-   { "forms", HTMLDocument::Forms, DontDelete|ReadOnly, 0, &HTMLDocumentTableEntries[32] },
+   { "forms", HTMLDocument::Forms, DontDelete|ReadOnly, 0, &HTMLDocumentTableEntries[33] },
    { "anchors", HTMLDocument::Anchors, DontDelete|ReadOnly, 0, 0 },
-   { "getElementsByName", HTMLDocument::GetElementsByName, DontDelete|Function, 1, &HTMLDocumentTableEntries[35] },
+   { "close", HTMLDocument::Close, DontDelete|Function, 0, 0 },
+   { "getElementsByName", HTMLDocument::GetElementsByName, DontDelete|Function, 1, &HTMLDocumentTableEntries[36] },
    { "captureEvents", HTMLDocument::CaptureEvents, DontDelete|Function, 0, 0 },
    { "fgColor", HTMLDocument::FgColor, DontDelete, 0, 0 },
    { "linkColor", HTMLDocument::LinkColor, DontDelete, 0, 0 },
@@ -44,7 +45,7 @@ const struct HashEntry HTMLDocumentTableEntries[] = {
    { "width", HTMLDocument::Width, DontDelete|ReadOnly, 0, 0 }
 };
 
-const struct HashTable HTMLDocumentTable = { 2, 39, HTMLDocumentTableEntries, 30 };
+const struct HashTable HTMLDocumentTable = { 2, 40, HTMLDocumentTableEntries, 30 };
 
 } // namespace
 
index a94900f..7384993 100644 (file)
@@ -112,6 +112,10 @@ unsigned long HTMLCollectionImpl::calcLength(NodeImpl *current) const
                 if(e->id() == ID_OBJECT || e->id() == ID_APPLET)
                     len++;
                 break;
+            case DOC_EMBEDS:   // all EMBED elements
+                if(e->id() == ID_EMBED)
+                    len++;
+                break;
             case DOC_LINKS:     // all A _and_ AREA elements with a value for href
                 if(e->id() == ID_A || e->id() == ID_AREA)
                     if(!e->getAttribute(ATTR_HREF).isNull())
@@ -197,6 +201,10 @@ NodeImpl *HTMLCollectionImpl::getItem(NodeImpl *current, int index, int &len) co
                 if(e->id() == ID_OBJECT || e->id() == ID_APPLET)
                     len++;
                 break;
+            case DOC_EMBEDS:   // all EMBED elements
+                if(e->id() == ID_EMBED)
+                    len++;
+                break;
             case DOC_LINKS:     // all A _and_ AREA elements with a value for href
                 if(e->id() == ID_A || e->id() == ID_AREA)
                     if(!e->getAttribute(ATTR_HREF).isNull())
@@ -321,6 +329,10 @@ NodeImpl *HTMLCollectionImpl::getNamedItem( NodeImpl *current, int attr_id,
                 if(e->id() == ID_OBJECT || e->id() == ID_APPLET)
                     check = true;
                 break;
+            case DOC_EMBEDS:   // all EMBED elements
+                if(e->id() == ID_EMBED)
+                    check = true;
+                break;
             case DOC_LINKS:     // all A _and_ AREA elements with a value for href
                 if(e->id() == ID_A || e->id() == ID_AREA)
                     if(!e->getAttribute(ATTR_HREF).isNull())
index 9a519ac..7aae6c4 100644 (file)
@@ -52,6 +52,7 @@ public:
         // from HTMLDocument
         DOC_IMAGES,    // all IMG elements in the document
         DOC_APPLETS,   // all OBJECT and APPLET elements
+        DOC_EMBEDS,   // all EMBED elements
         DOC_FORMS,     // all FORMS
         DOC_LINKS,     // all A _and_ AREA elements with a value for href
         DOC_ANCHORS,      // all A elements with a value for name
index 96282dd..3ca4928 100644 (file)
@@ -227,6 +227,29 @@ NodeImpl::Id HTMLEmbedElementImpl::id() const
     return ID_EMBED;
 }
 
+#if APPLE_CHANGES
+KJS::Bindings::Instance *HTMLEmbedElementImpl::getEmbedInstance() const
+{
+    KHTMLPart* part = getDocument()->part();
+    if (!part)
+        return 0;
+
+    if (embedInstance)
+        return embedInstance;
+    
+    RenderPartObject *r = static_cast<RenderPartObject*>(m_render);
+    if (r) {
+        if (r->widget()){
+            // Call into the part (and over the bridge) to pull the Bindings::Instance
+            // from the guts of the Java VM.
+            void *_view = r->widget()->getView();
+            embedInstance = KWQ(part)->getEmbedInstanceForView((NSView *)_view);
+        }
+    }
+    return embedInstance;
+}
+#endif
+
 bool HTMLEmbedElementImpl::mapToEntry(NodeImpl::Id attr, MappedAttributeEntry& result) const
 {
     switch (attr) {
index 9798f0f..0c18901 100644 (file)
@@ -70,7 +70,9 @@ protected:
     khtml::VAlign valign;
 
 private:
+#if APPLE_CHANGES
     mutable KJS::Bindings::Instance *appletInstance;
+#endif
 };
 
 // -------------------------------------------------------------------------
@@ -93,9 +95,18 @@ public:
     
     virtual bool isURLAttribute(AttributeImpl *attr) const;
 
+#if APPLE_CHANGES
+    KJS::Bindings::Instance *getEmbedInstance() const;
+#endif
+
     QString url;
     QString pluginPage;
     QString serviceType;
+
+#if APPLE_CHANGES
+private:
+    mutable KJS::Bindings::Instance *embedInstance;
+#endif
 };
 
 // -------------------------------------------------------------------------
index 9678c8d..98537c9 100644 (file)
@@ -284,6 +284,7 @@ public:
     void didTellBridgeAboutLoad(const QString &urlString);
     bool haveToldBridgeAboutLoad(const QString &urlString);
 
+    KJS::Bindings::Instance *getEmbedInstanceForView (NSView *aView);
     KJS::Bindings::Instance *getAppletInstanceForView (NSView *aView);
     void addPluginRootObject(const KJS::Bindings::RootObject *root);
     void cleanupPluginRootObjects();
index 3ad1879..5b9f00c 100644 (file)
@@ -3277,6 +3277,20 @@ KJS::Bindings::Instance *KWQKHTMLPart::getAppletInstanceForView (NSView *aView)
     return 0;
 }
 
+@interface NSObject (WebPlugIn)
+- (id)objectForWebScript;
+@end
+
+KJS::Bindings::Instance *KWQKHTMLPart::getEmbedInstanceForView (NSView *aView)
+{
+    if ([aView respondsToSelector:@selector(objectForWebScript)]){
+        id object = [aView objectForWebScript];
+        if (object)
+            return KJS::Bindings::Instance::createBindingForLanguageInstance (KJS::Bindings::Instance::ObjectiveCLanguage, object);
+    }
+    return 0;
+}
+
 void KWQKHTMLPart::addPluginRootObject(const KJS::Bindings::RootObject *root)
 {
     rootObjects.append (root);