Bug 763171 - Move display synced tab logic to nsBrowserGlue.js; r=gavin

This commit is contained in:
Gregory Szorc 2012-06-29 15:30:45 -07:00
parent e0ff4314da
commit de2380b0b8
2 changed files with 28 additions and 19 deletions

View File

@ -16,7 +16,6 @@ let gSyncUI = {
"weave:ui:sync:error",
"weave:ui:sync:finish",
"weave:ui:clear-error",
"weave:engine:clients:display-uri",
],
_unloaded: false,
@ -397,21 +396,6 @@ let gSyncUI = {
this.updateUI();
},
/**
* Observer called when display URI command is received.
*/
onDisplayURI: function onDisplayURI(data) {
if (!gBrowser) {
return;
}
try {
gBrowser.addTab(data.wrappedJSObject.object.uri);
} catch (ex) {
Cu.reportError("Error displaying tab received by Sync: " + ex);
}
},
observe: function SUI_observe(subject, topic, data) {
if (this._unloaded) {
Cu.reportError("SyncUI observer called after unload: " + topic);
@ -461,9 +445,6 @@ let gSyncUI = {
case "weave:ui:clear-error":
this.clearError();
break;
case "weave:engine:clients:display-uri":
this.onDisplayURI(subject);
break;
}
},

View File

@ -182,6 +182,9 @@ BrowserGlue.prototype = {
case "weave:service:ready":
this._setSyncAutoconnectDelay();
break;
case "weave:engine:clients:display-uri":
this._onDisplaySyncURI(subject);
break;
#endif
case "session-save":
this._setPrefToSaveSession(true);
@ -265,6 +268,7 @@ BrowserGlue.prototype = {
#endif
#ifdef MOZ_SERVICES_SYNC
os.addObserver(this, "weave:service:ready", false);
os.addObserver(this, "weave:engine:clients:display-uri", false);
#endif
os.addObserver(this, "session-save", false);
os.addObserver(this, "places-init-complete", false);
@ -292,6 +296,7 @@ BrowserGlue.prototype = {
#endif
#ifdef MOZ_SERVICES_SYNC
os.removeObserver(this, "weave:service:ready", false);
os.removeObserver(this, "weave:engine:clients:display-uri", false);
#endif
os.removeObserver(this, "session-save");
if (this._isIdleObserver)
@ -1506,6 +1511,29 @@ BrowserGlue.prototype = {
#endif
},
#ifdef MOZ_SERVICES_SYNC
/**
* Called as an observer when Sync's "display URI" notification is fired.
*
* We open the received URI in a background tab.
*
* Eventually, this will likely be replaced by a more robust tab syncing
* feature. This functionality is considered somewhat evil by UX because it
* opens a new tab automatically without any prompting. However, it is a
* lesser evil than sending a tab to a specific device (from e.g. Fennec)
* and having nothing happen on the receiving end.
*/
_onDisplaySyncURI: function _onDisplaySyncURI(data) {
try {
let tabbrowser = this.getMostRecentBrowserWindow().gBrowser;
// The payload is wrapped weirdly because of how Sync does notifications.
tabbrowser.addTab(data.wrappedJSObject.object.uri);
} catch (ex) {
Cu.reportError("Error displaying tab received by Sync: " + ex);
}
},
#endif
// for XPCOM
classID: Components.ID("{eab9012e-5f74-4cbc-b2b5-a590235513cc}"),