Bug 944825: Prompt for default when attempting to switch to Metro.
authorMarina Samuel <msamuel@mozilla.com>
Tue, 03 Dec 2013 13:29:04 -0500
changeset 174017 ab1336aaf9db35df0950a9c35bf11a4a7936dde8
parent 174016 3831bd01eb417ced6620c4ba35e50e6066efec8a
child 174018 a7d753c6f061c1420091116e0e3c191760f9d5f6
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs944825
milestone28.0a1
Bug 944825: Prompt for default when attempting to switch to Metro.
browser/base/content/browser.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -2499,26 +2499,70 @@ function getMeOutOfHere() {
   content.location = url;
 }
 
 function BrowserFullScreen()
 {
   window.fullScreen = !window.fullScreen;
 }
 
+function _checkDefaultAndSwitchToMetro() {
+#ifdef HAVE_SHELL_SERVICE
+#ifdef XP_WIN
+#ifdef MOZ_METRO
+  let shell = Components.classes["@mozilla.org/browser/shell-service;1"].
+    getService(Components.interfaces.nsIShellService);
+  let isDefault = shell.isDefaultBrowser(false, false);
+
+  if (isDefault) {
+    let appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"].
+      getService(Components.interfaces.nsIAppStartup);
+
+    Services.prefs.setBoolPref("browser.sessionstore.resume_session_once", true);
+    appStartup.quit(Components.interfaces.nsIAppStartup.eAttemptQuit |
+                    Components.interfaces.nsIAppStartup.eRestartTouchEnvironment);
+    return true;
+  }
+  return false;
+#endif
+#endif
+#endif
+}
+
 function SwitchToMetro() {
-  let appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"].
-    getService(Components.interfaces.nsIAppStartup);
-
-  appStartup.quit(Components.interfaces.nsIAppStartup.eAttemptQuit |
-                  Components.interfaces.nsIAppStartup.eRestartTouchEnvironment);
+#ifdef HAVE_SHELL_SERVICE
+#ifdef XP_WIN
+#ifdef MOZ_METRO
+  if (this._checkDefaultAndSwitchToMetro()) {
+    return;
+  }
+
+  let shell = Components.classes["@mozilla.org/browser/shell-service;1"].
+    getService(Components.interfaces.nsIShellService);
+
+  shell.setDefaultBrowser(false, false);
+
+  let intervalID = window.setInterval(this._checkDefaultAndSwitchToMetro, 1000);
+  window.setTimeout(function() { window.clearInterval(intervalID); }, 10000);
+#endif
+#endif
+#endif
+}
+
+function isInWin8() {
+  let sysInfo = Services.sysinfo;
+  let osName = sysInfo.getProperty("name");
+  let version = sysInfo.getProperty("version");
+
+  // Windows 8 is version >= 6.2
+  return osName == "Windows_NT" && version >= 6.2;
 }
 
 function updateSwitchToMetroVisibility() {
-  if (PrivateBrowsingUtils.isWindowPrivate(window)) {
+  if (PrivateBrowsingUtils.isWindowPrivate(window) || !isInWin8()) {
     document.getElementById("switch-to-metro").hidden = true;
   }
 }
 
 function onFullScreen(event) {
   FullScreen.toggle(event);
 }