mozilla
Your Search Results

    Questions and answers from the newsgroups 2006 10 27

    Return to mozilla-dev-extensions


    FAQ

    (↑ top)

    How to "migrate" an existing FF extension to Thunderbird?
    Step 1: Add Thunderbird compatibility info to install.rdf.
    Step 2: Overlay messenger.xul { instead of / as well as } browser.xul.
    Step 3: Add code to fix errors that crop up now that your extension is running in Thunderbird.
    Hint: Look at how the autohidestatusbar extension (which works in Firefox, Thunderbird and seaMonkey) does it.
    Does any one know why radio button icon does not show in sidebars?
    Many widgets work in boilerplate code from simpler sidebars, but to use radio buttons one must include the browser stylesheet.
    <?xml-stylesheet href="chrome://browser/skin/browser.css" type="text/css" ?>
    needed for e.g.radio button icons
    <?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?> this is the more general solution.
    How to control window watcher?
    Not sure that it's possible to resize and move a window immediately after it's been created, you might try waiting for it to load first.
    After changed the openWindow call to
    ww.openWindow(null, url, 'Title of Window', features, null);
    was able to add events handlers and control the window. So it must of been an issue with using the browser XUL.
    How to parse the DOM?
    content.document?
    Is there a way to trigger screengrab by command line args?
    This is a standard XPCOM component. You install/use it by putting in your extension's/application's 'components' folder: http://developer.mozilla.org/en/docs/Bundles
    Whether you'll be able to "call the necessary javascript" depends on what exactly you're going to call. Do you have the actual screen grabbing code? I'd start with that rather than the cmd line handler.
    compreg.dat / xpti.dat contain information about registered components and interfaces. These files are written out by Firefox after the XPCOM registration process.
    During the registration process, Firefox looks in a few predefined places (like app's and each extension's components folder) for files that may contain components or interfaces.
    For each file that might provide components (e.g. js or binary so or dll), it tries to run its registration function, which calls back into component manager to register the components it provides (and adds them to XPCOM "categories" if needed). Each typelib (xpt) file is scanned for interfaces.
    So all you need to do is to put a specially-crafted component file in one of folders Firefox searches for components and trigger the registration process (a common way to do it when developing is to delete compreg.dat). Or just create an XPI with your component in its components/ folder and install it; autoregistration happens after installing XPIs too.
    There's a separate "scope" (different global object) for each "window" (which is not just windows in the window manager sense - see http://developer.mozilla.org/en/docs...in_chrome_c...) and for each XPCOM component.
    That extension's code most likely lives in a browser.xul overlay, meaning it's is in a different scope than your cmd line handler's code. On the other hand, the handler's code is invoked early when you can't make screen shots of the page yet. So you'll probably have to find a way to defer the handling until the browser window opens.
    How to get return value from modal dialog?
    Here's one way to do it.
    The code to open the a dialog named mydialog.xul and pass it arguments:
     var params = {inn:{name:"foo", description:"bar", enabled:true}, out:null};        
      window.openDialog("chrome://myext/chrome/mydialog.xul", "",
        "chrome, dialog, modal, resizable=yes", params).focus();
      if (params.out) {
       // user clicked ok--process changed arguments (write them to disk or whatever)
     }
    
    mydialog.xul:
     <dialog 
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 
     id="theId"   title="some title"
     ondialogaccept="return onOK();"
     onload="onLoad();"
     persist="screenX screenY width height"
     windowtype="mywintype">
     <script type="application/x-javascript" src="chrome://myext/content/mydialog.js"/>
     // xul here
    </dialog>
    
    mydialog.js:
    function onLoad() {
     sizeToContent();
     // use the arguments passed to us
     document.getElementById("name").value = window.arguments[0].inn.name;
     document.getElementById("description").value = window.arguments[0].inn.description;
     document.getElementById("enabled").checked = window.arguments[0].inn.enabled;
    }
    
    function onOK() {
      // return the changed arguments.
      // notice if user clicks cancel, window.arguments[0].out remains null
      window.arguments[0].out = {name:document.getElementById("name").value,
           description:document.getElementById("description").value,    
           enabled:document.getElementById("enabled").checked};
      return true; 
    }
    
    How to update internet search RDF?
    nsIRDFRemoteDataSource
    <http://www.xulplanet.com/references/...RDFRemoteDataS...>
    This interface appears to have several methods you can use including: void Flush ( )
    Request that a data source write it's contents out to permanent storage,if applicable.
    void Refresh ( PRBool blocking )
    
    Refresh the remote datasource, re-loading its contents from the URI.
    Arguments:
       blocking: If true, the call will block until the data source has completely reloaded. 
    
    How to build a Turkish dictionary?
    What you need is a myspell dictionary. This is the same dictionary format used by OpenOffice. I don't know whether we have any good documentation on the format, though the web probably does.
    Once you have the .aff and .dic files, let the Turkish l10n team know and

    they can create the extension using my dictionary-packager tool.

    How to call a JS function from toolbar?
    It is not recommended to do that, as it may cause security bugs. XPCNativeWrapper is the security measure preventing you from accessing JS inside content webpage (see

    http://developer.mozilla.org/en/docs/XPCNativeWrapper ).

    If you control the webpage, it's better to communicate to it via DOM events.
    If you absolutely have to access unsafe JS objects, you can do that using wrappedJSObject property. It's probably a good idea to avoid interacting with the page directly from chrome though, run the code in a sandbox (http://developer.mozilla.org/en/docs....evalInSandbox) instead. Something like:
    var s = Components.utils.Sandbox(content);
    s.win = content;
    Components.utils.evalInSandbox("win.function()", s); 
    
    For Firefox, use nsIExtensionManager.uninstallItem(). See: http://www.xulplanet.com/references/...ExtensionManag...
    Mozilla will be much more difficult as there's no EM. Not sure how you can do it programmatically without invoking an install script
    How to build an extension that execute a program on the client hard drive? or is there away execute the program from the web page?
    Introduction to extensions: http://developer.mozilla.org/en/docs...g_an_Extension
    Quickstart wizard: http://ted.mielczarek.org/code/mozilla/extensionwiz/
    Running applications: http://kb.mozillazine.org/Running_applications
    Catching an event in dispatched by a webpage:
    http://forums.mozillazine.org/viewto...005555#1005555
    You *can* do it right from a web page if the user grants permissions. Try this (obviously it won't work in IE):
    <html>
    <head>
    <title>Execute Any Process</title>
    <script>
    function executeFile() {
       netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
       var nsIFilePicker = Components.interfaces.nsIFilePicker;
       var fp =
         Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
       fp.init(window, "Select a File To Execute", nsIFilePicker.modeOpen);
       fp.appendFilters(nsIFilePicker.filterAll);
       var res = fp.show();
       if (res == nsIFilePicker.returnOK) {
         var process =
           Components.classes["@mozilla.org/process/util;1"]
           .createInstance(Components.interfaces.nsIProcess);
         process.init(fp.file);
         process.run(false, null, 0);
       }
    }
    </script>
    </head>
    <body>
        <input type="button" value="Run a process" onclick="executeFile()"/>
    </body>
    </html>
    
    There are more elaborate version that handles non-executable filetypes (e.g., .jpg) here: http://pastebin.mozilla.org/1066
    When using these scripts, the user is prompted by Firefox/Mozilla/SeaMonkey to grant permissions that allow the scripts to do nefarious things to his computer. Therefore, you might consider signing the script so the user knows it hasn't been tampered with, say, a man-in-the-middle attack: http://www.mozilla.org/projects/secu...nts/jssec.html
    Also consider hosting the scripts on an SSL-secured page. Alternatively there's a way to grant advanced privileges to -signed- pages.
    Here are pointers to more information:
    http://www.mozilla.org/projects/secu...d-scripts.html
    http://www.mozilla.org/projects/secu...ned-script-exa...
    (doesn't work - https://bugzilla.mozilla.org/show_bug.cgi?id=358436 )
    Note that it requires you to
    a) sign the JAR
    b) serve the JAR over HTTPS
    c) use enablePrivilege, which shows a confirmation dialog to the user before your script can run with elevated privileges.

    UAQ

    (↑ top)

    Document Tags and Contributors

    Contributors to this page: Ptak82, Mckwan
    Last updated by: Mckwan,