layout/tools/recording/recording-cmdline.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/tools/recording/recording-cmdline.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,74 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
     1.9 +
    1.10 +const nsISupports                    = Components.interfaces.nsISupports;
    1.11 +  
    1.12 +const nsICommandLine                 = Components.interfaces.nsICommandLine;
    1.13 +const nsICommandLineHandler          = Components.interfaces.nsICommandLineHandler;
    1.14 +const nsISupportsString              = Components.interfaces.nsISupportsString;
    1.15 +const nsIWindowWatcher               = Components.interfaces.nsIWindowWatcher;
    1.16 +
    1.17 +function RecordingCmdLineHandler() {}
    1.18 +RecordingCmdLineHandler.prototype =
    1.19 +{
    1.20 +    classID: Components.ID('{86FB70EC-90FF-45AD-A1C1-F77D3C1184E9}'),
    1.21 +
    1.22 +    /* nsISupports */
    1.23 +    QueryInterface: XPCOMUtils.generateQI([nsICommandLineHandler]),
    1.24 +
    1.25 +    /* nsICommandLineHandler */
    1.26 +    handle : function handler_handle(cmdLine) {
    1.27 +        var args = { };
    1.28 +        args.wrappedJSObject = args;
    1.29 +        try {
    1.30 +            var uristr = cmdLine.handleFlagWithParam("recording", false);
    1.31 +            if (uristr == null)
    1.32 +                return;
    1.33 +            try {
    1.34 +                args.uri = cmdLine.resolveURI(uristr).spec;
    1.35 +            }
    1.36 +            catch (e) {
    1.37 +                return;
    1.38 +            }
    1.39 +        }
    1.40 +        catch (e) {
    1.41 +            cmdLine.handleFlag("recording", true);
    1.42 +        }
    1.43 +
    1.44 +        /**
    1.45 +         * Manipulate preferences by adding to the *default* branch.  Adding
    1.46 +         * to the default branch means the changes we make won't get written
    1.47 +         * back to user preferences.
    1.48 +         *
    1.49 +         * We want to do this here rather than in reftest.js because it's
    1.50 +         * important to set the recording pref before the platform Init gets
    1.51 +         * called.
    1.52 +         */
    1.53 +        var prefs = Components.classes["@mozilla.org/preferences-service;1"].
    1.54 +                    getService(Components.interfaces.nsIPrefService);
    1.55 +        var branch = prefs.getDefaultBranch("");
    1.56 +
    1.57 +        try {
    1.58 +            var outputstr = cmdLine.handleFlagWithParam("recording-output", false);
    1.59 +            if (outputstr != null) {
    1.60 +                branch.setCharPref("gfx.2d.recordingfile", outputstr);
    1.61 +            }
    1.62 +        } catch (e) { }
    1.63 +
    1.64 +        branch.setBoolPref("gfx.2d.recording", true);
    1.65 +
    1.66 +        var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
    1.67 +                               .getService(nsIWindowWatcher);
    1.68 +        wwatch.openWindow(null, "chrome://recording/content/recording.xul", "_blank",
    1.69 +                          "chrome,dialog=no,all", args);
    1.70 +        cmdLine.preventDefault = true;
    1.71 +    },
    1.72 +
    1.73 +    helpInfo : "  -recording <file>  Record drawing for a given URL.\n" +
    1.74 +               "  -recording-output <file> Specify destination file for a drawing recording.\n"
    1.75 +};
    1.76 +
    1.77 +this.NSGetFactory = XPCOMUtils.generateNSGetFactory([RecordingCmdLineHandler]);

mercurial