referingURI attribute not returning uri object for nsIWebNav




Embedding: APIs
16 years ago
15 years ago


(Reporter: David Epstein, Assigned: bz)



Firefox Tracking Flags

(Not tracked)




16 years ago
Mozilla 0.9.9 Gecko 20020415. TestEmbed and JS.

referingURI attribute isn't returning a uri object. Hence, can't get a uri
string using nsIURI::spec(), for input into loadURI() (4th param).

In C++, I used this code snippet:

  nsCOMPtr<nsIURI> theUri;

   rv =  qaWebNav->GetReferingURI(getter_AddRefs(theUri));

   if (!theUri) {
      QAOutput("We didn't get the refering URI. Test failed.", 2);
	  RvTestResult(rv, "GetReferingURI() test", 2);

   nsCAutoString uriString;
   rv = theUri->GetSpec(uriString);
   RvTestResult(rv, "nsIURI::GetSpec() for nsIWebNav test", 1);

It's NOT getting theURI, so it returns "We didn't get the referring URI..."

In JS, I used this snippet:

 var getRefURI = testReferingURI(webNav);
 alert("getRefURI attribute value = " + getRefURI);  (returns null)

function testReferingURI(webNav)
  if (!webNav) {
    alert("Didn't get web navigation object");
    return false;
    // Get the refering URI
  getRefURI = webNav.referingURI;
 // alert("The refering uri = " + getRefURI.spec);

  return getRefURI;     

// webNav is evaluated as real object, but getRefURI is not defined.

Comment 1

16 years ago
change qa contact to depstein
QA Contact: mdunn → depstein


15 years ago
QA Contact: depstein → carosendahl
How did you test exactly?  If there is no referring URI, then that attribute
will be null.

So what's important here is the method by which the page you're running the test
script or test C++ on was loaded.
Keywords: qawanted

Comment 3

15 years ago
This has been problematic. I've tried this with 2 methods:
1) Call webNav->LoadURI() with a nsIURI referrer object.   OR
2) NS_NewURI() with a nsIURI referrer. 
Then call rv = webNav->GetReferingURI(getter_AddRefs(theURI));
Either way, theURI returns null. Though rv succeeds. Any ideas?
Ah, OK.  Looks like the docshell simply never sets its referring URI to anything

I can fix this, but not for a few weeks... so if someone has time before then,
feel free to do it.
Assignee: rpotts → bzbarsky
Keywords: qawanted
OS: Windows NT → All
Priority: -- → P2
Hardware: PC → All
Target Milestone: --- → mozilla1.4alpha

Comment 5

15 years ago
Hi David,

Where are you getting and calling your nsIWebNavigation from?

The docshell's referring URI is set from nsDocShell::SetupRefreshURI. Despite
the misleading name, this function calls SetReferrerURI when a new URI loads
which in turn should ensure GetReferingURI returns a meanginful value. I've step
debugged this to ensure that is the case. Obviously the first page you load will
have no referring URI, so you have to click through some links to verify the

BTW, referingURI really needs to be spelt properly :) Should ensure it is before
this interface is frozen.
So.  Perhaps we should clarify in the comments that "referingURI" is only there
when the page being viewed is the result of a redirect, as opposed to being the
equivalent of the HTTP "Referer" header?

Better yet, if this is the point of that member we should rename it to something
like "redirectingURI" to make it clear what's going on, no?

Comment 7

15 years ago
No, it is properly named. The referring uri property should return you the uri
which sent you to this uri - it should correspond to the referrer value in the
page's http request. The referrer would contain for example the uri of the page
with the link you clicked on to reach this page.
OK. Then we need to fix that to be true; currently it does _not_ contain the
referring URI if the page is not the result of a redirect.

Comment 9

15 years ago
In TestEmbed (see above url) I get the nsIWebNavigation object by QI'ing off the
nsIWebBrowser object in BrowserView.cpp:

mWebNav = do_QueryInterface(mWebBrowser, &rv);

Then I pass mWebNav into the constructor of the web nav test class in
nsIWebNav.cpp and assign a local object to it:

CNsIWebNav::CNsIWebNav(nsIWebNavigation *mWebNav)
	qaWebNav = mWebNav ;

I've had no trouble accessing other methods from this interface. And rv =
qaWebNav->GetReferingURI(getter_AddRefs(theURI)) returns success. The problem is
that theURI returns null.

Comment 10

15 years ago
OK it's returning different referring URIs for successive link clicks. My
mistake was the way I was passing the referrer to LoadURI(). This code segment
will work:

   nsCOMPtr<nsIURI> theURI;
   nsCAutoString uriString, uriString2;
   uriString = "";   // the referrer
   rv = NS_NewURI(getter_AddRefs(theURI), uriString);  // we get theURI here

   uriString2 = ""; // the referred uri
   rv = qaWebNav->LoadURI(NS_ConvertASCIItoUCS2(uriString2).get(),
		nsIWebNavigation::LOAD_FLAGS_NONE, theURI, nsnull, nsnull);

   rv = qaWebNav->GetReferingURI(getter_AddRefs(theURI)); // we get theURI here
   RvTestResult(rv, "GetReferingURI() test", displayMode); // returns success

So it appears to be working OK. Sorry about not seeing this sooner. I'd say mark
this one WFM unless some other problem is detected.
Ah, nevermind.  SetupRefreshURI is always called.  Yeah, this works if there is
an actual referrer.
Last Resolved: 15 years ago
Resolution: --- → WORKSFORME

Comment 12

15 years ago
You need to log in before you can comment on or make changes to this bug.