Bug 1343510 - Add createdWeeksAgo and resetWeeksAgo to appInfo. r=MattN

MozReview-Commit-ID: 9UDG1z1wV3R

--HG--
extra : rebase_source : 299052c1bdba6755258b4e644e1b73c2c79a7e01
This commit is contained in:
Giorgos Logiotatidis 2017-06-30 08:52:08 -07:00
Родитель 0f253d0e4c
Коммит 1b62eae6c7
3 изменённых файлов: 85 добавлений и 37 удалений

Просмотреть файл

@ -481,6 +481,13 @@ if (typeof Mozilla == "undefined") {
* @property {String} distribution - Contains the distributionId property. This value will be
* "default" in most cases but can differ for repack or
* funnelcake builds. Since Fx48
* @property {Number} profileCreatedWeeksAgo - The number of weeks since the profile was created,
* starting from 0 for profiles dating less than
* seven days old. Since Fx56.
* @property {Number} profileResetWeeksAgo - The number of weeks since the profile was last reset,
* starting from 0 for profiles reset less than seven
* days ago. If the profile has never been reset it
* returns null. Since Fx56.
* @property {String} version - Version string e.g. "48.0a2"
* @since 35
*/

Просмотреть файл

@ -29,6 +29,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "BrowserUITelemetry",
"resource:///modules/BrowserUITelemetry.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
"resource://gre/modules/PrivateBrowsingUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "ProfileAge",
"resource://gre/modules/ProfileAge.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "ReaderParent",
"resource:///modules/ReaderParent.jsm");
@ -1483,43 +1485,7 @@ this.UITour = {
getConfiguration(aMessageManager, aWindow, aConfiguration, aCallbackID) {
switch (aConfiguration) {
case "appinfo":
let props = ["defaultUpdateChannel", "version"];
let appinfo = {};
props.forEach(property => appinfo[property] = Services.appinfo[property]);
// Identifier of the partner repack, as stored in preference "distribution.id"
// and included in Firefox and other update pings. Note this is not the same as
// Services.appinfo.distributionID (value of MOZ_DISTRIBUTION_ID is set at build time).
let distribution =
Services.prefs.getDefaultBranch("distribution.").getCharPref("id", "default");
appinfo["distribution"] = distribution;
let isDefaultBrowser = null;
try {
let shell = aWindow.getShellService();
if (shell) {
isDefaultBrowser = shell.isDefaultBrowser(false);
}
} catch (e) {}
appinfo["defaultBrowser"] = isDefaultBrowser;
let canSetDefaultBrowserInBackground = true;
if (AppConstants.isPlatformAndVersionAtLeast("win", "6.2") ||
AppConstants.isPlatformAndVersionAtLeast("macosx", "10.10")) {
canSetDefaultBrowserInBackground = false;
} else if (AppConstants.platform == "linux") {
// The ShellService may not exist on some versions of Linux.
try {
aWindow.getShellService();
} catch (e) {
canSetDefaultBrowserInBackground = null;
}
}
appinfo["canSetDefaultBrowserInBackground"] =
canSetDefaultBrowserInBackground;
this.sendPageCallback(aMessageManager, aCallbackID, appinfo);
this.getAppInfo(aMessageManager, aWindow, aCallbackID);
break;
case "availableTargets":
this.getAvailableTargets(aMessageManager, aWindow, aCallbackID);
@ -1576,6 +1542,64 @@ this.UITour = {
}
},
getAppInfo(aMessageManager, aWindow, aCallbackID) {
(async() => {
let props = ["defaultUpdateChannel", "version"];
let appinfo = {};
props.forEach(property => appinfo[property] = Services.appinfo[property]);
// Identifier of the partner repack, as stored in preference "distribution.id"
// and included in Firefox and other update pings. Note this is not the same as
// Services.appinfo.distributionID (value of MOZ_DISTRIBUTION_ID is set at build time).
let distribution =
Services.prefs.getDefaultBranch("distribution.").getCharPref("id", "default");
appinfo["distribution"] = distribution;
let isDefaultBrowser = null;
try {
let shell = aWindow.getShellService();
if (shell) {
isDefaultBrowser = shell.isDefaultBrowser(false);
}
} catch (e) {}
appinfo["defaultBrowser"] = isDefaultBrowser;
let canSetDefaultBrowserInBackground = true;
if (AppConstants.isPlatformAndVersionAtLeast("win", "6.2") ||
AppConstants.isPlatformAndVersionAtLeast("macosx", "10.10")) {
canSetDefaultBrowserInBackground = false;
} else if (AppConstants.platform == "linux") {
// The ShellService may not exist on some versions of Linux.
try {
aWindow.getShellService();
} catch (e) {
canSetDefaultBrowserInBackground = null;
}
}
appinfo["canSetDefaultBrowserInBackground"] =
canSetDefaultBrowserInBackground;
// Expose Profile creation and last reset dates in weeks.
const ONE_WEEK = 7 * 24 * 60 * 60 * 1000;
let profileAge = new ProfileAge(null, null);
let createdDate = await profileAge.created;
let resetDate = await profileAge.reset;
let createdWeeksAgo = Math.floor((Date.now() - createdDate) / ONE_WEEK);
let resetWeeksAgo = null;
if (resetDate) {
resetWeeksAgo = Math.floor((Date.now() - resetDate) / ONE_WEEK);
}
appinfo["profileCreatedWeeksAgo"] = createdWeeksAgo;
appinfo["profileResetWeeksAgo"] = resetWeeksAgo;
this.sendPageCallback(aMessageManager, aCallbackID, appinfo);
})().catch(err => {
log.error(err);
this.sendPageCallback(aMessageManager, aCallbackID, {});
})
},
getAvailableTargets(aMessageManager, aChromeWindow, aCallbackID) {
(async () => {
let window = aChromeWindow;

Просмотреть файл

@ -8,6 +8,8 @@ var gContentAPI;
var gContentWindow;
Components.utils.import("resource://testing-common/TelemetryArchiveTesting.jsm", this);
Components.utils.import("resource://gre/modules/ProfileAge.jsm", this);
function test() {
UITourTest();
@ -303,6 +305,21 @@ var tests = [
});
});
},
function test_getConfigurationProfileAge(done) {
gContentAPI.getConfiguration("appinfo", (result) => {
ok(typeof(result.profileCreatedWeeksAgo) === "number", "profileCreatedWeeksAgo should be number.");
ok(result.profileResetWeeksAgo === null, "profileResetWeeksAgo should be null.");
// Set profile reset date to 15 days ago.
let profileAccessor = new ProfileAge();
profileAccessor.recordProfileReset(Date.now() - (15 * 24 * 60 * 60 * 1000));
gContentAPI.getConfiguration("appinfo", (result2) => {
ok(typeof(result2.profileResetWeeksAgo) === "number", "profileResetWeeksAgo should be number.");
is(result2.profileResetWeeksAgo, 2, "profileResetWeeksAgo should be 2.");
done();
});
});
},
function test_addToolbarButton(done) {
let placement = CustomizableUI.getPlacementOfWidget("panic-button");
is(placement, null, "default UI has panic button in the palette");