Search code examples
c++interfacemozillaxpcom

nsIURI has no member 'asciiSpec', 'asciiHost', etc. error


I have made some modifications to nsMediaStream.h/cpp in the Mozilla (6.0.2) code and one of them requires that I get the ASCII string from the nsIURI class used by the Mozilla framework for representing and parsing URIs. Seems easy enough, one might think. The Mozilla documentation (https://developer.mozilla.org/en/nsIURI) tells me that I can use the attribute asciiSpec to obtain such a string. The documentation for nsACString is horribly confusing, but that's another matter.

Where things go south is that when I try to use the nsIURI variable mURI of nsMediaStream using

mURI->asciiSpec

I get the following error from the MSVC compiler:

[..]/content/media/nsMediaStream.cpp(146) :
 error C2039: 'asciiSpec' : is not a member of 'nsIURI'
        [..]\obj-i686-pc-mingw32\dist\include\nsIURI.h(83) : see declaration of 'nsIURI'

When I look at the referenced nsIURI.h file, which is generated from an interface IDL file, I see the following: http://google-web-toolkit.googlecode.com/svn/plugin-sdks/gecko-sdks/gecko-1.9.0/include/nsIURI.h

As far as I can tell said header file has no relevance at all to nsIURI as used in the Mozilla code and seems more of an interface/prototype than an actual class. None of the attributes and methods listed in the documentation are present. MSVC seems to agree with me on this.

I feel like I'm missing something big here, but even after spending months in the Mozilla source and surviving the build system I can't seem to figure this one out, nor can anyone else I have asked so far. Any clues would be more than appreciated :)


Solution

  • When using XPCOM from C++ there are no properties - all interface properties are transformed into getter/setter methods. The interface definition files (IDL files) are compiled into regular C++ header files using xpidl tool - so the file you found is the correct one but it is generated automatically. You would get asciiSpec property like this:

    nsCString spec;
    nsresult rv = mURI->GetAsciiSpec(spec);
    if (NS_FAILED(rv))
      ...  // handle error
    else
      ...  // do something with spec variable
    

    There is no SetAsciiSpec method because this property is read-only.