bug 904230. Make nsIWinMetroUtils available as Services.metro. r=mbrubeck for the metro piece. r=rnewman for the sync piece. r=dolske for the toolkit piece.

This commit is contained in:
Tim Abraldes 2013-08-28 10:27:32 -07:00
parent d2af46d2a9
commit bf1450a127
16 changed files with 44 additions and 88 deletions

View File

@ -1,3 +1,4 @@
// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@ -417,21 +418,6 @@ var gSyncSetup = {
}
},
#ifdef XP_WIN
#ifdef MOZ_METRO
_securelyStoreForMetroSync: function(weaveEmail, weavePassword, weaveKey) {
try {
let metroUtils = Cc["@mozilla.org/windows-metroutils;1"].
createInstance(Ci.nsIWinMetroUtils);
if (!metroUtils)
return;
metroUtils.storeSyncInfo(weaveEmail, weavePassword, weaveKey);
} catch (ex) {
}
},
#endif
#endif
onWizardAdvance: function () {
// Check pageIndex so we don't prompt before the Sync setup wizard appears.
// This is a fallback in case the Master Password gets locked mid-wizard.
@ -489,7 +475,7 @@ var gSyncSetup = {
#ifdef XP_WIN
#ifdef MOZ_METRO
if (document.getElementById("metroSetupCheckbox").checked) {
this._securelyStoreForMetroSync(email, password, Weave.Service.identity.syncKey);
Services.metro.storeSyncInfo(email, password, Weave.Service.identity.syncKey);
}
#endif
#endif

View File

@ -70,7 +70,7 @@ var ContentAreaObserver = {
},
get isKeyboardOpened() {
return MetroUtils.keyboardVisible;
return Services.metro.keyboardVisible;
},
get isKeyboardTransitioning() {
@ -182,7 +182,7 @@ var ContentAreaObserver = {
updateAppBarPosition: function updateAppBarPosition(aForceDown) {
// Adjust the app and find bar position above the soft keyboard
let keyboardHeight = aForceDown ? 0 : MetroUtils.keyboardHeight;
let keyboardHeight = aForceDown ? 0 : Services.metro.keyboardHeight;
Elements.navbar.style.bottom = keyboardHeight + "px";
Elements.contextappbar.style.bottom = keyboardHeight + "px";
Elements.findbar.style.bottom = keyboardHeight + "px";
@ -335,7 +335,7 @@ var ContentAreaObserver = {
},
_getViewableHeightForContent: function (contentHeight) {
let keyboardHeight = MetroUtils.keyboardHeight;
let keyboardHeight = Services.metro.keyboardHeight;
return contentHeight - keyboardHeight;
},

View File

@ -246,7 +246,7 @@ var ContextCommands = {
jsShell: function cc_jsShell() {
// XXX for debugging, this only works when running on the desktop.
if (!MetroUtils.immersive)
if (!Services.metro.immersive)
window.openDialog("chrome://browser/content/shell.xul", "_blank",
"all=no,scrollbars=yes,resizable=yes,dialog=no");
},

View File

@ -125,7 +125,7 @@ var Appbar = {
typesArray.push("find-in-page");
if (ConsolePanelView.enabled)
typesArray.push("open-error-console");
if (!MetroUtils.immersive)
if (!Services.metro.immersive)
typesArray.push("open-jsshell");
try {
@ -161,7 +161,7 @@ var Appbar = {
var uri = Services.io.newURI(Browser.selectedBrowser.currentURI.spec,
null, null);
if (uri.schemeIs('http') || uri.schemeIs('https')) {
MetroUtils.launchInDesktop(Browser.selectedBrowser.currentURI.spec, "");
Services.metro.launchInDesktop(Browser.selectedBrowser.currentURI.spec, "");
}
} catch(ex) {
}

View File

@ -41,28 +41,6 @@ XPCOMUtils.defineLazyModuleGetter(this, "OS",
* Services
*/
#ifdef XP_WIN
XPCOMUtils.defineLazyServiceGetter(this, "MetroUtils",
"@mozilla.org/windows-metroutils;1",
"nsIWinMetroUtils");
#else
// Stub nsIWinMetroUtils implementation for testing on non-Windows platforms:
var MetroUtils = {
snappedState: Ci.nsIWinMetroUtils.fullScreenLandscape,
immersive: false,
handPreference: Ci.nsIWinMetroUtils.handPreferenceLeft,
unsnap: function() {},
launchInDesktop: function() {},
pinTileAsync: function() {},
unpinTileAsync: function() {},
isTilePinned: function() { return false; },
keyboardVisible: false,
keyboardX: 0,
keyboardY: 0,
keyboardWidth: 0,
keyboardHeight: 0
};
#endif
XPCOMUtils.defineLazyServiceGetter(this, "StyleSheetSvc",
"@mozilla.org/content/style-sheet-service;1",
"nsIStyleSheetService");

View File

@ -648,8 +648,8 @@ var BrowserUI = {
_adjustDOMforViewState: function(aState) {
let currViewState = aState;
if (!currViewState && MetroUtils.immersive) {
switch (MetroUtils.snappedState) {
if (!currViewState && Services.metro.immersive) {
switch (Services.metro.snappedState) {
case Ci.nsIWinMetroUtils.fullScreenLandscape:
currViewState = "landscape";
break;
@ -1286,7 +1286,7 @@ var SettingsCharm = {
*/
addEntry: function addEntry(aEntry) {
try {
let id = MetroUtils.addSettingsPanelEntry(aEntry.label);
let id = Services.metro.addSettingsPanelEntry(aEntry.label);
this._entries.set(id, aEntry);
} catch (e) {
// addSettingsPanelEntry does not work on non-Metro platforms

View File

@ -177,7 +177,7 @@ var Browser = {
Task.spawn(function() {
// Activation URIs come from protocol activations, secondary tiles, and file activations
let activationURI = yield this.getShortcutOrURI(MetroUtils.activationURI);
let activationURI = yield this.getShortcutOrURI(Services.metro.activationURI);
let self = this;
function loadStartupURI() {
@ -733,10 +733,10 @@ var Browser = {
var ios = Components.classes["@mozilla.org/network/io-service;1"].
getService(Components.interfaces.nsIIOService);
var uriSpec = ios.newFileURI(file).spec;
MetroUtils.pinTileAsync(this._currentPageTileID,
Browser.selectedBrowser.contentTitle, // short name
Browser.selectedBrowser.contentTitle, // display name
"metrobrowser -url " + Browser.selectedBrowser.currentURI.spec,
Services.metro.pinTileAsync(this._currentPageTileID,
Browser.selectedBrowser.contentTitle, // short name
Browser.selectedBrowser.contentTitle, // display name
"metrobrowser -url " + Browser.selectedBrowser.currentURI.spec,
uriSpec, uriSpec);
},
@ -755,17 +755,17 @@ var Browser = {
},
unpinSite: function browser_unpinSite() {
if (!MetroUtils.immersive)
if (!Services.metro.immersive)
return;
MetroUtils.unpinTileAsync(this._currentPageTileID);
Services.metro.unpinTileAsync(this._currentPageTileID);
},
isSitePinned: function browser_isSitePinned() {
if (!MetroUtils.immersive)
if (!Services.metro.immersive)
return false;
return MetroUtils.isTilePinned(this._currentPageTileID);
return Services.metro.isTilePinned(this._currentPageTileID);
},
starSite: function browser_starSite(callback) {

View File

@ -84,7 +84,7 @@ var Downloads = {
let file = this._getLocalFile(fileURI);
try {
file && MetroUtils.launchInDesktop(aDownload.target.spec, "");
file && Services.metro.launchInDesktop(aDownload.target.spec, "");
} catch (ex) {
Util.dumpLn("Failed to open download, with id: "+id+", download target URI spec: " + fileURI.spec);
Util.dumpLn("Failed download source:"+(aDownload.source && aDownload.source.spec));

View File

@ -65,7 +65,7 @@ let FlyoutPanelsUI = {
this._currentFlyout._onBackButton();
} else {
this.hide();
MetroUtils.showSettingsFlyout();
Services.metro.showSettingsFlyout();
}
},

View File

@ -11,7 +11,7 @@ var AlertsHelper = {
this._listener = aListener;
this._cookie = aCookie;
MetroUtils.showNativeToast(aTitle, aText, aImageURL);
Services.metro.showNativeToast(aTitle, aText, aImageURL);
},
observe: function(aSubject, aTopic, aData) {

View File

@ -379,7 +379,8 @@ MenuPopup.prototype = {
let screenHeight = ContentAreaObserver.height;
// Add padding on the side of the menu per the user's hand preference
let leftHand = MetroUtils.handPreference == MetroUtils.handPreferenceLeft;
let leftHand =
Services.metro.handPreference == Ci.nsIWinMetroUtils.handPreferenceLeft;
if (aSource && aSource == Ci.nsIDOMMouseEvent.MOZ_SOURCE_TOUCH) {
this.commands.setAttribute("left-hand", leftHand);
}

View File

@ -111,8 +111,8 @@ var StartUI = {
_adjustDOMforViewState: function(aState) {
let currViewState = aState;
if (!currViewState && this.chromeWin.MetroUtils.immersive) {
switch (this.chromeWin.MetroUtils.snappedState) {
if (!currViewState && Services.metro.immersive) {
switch (Services.metro.snappedState) {
case Ci.nsIWinMetroUtils.fullScreenLandscape:
currViewState = "landscape";
break;

View File

@ -14,13 +14,13 @@ gTests.push({
// http://msdn.microsoft.com/en-us/library/windows/apps/hh465404.aspx#user-driven_invocation
//
// Instead, we will use this mock object to simulate keyboard changes.
let originalUtils = window.MetroUtils;
window.MetroUtils = {
let originalUtils = Services.metro;
Services.metro = {
keyboardHeight: 0,
keyboardVisible: false
};
registerCleanupFunction(function() {
window.MetroUtils = originalUtils;
Services.metro = originalUtils;
});
let tab = yield addTab(chromeRoot + "browser_onscreen_keyboard.html");
@ -37,8 +37,8 @@ gTests.push({
SelectionHelperUI.attachToCaret(tab.browser, rect0.left + 5, rect0.top + 5);
// "Show" the keyboard.
MetroUtils.keyboardHeight = 100;
MetroUtils.keyboardVisible = true;
Services.metro.keyboardHeight = 100;
Services.metro.keyboardVisible = true;
Services.obs.notifyObservers(null, "metro_softkeyboard_shown", null);
let event = yield waitForEvent(window, "MozDeckOffsetChanged");
@ -49,8 +49,8 @@ gTests.push({
is(rect1browserY, rect0browserY + 100, "text field moves up by 100px");
// "Hide" the keyboard.
MetroUtils.keyboardHeight = 0;
MetroUtils.keyboardVisible = false;
Services.metro.keyboardHeight = 0;
Services.metro.keyboardVisible = false;
Services.obs.notifyObservers(null, "metro_softkeyboard_hidden", null);
yield waitForEvent(window, "MozDeckOffsetChanged");

View File

@ -47,7 +47,7 @@ const mochitestPath = splitPath.join('/') + '/';
function isLandscapeMode()
{
return (MetroUtils.snappedState == Ci.nsIWinMetroUtils.fullScreenLandscape);
return (Services.metro.snappedState == Ci.nsIWinMetroUtils.fullScreenLandscape);
}
function setDevPixelEqualToPx()

View File

@ -74,7 +74,12 @@ let initTable = [
["DOMRequest", "@mozilla.org/dom/dom-request-service;1", "nsIDOMRequestService"],
["focus", "@mozilla.org/focus-manager;1", "nsIFocusManager"],
["uriFixup", "@mozilla.org/docshell/urifixup;1", "nsIURIFixup"],
["blocklist", "@mozilla.org/extensions/blocklist;1", "nsIBlocklistService"]
["blocklist", "@mozilla.org/extensions/blocklist;1", "nsIBlocklistService"],
#ifdef XP_WIN
#ifdef MOZ_METRO
["metro", "@mozilla.org/windows-metroutils;1", "nsIWinMetroUtils"],
#endif
#endif
];
initTable.forEach(function ([name, contract, intf])

View File

@ -747,24 +747,10 @@ function getCanStageUpdates() {
return canStageUpdatesSession;
}
XPCOMUtils.defineLazyGetter(this, "gIsMetro", function aus_gIsMetro() {
#ifdef XP_WIN
#ifdef MOZ_METRO
try {
let metroUtils = Cc["@mozilla.org/windows-metroutils;1"].
createInstance(Ci.nsIWinMetroUtils);
return metroUtils && metroUtils.immersive;
} catch (e) {}
#endif
#endif
return false;
});
XPCOMUtils.defineLazyGetter(this, "gMetroUpdatesEnabled", function aus_gMetroUpdatesEnabled() {
#ifdef XP_WIN
#ifdef MOZ_METRO
if (gIsMetro) {
if (Services.metro.immersive) {
let metroUpdate = getPref("getBoolPref", PREF_APP_UPDATE_METRO_ENABLED, true);
if (!metroUpdate) {
LOG("gMetroUpdatesEnabled - unable to automatically check for metro " +
@ -2805,7 +2791,7 @@ UpdateService.prototype = {
LOG("UpdateService:_selectAndInstallUpdate - prompting because the " +
"update snippet specified showPrompt");
this._showPrompt(update);
if (!gIsMetro) {
if (!Services.metro || !Services.metro.immersive) {
this._backgroundUpdateCheckCodePing(PING_BGUC_SHOWPROMPT_SNIPPET);
return;
}
@ -2815,7 +2801,7 @@ UpdateService.prototype = {
LOG("UpdateService:_selectAndInstallUpdate - prompting because silent " +
"install is disabled");
this._showPrompt(update);
if (!gIsMetro) {
if (!Services.metro || !Services.metro.immersive) {
this._backgroundUpdateCheckCodePing(PING_BGUC_SHOWPROMPT_PREF);
return;
}