Closed Bug 169513 Opened 22 years ago Closed 22 years ago

Add the means to obtain the DOM from a plugin

Categories

(Core Graveyard :: Plug-ins, defect, P3)

defect

Tracking

(Not tracked)

RESOLVED FIXED
mozilla1.2beta

People

(Reporter: adamlock, Assigned: peterl-bugs)

Details

(Whiteboard: [PL2:P3][DOM])

Attachments

(1 file, 1 obsolete file)

Plugins should be able to get at the DOM in some easy fashion, such as via
NPN_GetValue.

Apparantly it is possible to obtain the DOM through a tortuous hack involving a
call to NPN_GetURL, supplying a javascript: url to set a property back on the
plugin but it's nasty.
Setting out to 1.4, this is something that we should investigate and spec out.
Priority: -- → P3
Whiteboard: [PL2:P3][DOM]
Target Milestone: --- → mozilla1.4alpha
Adam,

By "it's nasty" I'm assuming you mean:
http://mozilla.org/projects/plugins/bi-directional-plugin-scripting.html .  In
addition to NPN_GetURL, there's one other proposal on the table, but it might
not be exactly what you want.  What kind of work does this block?  Could you
give us some clues as to where this would be useful?  If this blocks any of the
projects you are working on, we ought to think about re-prioritization.
Some controls ask my ActiveX plugin if it implements IHTMLDocument /
IWebBrowser, for the purposes of calculating base urls properly, navigating etc.
In order for the plugin to provide this support I need to obtain the equivalent
interfaces from from Mozilla.

I don't see a way of doing this, short of the hack. It seems to me that
obtaining the DOM is something all kinds of plugins will want to do and in fact
it was possible under LiveConnect but not now. A new property on NPN_GetValue
could solve that.
The XPCOM plugin API does provide a way of getting to the DOM node of the
element which started the plugin:

nsCOMPtr<nsIPluginInstance> inst = mPluginInstance
nsCOMPtr<nsIPluginInstancePeer> pip;
inst->GetPeer(*getter_AddRefs(pip));
nsCOMPtr<nsIPluginTagInfo2> pti2 = do_QueryInterface(pip));
if (pti2) {
  nsCOMPtr<nsIDOMElement> e;
  pti2->GetDOMElement(getter_AddRefs(e));
}

Also, is this needed in full-page mode?
I thought the XPCOM plugin api was deprecated though? If plugin vendors are
expected to code to the NPAPI it makes sense that we expose the DOM in a sane
manner to them.

I don't know offhand what the situation should be for fullpage plugins. The
plugin viewer class does appear to create a DOM document so perhaps it should be
accesible from there too, or at least the DOM window.
We can add that code in the 4x layer and return pointers through NPN_GetValue. 

How about adding these variables: 
NPNVDOMElement   
NPNVDOMDocument
NPNVDOMWindow

--->taking bug
Assignee: beppe → peterl
This sounds like a good and simple way to do it
Ian Oeschger should be in the loop, since at some point (when ready!) these
should work their way into the official write-up of the Plugin API:
http://devedge.netscape.com/library/manuals/2002/plugin/1.0/
Cc'ing Oeschger
Attached patch patch v.1 (obsolete) — Splinter Review
First patch implementing new NPAPI variables to get to the DOM.
I've tested the NPNVDOMWindow so far and it works great.

I don't see anything wrong with the other two values from an API perspective but
I will have to exercise the code to say if it works properly. I'll report back...
Status: NEW → ASSIGNED
Keywords: patch, review
Target Milestone: mozilla1.4alpha → mozilla1.2beta
NPNVDOMElement works too so fom my perspective as a NPAPI client this patch
works fine. If you wish to consider to moving the functionality out of
NPN_GetValue and into something more specialised (e.g. NPN_GetInterface) then
feel free to do so but it satisfies my requirements in its current form.

r=adamlock
Attachment #100675 - Flags: superreview+
Comment on attachment 100675 [details] [diff] [review]
patch v.1

sr=beard

BTW, you could slightly optimize this at the expense of clarity:

+	 *(nsIDOMElement**)result = e.get();
+	 NS_ADDREF(*(nsISupports**)result);

could be written as:

+	 NS_ADDREF(*(nsIDOMElement**)result = e.get());

Saves an extra derefernce of the result pointer.
changes made and patch checked into trunk, marking FIXED.

/cvsroot/mozilla/modules/plugin/base/public/npapi.h
new revision: 3.24; previous revision: 3.23

/cvsroot/mozilla/modules/plugin/base/src/ns4xPlugin.cpp
new revision: 1.93; previous revision: 1.92

We should probably document these new npapi variables for NPN_GetValue:
+  NPNVDOMElement     = 11,   /* available in Mozilla 1.2 */
+  NPNVDOMDocument    = 12,
+  NPNVDOMWindow      = 13
Status: ASSIGNED → RESOLVED
Closed: 22 years ago
Keywords: review
Resolution: --- → FIXED
It seems like NPNDOMDocument is not strictly necessary... Given a DOMNode you
can obtain its document via the 'ownerDocument' property --  this is part of the
DOM 1 spec.

Since Node.ownerDocument is already a public API do we really need to expose
another accessor via the plugin API ?

I think that exposing the DOMElement and its corrosponding window is probably
enough...

-- rick

ah, no need to expose the document. Here's a patch to remove the bloat.
Attachment #100675 - Attachment is obsolete: true
Comment on attachment 103578 [details] [diff] [review]
remove NPNVDOMDocument patch

r=av
Attachment #103578 - Flags: review+
Comment on attachment 103578 [details] [diff] [review]
remove NPNVDOMDocument patch

sr=rpotts@netscape.com
Attachment #103578 - Flags: superreview+
Comment on attachment 103578 [details] [diff] [review]
remove NPNVDOMDocument patch

a=roc+moz for trunk
Attachment #103578 - Flags: approval+
This has approval.  If it doesn't get checked in by the early morning tree
closure on Nov 5, 2002 it's going to have to wait until after the branch is cut.
that's bug 177522. feel free to complain. i've done all i can.
Product: Core → Core Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: