mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
Backed out changeset 19ae3d5f6884 (bug 1038648) for failures in test_loopservice_initialize.js
This commit is contained in:
parent
9205646493
commit
b56f2eab68
@ -33,6 +33,7 @@ function injectLoopAPI(targetWindow) {
|
||||
*/
|
||||
doNotDisturb: {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
get: function() {
|
||||
return MozLoopService.doNotDisturb;
|
||||
},
|
||||
@ -48,6 +49,7 @@ function injectLoopAPI(targetWindow) {
|
||||
*/
|
||||
locale: {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
get: function() {
|
||||
return MozLoopService.locale;
|
||||
}
|
||||
@ -63,6 +65,7 @@ function injectLoopAPI(targetWindow) {
|
||||
*/
|
||||
getStrings: {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: function(key) {
|
||||
return MozLoopService.getStrings(key);
|
||||
@ -82,6 +85,7 @@ function injectLoopAPI(targetWindow) {
|
||||
*/
|
||||
ensureRegistered: {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: function(callback) {
|
||||
// We translate from a promise to a callback, as we can't pass promises from
|
||||
@ -108,6 +112,7 @@ function injectLoopAPI(targetWindow) {
|
||||
*/
|
||||
noteCallUrlExpiry: {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: function(expiryTimeSeconds) {
|
||||
MozLoopService.noteCallUrlExpiry(expiryTimeSeconds);
|
||||
@ -125,6 +130,7 @@ function injectLoopAPI(targetWindow) {
|
||||
*/
|
||||
setLoopCharPref: {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: function(prefName, value) {
|
||||
MozLoopService.setLoopCharPref(prefName, value);
|
||||
@ -146,6 +152,7 @@ function injectLoopAPI(targetWindow) {
|
||||
*/
|
||||
getLoopCharPref: {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: function(prefName) {
|
||||
return MozLoopService.getLoopCharPref(prefName);
|
||||
@ -157,6 +164,7 @@ function injectLoopAPI(targetWindow) {
|
||||
*/
|
||||
startAlerting: {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: function() {
|
||||
let chromeWindow = getChromeWindow(targetWindow);
|
||||
@ -180,6 +188,7 @@ function injectLoopAPI(targetWindow) {
|
||||
*/
|
||||
stopAlerting: {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: function() {
|
||||
if (ringerStopper) {
|
||||
@ -215,6 +224,7 @@ function injectLoopAPI(targetWindow) {
|
||||
*/
|
||||
hawkRequest: {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: function(path, method, payloadObj, callback) {
|
||||
// XXX Should really return a DOM promise here.
|
||||
@ -229,7 +239,6 @@ function injectLoopAPI(targetWindow) {
|
||||
|
||||
let contentObj = Cu.createObjectIn(targetWindow);
|
||||
Object.defineProperties(contentObj, api);
|
||||
Object.seal(contentObj);
|
||||
Cu.makeObjectPropsNormal(contentObj);
|
||||
|
||||
targetWindow.navigator.wrappedJSObject.__defineGetter__("mozLoop", function() {
|
||||
|
@ -47,13 +47,6 @@ XPCOMUtils.defineLazyServiceGetter(this, "uuidgen",
|
||||
"@mozilla.org/uuid-generator;1",
|
||||
"nsIUUIDGenerator");
|
||||
|
||||
let gRegisteredDeferred = null;
|
||||
let gPushHandler = null;
|
||||
let gHawkClient = null;
|
||||
let gRegisteredLoopServer = false;
|
||||
let gLocalizedStrings = null;
|
||||
let gInitializeTimer = null;
|
||||
|
||||
/**
|
||||
* Internal helper methods and state
|
||||
*
|
||||
@ -63,7 +56,7 @@ let gInitializeTimer = null;
|
||||
*/
|
||||
let MozLoopServiceInternal = {
|
||||
// The uri of the Loop server.
|
||||
get loopServerUri() Services.prefs.getCharPref("loop.server"),
|
||||
loopServerUri: Services.prefs.getCharPref("loop.server"),
|
||||
|
||||
// The current deferred for the registration process. This is set if in progress
|
||||
// or the registration was successful. This is null if a registration attempt was
|
||||
@ -144,18 +137,18 @@ let MozLoopServiceInternal = {
|
||||
* rejected with an error code or string.
|
||||
*/
|
||||
promiseRegisteredWithServers: function(mockPushHandler) {
|
||||
if (gRegisteredDeferred) {
|
||||
return gRegisteredDeferred.promise;
|
||||
if (this._registeredDeferred) {
|
||||
return this._registeredDeferred.promise;
|
||||
}
|
||||
|
||||
gRegisteredDeferred = Promise.defer();
|
||||
this._registeredDeferred = Promise.defer();
|
||||
// We grab the promise early in case .initialize or its results sets
|
||||
// it back to null on error.
|
||||
let result = gRegisteredDeferred.promise;
|
||||
let result = this._registeredDeferred.promise;
|
||||
|
||||
gPushHandler = mockPushHandler || MozLoopPushHandler;
|
||||
this._pushHandler = mockPushHandler || MozLoopPushHandler;
|
||||
|
||||
gPushHandler.initialize(this.onPushRegistered.bind(this),
|
||||
this._pushHandler.initialize(this.onPushRegistered.bind(this),
|
||||
this.onHandleNotification.bind(this));
|
||||
|
||||
return result;
|
||||
@ -175,8 +168,8 @@ let MozLoopServiceInternal = {
|
||||
* rejected with this JSON-parsed response.
|
||||
*/
|
||||
hawkRequest: function(path, method, payloadObj) {
|
||||
if (!gHawkClient) {
|
||||
gHawkClient = new HawkClient(this.loopServerUri);
|
||||
if (!this._hawkClient) {
|
||||
this._hawkClient = new HawkClient(this.loopServerUri);
|
||||
}
|
||||
|
||||
let sessionToken;
|
||||
@ -193,7 +186,7 @@ let MozLoopServiceInternal = {
|
||||
2 * 32, true);
|
||||
}
|
||||
|
||||
return gHawkClient.request(path, method, credentials, payloadObj);
|
||||
return this._hawkClient.request(path, method, credentials, payloadObj);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -212,8 +205,8 @@ let MozLoopServiceInternal = {
|
||||
} else {
|
||||
// XXX Bubble the precise details up to the UI somehow (bug 1013248).
|
||||
console.warn("Loop server sent an invalid session token");
|
||||
gRegisteredDeferred.reject("session-token-wrong-size");
|
||||
gRegisteredDeferred = null;
|
||||
this._registeredDeferred.reject("session-token-wrong-size");
|
||||
this._registeredDeferred = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -228,8 +221,8 @@ let MozLoopServiceInternal = {
|
||||
*/
|
||||
onPushRegistered: function(err, pushUrl) {
|
||||
if (err) {
|
||||
gRegisteredDeferred.reject(err);
|
||||
gRegisteredDeferred = null;
|
||||
this._registeredDeferred.reject(err);
|
||||
this._registeredDeferred = null;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -251,7 +244,8 @@ let MozLoopServiceInternal = {
|
||||
if (!this.storeSessionToken(response.headers))
|
||||
return;
|
||||
|
||||
gRegisteredDeferred.resolve();
|
||||
this.registeredLoopServer = true;
|
||||
this._registeredDeferred.resolve();
|
||||
// No need to clear the promise here, everything was good, so we don't need
|
||||
// to re-register.
|
||||
}, (error) => {
|
||||
@ -272,8 +266,8 @@ let MozLoopServiceInternal = {
|
||||
|
||||
// XXX Bubble the precise details up to the UI somehow (bug 1013248).
|
||||
Cu.reportError("Failed to register with the loop server. error: " + error);
|
||||
gRegisteredDeferred.reject(error.errno);
|
||||
gRegisteredDeferred = null;
|
||||
this._registeredDeferred.reject(error.errno);
|
||||
this._registeredDeferred = null;
|
||||
}
|
||||
);
|
||||
},
|
||||
@ -299,8 +293,8 @@ let MozLoopServiceInternal = {
|
||||
* @returns {Object} a map of element ids with attributes to set.
|
||||
*/
|
||||
get localizedStrings() {
|
||||
if (gLocalizedStrings)
|
||||
return gLocalizedStrings;
|
||||
if (this._localizedStrings)
|
||||
return this._localizedStrings;
|
||||
|
||||
var stringBundle =
|
||||
Services.strings.createBundle('chrome://browser/locale/loop/loop.properties');
|
||||
@ -322,7 +316,7 @@ let MozLoopServiceInternal = {
|
||||
map[key][property] = string.value;
|
||||
}
|
||||
|
||||
return gLocalizedStrings = map;
|
||||
return this._localizedStrings = map;
|
||||
},
|
||||
|
||||
/**
|
||||
@ -451,7 +445,6 @@ let MozLoopServiceInternal = {
|
||||
Chat.open(contentWindow, origin, title, url, undefined, undefined, callback);
|
||||
}
|
||||
};
|
||||
Object.freeze(MozLoopServiceInternal);
|
||||
|
||||
/**
|
||||
* Public API
|
||||
@ -481,10 +474,10 @@ this.MozLoopService = {
|
||||
// Kick off the push notification service into registering after a timeout
|
||||
// this ensures we're not doing too much straight after the browser's finished
|
||||
// starting up.
|
||||
gInitializeTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
||||
gInitializeTimer.initWithCallback(function() {
|
||||
this._initializeTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
||||
this._initializeTimer.initWithCallback(function() {
|
||||
this.register();
|
||||
gInitializeTimer = null;
|
||||
this._initializeTimer = null;
|
||||
}.bind(this),
|
||||
MozLoopServiceInternal.initialRegistrationDelayMilliseconds, Ci.nsITimer.TYPE_ONE_SHOT);
|
||||
},
|
||||
@ -630,4 +623,3 @@ this.MozLoopService = {
|
||||
return MozLoopServiceInternal.hawkRequest(path, method, payloadObj);
|
||||
},
|
||||
};
|
||||
Object.freeze(this.MozLoopService);
|
||||
|
Loading…
Reference in New Issue
Block a user