Backed out changeset ca2fd67a4cf7 (bug 1029942) for bc1 orange

This commit is contained in:
Wes Kocher 2014-07-08 15:11:31 -07:00
parent 670e1f258e
commit 2d8c232a05
5 changed files with 14 additions and 327 deletions

View File

@ -179,11 +179,8 @@ SocialUI = {
},
// This handles "ActivateSocialFeature" events fired against content documents
// in this window. If this activation happens from within Firefox, such as
// about:home or the share panel, we bypass the enable prompt. Any website
// activation, such as from the activations directory or a providers website
// will still get the prompt.
_activationEventHandler: function SocialUI_activationHandler(e, aBypassUserEnable=false) {
// in this window.
_activationEventHandler: function SocialUI_activationHandler(e) {
let targetDoc;
let node;
if (e.target instanceof HTMLDocument) {
@ -197,7 +194,8 @@ SocialUI = {
if (!(targetDoc instanceof HTMLDocument))
return;
if (!aBypassUserEnable && targetDoc.defaultView != content)
// Ignore events fired in background tabs or iframes
if (targetDoc.defaultView != content)
return;
// If we are in PB mode, we silently do nothing (bug 829404 exists to
@ -237,7 +235,7 @@ SocialUI = {
openUILinkIn(provider.postActivationURL, "tab");
}
});
}, aBypassUserEnable);
});
},
showLearnMore: function() {

View File

@ -24,7 +24,6 @@ support-files =
social_worker.js
unchecked.jpg
[browser_aboutHome_activation.js]
[browser_addons.js]
[browser_blocklist.js]
[browser_defaults.js]

View File

@ -1,286 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
let SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService;
XPCOMUtils.defineLazyModuleGetter(this, "Promise",
"resource://gre/modules/Promise.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Task",
"resource://gre/modules/Task.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "AboutHomeUtils",
"resource:///modules/AboutHome.jsm");
registerCleanupFunction(function() {
// Ensure we don't pollute prefs for next tests.
Services.prefs.clearUserPref("browser.aboutHomeSnippets.updateUrl");
});
let snippet =
' <script>' +
' var manifest = {' +
' "name": "Demo Social Service",' +
' "origin": "https://example.com",' +
' "iconURL": "chrome://branding/content/icon16.png",' +
' "icon32URL": "chrome://branding/content/favicon32.png",' +
' "icon64URL": "chrome://branding/content/icon64.png",' +
' "sidebarURL": "https://example.com/browser/browser/base/content/test/social/social_sidebar.html",' +
' "postActivationURL": "https://example.com/browser/browser/base/content/test/social/social_postActivation.html",' +
' };' +
' function activateProvider(node) {' +
' node.setAttribute("data-service", JSON.stringify(manifest));' +
' var event = new CustomEvent("ActivateSocialFeature");' +
' node.dispatchEvent(event);' +
' }' +
' </script>' +
' <div id="activationSnippet" onclick="activateProvider(this)">' +
' <img src="chrome://branding/content/favicon32.png"></img>' +
' </div>';
// enable one-click activation
let snippet2 =
' <script>' +
' var manifest = {' +
' "name": "Demo Social Service",' +
' "origin": "https://example.com",' +
' "iconURL": "chrome://branding/content/icon16.png",' +
' "icon32URL": "chrome://branding/content/favicon32.png",' +
' "icon64URL": "chrome://branding/content/icon64.png",' +
' "sidebarURL": "https://example.com/browser/browser/base/content/test/social/social_sidebar.html",' +
' "postActivationURL": "https://example.com/browser/browser/base/content/test/social/social_postActivation.html",' +
' "oneclick": true' +
' };' +
' function activateProvider(node) {' +
' node.setAttribute("data-service", JSON.stringify(manifest));' +
' var event = new CustomEvent("ActivateSocialFeature");' +
' node.dispatchEvent(event);' +
' }' +
' </script>' +
' <div id="activationSnippet" onclick="activateProvider(this)">' +
' <img src="chrome://branding/content/favicon32.png"></img>' +
' </div>';
let gTests = [
{
desc: "Test activation with enable panel",
setup: function (aSnippetsMap)
{
// This must be some incorrect xhtml code.
aSnippetsMap.set("snippets", snippet);
},
run: function (aSnippetsMap)
{
let deferred = Promise.defer();
let doc = gBrowser.selectedTab.linkedBrowser.contentDocument;
let snippetsElt = doc.getElementById("snippets");
ok(snippetsElt, "Found snippets element");
ok(!!doc.getElementById("activationSnippet"),
"The snippet is present.");
activateProvider(gBrowser.selectedTab, true, function() {
ok(SocialSidebar.provider, "provider activated");
checkSocialUI();
is(gBrowser.contentDocument.location.href, SocialSidebar.provider.manifest.postActivationURL);
gBrowser.removeTab(gBrowser.selectedTab);
SocialService.uninstallProvider(SocialSidebar.provider.origin, function () {
info("provider uninstalled");
aSnippetsMap.delete("snippets");
deferred.resolve(true);
});
});
return deferred.promise;
}
},
{
desc: "Test activation bypassing enable panel",
setup: function (aSnippetsMap)
{
// This must be some incorrect xhtml code.
aSnippetsMap.set("snippets", snippet2);
},
run: function (aSnippetsMap)
{
let deferred = Promise.defer();
let doc = gBrowser.selectedTab.linkedBrowser.contentDocument;
let snippetsElt = doc.getElementById("snippets");
ok(snippetsElt, "Found snippets element");
ok(!!doc.getElementById("activationSnippet"),
"The snippet is present.");
activateProvider(gBrowser.selectedTab, false, function() {
ok(SocialSidebar.provider, "provider activated");
checkSocialUI();
is(gBrowser.contentDocument.location.href, SocialSidebar.provider.manifest.postActivationURL);
gBrowser.removeTab(gBrowser.selectedTab);
SocialService.uninstallProvider(SocialSidebar.provider.origin, function () {
info("provider uninstalled");
aSnippetsMap.delete("snippets");
deferred.resolve(true);
});
});
return deferred.promise;
}
}
];
function test()
{
waitForExplicitFinish();
requestLongerTimeout(2);
ignoreAllUncaughtExceptions();
Task.spawn(function () {
for (let test of gTests) {
info(test.desc);
// Make sure we don't try to load snippets from the network.
Services.prefs.setCharPref("browser.aboutHomeSnippets.updateUrl", "nonexistent://test");
// Create a tab to run the test.
let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank");
// Add an event handler to modify the snippets map once it's ready.
let snippetsPromise = promiseSetupSnippetsMap(tab, test.setup);
// Start loading about:home and wait for it to complete.
yield promiseTabLoadEvent(tab, "about:home", "AboutHomeLoadSnippetsSucceeded");
// This promise should already be resolved since the page is done,
// but we still want to get the snippets map out of it.
let snippetsMap = yield snippetsPromise;
info("Running test");
let testPromise = test.run(snippetsMap);
yield testPromise;
info("Cleanup");
gBrowser.removeCurrentTab();
}
}).then(finish, ex => {
ok(false, "Unexpected Exception: " + ex);
finish();
});
}
/**
* Starts a load in an existing tab and waits for it to finish (via some event).
*
* @param aTab
* The tab to load into.
* @param aUrl
* The url to load.
* @param aEvent
* The load event type to wait for. Defaults to "load".
* @return {Promise} resolved when the event is handled.
*/
function promiseTabLoadEvent(aTab, aURL, aEventType="load")
{
let deferred = Promise.defer();
info("Wait tab event: " + aEventType);
aTab.linkedBrowser.addEventListener(aEventType, function load(event) {
if (event.originalTarget != aTab.linkedBrowser.contentDocument ||
event.target.location.href == "about:blank") {
info("skipping spurious load event");
return;
}
aTab.linkedBrowser.removeEventListener(aEventType, load, true);
info("Tab event received: " + aEventType);
deferred.resolve();
}, true, true);
aTab.linkedBrowser.loadURI(aURL);
return deferred.promise;
}
/**
* Cleans up snippets and ensures that by default we don't try to check for
* remote snippets since that may cause network bustage or slowness.
*
* @param aTab
* The tab containing about:home.
* @param aSetupFn
* The setup function to be run.
* @return {Promise} resolved when the snippets are ready. Gets the snippets map.
*/
function promiseSetupSnippetsMap(aTab, aSetupFn)
{
let deferred = Promise.defer();
info("Waiting for snippets map");
aTab.linkedBrowser.addEventListener("AboutHomeLoadSnippets", function load(event) {
aTab.linkedBrowser.removeEventListener("AboutHomeLoadSnippets", load, true);
let cw = aTab.linkedBrowser.contentWindow.wrappedJSObject;
// The snippets should already be ready by this point. Here we're
// just obtaining a reference to the snippets map.
cw.ensureSnippetsMapThen(function (aSnippetsMap) {
aSnippetsMap = Cu.waiveXrays(aSnippetsMap);
info("Got snippets map: " +
"{ last-update: " + aSnippetsMap.get("snippets-last-update") +
", cached-version: " + aSnippetsMap.get("snippets-cached-version") +
" }");
// Don't try to update.
aSnippetsMap.set("snippets-last-update", Date.now());
aSnippetsMap.set("snippets-cached-version", AboutHomeUtils.snippetsVersion);
// Clear snippets.
aSnippetsMap.delete("snippets");
aSetupFn(aSnippetsMap);
deferred.resolve(aSnippetsMap);
});
}, true, true);
return deferred.promise;
}
function sendActivationEvent(tab, callback) {
// hack Social.lastEventReceived so we don't hit the "too many events" check.
Social.lastEventReceived = 0;
let doc = tab.linkedBrowser.contentDocument;
// if our test has a frame, use it
if (doc.defaultView.frames[0])
doc = doc.defaultView.frames[0].document;
let button = doc.getElementById("activationSnippet");
EventUtils.synthesizeMouseAtCenter(button, {}, doc.defaultView);
executeSoon(callback);
}
function activateProvider(tab, expectPanel, aCallback) {
if (expectPanel) {
let panel = document.getElementById("servicesInstall-notification");
PopupNotifications.panel.addEventListener("popupshown", function onpopupshown() {
PopupNotifications.panel.removeEventListener("popupshown", onpopupshown);
panel.button.click();
});
}
sendActivationEvent(tab, function() {
waitForProviderLoad(function() {
ok(SocialSidebar.provider, "new provider is active");
ok(SocialSidebar.opened, "sidebar is open");
checkSocialUI();
executeSoon(aCallback);
});
});
}
function waitForProviderLoad(cb) {
Services.obs.addObserver(function providerSet(subject, topic, data) {
Services.obs.removeObserver(providerSet, "social:provider-enabled");
info("social:provider-enabled observer was notified");
waitForCondition(function() {
let sbrowser = document.getElementById("social-sidebar-browser");
let provider = SocialSidebar.provider;
let postActivation = provider && gBrowser.contentDocument.location.href == provider.origin + "/browser/browser/base/content/test/social/social_postActivation.html";
return provider &&
postActivation &&
sbrowser.docShellIsActive;
}, function() {
// executeSoon to let the browser UI observers run first
executeSoon(cb);
},
"waitForProviderLoad: provider profile was not set");
}, "social:provider-enabled", false);
}

View File

@ -168,8 +168,8 @@ this.Social = {
return SocialService.getManifestByOrigin(origin);
},
installProvider: function(doc, data, installCallback, aBypassUserEnable=false) {
SocialService.installProvider(doc, data, installCallback, aBypassUserEnable);
installProvider: function(doc, data, installCallback) {
SocialService.installProvider(doc, data, installCallback);
},
uninstallProvider: function(origin, aCallback) {

View File

@ -151,17 +151,7 @@ XPCOMUtils.defineLazyGetter(SocialServiceInternal, "providers", function () {
});
function getOriginActivationType(origin) {
// access from moz-safe-about scheme will throw exception in getManifestPrefname
try {
var prefname = SocialServiceInternal.getManifestPrefname(origin);
} catch(e) {
// if this is an about uri, treat it as a directory
let originUri = Services.io.newURI(origin, null, null);
if (originUri.scheme == "moz-safe-about") {
return "internal";
}
throw e;
}
let prefname = SocialServiceInternal.getManifestPrefname(origin);
if (Services.prefs.getDefaultBranch("social.manifest.").getPrefType(prefname) == Services.prefs.PREF_STRING)
return 'builtin';
@ -514,7 +504,7 @@ this.SocialService = {
let featureURLs = ['workerURL', 'sidebarURL', 'shareURL', 'statusURL', 'markURL'];
let resolveURLs = featureURLs.concat(['postActivationURL']);
if (type == 'directory' || type == 'internal') {
if (type == 'directory') {
// directory provided manifests must have origin in manifest, use that
if (!data['origin']) {
Cu.reportError("SocialService.manifestFromData directory service provided manifest without origin.");
@ -579,7 +569,7 @@ this.SocialService = {
let productName = brandBundle.GetStringFromName("brandShortName");
let message = browserBundle.formatStringFromName("service.install.description",
[aAddonInstaller.addon.manifest.name, productName], 2);
[requestingURI.host, productName], 2);
let action = {
label: browserBundle.GetStringFromName("service.install.ok.label"),
@ -598,7 +588,7 @@ this.SocialService = {
action, [], options);
},
installProvider: function(aDOMDocument, data, installCallback, aBypassUserEnable=false) {
installProvider: function(aDOMDocument, data, installCallback) {
let manifest;
let installOrigin = aDOMDocument.nodePrincipal.origin;
@ -613,10 +603,6 @@ this.SocialService = {
if (addon && addon.blocklistState == Ci.nsIBlocklistService.STATE_BLOCKED)
throw new Error("installProvider: provider with origin [" +
installOrigin + "] is blocklisted");
// manifestFromData call above will enforce correct origin. To support
// activation from about: uris, we need to be sure to use the updated
// origin on the manifest.
installOrigin = manifest.origin;
}
let id = getAddonIDFromOrigin(installOrigin);
@ -626,7 +612,7 @@ this.SocialService = {
aAddon.userDisabled = false;
}
schedule(function () {
this._installProvider(aDOMDocument, manifest, aBypassUserEnable, aManifest => {
this._installProvider(aDOMDocument, manifest, aManifest => {
this._notifyProviderListeners("provider-installed", aManifest.origin);
installCallback(aManifest);
});
@ -634,7 +620,7 @@ this.SocialService = {
}.bind(this));
},
_installProvider: function(aDOMDocument, manifest, aBypassUserEnable, installCallback) {
_installProvider: function(aDOMDocument, manifest, installCallback) {
let sourceURI = aDOMDocument.location.href;
let installOrigin = aDOMDocument.nodePrincipal.origin;
@ -667,18 +653,8 @@ this.SocialService = {
if (manifest.builtin)
delete manifest.builtin;
}
case "internal":
// double check here since "builtin" falls through this as well.
aBypassUserEnable = installType == "internal" && manifest.oneclick;
case "directory":
// a manifest is requried, and will have been vetted by reviewers. We
// also handle in-product installations without the verification step.
if (aBypassUserEnable) {
installer = new AddonInstaller(sourceURI, manifest, installCallback);
installer.install();
return;
}
// otherwise fall through to the install below which presents the panel
// a manifest is requried, and will have been vetted by reviewers
case "whitelist":
// a manifest is required, we'll catch a missing manifest below.
if (!manifest)