Closed Bug 451401 Opened 17 years ago Closed 17 years ago

NewAPI: Add access to underlying XPCOM objects

Categories

(Core Graveyard :: Embedding: APIs, enhancement)

enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: pelle.johnsen, Unassigned)

Details

Attachments

(1 file, 1 obsolete file)

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1 Build Identifier: It should be possible to get access to the underlying XPCOM objects for gaining using the functionality not yet provided by the new API. A couple of options for this has been suggested: (1) return a nsIWebBrowser* but this is often not the desired interface (2) return a nsISupports* and then use QueryInterface/GetInterface (3) return a nsIInterfaceRequestor* (4) have a GetInterface(const IID&, void**) directly on MozView, but this doesn't play too well with nsCOMPtr So far (3) looks most promising and allows client code like this: #include "nsIInterfaceRequestor.h" #include "nsIInterfaceRequestorUtils.h" #include "nsIDocShell.h" ... nsCOMPtr<nsIDocShell> docshell = do_GetInterface(pMozView->GetInterfaceRequestor()); Reproducible: Always Steps to Reproduce: 1. 2. 3.
Added preliminary patch for option (3)
Comment on attachment 334696 [details] [diff] [review] Patch for option (3) to add access to XPCOM r? dcamp, mfinkle
Attachment #334696 - Flags: review?(mark.finkle)
Attachment #334696 - Flags: review?(dcamp)
Shouldn't there be some API documentation saying the caller needs to release this? Or should we just be using already_AddRefed?
Hmmm, it would be nicest if the embedder didn't have to explicitly release it. But it should at least be very clear that releasing is required. Maybe it is better to have it like this: nsresult GetInterfaceRequestor(nsIInterfaceRequestor** aInterfaceRequestor) and then have embedders use getter_AddRefs As an alternative MozView could hold the raw pointer, and then we just document that it is only valid as long as the MozView instance lives.
> But it should at least be very clear that releasing is required. Right. So is there a reason we're not using already_AddRefed? Embedders can use nsCOMPtr, right?
Yes and they should if they want to use this :) The thing I don't like about already_AddRefed is that I believe it will need to #include <nsCOMPtr.h> even for embedders who are only using the new api and don't need access to xpcom. My hope was that users of the new api would only have to #include the new stuff and thus didn't have to setup the include paths needed for xpcom.
Ah. Then yeah, out param is probably better, with comments about why it's that way.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Technically, you can forward-declare template<class T> class already_AddRefed; Not sure if you actually want to, of course.
Created new patch using out param
Attachment #334696 - Attachment is obsolete: true
Attachment #336030 - Flags: review?(mark.finkle)
Attachment #334696 - Flags: review?(mark.finkle)
Attachment #334696 - Flags: review?(dcamp)
Comment on attachment 336030 [details] [diff] [review] Changed to use out param Yeah, we'll need something like this for a while.
Attachment #336030 - Flags: review?(mark.finkle) → review+
Status: NEW → RESOLVED
Closed: 17 years ago
Resolution: --- → FIXED
Product: Core → Core Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: