Hi People, I'm looking for a little "Newbie Guidance" here. I've been
tasked with constructing a non-trivial toolbar for Firefox, on XP. The
problem is that my first simple experiment (other than doing Alex
Sirota's tutorial http://www.iosart.com/firefox/xpcom) in XPCOM has
hit a brick wall:
First Experiment: Write a simple XPCOM module with a method getHost
that returns, as a long, the HWND of the enclosing browser,
i.e. chrome window.
My main reason for wanting the HWND is, irrelevant really, but boils
down to desiring a unique identitfier I can use to refer to that
instance of my toolbar.
So here were the steps I took to reach my current impasse:
1. Download the mozilla source (the head as it was on 7/25/2006) and
build an optimized static version.
2. Then using the resulting build's dist/sdk and dist/include build a
little XPCOM module that gets the HWND from the read only property of
the nsIAccessibleDocument of the root document.
I can get other read only properties of the nsIAccessibleDocument,
such as the URL, but not the HWND. Aaron Leventhal was kind enough to
answer a query on mozilla.dev.accessibility that suggests, to me, that
my problems are more basic.
Now, for just a little more detail. My XPCom component has a method
called, unflatteringly, Grovel that is called from the java script (in
response to a button click) in my toolbar. My toolbar is living inside
forefox 1.5:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6)
Gecko/20060728 Firefox/1.5.0.6
The javascript call looks like:
function doMyXPCOM(){
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const cid = '@mydomain.com/MyComponent;1';
var obj = Components.classes[cid].createInstance();
obj = obj.QueryInterface(Components.interfaces.IMyComponent);
res = obj.Grovel(document);
alert('doMyXPCOM(): Grovel(document) = ' + res + '!');
} catch (err) { alert(err); return; }
}
and works like a charm if my method does something like return the
length of the URL. However whenever I try to get the HWND it crashes,
the top of the stack is a call to
xpcom_core!nsAString_internal::SetLength
with my method being the next on the stack.
To give you some idea of my cluelessness: I tried rebuilding a mozilla
with optimizations off:
ac_add_options --disable-optimize
ac_add_options --enable-debug
ac_add_options --disable-static --enable-shared
ac_add_options --disable-tests
to see if the corresponding sdk etc would give me a better clue to why
I'm in front of this brick wall with little head dints in it. But alas
even my non problematic XPCOM would not work with this build. So where
did I go wrong?
Oh, just to be complete, here is the code for my Grovel method, but I
suspect my problem lies elsewhere...
/* long Grovel (in nsIDOMNode noodle); */
NS_IMETHODIMP MyComponent::Grovel(nsIDOMNode *noodle, PRInt32
*_retval){
long retnum = 0;
nsresult rv;
nsCOMPtr<nsIAccessibleRetrieval> refp =
do_CreateInstance("@mozilla.org/accessibleRetrieval;1", &rv);
if(NS_SUCCEEDED(rv)){ retnum = 1; } else { return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIAccessible> accnode;
rv = refp->GetAccessibleFor(noodle, getter_AddRefs(accnode));
if(NS_SUCCEEDED(rv)){ retnum = 2; } else { return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIAccessibleDocument> accdocnode(
do_QueryInterface(accnode, &rv) );
if(NS_SUCCEEDED(rv)){ retnum = 3; } else { return NS_ERROR_FAILURE;
}
// this crashes:
void *wh = NULL;
rv = accdocnode->GetWindowHandle(&wh);
if(NS_SUCCEEDED(rv)){ retnum = (long)wh; } else { return
NS_ERROR_FAILURE; }
// this works fine:
// nsString aTitle;
// rv = accdocnode->GetTitle(aTitle);
// if(NS_SUCCEEDED(rv)){ retnum = 4 + aTitle.Length(); } else {
return NS_ERROR_FAILURE; }
*_retval = retnum;
return NS_OK;
}
_______________________________________________
dev-tech-xpcom mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-xpcom