Skip to content

Commit

Permalink
Bug 763171 - Move display synced tab logic to nsBrowserGlue.js; r=gavin
Browse files Browse the repository at this point in the history
  • Loading branch information
indygreg committed Jun 29, 2012
1 parent 2fa79c3 commit f0a9e3d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
19 changes: 0 additions & 19 deletions browser/base/content/browser-syncui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -461,9 +445,6 @@ let gSyncUI = {
case "weave:ui:clear-error":
this.clearError();
break;
case "weave:engine:clients:display-uri":
this.onDisplayURI(subject);
break;
}
},

Expand Down
28 changes: 28 additions & 0 deletions browser/components/nsBrowserGlue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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}"),
Expand Down

0 comments on commit f0a9e3d

Please sign in to comment.