Bug 788829 - Call SetSizeConstraints even if a popup is not open. r=enndeakin
[gecko.git] / toolkit / webapps / WebappOSUtils.jsm
blob1fb802f790df4a9fc7f4af7de1129ed087b901f5
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 const Cc = Components.classes;
6 const Ci = Components.interfaces;
7 const CC = Components.Constructor;
8 const Cu = Components.utils;
10 Cu.import("resource://gre/modules/Services.jsm");
12 let EXPORTED_SYMBOLS = ["WebappOSUtils"];
14 let WebappOSUtils = {
15   launch: function(aData) {
16 #ifdef XP_WIN
17     let appRegKey;
18     try {
19       let open = CC("@mozilla.org/windows-registry-key;1",
20                     "nsIWindowsRegKey", "open");
21       let initWithPath = CC("@mozilla.org/file/local;1",
22                             "nsILocalFile", "initWithPath");
23       let initProcess = CC("@mozilla.org/process/util;1",
24                            "nsIProcess", "init");
26       appRegKey = open(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
27                        "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" +
28                        aData.origin, Ci.nsIWindowsRegKey.ACCESS_READ);
30       let launchTarget = initWithPath(appRegKey.readStringValue("InstallLocation"));
31       launchTarget.append(appRegKey.readStringValue("AppFilename") + ".exe");
33       let process = initProcess(launchTarget);
34       process.runwAsync([], 0);
35     } catch (e) {
36       return false;
37     } finally {
38       if (appRegKey) {
39         appRegKey.close();
40       }
41     }
43     return true;
44 #elifdef XP_MACOSX
45     let mwaUtils = Cc["@mozilla.org/widget/mac-web-app-utils;1"]
46                     .createInstance(Ci.nsIMacWebAppUtils);
47     let appPath;
48     try {
49       appPath = mwaUtils.pathForAppWithIdentifier(aData.origin);
50     } catch (e) {}
52     if (appPath) {
53       mwaUtils.launchAppWithIdentifier(aData.origin);
54       return true;
55     }
57     return false;
58 #elifdef XP_UNIX
59     let origin = Services.io.newURI(aData.origin, null, null);
60     let installDir = "." + origin.scheme + ";" +
61                      origin.host +
62                      (origin.port != -1 ? ";" + origin.port : "");
64     let exeFile = Services.dirsvc.get("Home", Ci.nsIFile);
65     exeFile.append(installDir);
66     exeFile.append("webapprt-stub");
68     try {
69       if (exeFile.exists()) {
70         let process = Cc["@mozilla.org/process/util;1"]
71                         .createInstance(Ci.nsIProcess);
72         process.init(exeFile);
73         process.runAsync([], 0);
74         return true;
75       }
76     } catch (e) {}
78     return false;
79 #endif
80   },
82   uninstall: function(aData) {
83 #ifdef XP_UNIX
84 #ifndef XP_MACOSX
85     let origin = Services.io.newURI(aData.origin, null, null);
86     let installDir = "." + origin.scheme + ";" +
87                      origin.host +
88                      (origin.port != -1 ? ";" + origin.port : "");
90     let exeFile = Services.dirsvc.get("Home", Ci.nsIFile);
91     exeFile.append(installDir);
92     exeFile.append("webapprt-stub");
94     try {
95       if (exeFile.exists()) {
96         var process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
97         process.init(exeFile);
98         process.runAsync(["-remove"], 1);
99         return true;
100       }
101     } catch(e) {}
103     return false;
104 #endif
105 #endif
106   }