mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-13 05:15:45 +00:00
Bug 563738 (part2) - Add current Mozilla "snippets" (links and special events) in the about:home page. r=gavin,Pike a=blocking
This commit is contained in:
parent
9ea772520a
commit
b95ebd5cd9
@ -109,3 +109,7 @@ body[dir="rtl"] #searchEngineLinks {
|
||||
#aboutMozilla {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#defaultSnippets {
|
||||
text-align: center;
|
||||
}
|
||||
|
@ -54,16 +54,31 @@ const SEARCH_ENGINES = {
|
||||
}
|
||||
};
|
||||
|
||||
// The process of adding a new default snippet involves:
|
||||
// * add a new entity to aboutHome.dtd
|
||||
// * add a <span/> for it in aboutHome.xhtml
|
||||
// * add an entry here in the proper ordering (based on spans)
|
||||
// The <a/> part of the snippet will be linked to the corresponding url.
|
||||
const DEFAULT_SNIPPETS_URLS = [
|
||||
"http://www.mozilla.com/firefox/4.0/features"
|
||||
, "https://addons.mozilla.org/firefox/?browse=featured"
|
||||
];
|
||||
|
||||
const SNIPPETS_UPDATE_INTERVAL_MS = 86400000; // 1 Day.
|
||||
|
||||
let gSearchEngine;
|
||||
|
||||
function onLoad(event)
|
||||
{
|
||||
setupSearchEngine();
|
||||
document.getElementById("searchText").focus();
|
||||
|
||||
loadSnippets();
|
||||
}
|
||||
|
||||
|
||||
function onSearchSubmit(aEvent) {
|
||||
function onSearchSubmit(aEvent)
|
||||
{
|
||||
let searchTerms = document.getElementById("searchText").value;
|
||||
if (gSearchEngine && searchTerms.length > 0) {
|
||||
const SEARCH_TOKENS = {
|
||||
@ -80,7 +95,8 @@ function onSearchSubmit(aEvent) {
|
||||
}
|
||||
|
||||
|
||||
function setupSearchEngine() {
|
||||
function setupSearchEngine()
|
||||
{
|
||||
gSearchEngine = JSON.parse(localStorage["search-engine"]);
|
||||
|
||||
// Look for extended information, like logo and links.
|
||||
@ -115,3 +131,56 @@ function setupSearchEngine() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function loadSnippets()
|
||||
{
|
||||
// Check last snippets update.
|
||||
let lastUpdate = localStorage["snippets-last-update"];
|
||||
let updateURL = localStorage["snippets-update-url"];
|
||||
if (updateURL && (!lastUpdate ||
|
||||
Date.now() - lastUpdate > SNIPPETS_UPDATE_INTERVAL_MS)) {
|
||||
// Try to update from network.
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.mozBackgroundRequest = true;
|
||||
xhr.open('GET', updateURL, true);
|
||||
xhr.onerror = function (event) {
|
||||
showSnippets();
|
||||
};
|
||||
xhr.onload = function (event)
|
||||
{
|
||||
if (xhr.status == 200) {
|
||||
localStorage["snippets"] = xhr.responseText;
|
||||
localStorage["snippets-last-update"] = Date.now();
|
||||
}
|
||||
showSnippets();
|
||||
};
|
||||
xhr.send(null);
|
||||
} else {
|
||||
showSnippets();
|
||||
}
|
||||
}
|
||||
|
||||
function showSnippets()
|
||||
{
|
||||
let snippets = localStorage["snippets"];
|
||||
if (snippets) {
|
||||
let snippetsElt = document.getElementById("snippets");
|
||||
snippetsElt.innerHTML = snippets;
|
||||
snippetsElt.hidden = false;
|
||||
} else {
|
||||
// If there are no saved snippets, show one of the default ones.
|
||||
let defaultSnippetsElt = document.getElementById("defaultSnippets");
|
||||
let entries = defaultSnippetsElt.querySelectorAll("span");
|
||||
// Choose a random snippet. Assume there is always at least one.
|
||||
let randIndex = Math.round(Math.random() * (entries.length - 1));
|
||||
let entry = entries[randIndex];
|
||||
// Inject url in the eventual link.
|
||||
if (DEFAULT_SNIPPETS_URLS[randIndex]) {
|
||||
let links = entry.getElementsByTagName("a");
|
||||
if (links.length != 1)
|
||||
return; // Something is messed up in this entry, we support just 1 link.
|
||||
links[0].href = DEFAULT_SNIPPETS_URLS[randIndex];
|
||||
}
|
||||
entry.hidden = false;
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +81,11 @@
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="defaultSnippets">
|
||||
<span hidden="true">&abouthome.defaultSnippet1.v1;</span>
|
||||
<span hidden="true">&abouthome.defaultSnippet2.v1;</span>
|
||||
</div>
|
||||
<div id="snippets" hidden="true"/>
|
||||
<div id="bottomSection">
|
||||
<div id="aboutMozilla">
|
||||
<a href="http://www.mozilla.com/about/">&abouthome.aboutMozilla;</a>
|
||||
|
@ -585,6 +585,7 @@ nsBrowserContentHandler.prototype = {
|
||||
if (override != OVERRIDE_NONE) {
|
||||
// Setup the default search engine to about:home page.
|
||||
AboutHomeUtils.loadDefaultSearchEngine();
|
||||
AboutHomeUtils.loadSnippetsURL();
|
||||
|
||||
switch (override) {
|
||||
case OVERRIDE_NEW_PROFILE:
|
||||
@ -903,7 +904,17 @@ let AboutHomeUtils = {
|
||||
, searchUrl: submission.uri.spec
|
||||
}
|
||||
this._storage.setItem("search-engine", JSON.stringify(engine));
|
||||
}
|
||||
},
|
||||
|
||||
loadSnippetsURL: function AHU_loadSnippetsURL()
|
||||
{
|
||||
const STARTPAGE_VERSION = 1;
|
||||
const SNIPPETS_URL = "http://snippets.mozilla.com/" + STARTPAGE_VERSION + "/%NAME%/%VERSION%/%APPBUILDID%/%BUILD_TARGET%/%LOCALE%/%CHANNEL%/%OS_VERSION%/%DISTRIBUTION%/%DISTRIBUTION_VERSION%/";
|
||||
let updateURL = Components.classes["@mozilla.org/toolkit/URLFormatterService;1"].
|
||||
getService(Components.interfaces.nsIURLFormatter).
|
||||
formatURL(SNIPPETS_URL);
|
||||
this._storage.setItem("snippets-update-url", updateURL);
|
||||
},
|
||||
};
|
||||
|
||||
var components = [nsBrowserContentHandler, nsDefaultCommandLineHandler];
|
||||
|
@ -6,7 +6,9 @@
|
||||
|
||||
<!ENTITY abouthome.pageTitle "&brandFullName; Start Page">
|
||||
|
||||
<!-- LOCALIZATION NOTE (brandStart): brandShortName must be in a <span/> -->
|
||||
<!-- LOCALIZATION NOTE (abouthome.brandStart):
|
||||
brandShortName must be in a <span/>
|
||||
-->
|
||||
<!ENTITY abouthome.brandStart "<span>&brandShortName;</span> Start">
|
||||
|
||||
<!ENTITY abouthome.searchEngineButton.label "Search">
|
||||
@ -15,3 +17,12 @@
|
||||
<!ENTITY abouthome.searchEngineLinks.preferences "Preferences">
|
||||
|
||||
<!ENTITY abouthome.aboutMozilla "About Mozilla">
|
||||
|
||||
<!-- LOCALIZATION NOTE (abouthome.defaultSnippet1.v1):
|
||||
text in <a/> will be linked to the Firefox features page on mozilla.com
|
||||
-->
|
||||
<!ENTITY abouthome.defaultSnippet1.v1 "Thanks for choosing Firefox! To get the most out of your browser, learn more about the <a>latest features</a>.">
|
||||
<!-- LOCALIZATION NOTE (abouthome.defaultSnippet2.v1):
|
||||
text in <a/> will be linked to the featured add-ons on addons.mozilla.org
|
||||
-->
|
||||
<!ENTITY abouthome.defaultSnippet2.v1 "It's easy to customize your Firefox exactly the way you want it. <a>Choose from thousands of add-ons</a>.">
|
||||
|
Loading…
Reference in New Issue
Block a user