atom feed8 messages in org.mozilla.lists.dev-tech-xulRe: suppressing alert prompt and conf...
FromSent OnAttachments
hadi...@gmail.comMay 29, 2008 8:26 pm 
ArivaldMay 30, 2008 12:56 am 
hadi...@gmail.comMay 30, 2008 3:02 am 
ArivaldMay 30, 2008 4:42 am 
hadi...@gmail.comMay 30, 2008 7:25 am 
hadi...@gmail.comMay 31, 2008 1:55 am 
hadi...@gmail.comMay 31, 2008 8:01 pm 
hadi...@gmail.comJun 1, 2008 7:34 pm 
Subject:Re: suppressing alert prompt and confirm.
From:hadi...@gmail.com (hadi@gmail.com)
Date:May 31, 2008 8:01:36 pm
List:org.mozilla.lists.dev-tech-xul

I search and read find out he issue for no 1.

apparently xul has a notion of trusted content and non trusted content. i modified the code a bit base on the description: <browser id="main-browser" flex="1" context="popup_content" tooltip="tooltip_content" autocompletepopup="popup_autocomplete" disablehistory="true" src="http://localhost:8080/index.html" />

note that i have removed the type attributes. according to the article i found, http://developer.mozilla.org/en/docs/XPCNativeWrapper#Deep_vs._Shallow if we have type specified to content or content-primary, it will become untrusted document and it will create a wrapper surrounding the objects. Which will means the object refer by xul main window and inside the html documents no longer the same (some one correct me if i am wrong :P).

I override the alert function using this

var windowx = document.getElementById('main-browser').contentWindow;

windowx.orgAlert = windowx.alert;

windowx.alert = function(msg) { windowx.orgAlert("New alert!\noriginal message is:\n" + msg); }

and it works, the alert inside the html content printed the new message.

But, using this has I disadvantage, trusted content has privilege to access the chrome object also. This will means that if the content providers aware that you are running using such privileges, it can hijack the chrome (main window).

My question, if we are dealing with non trusted content (when we specified type=content or type=content-primary) is there a way to access the window object via the xul main window? logically thinking, it should be able to do so, but I still need to dig around. any one with suggestion or pointer will be very much of help.

thks in advance.

On May 31, 4:55 am, hadi@gmail.com wrote:

Hi Arivald,

I have tested the code, but it seems like it doesn't work out fine. I did run it as a main window (using xulrunner.exe application.ini to start it). version 1.8.0.4

here is the result when i run it. 1. for the first solution, overriding the alert function. window.content.window.alert = some other functions..... when I tested using the window.content.window.alert ('some message') in the xul main window, it did print out the additional message i put it in. but... when the html inside the browser called alert('some message'), it does not used the alert function that I overrides. my guess is that they refer to 2 different window object when i call it using within xul and when i called it inside the html. some what the window.content.window object does not related to the window object (inside the thml documents loaded by the browser object).

2. for the document.getAnonymousNodes based on the example u gives, it will return the reference to the anon nodes. but when i uses this example codes: <?xml version="1.0"?> <?xml-stylesheet href="chrome://global/skin/" type="text/css"?> <window id="someID" title="Hello" width="600" height="600" xmlns="http://www.mozilla.org/keymaster/gatekeeper/ there.is.only.xul"> <script type="application/x-javascript"> function loadURL(browserElem,pUrl) { browserElem.setAttribute("src",pUrl);}

function checkAnonNode() { alert(document.getElementById('id1')); alert(document.getAnonymousNodes(document.getElementById('id1')));}

</script> <vbox> <tabbrowser id="id1" /> <tabbox id="tabBrowser"> <tabs> <tab label="Tab1"/> <tab label="Tab2"/> <tab label="Tab3"/> </tabs> <tabpanels width="500" height="500"> <browser id="browserTab1" src="http://www.mozilla.org"/> <browser id="browserTab2"/> <browser id="browserTab3"/> </tabpanels> </tabbox> <hbox> <button id="btnLoadBrowserContent" label="Load URL"

oncommand="loadURL(document.getElementById('browserTab2'),'http:// localhost:8080/index.html')"/> <button id="anonButtonCheck" label="Anon button check" oncommand="checkAnonNode();"/> </hbox> </vbox> </window>

the alert gives the [object XULElement] and [object NodeList] when i change the reference to the browser widget (id : browserTab1), the alert gives me [object XULElement] and null.

it seems the tabbrowser widgets and browser widgets do difference but both a returning [object XULElement] did I miss something??

On May 30, 10:25 am, hadi@gmail.com wrote:

Hi Arivald,

Thanks for the pointer. Its very detailed.

I will take sometimes to work on it to see whether in overall it can achieved what I need.

On May 30, 7:42 am, Arivald <arivald_@AT_interia_DOT_pl> wrote:

hadi@gmail.com pisze:

Thanks Arivald,

I have tested your response, but I got stuck 1. document.getElementById('content') --> this does not give the reference to the browser object, currently it return null.

You run it in Firefox? In context of main window? document.getElementById('content') will work in FF. and it return reference to <tabbrowser>, which can be used to get current active <browser>

But i saw in your other message, you post some XUL code you using your own window with your browser? so it is simpler...

<browser> with attrib type="content-primary" is always accessibe via "window.content".

I use your code it to make example for you:

<?xml version="1.0"?> <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>

<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <browser flex="1" type="content-primary" context="popup_content" tooltip="tooltip_content" autocompletepopup="popup_autocomplete" disablehistory="true" src="someinternalurls" />

<button label="show message" oncommand="go()"/> <script>

function go() { alert("Current implementation of content alert():\n\n" + window.content.window.alert); //window.content.window.alert('This is window.content.window.alert()');

//save copy window.content.window.orgAlert = window.content.window.alert; //replace window.content.window.alert = function(msg) { window.content.window.orgAlert("New alert!\noriginal message is:\n" + msg); } alert("Current implementation of content alert():\n\n" + window.content.window.alert);

//use window.content.window.alert('show some message ...');

//restore orig. window.content.window.orgAlert = window.content.window.alert; alert("Current implementation of content alert():\n\n" + window.content.window.alert);

}

</script> </window>

I tested in in "Real-time XUL Editor", part of "Extension developer" extension. BTW: it is very useful extension :-D

I recommend you to replace original alert() after content document is loaded. If you do it too early, you change may be resetted to defaults by loading code.

2. i tried to run this codes document.getAnonymousNodes(this) but it gives me errors as: [Exception... "Could not convert JavaScript argument arg 0 [nsIDOMDocumentXBL.getAnonymousedNodes]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location ...] my "this" is refer to [object ChromeWindow] I run the script under the xul window.

[object ChromeWindow] is not a DOM Element! Did you read documentation? Tryhttp://developer.mozilla.org/en/docs/Main_Page

Using "getAnonymousNodes" you may retrieve direct anonymous children of some DOM Element. Example:

<?xml version="1.0"?> <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>

<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <tabbrowser id="id1" /> <button label="show message" oncommand="go()"/> <script> function go() { alert( document.getAnonymousNodes(document.getElementById('id1')));}

</script> </window>

BTW: Did you try to inspect your window in DOM Inspector? It is *very* helpful...