On 2015-01-20 11:42 AM, Tomasz wrote:

You can do something similar to the beginning of
mozilla::dom::CheckPermissions to get an nsPIDOMWindow*, and then call
GetDocumentURI() on it.

Thank you Ehsan. I tried to do that, but I did not afford to make that working. 
Probably, because I have totally no experience with Firefox code (actually, it 
is the first time I am looking at it) and I have no idea how the things are 
implemented there...

So, in mozilla-central/dom/bindings/BindingUtils.cpp, there is a function:

-----------------------------------------------------------------------
bool CheckPermissions(JSContext* aCx, JSObject* aObj, const char* const 
aPermissions[])
{
   JS::Rooted<JSObject*> rootedObj(aCx, aObj);
   nsPIDOMWindow* window = xpc::WindowGlobalOrNull(rootedObj);
-----------------------------------------------------------------------

In every file generated by the Python script 
mozilla-central/dom/bindings/Codegen.py, the function headers are a little bit 
different, for example:

-----------------------------------------------------------------------
set_border_spacing(JSContext* cx, JS::Handle<JSObject*> obj, 
nsDOMCSSDeclaration* self, JSJitSetterCallArgs args)
-----------------------------------------------------------------------

It means that the second argument is JS::Handle<JSObject*> instead of JSObject* 
as in the previous case. I found that JS::Handle is just a const reference to 
JS::Rooted, so, if I understand correctly, I should just add the following line to 
mozilla-central/dom/bindings/Codegen.py:

-----------------------------------------------------------------------
cgThings.append(CGGeneric('nsPIDOMWindow* cwindow = 
xpc::WindowGlobalOrNull(obj);\n'))
-----------------------------------------------------------------------

However, when I do that, an error appears:

-----------------------------------------------------------------------
error: cannot convert 'nsGlobalWindow*' to 'nsPIDOMWindow*' in initialization
-----------------------------------------------------------------------

So, I tried to use nsGlobalWindow* instead of nsPIDOMWindow*:

-----------------------------------------------------------------------
cgThings.append(CGGeneric('nsGlobalWindow* cwindow = 
xpc::WindowGlobalOrNull(obj);\n'))
-----------------------------------------------------------------------

and I obtained no errors from the compiler (only warnings about the unused 
variable, which is normal). However, I am not able to do anything with this 
variable. If I try any of the following lines:

-----------------------------------------------------------------------
cgThings.append(CGGeneric('nsIURI* oURI = cwindow->GetDocumentURI();\n'))
cgThings.append(CGGeneric('nsPIDOMWindow* qwerty = 
cwindow->GetPrivateParent();\n'))
-----------------------------------------------------------------------

I am obtaining 2 different errors:

-----------------------------------------------------------------------
error: invalid use of incomplete type 'class nsGlobalWindow' nsIURI* oURI = 
cwindow->GetDocumentURI();

../../dist/include/mozilla/dom/ScriptSettings.h:21:7: error: forward 
declaration of 'class nsGlobalWindow'
class nsGlobalWindow
-----------------------------------------------------------------------

Any idea what is the problem here?

You need to #include "nsGlobalWindow.h" in order to be able to use the type. Look for occurrences of CGHeaders in Codegen.py to see how to add a header #include statement to a generated bindings file.

_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to