Bug 1344319 - Create Activity Stream browser extension. r=rhelmer

MozReview-Commit-ID: EUthIoHKlOm

--HG--
extra : rebase_source : c2f81b795b79eae4b2dca6526f5000181d3fa2c5
This commit is contained in:
k88hudson 2017-03-09 14:56:28 -05:00
Родитель cf1be9f14d
Коммит b61a06ef8e
8 изменённых файлов: 186 добавлений и 0 удалений

94
browser/extensions/activity-stream/bootstrap.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,94 @@
/* 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/. */
/* globals Components, XPCOMUtils, Preferences, ActivityStream */
"use strict";
const {utils: Cu} = Components;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Preferences.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "ActivityStream",
"resource://activity-stream/lib/ActivityStream.jsm");
const ACTIVITY_STREAM_ENABLED_PREF = "browser.newtabpage.activity-stream.enabled";
const REASON_STARTUP_ON_PREF_CHANGE = "PREF_ON";
const REASON_SHUTDOWN_ON_PREF_CHANGE = "PREF_OFF";
const ACTIVITY_STREAM_OPTIONS = {newTabURL: "about:newtab"};
let activityStream;
let startupData;
/**
* init - Initializes an instance of ActivityStream. This could be called by
* the startup() function exposed by bootstrap.js, or it could be called
* when ACTIVITY_STREAM_ENABLED_PREF is changed from false to true.
*
* @param {string} reason - Reason for initialization. Could be install, upgrade, or PREF_ON
*/
function init(reason) {
// Don't re-initialize
if (activityStream && activityStream.initialized) {
return;
}
const options = Object.assign({}, startupData || {}, ACTIVITY_STREAM_OPTIONS);
activityStream = new ActivityStream(options);
activityStream.init(reason);
}
/**
* uninit - Uninitializes the activityStream instance, if it exsits.This could be
* called by the shutdown() function exposed by bootstrap.js, or it could
* be called when ACTIVITY_STREAM_ENABLED_PREF is changed from true to false.
*
* @param {type} reason Reason for uninitialization. Could be uninstall, upgrade, or PREF_OFF
*/
function uninit(reason) {
if (activityStream) {
activityStream.uninit(reason);
activityStream = null;
}
}
/**
* onPrefChanged - handler for changes to ACTIVITY_STREAM_ENABLED_PREF
*
* @param {bool} isEnabled Determines whether Activity Stream is enabled
*/
function onPrefChanged(isEnabled) {
if (isEnabled) {
init(REASON_STARTUP_ON_PREF_CHANGE);
} else {
uninit(REASON_SHUTDOWN_ON_PREF_CHANGE);
}
}
// The functions below are required by bootstrap.js
this.install = function install(data, reason) {};
this.startup = function startup(data, reason) {
// Cache startup data which contains stuff like the version number, etc.
// so we can use it when we init
startupData = data;
// Listen for changes to the pref that enables Activity Stream
Preferences.observe(ACTIVITY_STREAM_ENABLED_PREF, onPrefChanged);
// Only initialize if the pref is true
if (Preferences.get(ACTIVITY_STREAM_ENABLED_PREF)) {
init(reason);
}
};
this.shutdown = function shutdown(data, reason) {
// Uninitialize Activity Stream
startupData = null;
uninit(reason);
// Stop listening to the pref that enables Activity Stream
Preferences.ignore(ACTIVITY_STREAM_ENABLED_PREF, onPrefChanged);
};
this.uninstall = function uninstall(data, reason) {};

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

@ -0,0 +1,12 @@
<!doctype html>
<html lang="en-us" dir="ltr">
<head>
<meta charset="utf-8">
<title>New Tab</title>
</head>
<body>
<div id="root">
<h1>New Tab</h1>
</div>
</body>
</html>

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

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
#filter substitution
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>activity-stream@mozilla.org</em:id>
<em:type>2</em:type>
<em:bootstrap>true</em:bootstrap>
<em:unpack>false</em:unpack>
<em:version>0.0.0</em:version>
<em:name>Activity Stream</em:name>
<em:description>A rich visual history feed and a reimagined home page make it easier than ever to find exactly what you're looking for in Firefox.</em:description>
<em:multiprocessCompatible>true</em:multiprocessCompatible>
<em:targetApplication>
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>@MOZ_APP_VERSION@</em:minVersion>
<em:maxVersion>@MOZ_APP_MAXVERSION@</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
</RDF>

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

@ -0,0 +1,8 @@
# 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/.
[features/activity-stream@mozilla.org] chrome.jar:
% resource activity-stream %content/
content/lib/ (./lib/*)
content/data/ (./data/*)

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

@ -0,0 +1,28 @@
/* 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/. */
"use strict";
class ActivityStream {
/**
* constructor - Initializes an instance of ActivityStream
*
* @param {object} options Options for the ActivityStream instance
* @param {string} options.id Add-on ID. e.g. "activity-stream@mozilla.org".
* @param {string} options.version Version of the add-on. e.g. "0.1.0"
* @param {string} options.newTabURL URL of New Tab page on which A.S. is displayed. e.g. "about:newtab"
*/
constructor(options) {
this.initialized = false;
this.options = options;
}
init() {
this.initialized = true;
}
uninit() {
this.initialized = false;
}
}
this.EXPORTED_SYMBOLS = ["ActivityStream"];

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

@ -0,0 +1,18 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.
DEFINES['MOZ_APP_VERSION'] = CONFIG['MOZ_APP_VERSION']
DEFINES['MOZ_APP_MAXVERSION'] = CONFIG['MOZ_APP_MAXVERSION']
FINAL_TARGET_FILES.features['activity-stream@mozilla.org'] += [
'bootstrap.js',
]
FINAL_TARGET_PP_FILES.features['activity-stream@mozilla.org'] += [
'install.rdf.in'
]
JAR_MANIFESTS += ['jar.mn']

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

@ -30,5 +30,6 @@ if CONFIG['MOZ_MORTAR']:
# Nightly-only system add-ons
if CONFIG['NIGHTLY_BUILD']:
DIRS += [
'activity-stream',
'webcompat-reporter',
]

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

@ -16,6 +16,7 @@
"{firefox}\\browser\\features\\webcompat@mozilla.org.xpi": {"mincount": 0, "maxcount": 100, "minbytes": 0, "maxbytes": 10000000},
"{firefox}\\browser\\features\\webcompat-reporter@mozilla.org.xpi": {"mincount": 0, "maxcount": 100, "minbytes": 0, "maxbytes": 10000000},
"{firefox}\\browser\\features\\shield-recipe-client@mozilla.org.xpi": {"mincount": 0, "maxcount": 100, "minbytes": 0, "maxbytes": 10000000},
"{firefox}\\browser\\features\\activity-stream@mozilla.org.xpi": {"mincount": 0, "maxcount": 100, "minbytes": 0, "maxbytes": 10000000},
"{talos}\\talos\\tests\\tp5n\\tp5n.manifest": {"mincount": 0, "maxcount": 8, "minbytes": 0, "maxbytes": 32786},
"{talos}\\talos\\tests\\tp5n\\tp5n.manifest.develop": {"mincount": 0, "maxcount": 8, "minbytes": 0, "maxbytes": 32786},
"{profile}\\localstore.rdf": {"mincount": 2, "maxcount": 2, "minbytes": 8192, "maxbytes": 8192},