mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-16 06:45:42 +00:00
Backout 82464c35d37a (Bug 808215) for a regression and test failures.
This commit is contained in:
parent
546fc65113
commit
f4398db8b4
@ -18,11 +18,6 @@ let SocialUI = {
|
||||
Services.obs.addObserver(this, "social:recommend-info-changed", false);
|
||||
Services.obs.addObserver(this, "social:frameworker-error", false);
|
||||
Services.obs.addObserver(this, "social:provider-set", false);
|
||||
#ifndef MOZ_PER_WINDOW_PRIVATE_BROWSING
|
||||
// this observer is necessary so things are also correctly updated
|
||||
// when per-window PB isn't active
|
||||
Services.obs.addObserver(this, "private-browsing", false);
|
||||
#endif
|
||||
|
||||
Services.prefs.addObserver("social.sidebar.open", this, false);
|
||||
Services.prefs.addObserver("social.toast-notifications.enabled", this, false);
|
||||
@ -46,9 +41,6 @@ let SocialUI = {
|
||||
Services.obs.removeObserver(this, "social:recommend-info-changed");
|
||||
Services.obs.removeObserver(this, "social:frameworker-error");
|
||||
Services.obs.removeObserver(this, "social:provider-set");
|
||||
#ifndef MOZ_PER_WINDOW_PRIVATE_BROWSING
|
||||
Services.obs.removeObserver(this, "private-browsing");
|
||||
#endif
|
||||
|
||||
Services.prefs.removeObserver("social.sidebar.open", this);
|
||||
Services.prefs.removeObserver("social.toast-notifications.enabled", this);
|
||||
@ -128,7 +120,7 @@ let SocialUI = {
|
||||
}
|
||||
break;
|
||||
case "social:frameworker-error":
|
||||
if (this.enabled && Social.provider.origin == data) {
|
||||
if (Social.provider && Social.provider.origin == data) {
|
||||
SocialSidebar.setSidebarErrorMessage("frameworker-error");
|
||||
}
|
||||
break;
|
||||
@ -140,14 +132,6 @@ let SocialUI = {
|
||||
SocialToolbar.updateButton();
|
||||
}
|
||||
break;
|
||||
|
||||
#ifndef MOZ_PER_WINDOW_PRIVATE_BROWSING
|
||||
case "private-browsing":
|
||||
this._updateEnabledState();
|
||||
this._updateActiveUI();
|
||||
SocialToolbar.init();
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
} catch (e) {
|
||||
Components.utils.reportError(e + "\n" + e.stack);
|
||||
@ -172,7 +156,7 @@ let SocialUI = {
|
||||
|
||||
_updateActiveUI: function SocialUI_updateActiveUI() {
|
||||
let broadcaster = document.getElementById("socialActiveBroadcaster");
|
||||
broadcaster.hidden = !this.enabled;
|
||||
broadcaster.hidden = !Social.active;
|
||||
|
||||
if (!Social.provider)
|
||||
return;
|
||||
@ -219,11 +203,6 @@ let SocialUI = {
|
||||
if (whitelist.split(",").indexOf(providerOrigin) == -1)
|
||||
return;
|
||||
|
||||
// If we are in PB mode, we silently do nothing (bug 829404 exists to
|
||||
// do something sensible here...)
|
||||
if (PrivateBrowsingUtils.isWindowPrivate(window))
|
||||
return;
|
||||
|
||||
// If the last event was received < 1s ago, ignore this one
|
||||
let now = Date.now();
|
||||
if (now - Social.lastEventReceived < 1000)
|
||||
@ -306,30 +285,7 @@ let SocialUI = {
|
||||
if (confirmationIndex == 0) {
|
||||
Social.deactivateFromOrigin(Social.provider.origin);
|
||||
}
|
||||
},
|
||||
|
||||
get _chromeless() {
|
||||
// Is this a popup window that doesn't want chrome shown?
|
||||
let docElem = document.documentElement;
|
||||
let chromeless = docElem.getAttribute("chromehidden").indexOf("extrachrome") >= 0;
|
||||
// This property is "fixed" for a window, so avoid doing the check above
|
||||
// multiple times...
|
||||
delete this._chromeless;
|
||||
this._chromeless = chromeless;
|
||||
return chromeless;
|
||||
},
|
||||
|
||||
get enabled() {
|
||||
// Returns whether social is enabled *for this window*.
|
||||
if (this._chromeless
|
||||
#ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
|
||||
|| PrivateBrowsingUtils.isWindowPrivate(window)
|
||||
#endif
|
||||
)
|
||||
return false;
|
||||
return !!(Social.active && Social.provider && Social.provider.enabled);
|
||||
},
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
let SocialChatBar = {
|
||||
@ -339,7 +295,11 @@ let SocialChatBar = {
|
||||
// Whether the chatbar is available for this window. Note that in full-screen
|
||||
// mode chats are available, but not shown.
|
||||
get isAvailable() {
|
||||
return SocialUI.enabled && Social.haveLoggedInUser();
|
||||
if (!Social.haveLoggedInUser())
|
||||
return false;
|
||||
let docElem = document.documentElement;
|
||||
let chromeless = docElem.getAttribute("chromehidden").indexOf("extrachrome") >= 0;
|
||||
return Social.uiVisible && !chromeless;
|
||||
},
|
||||
// Does this chatbar have any chats (whether minimized, collapsed or normal)
|
||||
get hasChats() {
|
||||
@ -434,7 +394,7 @@ let SocialFlyout = {
|
||||
|
||||
_createFrame: function() {
|
||||
let panel = this.panel;
|
||||
if (!SocialUI.enabled || panel.firstChild)
|
||||
if (!Social.provider || panel.firstChild)
|
||||
return;
|
||||
// create and initialize the panel for this window
|
||||
let iframe = document.createElement("iframe");
|
||||
@ -511,7 +471,7 @@ let SocialFlyout = {
|
||||
// Hide any other social panels that may be open.
|
||||
document.getElementById("social-notification-panel").hidePopup();
|
||||
|
||||
if (!SocialUI.enabled)
|
||||
if (!Social.provider)
|
||||
return;
|
||||
let panel = this.panel;
|
||||
if (!panel.firstChild)
|
||||
@ -577,7 +537,7 @@ let SocialShareButton = {
|
||||
// changes, via updateProvider)
|
||||
updateProfileInfo: function SSB_updateProfileInfo() {
|
||||
let profileRow = document.getElementById("unsharePopupHeader");
|
||||
let profile = SocialUI.enabled ? Social.provider.profile : null;
|
||||
let profile = Social.provider.profile;
|
||||
if (profile && profile.displayName) {
|
||||
profileRow.hidden = false;
|
||||
let portrait = document.getElementById("socialUserPortrait");
|
||||
@ -609,7 +569,7 @@ let SocialShareButton = {
|
||||
updateButtonHiddenState: function SSB_updateButtonHiddenState() {
|
||||
let shareButton = this.shareButton;
|
||||
if (shareButton)
|
||||
shareButton.hidden = !SocialUI.enabled || Social.provider.recommendInfo == null ||
|
||||
shareButton.hidden = !Social.uiVisible || Social.provider.recommendInfo == null ||
|
||||
!Social.haveLoggedInUser() ||
|
||||
!this.canSharePage(gBrowser.currentURI);
|
||||
|
||||
@ -675,7 +635,7 @@ let SocialShareButton = {
|
||||
let shareButton = this.shareButton;
|
||||
let currentPageShared = shareButton && !shareButton.hidden && Social.isPageShared(gBrowser.currentURI);
|
||||
|
||||
let recommendInfo = SocialUI.enabled ? Social.provider.recommendInfo : null;
|
||||
let recommendInfo = Social.provider ? Social.provider.recommendInfo : null;
|
||||
// Provide a11y-friendly notification of share.
|
||||
let status = document.getElementById("share-button-status");
|
||||
if (status) {
|
||||
@ -717,10 +677,10 @@ var SocialMenu = {
|
||||
|
||||
let separator = document.getElementById("socialAmbientMenuSeparator");
|
||||
separator.hidden = true;
|
||||
let provider = SocialUI.enabled ? Social.provider : null;
|
||||
if (!provider)
|
||||
if (!Social.uiVisible)
|
||||
return;
|
||||
|
||||
let provider = Social.provider;
|
||||
let iconNames = Object.keys(provider.ambientNotificationIcons);
|
||||
for (let name of iconNames) {
|
||||
let icon = provider.ambientNotificationIcons[name];
|
||||
@ -758,7 +718,7 @@ var SocialToolbar = {
|
||||
|
||||
// Called when the Social.provider changes
|
||||
updateProvider: function () {
|
||||
if (!SocialUI.enabled)
|
||||
if (!Social.provider)
|
||||
return;
|
||||
this.button.style.listStyleImage = "url(" + Social.provider.iconURL + ")";
|
||||
this.button.setAttribute("label", Social.provider.name);
|
||||
@ -776,7 +736,7 @@ var SocialToolbar = {
|
||||
// socialActiveBroadcaster is responsible for that.
|
||||
updateButtonHiddenState: function SocialToolbar_updateButtonHiddenState() {
|
||||
let tbi = document.getElementById("social-toolbar-item");
|
||||
let socialEnabled = SocialUI.enabled;
|
||||
let socialEnabled = Social.uiVisible;
|
||||
for (let className of ["social-statusarea-separator", "social-statusarea-user"]) {
|
||||
for (let element of document.getElementsByClassName(className))
|
||||
element.hidden = !socialEnabled;
|
||||
@ -832,7 +792,7 @@ var SocialToolbar = {
|
||||
const CACHE_PREF_NAME = "social.cached.ambientNotificationIcons";
|
||||
// provider.profile == undefined means no response yet from the provider
|
||||
// to tell us whether the user is logged in or not.
|
||||
if (!SocialUI.enabled ||
|
||||
if (!provider.enabled ||
|
||||
(!Social.haveLoggedInUser() && provider.profile !== undefined)) {
|
||||
// Either no enabled provider, or there is a provider and it has
|
||||
// responded with a profile and the user isn't loggedin. The icons
|
||||
@ -1044,8 +1004,8 @@ var SocialToolbar = {
|
||||
while (providerMenuSep.previousSibling.nodeName == "menuitem") {
|
||||
menu.removeChild(providerMenuSep.previousSibling);
|
||||
}
|
||||
// only show a selection if enabled and there is more than one
|
||||
if (!SocialUI.enabled || Social.providers.length < 2) {
|
||||
// only show a selection if there is more than one
|
||||
if (!Social.enabled || providers.length < 2) {
|
||||
providerMenuSep.hidden = true;
|
||||
return;
|
||||
}
|
||||
@ -1086,7 +1046,15 @@ var SocialSidebar = {
|
||||
|
||||
// Whether the sidebar can be shown for this window.
|
||||
get canShow() {
|
||||
return SocialUI.enabled && Social.provider.sidebarURL;
|
||||
return Social.uiVisible && Social.provider.sidebarURL && !this.chromeless;
|
||||
},
|
||||
|
||||
// Whether this is a "chromeless window" (e.g. popup window). We don't show
|
||||
// the sidebar in these windows.
|
||||
get chromeless() {
|
||||
let docElem = document.documentElement;
|
||||
return docElem.getAttribute('disablechrome') ||
|
||||
docElem.getAttribute('chromehidden').contains("toolbar");
|
||||
},
|
||||
|
||||
// Whether the user has toggled the sidebar on (for windows where it can appear)
|
||||
|
@ -29,13 +29,9 @@ _BROWSER_FILES = \
|
||||
social_worker.js \
|
||||
$(NULL)
|
||||
|
||||
ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
|
||||
ifndef MOZ_PER_WINDOW_PRIVATE_BROWSING
|
||||
_BROWSER_FILES += \
|
||||
browser_social_perwindowPB.js \
|
||||
$(NULL)
|
||||
else
|
||||
_BROWSER_FILES += \
|
||||
browser_social_globalPB.js \
|
||||
browser_social.js \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
|
@ -1,82 +0,0 @@
|
||||
/* 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/. */
|
||||
|
||||
function openTab(win, url, callback) {
|
||||
let newTab = win.gBrowser.addTab(url);
|
||||
let tabBrowser = win.gBrowser.getBrowserForTab(newTab);
|
||||
tabBrowser.addEventListener("load", function tabLoadListener() {
|
||||
tabBrowser.removeEventListener("load", tabLoadListener, true);
|
||||
win.gBrowser.selectedTab = newTab;
|
||||
callback(newTab);
|
||||
}, true)
|
||||
}
|
||||
|
||||
// Tests for per-window private browsing.
|
||||
function openPBWindow(callback) {
|
||||
let w = OpenBrowserWindow({private: true});
|
||||
w.addEventListener("load", function loadListener() {
|
||||
w.removeEventListener("load", loadListener);
|
||||
openTab(w, "http://example.com", function() {
|
||||
callback(w);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function postAndReceive(port, postTopic, receiveTopic, callback) {
|
||||
port.onmessage = function(e) {
|
||||
if (e.data.topic == receiveTopic)
|
||||
callback();
|
||||
}
|
||||
port.postMessage({topic: postTopic});
|
||||
}
|
||||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
|
||||
let manifest = { // normal provider
|
||||
name: "provider 1",
|
||||
origin: "https://example.com",
|
||||
sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html",
|
||||
workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js",
|
||||
iconURL: "https://example.com/browser/browser/base/content/test/social/moz.png"
|
||||
};
|
||||
runSocialTestWithProvider(manifest, function (finishcb) {
|
||||
openTab(window, "http://example.com", function(newTab) {
|
||||
runSocialTests(tests, undefined, undefined, function() {
|
||||
window.gBrowser.removeTab(newTab);
|
||||
finishcb();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
var tests = {
|
||||
testPrivateBrowsing: function(next) {
|
||||
let port = Social.provider.getWorkerPort();
|
||||
ok(port, "provider has a port");
|
||||
postAndReceive(port, "test-init", "test-init-done", function() {
|
||||
// social features should all be enabled in the existing window.
|
||||
info("checking main window ui");
|
||||
ok(window.SocialUI.enabled, "social is enabled in normal window");
|
||||
checkSocialUI(window);
|
||||
// open a new private-window
|
||||
openPBWindow(function(pbwin) {
|
||||
// The provider should remain alive.
|
||||
postAndReceive(port, "ping", "pong", function() {
|
||||
// the new window should have no social features at all.
|
||||
info("checking private window ui");
|
||||
ok(!pbwin.SocialUI.enabled, "social is disabled in a PB window");
|
||||
checkSocialUI(pbwin);
|
||||
// but they should all remain enabled in the initial window
|
||||
info("checking main window ui");
|
||||
ok(window.SocialUI.enabled, "social is still enabled in normal window");
|
||||
checkSocialUI(window);
|
||||
// that's all folks...
|
||||
pbwin.close();
|
||||
next();
|
||||
})
|
||||
});
|
||||
});
|
||||
},
|
||||
}
|
@ -148,35 +148,3 @@ function runSocialTests(tests, cbPreTest, cbPostTest, cbFinish) {
|
||||
}
|
||||
runNextTest();
|
||||
}
|
||||
|
||||
// A fairly large hammer which checks all aspects of the SocialUI for
|
||||
// internal consistency.
|
||||
function checkSocialUI(win) {
|
||||
let win = win || window;
|
||||
let doc = win.document;
|
||||
let provider = Social.provider;
|
||||
let enabled = win.SocialUI.enabled;
|
||||
function isbool(a, b, msg) {
|
||||
is(!!a, !!b, msg);
|
||||
}
|
||||
isbool(win.SocialSidebar.canShow, enabled, "social sidebar active?");
|
||||
if (enabled)
|
||||
isbool(win.SocialSidebar.opened, enabled, "social sidebar open?");
|
||||
isbool(win.SocialChatBar.isAvailable, enabled && Social.haveLoggedInUser(), "chatbar available?");
|
||||
isbool(!win.SocialChatBar.chatbar.hidden, enabled && Social.haveLoggedInUser(), "chatbar visible?");
|
||||
isbool(!win.SocialShareButton.shareButton.hidden, enabled && provider.recommendInfo, "share button visible?");
|
||||
isbool(!doc.getElementById("social-toolbar-item").hidden, enabled, "toolbar items visible?");
|
||||
if (enabled)
|
||||
todo_is(win.SocialToolbar.button.style.listStyleImage, 'url("' + provider.iconURL + '")', "Bug 821262 - toolbar button has provider icon");
|
||||
|
||||
// and for good measure, check all the social commands.
|
||||
// Social:Remove - never disabled directly but parent nodes are
|
||||
todo_is(!doc.getElementById("Social:Toggle").hidden, enabled, "Bug 821262 - Social:Toggle visible?");
|
||||
todo_is(!doc.getElementById("Social:ToggleNotifications").hidden, enabled, "Bug 821262 - Social:ToggleNotifications visible?");
|
||||
isbool(!doc.getElementById("Social:FocusChat").hidden, enabled && Social.haveLoggedInUser(), "Social:FocusChat visible?");
|
||||
isbool(doc.getElementById("Social:FocusChat").getAttribute("disabled"), enabled ? "false" : "true", "Social:FocusChat disabled?");
|
||||
is(doc.getElementById("Social:SharePage").getAttribute("disabled"), enabled && provider.recommendInfo ? "false" : "true", "Social:SharePage visible?");
|
||||
|
||||
// broadcasters.
|
||||
isbool(!doc.getElementById("socialActiveBroadcaster").hidden, enabled, "socialActiveBroadcaster hidden?");
|
||||
}
|
||||
|
@ -22,17 +22,14 @@ EXTRA_JS_MODULES = \
|
||||
offlineAppCache.jsm \
|
||||
SignInToWebsite.jsm \
|
||||
TelemetryTimestamps.jsm \
|
||||
Social.jsm \
|
||||
webappsUI.jsm \
|
||||
webrtcUI.jsm \
|
||||
KeywordURLResetPrompter.jsm \
|
||||
SharedFrame.jsm \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_PP_JS_MODULES = \
|
||||
RecentWindow.jsm \
|
||||
Social.jsm \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_PP_JS_MODULES = RecentWindow.jsm
|
||||
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
|
||||
EXTRA_JS_MODULES += \
|
||||
|
@ -84,9 +84,7 @@ this.Social = {
|
||||
}
|
||||
|
||||
if (!this._addedObservers) {
|
||||
#ifndef MOZ_PER_WINDOW_PRIVATE_BROWSING
|
||||
Services.obs.addObserver(this, "private-browsing", false);
|
||||
#endif
|
||||
Services.obs.addObserver(this, "social:pref-changed", false);
|
||||
this._addedObservers = true;
|
||||
}
|
||||
@ -133,7 +131,6 @@ this.Social = {
|
||||
},
|
||||
|
||||
observe: function(aSubject, aTopic, aData) {
|
||||
#ifndef MOZ_PER_WINDOW_PRIVATE_BROWSING
|
||||
if (aTopic == "private-browsing") {
|
||||
if (aData == "enter") {
|
||||
this._enabledBeforePrivateBrowsing = this.enabled;
|
||||
@ -147,9 +144,7 @@ this.Social = {
|
||||
this.enabled = false;
|
||||
this.enabled = this._enabledBeforePrivateBrowsing;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
if (aTopic == "social:pref-changed") {
|
||||
} else if (aTopic == "social:pref-changed") {
|
||||
// Make sure our provider's enabled state matches the overall state of the
|
||||
// social components.
|
||||
if (this.provider)
|
||||
@ -157,6 +152,10 @@ this.Social = {
|
||||
}
|
||||
},
|
||||
|
||||
get uiVisible() {
|
||||
return this.provider && this.provider.enabled;
|
||||
},
|
||||
|
||||
set enabled(val) {
|
||||
SocialService.enabled = val;
|
||||
},
|
||||
|
@ -15,9 +15,6 @@ EXTRA_JS_MODULES = \
|
||||
MessagePortWorker.js \
|
||||
SocialService.jsm \
|
||||
WorkerAPI.jsm \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_PP_JS_MODULES = \
|
||||
MozSocialAPI.jsm \
|
||||
$(NULL)
|
||||
|
||||
|
@ -8,9 +8,6 @@ Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "SocialService", "resource://gre/modules/SocialService.jsm");
|
||||
#ifndef MOZ_PER_WINDOW_PRIVATE_BROWSING
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils", "resource://gre/modules/PrivateBrowsingUtils.jsm");
|
||||
#endif
|
||||
|
||||
this.EXPORTED_SYMBOLS = ["MozSocialAPI", "openChatWindow"];
|
||||
|
||||
@ -43,11 +40,7 @@ this.MozSocialAPI = {
|
||||
function injectController(doc, topic, data) {
|
||||
try {
|
||||
let window = doc.defaultView;
|
||||
if (!window
|
||||
#ifndef MOZ_PER_WINDOW_PRIVATE_BROWSING
|
||||
|| !PrivateBrowsingUtils.isWindowPrivate(window)
|
||||
#endif
|
||||
)
|
||||
if (!window)
|
||||
return;
|
||||
|
||||
// Do not attempt to load the API into about: error pages
|
||||
@ -235,12 +228,7 @@ function getChromeWindow(contentWin) {
|
||||
}
|
||||
|
||||
function isWindowGoodForChats(win) {
|
||||
return win.SocialChatBar
|
||||
&& win.SocialChatBar.isAvailable
|
||||
#ifndef MOZ_PER_WINDOW_PRIVATE_BROWSING
|
||||
&& !PrivateBrowsingUtils.isWindowPrivate(win)
|
||||
#endif
|
||||
;
|
||||
return win.SocialChatBar && win.SocialChatBar.isAvailable;
|
||||
}
|
||||
|
||||
function findChromeWindowForChats(preferredWindow) {
|
||||
|
Loading…
Reference in New Issue
Block a user