18.04.2016 Views

Professional JavaScript For Web Developers

javascript for learners.

javascript for learners.

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Deployment Issues<br />

You may remember this line of code from Chapter 17, “<strong>Web</strong> Services.” This privilege was necessary in<br />

order to complete the <strong>Web</strong> Service calls. The UniversalBrowserRead privilege also allows you to<br />

access the URLs in the browser’s history, such as the following:<br />

netscape.security.PrivilegeManager.enablePrivilege(“UniversalBrowserRead”);<br />

for (var i=0; i < history.length; i++){<br />

alert(history[i]);<br />

}<br />

This script outputs the URL of each page in the browser’s history, as stored in the history object.<br />

As soon as you have completed the use of privileged actions, it’s best to disable the privilege to ensure<br />

that no malicious scripts can use the privilege:<br />

netscape.security.PrivilegeManager.enablePrivilege(“UniversalBrowserRead”);<br />

for (var i=0; i < history.length; i++){<br />

alert(history[i]);<br />

}<br />

netscape.security.PrivilegeManager.disablePrivilege(“UniversalBrowserRead”);<br />

The UniversalBrowserWrite privilege is perhaps the most interesting because it enables you to avoid<br />

the window restrictions mentioned earlier in this chapter. When this privilege is enabled, you can:<br />

❑<br />

❑<br />

❑<br />

❑<br />

Resize windows to be less than 100 x 100 or greater than the user’s desktop size.<br />

Move windows off screen.<br />

Create windows without a window title.<br />

Close a window using close() regardless of how the window was opened.<br />

If a privilege is requested and not accepted, then the <strong>JavaScript</strong> Console displays a message saying,<br />

“User did not grant privilege”.<br />

Signed scripts<br />

In order to use the extended privileges, your script must be signed. <strong>JavaScript</strong> files can be signed in the<br />

same manner as applets, and doing so allows access to these privileges. Signing a script involves obtaining<br />

a digital certificate from a security firm that authenticates the script’s location, publisher, and usage.<br />

When a signed script is loaded, the browser displays a message asking if the signed script should be<br />

allowed to access the extended privileges it may use.<br />

The Mozilla Foundation provides SignTool to aid in the signing of scripts. This small utility packages a<br />

script into a JAR file along with its digital certificate. In order to use signed scripts, the containing HTML<br />

page must be accessed using a URL with the following format:<br />

jar:http://www.yourdomain.com/signedscripts.jar!/page.htm<br />

When the script is properly signed and accessed with an appropriate URL, the user just accepts the digital<br />

certificate; he is not required to allow each privilege as it is enabled.<br />

567

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!