3

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 :)

Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
MayaPosch
  • 315
  • 8
  • 20

1 Answers1

3

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.

Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
  • 1
    Awesome, I wish the Mozilla docs were this clear :) Maybe this answer would make for a nice addition to the Mozilla wiki? At any rate, thanks a lot for your help, Wladimir :) – MayaPosch Nov 20 '11 at 00:04
  • 1
    @MayaPosch: This article seems to give a good overview: https://developer.mozilla.org/en/Creating_XPCOM_Components/An_Overview_of_XPCOM. But - yes, it doesn't explain how the transformation from IDL files into C++ headers works exactly (particularly method name capitalization and replacing of properties). – Wladimir Palant Nov 20 '11 at 00:28
  • 1
    Thank you for that link. Looking back at my earlier attempts to get it to work I actually came close to the example you posted, just that I didn't know which string type to use. nsACString obviously can't be used. (Return) types for those IDLs aren't very clear at the best of times, to be honest :) – MayaPosch Nov 20 '11 at 10:04