Bug 782882 - only allow sharing of http or https urls. r=jaws

This commit is contained in:
Mark Hammond 2012-10-25 16:44:53 +11:00
parent 714d9d9e97
commit faf98a8a52
2 changed files with 70 additions and 9 deletions

View File

@ -509,11 +509,17 @@ let SocialShareButton = {
this.unsharePopup.hidePopup();
},
canSharePage: function SSB_canSharePage(aURI) {
// We only allow sharing of http or https
return aURI && (aURI.schemeIs('http') || aURI.schemeIs('https'));
},
updateButtonHiddenState: function SSB_updateButtonHiddenState() {
let shareButton = this.shareButton;
if (shareButton)
shareButton.hidden = !Social.uiVisible || this.promptImages == null ||
!SocialUI.haveLoggedInUser();
!SocialUI.haveLoggedInUser() ||
!this.canSharePage(gBrowser.currentURI);
},
onClick: function SSB_onClick(aEvent) {
@ -566,7 +572,12 @@ let SocialShareButton = {
},
updateShareState: function SSB_updateShareState() {
let currentPageShared = Social.isPageShared(gBrowser.currentURI);
// we might have been called due to a location change, and the new location
// might change the state of "can this url be shared"
this.updateButtonHiddenState();
let shareButton = this.shareButton;
let currentPageShared = shareButton && !shareButton.hidden && Social.isPageShared(gBrowser.currentURI);
// Provide a11y-friendly notification of share.
let status = document.getElementById("share-button-status");
@ -583,7 +594,6 @@ let SocialShareButton = {
}
// Update the share button, if present
let shareButton = this.shareButton;
if (!shareButton || shareButton.hidden)
return;

View File

@ -8,8 +8,8 @@ let prefName = "social.enabled",
function test() {
waitForExplicitFinish();
// Need to load a non-empty page for the social share button to appear
let tab = gBrowser.selectedTab = gBrowser.addTab("about:", {skipAnimation: true});
// Need to load a http/https/ftp/ftps page for the social share button to appear
let tab = gBrowser.selectedTab = gBrowser.addTab("https://example.com", {skipAnimation: true});
tab.linkedBrowser.addEventListener("load", function tabLoad(event) {
tab.linkedBrowser.removeEventListener("load", tabLoad, true);
executeSoon(tabLoaded);
@ -261,14 +261,65 @@ function testStillSharedAfterReopen() {
tab = gBrowser.selectedTab = gBrowser.addTab(toShare, {skipAnimation: true});
tab.linkedBrowser.addEventListener("load", function tabLoad(event) {
tab.linkedBrowser.removeEventListener("load", tabLoad, true);
is(shareButton.hasAttribute("shared"), true, "New tab to previously shared URL should reflect shared");
SocialShareButton.unsharePage();
gBrowser.removeTab(tab);
executeSoon(testDisable);
executeSoon(function() {
is(shareButton.hasAttribute("shared"), true, "New tab to previously shared URL should reflect shared");
SocialShareButton.unsharePage();
gBrowser.removeTab(tab);
executeSoon(testOnlyShareCertainUrlsTabSwitch);
});
}, true);
}, true);
}
function testOnlyShareCertainUrlsTabSwitch() {
let toShare = "http://example.com";
let notSharable = "about:blank";
let {shareButton} = SocialShareButton;
let tab = gBrowser.selectedTab = gBrowser.addTab(toShare);
let tabb = gBrowser.getBrowserForTab(tab);
tabb.addEventListener("load", function tabLoad(event) {
tabb.removeEventListener("load", tabLoad, true);
ok(!shareButton.hidden, "share button not hidden for http url");
let tab2 = gBrowser.selectedTab = gBrowser.addTab(notSharable);
let tabb2 = gBrowser.getBrowserForTab(tab2);
tabb2.addEventListener("load", function tabLoad(event) {
tabb2.removeEventListener("load", tabLoad, true);
ok(shareButton.hidden, "share button hidden for about:blank");
gBrowser.selectedTab = tab;
ok(!shareButton.hidden, "share button re-shown when switching back to http: url");
gBrowser.selectedTab = tab2;
ok(shareButton.hidden, "share button re-hidden when switching back to about:blank");
gBrowser.removeTab(tab);
gBrowser.removeTab(tab2);
executeSoon(testOnlyShareCertainUrlsSameTab);
}, true);
}, true);
}
function testOnlyShareCertainUrlsSameTab() {
let toShare = "http://example.com";
let notSharable = "about:blank";
let {shareButton} = SocialShareButton;
let tab = gBrowser.selectedTab = gBrowser.addTab(toShare);
let tabb = gBrowser.getBrowserForTab(tab);
tabb.addEventListener("load", function tabLoad(event) {
tabb.removeEventListener("load", tabLoad, true);
ok(!shareButton.hidden, "share button not hidden for http url");
tabb.addEventListener("load", function tabLoad(event) {
tabb.removeEventListener("load", tabLoad, true);
ok(shareButton.hidden, "share button hidden for about:blank");
tabb.addEventListener("load", function tabLoad(event) {
tabb.removeEventListener("load", tabLoad, true);
ok(!shareButton.hidden, "share button re-enabled http url");
gBrowser.removeTab(tab);
executeSoon(testDisable);
}, true);
tabb.loadURI(toShare);
}, true);
tabb.loadURI(notSharable);
}, true);
}
function testDisable() {
let shareButton = SocialShareButton.shareButton;
Services.prefs.setBoolPref(prefName, false);