Closed Bug 38094 Opened 25 years ago Closed 25 years ago

nsPluginHostImpl::GetURL does not work for relative URLs if target is null

Categories

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

defect

Tracking

(Not tracked)

VERIFIED FIXED

People

(Reporter: sean, Assigned: serhunt)

Details

(Keywords: testcase, Whiteboard: [nsbeta2-])

Attachments

(2 files)

A plugin calls nsIPluginManager::GetURL to programmatically load a URL. This is implemented by nsPluginHostImpl::GetURL. If the aTarget parameter of nsPluginHostImpl::GetURL is non-null, then the request is passed off to nsPluginInstanceOwner::GetURL. nsPluginInstanceOwner::GetURL creates an absolute URL from the owner's FullURL and the requested (potentially relative) URL by way of NS_MakeAbsoluteURI(). If the aTarget parameter is null and streamListener is non-null, the call is passed off to NewPluginURLStream(). NewPluginURLStream() does not turn a relative URL into an absolute URL. NewPluginURLStream() should do similar massaging of the requested URL as is done at http://lxr.mozilla.org/seamonkey/source/layout/html/base/src/nsObjectFrame.cpp#1 631.
Something along these lines - just don't know how to get the owner's full URL - see the TODO (sorry about line wraps): NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance, nsIPluginStreamListener* aListener) { nsIURI *url; nsAutoString fullurl; fullurl.Assign(aURL); nsPluginStreamListenerPeer *listenerPeer = (nsPluginStreamListenerPeer *)new nsPluginStreamListenerPeer(); if (listenerPeer == NULL) return NS_ERROR_OUT_OF_MEMORY; nsresult rv; if (aURL.Length() <= 0) return NS_OK; nsPluginInstancePeerImpl *peer; rv = aInstance->GetPeer((nsIPluginInstancePeer **)&peer); if (NS_OK == rv) { nsIPluginInstanceOwner *owner; rv = peer->GetOwner(owner); if (NS_OK == rv) { nsAutoString uniurl; uniurl.Assign(aURL); nsIURI* baseURL; // TODO: get Full URL from owner or from owner's owner // owner->mOwner->GetFullURL(baseURL); // Create an absolute URL rv = NS_MakeAbsoluteURI(fullurl, uniurl, baseURL); NS_IF_RELEASE(baseURL); NS_RELEASE(owner); } NS_RELEASE(peer); } rv = NS_NewURI(&url, fullurl);
This takes care of it: NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance, nsIPluginStreamListener* aListener) { nsIURI *url; nsAutoString absUrl; absUrl.Assign(aURL); nsPluginStreamListenerPeer *listenerPeer = (nsPluginStreamListenerPeer *)new nsPluginStreamListenerPeer(); if (listenerPeer == NULL) return NS_ERROR_OUT_OF_MEMORY; nsresult rv; if (aURL.Length() <= 0) return NS_OK; // get the full URL of the document that the plugin is embedded // in to create an absolute url in case aURL is relative nsPluginInstancePeerImpl *peer; rv = aInstance->GetPeer((nsIPluginInstancePeer **)&peer); if (NS_OK == rv) { nsIPluginInstanceOwner *owner; rv = peer->GetOwner(owner); if (NS_OK == rv) { nsCOMPtr<nsIDocument> doc; rv = owner->GetDocument(getter_AddRefs(doc)); if (NS_OK == rv) { nsCOMPtr<nsIURI> docURL( dont_AddRef(doc- >GetDocumentURL()) ); // Create an absolute URL rv = NS_MakeAbsoluteURI(absUrl, aURL, docURL); } NS_RELEASE(owner); } NS_RELEASE(peer); } rv = NS_NewURI(&url, absUrl);
sean, do you have a test case?
In the previously attached npsimple.cpp, go to line 935 for comments that explain the problem. Load the html file included in the zip using file: if you don't have the xpconnect plugin security work-around. Enter the relative path of a file you'd like the plugin to attempt to download. Trace the calls into GetURL per the comments. NewPluginURLStream fails if the path is relative. It works if it's absolute.
Status: NEW → ASSIGNED
Target Milestone: --- → M16
Keywords: patch, testcase
add 4xp keyword
Keywords: 4xp
*** Bug 42039 has been marked as a duplicate of this bug. ***
nominating nsbeta2 so that the patch can be checked in and so that xpcom plugins can be tested using an unmodified PR2 release.
Keywords: nsbeta2
nsbeta2-, but you can still checkin patches from external contributors with proper review and approval from module owner and brendan/waterson.
Whiteboard: [nsbeta2-]
Added up to date patch. It has a few more changes than the original patch: - moved a printf inside a #ifdef NS_DEBUG - made changes to my patch per comments received - applied changes to the places I copied code from - address potential leak of nsPluginStreamListenerPeer *listenerPeer in nsPluginHostImpl::NewPluginURLStream()
What should we do to get it in?
Looks good to me -- ra=brendan@mozilla.org. av, can you get this checked in? /be
Checked in. Marking fixed. Thanks, Sean.
Status: ASSIGNED → RESOLVED
Closed: 25 years ago
Resolution: --- → FIXED
marking verified.
Status: RESOLVED → VERIFIED
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: