зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1277026
- Disconnect Sync and show a notification on FxA remote disconnect. r=markh
MozReview-Commit-ID: Hxz1j5QDkfM --HG-- extra : transplant_source : J%82i%FD%AA%3D%E6%13%FB%A0%C8%5EC%8F%85%ADq%9C%B9%C8
This commit is contained in:
Родитель
bece0c3893
Коммит
c1194ab1a9
|
@ -312,6 +312,9 @@ BrowserGlue.prototype = {
|
|||
case "fxaccounts:onverified":
|
||||
this._showSyncStartedDoorhanger();
|
||||
break;
|
||||
case "fxaccounts:device_disconnected":
|
||||
this._onDeviceDisconnected();
|
||||
break;
|
||||
case "weave:engine:clients:display-uri":
|
||||
this._onDisplaySyncURI(subject);
|
||||
break;
|
||||
|
@ -530,6 +533,7 @@ BrowserGlue.prototype = {
|
|||
}
|
||||
os.addObserver(this, "weave:service:ready", false);
|
||||
os.addObserver(this, "fxaccounts:onverified", false);
|
||||
os.addObserver(this, "fxaccounts:device_disconnected", false);
|
||||
os.addObserver(this, "weave:engine:clients:display-uri", false);
|
||||
os.addObserver(this, "session-save", false);
|
||||
os.addObserver(this, "places-init-complete", false);
|
||||
|
@ -596,6 +600,7 @@ BrowserGlue.prototype = {
|
|||
}
|
||||
os.removeObserver(this, "weave:service:ready");
|
||||
os.removeObserver(this, "fxaccounts:onverified");
|
||||
os.removeObserver(this, "fxaccounts:device_disconnected");
|
||||
os.removeObserver(this, "weave:engine:clients:display-uri");
|
||||
os.removeObserver(this, "session-save");
|
||||
if (this._bookmarksBackupIdleTime) {
|
||||
|
@ -2504,6 +2509,19 @@ BrowserGlue.prototype = {
|
|||
}
|
||||
},
|
||||
|
||||
_onDeviceDisconnected() {
|
||||
let bundle = Services.strings.createBundle("chrome://browser/locale/accounts.properties");
|
||||
let title = bundle.GetStringFromName("deviceDisconnectedNotification.title");
|
||||
let body = bundle.GetStringFromName("deviceDisconnectedNotification.body");
|
||||
|
||||
let clickCallback = (subject, topic, data) => {
|
||||
if (topic != "alertclickcallback")
|
||||
return;
|
||||
this._openPreferences("sync");
|
||||
}
|
||||
AlertsService.showAlertNotification(null, title, body, true, null, clickCallback);
|
||||
},
|
||||
|
||||
_handleFlashHang: function() {
|
||||
++this._flashHangCount;
|
||||
if (this._flashHangCount < 2) {
|
||||
|
|
|
@ -28,3 +28,8 @@ verificationNotSentBody = We are unable to send a verification mail at this time
|
|||
# These strings are used in a notification shown after Sync is connected.
|
||||
syncStartNotification.title = Sync enabled
|
||||
syncStartNotification.body = Firefox will begin syncing momentarily.
|
||||
|
||||
# LOCALIZATION NOTE (deviceDisconnectedNotification.title, deviceDisconnectedNotification.body)
|
||||
# These strings are used in a notification shown after Sync was disconnected remotely.
|
||||
deviceDisconnectedNotification.title = Sync disconnected
|
||||
deviceDisconnectedNotification.body = This computer has been successfully disconnected from Firefox Sync.
|
||||
|
|
|
@ -59,6 +59,7 @@ var publicProperties = [
|
|||
"signOut",
|
||||
"updateUserAccountData",
|
||||
"updateDeviceRegistration",
|
||||
"handleDeviceDisconnection",
|
||||
"whenVerified"
|
||||
];
|
||||
|
||||
|
@ -1491,6 +1492,20 @@ FxAccountsInternal.prototype = {
|
|||
}).catch(error => this._logErrorAndResetDeviceRegistrationVersion(error));
|
||||
},
|
||||
|
||||
handleDeviceDisconnection(deviceId) {
|
||||
return this.currentAccountState.getUserAccountData()
|
||||
.then(data => data ? data.deviceId : null)
|
||||
.then(localDeviceId => {
|
||||
if (deviceId == localDeviceId) {
|
||||
this.notifyObservers(ON_DEVICE_DISCONNECTED_NOTIFICATION, deviceId);
|
||||
return this.signOut(true);
|
||||
}
|
||||
log.error(
|
||||
"The device ID to disconnect doesn't match with the local device ID.\n"
|
||||
+ "Local: " + localDeviceId + ", ID to disconnect: " + deviceId);
|
||||
});
|
||||
},
|
||||
|
||||
// If you change what we send to the FxA servers during device registration,
|
||||
// you'll have to bump the DEVICE_REGISTRATION_VERSION number to force older
|
||||
// devices to re-register when Firefox updates
|
||||
|
|
|
@ -89,6 +89,7 @@ exports.ONVERIFIED_NOTIFICATION = "fxaccounts:onverified";
|
|||
exports.ONLOGOUT_NOTIFICATION = "fxaccounts:onlogout";
|
||||
// Internal to services/fxaccounts only
|
||||
exports.ON_FXA_UPDATE_NOTIFICATION = "fxaccounts:update";
|
||||
exports.ON_DEVICE_DISCONNECTED_NOTIFICATION = "fxaccounts:device_disconnected";
|
||||
|
||||
exports.FXA_PUSH_SCOPE_ACCOUNT_UPDATE = "chrome://fxa-device-update";
|
||||
|
||||
|
|
|
@ -152,6 +152,9 @@ FxAccountsPushService.prototype = {
|
|||
}
|
||||
let payload = message.data.json();
|
||||
switch (payload.command) {
|
||||
case ON_DEVICE_DISCONNECTED_NOTIFICATION:
|
||||
this.fxAccounts.handleDeviceDisconnection(payload.data.id);
|
||||
break;
|
||||
default:
|
||||
this.log.warn("FxA Push command unrecognized: " + payload.command);
|
||||
}
|
||||
|
|
|
@ -143,6 +143,36 @@ add_test(function observePushTopicVerify() {
|
|||
pushService.observe(emptyMsg, mockPushService.pushTopic, FXA_PUSH_SCOPE_ACCOUNT_UPDATE);
|
||||
});
|
||||
|
||||
add_test(function observePushTopicDeviceDisconnected() {
|
||||
const deviceId = "bogusid";
|
||||
let msg = {
|
||||
data: {
|
||||
json: () => ({
|
||||
command: ON_DEVICE_DISCONNECTED_NOTIFICATION,
|
||||
data: {
|
||||
id: deviceId
|
||||
}
|
||||
})
|
||||
},
|
||||
QueryInterface: function() {
|
||||
return this;
|
||||
}
|
||||
};
|
||||
let customAccounts = Object.assign(mockFxAccounts, {
|
||||
handleDeviceDisconnection: function () {
|
||||
// checking verification status on push messages without data
|
||||
run_next_test();
|
||||
}
|
||||
});
|
||||
|
||||
let pushService = new FxAccountsPushService({
|
||||
pushService: mockPushService,
|
||||
fxAccounts: customAccounts,
|
||||
});
|
||||
|
||||
pushService.observe(msg, mockPushService.pushTopic, FXA_PUSH_SCOPE_ACCOUNT_UPDATE);
|
||||
});
|
||||
|
||||
add_test(function observeSubscriptionChangeTopic() {
|
||||
let customAccounts = Object.assign(mockFxAccounts, {
|
||||
updateDeviceRegistration: function () {
|
||||
|
|
Загрузка…
Ссылка в новой задаче