зеркало из https://github.com/mozilla/gecko-dev.git
Bug 760898: Only enable AITC if the Apps DOM API is used; r=gps
This commit is contained in:
Родитель
52604752b7
Коммит
e3be117f9e
|
@ -8,9 +8,9 @@ const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
||||||
|
|
||||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||||
Cu.import("resource://gre/modules/Services.jsm");
|
Cu.import("resource://gre/modules/Services.jsm");
|
||||||
Cu.import("resource://gre/modules/PlacesUtils.jsm");
|
|
||||||
|
|
||||||
Cu.import("resource://services-common/utils.js");
|
Cu.import("resource://services-common/utils.js");
|
||||||
|
Cu.import("resource://services-common/preferences.js");
|
||||||
|
|
||||||
function AitcService() {
|
function AitcService() {
|
||||||
this.aitc = null;
|
this.aitc = null;
|
||||||
|
@ -20,7 +20,6 @@ AitcService.prototype = {
|
||||||
classID: Components.ID("{a3d387ca-fd26-44ca-93be-adb5fda5a78d}"),
|
classID: Components.ID("{a3d387ca-fd26-44ca-93be-adb5fda5a78d}"),
|
||||||
|
|
||||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
|
||||||
Ci.nsINavHistoryObserver,
|
|
||||||
Ci.nsISupportsWeakReference]),
|
Ci.nsISupportsWeakReference]),
|
||||||
|
|
||||||
observe: function observe(subject, topic, data) {
|
observe: function observe(subject, topic, data) {
|
||||||
|
@ -34,7 +33,6 @@ AitcService.prototype = {
|
||||||
Services.obs.removeObserver(this, "sessionstore-windows-restored");
|
Services.obs.removeObserver(this, "sessionstore-windows-restored");
|
||||||
|
|
||||||
// Don't start AITC if classic sync is on.
|
// Don't start AITC if classic sync is on.
|
||||||
Cu.import("resource://services-common/preferences.js");
|
|
||||||
if (Preferences.get("services.sync.engine.apps", false)) {
|
if (Preferences.get("services.sync.engine.apps", false)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -43,43 +41,32 @@ AitcService.prototype = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start AITC service if apps.enabled is true. If false, we look
|
// Start AITC service only if apps.enabled is true. If false, setup
|
||||||
// in the browser history to determine if they're an "apps user". If
|
// an observer in case the value changes as a result of an access to
|
||||||
// an entry wasn't found, we'll watch for navigation to either the
|
// the DOM API.
|
||||||
// marketplace or dashboard and switch ourselves on then.
|
if (Preferences.get("dom.mozApps.used", false)) {
|
||||||
|
|
||||||
if (Preferences.get("apps.enabled", false)) {
|
|
||||||
this.start();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set commonly used URLs.
|
|
||||||
this.DASHBOARD_URL = CommonUtils.makeURI(
|
|
||||||
Preferences.get("services.aitc.dashboard.url")
|
|
||||||
);
|
|
||||||
this.MARKETPLACE_URL = CommonUtils.makeURI(
|
|
||||||
Preferences.get("services.aitc.marketplace.url")
|
|
||||||
);
|
|
||||||
|
|
||||||
if (this.hasUsedApps()) {
|
|
||||||
Preferences.set("apps.enabled", true);
|
|
||||||
this.start();
|
this.start();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait and see if the user wants anything apps related.
|
// Wait and see if the user wants anything apps related.
|
||||||
PlacesUtils.history.addObserver(this, true);
|
Preferences.observe("dom.mozApps.used", function checkIfEnabled() {
|
||||||
|
if (Preferences.get("dom.mozApps.used", false)) {
|
||||||
|
Preferences.ignore("dom.mozApps.used", checkIfEnabled, this);
|
||||||
|
this.start();
|
||||||
|
}
|
||||||
|
}, this);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
start: function start() {
|
start: function start() {
|
||||||
Cu.import("resource://services-aitc/main.js");
|
|
||||||
if (this.aitc) {
|
if (this.aitc) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log to stdout if enabled.
|
// Log to stdout if enabled.
|
||||||
|
Cu.import("resource://services-aitc/main.js");
|
||||||
Cu.import("resource://services-common/log4moz.js");
|
Cu.import("resource://services-common/log4moz.js");
|
||||||
let root = Log4Moz.repository.getLogger("Service.AITC");
|
let root = Log4Moz.repository.getLogger("Service.AITC");
|
||||||
root.level = Log4Moz.Level[Preferences.get("services.aitc.log.level")];
|
root.level = Log4Moz.Level[Preferences.get("services.aitc.log.level")];
|
||||||
|
@ -87,43 +74,9 @@ AitcService.prototype = {
|
||||||
root.addAppender(new Log4Moz.DumpAppender());
|
root.addAppender(new Log4Moz.DumpAppender());
|
||||||
}
|
}
|
||||||
this.aitc = new Aitc();
|
this.aitc = new Aitc();
|
||||||
|
Services.obs.notifyObservers(null, "service:aitc:started", null);
|
||||||
},
|
},
|
||||||
|
|
||||||
hasUsedApps: function hasUsedApps() {
|
|
||||||
// There is no easy way to determine whether a user is "using apps".
|
|
||||||
// The best we can do right now is to see if they have visited either
|
|
||||||
// the Mozilla dashboard or Marketplace. See bug 760898.
|
|
||||||
let gh = PlacesUtils.ghistory2;
|
|
||||||
if (gh.isVisited(this.DASHBOARD_URL)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (gh.isVisited(this.MARKETPLACE_URL)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
|
|
||||||
// nsINavHistoryObserver. We are only interested in onVisit().
|
|
||||||
onBeforeDeleteURI: function() {},
|
|
||||||
onBeginUpdateBatch: function() {},
|
|
||||||
onClearHistory: function() {},
|
|
||||||
onDeleteURI: function() {},
|
|
||||||
onDeleteVisits: function() {},
|
|
||||||
onEndUpdateBatch: function() {},
|
|
||||||
onPageChanged: function() {},
|
|
||||||
onPageExpired: function() {},
|
|
||||||
onTitleChanged: function() {},
|
|
||||||
|
|
||||||
onVisit: function onVisit(uri) {
|
|
||||||
if (!uri.equals(this.MARKETPLACE_URL) && !uri.equals(this.DASHBOARD_URL)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PlacesUtils.history.removeObserver(this);
|
|
||||||
Preferences.set("apps.enabled", true);
|
|
||||||
this.start();
|
|
||||||
return;
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const components = [AitcService];
|
const components = [AitcService];
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// Root logger
|
pref("dom.mozApps.used", false); // Set to true by DOMApplicationRegistry
|
||||||
pref("services.aitc.log.dump", false);
|
|
||||||
|
pref("services.aitc.log.dump", false); // Root logger
|
||||||
pref("services.aitc.log.level", "All");
|
pref("services.aitc.log.level", "All");
|
||||||
|
|
||||||
pref("services.aitc.browserid.url", "https://browserid.org/sign_in");
|
pref("services.aitc.browserid.url", "https://browserid.org/sign_in");
|
||||||
|
|
Загрузка…
Ссылка в новой задаче