2013-11-23 00:55:33 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
|
|
|
|
2014-02-19 17:58:06 +00:00
|
|
|
Cu.import("resource://gre/modules/Accounts.jsm");
|
2013-11-23 00:55:33 +00:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "Home", "resource://gre/modules/Home.jsm");
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "OS", "resource://gre/modules/osfile.jsm");
|
2013-12-03 00:54:21 +00:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "Task", "resource://gre/modules/Task.jsm");
|
2014-05-27 21:04:47 +00:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "UITelemetry", "resource://gre/modules/UITelemetry.jsm");
|
|
|
|
|
2013-11-23 00:55:33 +00:00
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "gEncoder", function() { return new gChromeWin.TextEncoder(); });
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "gDecoder", function() { return new gChromeWin.TextDecoder(); });
|
|
|
|
|
|
|
|
// URL to fetch snippets, in the urlFormatter service format.
|
|
|
|
const SNIPPETS_UPDATE_URL_PREF = "browser.snippets.updateUrl";
|
|
|
|
|
2013-12-03 00:54:21 +00:00
|
|
|
// URL to send stats data to metrics.
|
|
|
|
const SNIPPETS_STATS_URL_PREF = "browser.snippets.statsUrl";
|
|
|
|
|
2013-11-23 00:55:33 +00:00
|
|
|
// URL to fetch country code, a value that's cached and refreshed once per month.
|
|
|
|
const SNIPPETS_GEO_URL_PREF = "browser.snippets.geoUrl";
|
|
|
|
|
|
|
|
// Timestamp when we last updated the user's country code.
|
|
|
|
const SNIPPETS_GEO_LAST_UPDATE_PREF = "browser.snippets.geoLastUpdate";
|
|
|
|
|
|
|
|
// Pref where we'll cache the user's country.
|
|
|
|
const SNIPPETS_COUNTRY_CODE_PREF = "browser.snippets.countryCode";
|
|
|
|
|
2014-02-21 02:04:08 +00:00
|
|
|
// Pref where we store an array IDs of snippets that should not be shown again
|
|
|
|
const SNIPPETS_REMOVED_IDS_PREF = "browser.snippets.removedIds";
|
|
|
|
|
2013-11-23 00:55:33 +00:00
|
|
|
// How frequently we update the user's country code from the server (30 days).
|
|
|
|
const SNIPPETS_GEO_UPDATE_INTERVAL_MS = 86400000*30;
|
|
|
|
|
|
|
|
// Should be bumped up if the snippets content format changes.
|
|
|
|
const SNIPPETS_VERSION = 1;
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "gSnippetsURL", function() {
|
|
|
|
let updateURL = Services.prefs.getCharPref(SNIPPETS_UPDATE_URL_PREF).replace("%SNIPPETS_VERSION%", SNIPPETS_VERSION);
|
|
|
|
return Services.urlFormatter.formatURL(updateURL);
|
|
|
|
});
|
|
|
|
|
2013-12-03 00:54:21 +00:00
|
|
|
// Where we cache snippets data
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "gSnippetsPath", function() {
|
|
|
|
return OS.Path.join(OS.Constants.Path.profileDir, "snippets.json");
|
|
|
|
});
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "gStatsURL", function() {
|
|
|
|
return Services.prefs.getCharPref(SNIPPETS_STATS_URL_PREF);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Where we store stats about which snippets have been shown
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "gStatsPath", function() {
|
|
|
|
return OS.Path.join(OS.Constants.Path.profileDir, "snippets-stats.txt");
|
|
|
|
});
|
|
|
|
|
2013-11-23 00:55:33 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "gGeoURL", function() {
|
|
|
|
return Services.prefs.getCharPref(SNIPPETS_GEO_URL_PREF);
|
|
|
|
});
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "gCountryCode", function() {
|
|
|
|
try {
|
|
|
|
return Services.prefs.getCharPref(SNIPPETS_COUNTRY_CODE_PREF);
|
|
|
|
} catch (e) {
|
|
|
|
// Return an empty string if the country code pref isn't set yet.
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "gChromeWin", function() {
|
|
|
|
return Services.wm.getMostRecentWindow("navigator:browser");
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates snippet data and country code (if necessary).
|
|
|
|
*/
|
|
|
|
function update() {
|
|
|
|
// Check to see if we should update the user's country code from the geo server.
|
|
|
|
let lastUpdate = 0;
|
|
|
|
try {
|
|
|
|
lastUpdate = parseFloat(Services.prefs.getCharPref(SNIPPETS_GEO_LAST_UPDATE_PREF));
|
|
|
|
} catch (e) {}
|
|
|
|
|
|
|
|
if (Date.now() - lastUpdate > SNIPPETS_GEO_UPDATE_INTERVAL_MS) {
|
|
|
|
// We should update the snippets after updating the country code,
|
|
|
|
// so that we can filter snippets to add to the banner.
|
|
|
|
updateCountryCode(updateSnippets);
|
|
|
|
} else {
|
|
|
|
updateSnippets();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetches the user's country code from the geo server and stores the value in a pref.
|
|
|
|
*
|
|
|
|
* @param callback function called once country code is updated
|
|
|
|
*/
|
|
|
|
function updateCountryCode(callback) {
|
|
|
|
_httpGetRequest(gGeoURL, function(responseText) {
|
|
|
|
// Store the country code in a pref.
|
|
|
|
let data = JSON.parse(responseText);
|
|
|
|
Services.prefs.setCharPref(SNIPPETS_COUNTRY_CODE_PREF, data.country_code);
|
|
|
|
|
|
|
|
// Set last update time.
|
|
|
|
Services.prefs.setCharPref(SNIPPETS_GEO_LAST_UPDATE_PREF, Date.now());
|
|
|
|
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads snippets from snippets server, caches the response, and
|
|
|
|
* updates the home banner with the new set of snippets.
|
|
|
|
*/
|
|
|
|
function updateSnippets() {
|
|
|
|
_httpGetRequest(gSnippetsURL, function(responseText) {
|
2014-03-01 01:26:56 +00:00
|
|
|
try {
|
|
|
|
let messages = JSON.parse(responseText);
|
|
|
|
updateBanner(messages);
|
|
|
|
|
|
|
|
// Only cache the response if it is valid JSON.
|
|
|
|
cacheSnippets(responseText);
|
|
|
|
} catch (e) {
|
|
|
|
Cu.reportError("Error parsing snippets responseText: " + e);
|
|
|
|
}
|
2013-11-23 00:55:33 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Caches snippets server response text to `snippets.json` in profile directory.
|
|
|
|
*
|
|
|
|
* @param response responseText returned from snippets server
|
|
|
|
*/
|
|
|
|
function cacheSnippets(response) {
|
|
|
|
let data = gEncoder.encode(response);
|
2013-12-03 00:54:21 +00:00
|
|
|
let promise = OS.File.writeAtomic(gSnippetsPath, data, { tmpPath: gSnippetsPath + ".tmp" });
|
2013-11-23 00:55:33 +00:00
|
|
|
promise.then(null, e => Cu.reportError("Error caching snippets: " + e));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads snippets from cached `snippets.json`.
|
|
|
|
*/
|
|
|
|
function loadSnippetsFromCache() {
|
2013-12-03 00:54:21 +00:00
|
|
|
let promise = OS.File.read(gSnippetsPath);
|
2014-03-01 01:26:56 +00:00
|
|
|
promise.then(array => {
|
|
|
|
let messages = JSON.parse(gDecoder.decode(array));
|
|
|
|
updateBanner(messages);
|
|
|
|
}, e => {
|
2013-11-23 00:55:33 +00:00
|
|
|
if (e instanceof OS.File.Error && e.becauseNoSuchFile) {
|
2014-03-06 17:25:08 +00:00
|
|
|
Services.console.logStringMessage("Couldn't show snippets because cache does not exist yet.");
|
2013-11-23 00:55:33 +00:00
|
|
|
} else {
|
|
|
|
Cu.reportError("Error loading snippets from cache: " + e);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Array of the message ids added to the home banner, used to remove
|
|
|
|
// older set of snippets when new ones are available.
|
|
|
|
var gMessageIds = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates set of snippets in the home banner message rotation.
|
|
|
|
*
|
2014-03-01 01:26:56 +00:00
|
|
|
* @param messages JSON array of message data JSON objects.
|
2013-11-23 00:55:33 +00:00
|
|
|
* Each message object should have the following properties:
|
|
|
|
* - id (?): Unique identifier for this snippets message
|
|
|
|
* - text (string): Text to show as banner message
|
|
|
|
* - url (string): URL to open when banner is clicked
|
|
|
|
* - icon (data URI): Icon to appear in banner
|
2015-05-07 16:42:59 +00:00
|
|
|
* - countries (list of strings): Country codes for where this message should be shown (e.g. ["US", "GR"])
|
2013-11-23 00:55:33 +00:00
|
|
|
*/
|
2014-03-01 01:26:56 +00:00
|
|
|
function updateBanner(messages) {
|
2013-11-23 00:55:33 +00:00
|
|
|
// Remove the current messages, if there are any.
|
|
|
|
gMessageIds.forEach(function(id) {
|
|
|
|
Home.banner.remove(id);
|
|
|
|
})
|
|
|
|
gMessageIds = [];
|
|
|
|
|
2014-02-21 02:04:08 +00:00
|
|
|
try {
|
|
|
|
let removedSnippetIds = JSON.parse(Services.prefs.getCharPref(SNIPPETS_REMOVED_IDS_PREF));
|
|
|
|
messages = messages.filter(function(message) {
|
|
|
|
// Only include the snippet if it has not been previously removed.
|
|
|
|
return removedSnippetIds.indexOf(message.id) === -1;
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
// If the pref doesn't exist, there aren't any snippets to filter out.
|
|
|
|
}
|
|
|
|
|
2013-11-23 00:55:33 +00:00
|
|
|
messages.forEach(function(message) {
|
|
|
|
// Don't add this message to the banner if it's not supposed to be shown in this country.
|
2015-05-07 16:42:59 +00:00
|
|
|
if ("countries" in message && message.countries.indexOf(gCountryCode) === -1) {
|
2013-11-23 00:55:33 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-05-07 16:42:59 +00:00
|
|
|
|
2013-11-23 00:55:33 +00:00
|
|
|
let id = Home.banner.add({
|
|
|
|
text: message.text,
|
|
|
|
icon: message.icon,
|
2014-04-30 21:38:02 +00:00
|
|
|
weight: message.weight,
|
2013-11-23 00:55:33 +00:00
|
|
|
onclick: function() {
|
2015-11-13 20:37:40 +00:00
|
|
|
gChromeWin.BrowserApp.loadURI(message.url);
|
2016-02-11 20:29:25 +00:00
|
|
|
removeSnippet(id, message.id);
|
2014-05-28 23:01:02 +00:00
|
|
|
UITelemetry.addEvent("action.1", "banner", null, message.id);
|
2013-11-23 00:55:33 +00:00
|
|
|
},
|
2014-02-21 02:04:08 +00:00
|
|
|
ondismiss: function() {
|
2016-02-11 20:29:25 +00:00
|
|
|
removeSnippet(id, message.id);
|
2014-05-28 23:01:02 +00:00
|
|
|
UITelemetry.addEvent("cancel.1", "banner", null, message.id);
|
2014-02-21 02:04:08 +00:00
|
|
|
},
|
2013-11-23 00:55:33 +00:00
|
|
|
onshown: function() {
|
2013-12-03 00:54:21 +00:00
|
|
|
// 10% of the time, record the snippet id and a timestamp
|
|
|
|
if (Math.random() < .1) {
|
|
|
|
writeStat(message.id, new Date().toISOString());
|
|
|
|
}
|
2013-11-23 00:55:33 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
// Keep track of the message we added so that we can remove it later.
|
|
|
|
gMessageIds.push(id);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-02-21 02:04:08 +00:00
|
|
|
/**
|
2016-02-11 20:29:25 +00:00
|
|
|
* Removes a snippet message from the home banner rotation, and stores its
|
|
|
|
* snippet id in a pref so we'll never show it again.
|
2014-02-21 02:04:08 +00:00
|
|
|
*
|
2016-02-11 20:29:25 +00:00
|
|
|
* @param messageId unique id for home banner message, returned from Home.banner API
|
2014-02-21 02:04:08 +00:00
|
|
|
* @param snippetId unique id for snippet, sent from snippets server
|
|
|
|
*/
|
2016-02-11 20:29:25 +00:00
|
|
|
function removeSnippet(messageId, snippetId) {
|
|
|
|
// Remove the message from the home banner rotation.
|
|
|
|
Home.banner.remove(messageId);
|
|
|
|
|
|
|
|
// Remove the message from the stored message ids.
|
|
|
|
gMessageIds.splice(gMessageIds.indexOf(messageId), 1);
|
|
|
|
|
2014-02-21 02:04:08 +00:00
|
|
|
let removedSnippetIds;
|
|
|
|
try {
|
|
|
|
removedSnippetIds = JSON.parse(Services.prefs.getCharPref(SNIPPETS_REMOVED_IDS_PREF));
|
|
|
|
} catch (e) {
|
|
|
|
removedSnippetIds = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
removedSnippetIds.push(snippetId);
|
|
|
|
Services.prefs.setCharPref(SNIPPETS_REMOVED_IDS_PREF, JSON.stringify(removedSnippetIds));
|
|
|
|
}
|
|
|
|
|
2013-12-03 00:54:21 +00:00
|
|
|
/**
|
|
|
|
* Appends snippet id and timestamp to the end of `snippets-stats.txt`.
|
|
|
|
*
|
|
|
|
* @param snippetId unique id for snippet, sent from snippets server
|
|
|
|
* @param timestamp in ISO8601
|
|
|
|
*/
|
|
|
|
function writeStat(snippetId, timestamp) {
|
|
|
|
let data = gEncoder.encode(snippetId + "," + timestamp + ";");
|
|
|
|
|
2015-07-03 15:02:59 +00:00
|
|
|
Task.spawn(function() {
|
2013-12-03 00:54:21 +00:00
|
|
|
try {
|
|
|
|
let file = yield OS.File.open(gStatsPath, { append: true, write: true });
|
|
|
|
try {
|
|
|
|
yield file.write(data);
|
|
|
|
} finally {
|
|
|
|
yield file.close();
|
|
|
|
}
|
|
|
|
} catch (ex if ex instanceof OS.File.Error && ex.becauseNoSuchFile) {
|
|
|
|
// If the file doesn't exist yet, create it.
|
|
|
|
yield OS.File.writeAtomic(gStatsPath, data, { tmpPath: gStatsPath + ".tmp" });
|
|
|
|
}
|
|
|
|
}).then(null, e => Cu.reportError("Error writing snippets stats: " + e));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads snippets stats data from `snippets-stats.txt` and sends the data to metrics.
|
|
|
|
*/
|
|
|
|
function sendStats() {
|
|
|
|
let promise = OS.File.read(gStatsPath);
|
|
|
|
promise.then(array => sendStatsRequest(gDecoder.decode(array)), e => {
|
|
|
|
if (e instanceof OS.File.Error && e.becauseNoSuchFile) {
|
|
|
|
// If the file doesn't exist, there aren't any stats to send.
|
|
|
|
} else {
|
|
|
|
Cu.reportError("Error eading snippets stats: " + e);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends stats to metrics about which snippets have been shown.
|
|
|
|
* Appends snippet ids and timestamps as parameters to a GET request.
|
|
|
|
* e.g. https://snippets-stats.mozilla.org/mobile?s1=3825&t1=2013-11-17T18:27Z&s2=6326&t2=2013-11-18T18:27Z
|
|
|
|
*
|
|
|
|
* @param data contents of stats data file
|
|
|
|
*/
|
|
|
|
function sendStatsRequest(data) {
|
|
|
|
let params = [];
|
|
|
|
let stats = data.split(";");
|
|
|
|
|
|
|
|
// The last item in the array will be an empty string, so stop before then.
|
|
|
|
for (let i = 0; i < stats.length - 1; i++) {
|
|
|
|
let stat = stats[i].split(",");
|
|
|
|
params.push("s" + i + "=" + encodeURIComponent(stat[0]));
|
|
|
|
params.push("t" + i + "=" + encodeURIComponent(stat[1]));
|
|
|
|
}
|
|
|
|
|
|
|
|
let url = gStatsURL + "?" + params.join("&");
|
|
|
|
|
|
|
|
// Remove the file after succesfully sending the data.
|
|
|
|
_httpGetRequest(url, removeStats);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes text file where we store snippets stats.
|
|
|
|
*/
|
|
|
|
function removeStats() {
|
|
|
|
let promise = OS.File.remove(gStatsPath);
|
|
|
|
promise.then(null, e => Cu.reportError("Error removing snippets stats: " + e));
|
|
|
|
}
|
|
|
|
|
2013-11-23 00:55:33 +00:00
|
|
|
/**
|
|
|
|
* Helper function to make HTTP GET requests.
|
|
|
|
*
|
|
|
|
* @param url where we send the request
|
|
|
|
* @param callback function that is called with the xhr responseText
|
|
|
|
*/
|
|
|
|
function _httpGetRequest(url, callback) {
|
|
|
|
let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpRequest);
|
|
|
|
try {
|
|
|
|
xhr.open("GET", url, true);
|
|
|
|
} catch (e) {
|
|
|
|
Cu.reportError("Error opening request to " + url + ": " + e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
xhr.onerror = function onerror(e) {
|
|
|
|
Cu.reportError("Error making request to " + url + ": " + e.error);
|
|
|
|
}
|
|
|
|
xhr.onload = function onload(event) {
|
|
|
|
if (xhr.status !== 200) {
|
|
|
|
Cu.reportError("Request to " + url + " returned status " + xhr.status);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (callback) {
|
|
|
|
callback(xhr.responseText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xhr.send(null);
|
|
|
|
}
|
|
|
|
|
2014-01-18 00:08:44 +00:00
|
|
|
function loadSyncPromoBanner() {
|
2014-02-19 17:58:06 +00:00
|
|
|
Accounts.anySyncAccountsExist().then(
|
|
|
|
(exist) => {
|
|
|
|
// Don't show the banner if sync accounts exist.
|
|
|
|
if (exist) {
|
|
|
|
return;
|
|
|
|
}
|
2014-01-18 00:08:44 +00:00
|
|
|
|
2014-02-19 17:58:06 +00:00
|
|
|
let stringBundle = Services.strings.createBundle("chrome://browser/locale/sync.properties");
|
|
|
|
let text = stringBundle.GetStringFromName("promoBanner.message.text");
|
|
|
|
let link = stringBundle.GetStringFromName("promoBanner.message.link");
|
2014-01-18 00:08:44 +00:00
|
|
|
|
2014-02-22 17:41:31 +00:00
|
|
|
let id = Home.banner.add({
|
2014-02-19 17:58:06 +00:00
|
|
|
text: text + "<a href=\"#\">" + link + "</a>",
|
|
|
|
icon: "drawable://sync_promo",
|
|
|
|
onclick: function() {
|
2014-03-07 19:23:27 +00:00
|
|
|
// Remove the message, so that it won't show again for the rest of the app lifetime.
|
|
|
|
Home.banner.remove(id);
|
2014-02-19 17:58:06 +00:00
|
|
|
Accounts.launchSetup();
|
2014-05-27 21:04:47 +00:00
|
|
|
|
2014-05-28 23:01:02 +00:00
|
|
|
UITelemetry.addEvent("action.1", "banner", null, "syncpromo");
|
2014-02-22 17:41:31 +00:00
|
|
|
},
|
|
|
|
ondismiss: function() {
|
|
|
|
// Remove the sync promo message from the banner and never try to show it again.
|
|
|
|
Home.banner.remove(id);
|
|
|
|
Services.prefs.setBoolPref("browser.snippets.syncPromo.enabled", false);
|
2014-05-27 21:04:47 +00:00
|
|
|
|
2014-05-28 23:01:02 +00:00
|
|
|
UITelemetry.addEvent("cancel.1", "banner", null, "syncpromo");
|
2014-02-19 17:58:06 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
(err) => {
|
|
|
|
Cu.reportError("Error checking whether sync account exists: " + err);
|
2014-01-18 00:08:44 +00:00
|
|
|
}
|
2014-02-19 17:58:06 +00:00
|
|
|
);
|
2014-01-18 00:08:44 +00:00
|
|
|
}
|
|
|
|
|
2014-08-22 22:07:40 +00:00
|
|
|
function loadHomePanelsBanner() {
|
|
|
|
let stringBundle = Services.strings.createBundle("chrome://browser/locale/aboutHome.properties");
|
|
|
|
let text = stringBundle.GetStringFromName("banner.firstrunHomepage.text");
|
|
|
|
|
|
|
|
let id = Home.banner.add({
|
|
|
|
text: text,
|
|
|
|
icon: "drawable://homepage_banner_firstrun",
|
|
|
|
onclick: function() {
|
|
|
|
// Remove the message, so that it won't show again for the rest of the app lifetime.
|
|
|
|
Home.banner.remove(id);
|
|
|
|
// User has interacted with this snippet so don't show it again.
|
|
|
|
Services.prefs.setBoolPref("browser.snippets.firstrunHomepage.enabled", false);
|
|
|
|
|
|
|
|
UITelemetry.addEvent("action.1", "banner", null, "firstrun-homepage");
|
|
|
|
},
|
|
|
|
ondismiss: function() {
|
|
|
|
Home.banner.remove(id);
|
|
|
|
Services.prefs.setBoolPref("browser.snippets.firstrunHomepage.enabled", false);
|
|
|
|
|
|
|
|
UITelemetry.addEvent("cancel.1", "banner", null, "firstrun-homepage");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-11-23 00:55:33 +00:00
|
|
|
function Snippets() {}
|
|
|
|
|
|
|
|
Snippets.prototype = {
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsITimerCallback]),
|
|
|
|
classID: Components.ID("{a78d7e59-b558-4321-a3d6-dffe2f1e76dd}"),
|
|
|
|
|
|
|
|
observe: function(subject, topic, data) {
|
|
|
|
switch(topic) {
|
2014-01-28 07:01:00 +00:00
|
|
|
case "browser-delayed-startup-finished":
|
2014-08-25 22:31:49 +00:00
|
|
|
// Add snippets to be cycled through.
|
2014-08-22 22:07:40 +00:00
|
|
|
if (Services.prefs.getBoolPref("browser.snippets.firstrunHomepage.enabled")) {
|
|
|
|
loadHomePanelsBanner();
|
2014-08-25 22:31:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Services.prefs.getBoolPref("browser.snippets.syncPromo.enabled")) {
|
2014-01-18 00:08:44 +00:00
|
|
|
loadSyncPromoBanner();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Services.prefs.getBoolPref("browser.snippets.enabled")) {
|
|
|
|
loadSnippetsFromCache();
|
|
|
|
}
|
2013-11-23 00:55:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// By default, this timer fires once every 24 hours. See the "browser.snippets.updateInterval" pref.
|
|
|
|
notify: function(timer) {
|
2013-12-05 20:43:22 +00:00
|
|
|
if (!Services.prefs.getBoolPref("browser.snippets.enabled")) {
|
2013-11-23 00:55:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
update();
|
2013-12-03 00:54:21 +00:00
|
|
|
sendStats();
|
2013-11-23 00:55:33 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([Snippets]);
|