Bug 779360 - Implement mozSocial.isVisible API for social sidebar window, r=felipe

--HG--
extra : transplant_source : %1FB%A6T%7B%9D%60T%E6%95%CD%A7%27%E5%00%60%A5%B8%84%F8
This commit is contained in:
Jared Wein 2012-08-20 14:18:50 -07:00
Родитель 0fc5116bca
Коммит decc5c0f98
7 изменённых файлов: 138 добавлений и 38 удалений

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

@ -33,10 +33,17 @@ let SocialUI = {
observe: function SocialUI_observe(subject, topic, data) {
switch (topic) {
case "social:pref-changed":
this.updateToggleCommand();
SocialShareButton.updateButtonHiddenState();
SocialToolbar.updateButtonHiddenState();
SocialSidebar.updateSidebar();
// Exceptions here sometimes don't get reported properly, report them
// manually :(
try {
this.updateToggleCommand();
SocialShareButton.updateButtonHiddenState();
SocialToolbar.updateButtonHiddenState();
SocialSidebar.updateSidebar();
} catch (e) {
Components.utils.reportError(e);
throw e;
}
break;
case "social:ambient-notification-changed":
SocialToolbar.updateButton();
@ -279,7 +286,7 @@ var SocialToolbar = {
updateButtonHiddenState: function SocialToolbar_updateButtonHiddenState() {
this.button.hidden = !Social.uiVisible;
if (!Social.provider.profile || !Social.provider.profile.userName) {
if (!Social.provider || !Social.provider.profile || !Social.provider.profile.userName) {
["social-notification-box",
"social-status-iconbox"].forEach(function removeChildren(parentId) {
let parent = document.getElementById(parentId);
@ -468,6 +475,7 @@ var SocialSidebar = {
command.setAttribute("checked", !hideSidebar);
let sbrowser = document.getElementById("social-sidebar-browser");
sbrowser.docShell.isActive = !hideSidebar;
if (hideSidebar) {
this.dispatchEvent("sidebarhide");
// If we're disabled, unload the sidebar content

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

@ -263,6 +263,7 @@ _BROWSER_FILES = \
browser_social_toolbar.js \
browser_social_sidebar.js \
browser_social_mozSocial_API.js \
browser_social_isVisible.js \
social_panel.html \
social_sidebar.html \
social_window.html \

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

@ -0,0 +1,62 @@
/* 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 test() {
waitForExplicitFinish();
let manifest = { // normal provider
name: "provider 1",
origin: "https://example.com",
sidebarURL: "https://example.com/browser/browser/base/content/test/social_sidebar.html",
workerURL: "https://example.com/browser/browser/base/content/test/social_worker.js",
iconURL: "chrome://branding/content/icon48.png"
};
runSocialTestWithProvider(manifest, function (finishcb) {
runSocialTests(tests, undefined, undefined, finishcb);
});
}
var tests = {
testSidebarMessage: function(next) {
let port = Social.provider.port;
ok(port, "provider has a port");
port.postMessage({topic: "test-init"});
Social.provider.port.onmessage = function (e) {
let topic = e.data.topic;
switch (topic) {
case "got-sidebar-message":
// The sidebar message will always come first, since it loads by default
ok(true, "got sidebar message");
next();
break;
}
};
},
testIsVisible: function(next) {
let port = Social.provider.port;
port.onmessage = function (e) {
let topic = e.data.topic;
switch (topic) {
case "got-isVisible-response":
is(e.data.result, true, "Sidebar should be visible by default");
Social.toggleSidebar();
next();
}
};
port.postMessage({topic: "test-isVisible"});
},
testIsNotVisible: function(next) {
let port = Social.provider.port;
port.onmessage = function (e) {
let topic = e.data.topic;
switch (topic) {
case "got-isVisible-response":
is(e.data.result, false, "Sidebar should be hidden");
Services.prefs.clearUserPref("social.sidebar.open");
next();
}
};
port.postMessage({topic: "test-isVisible"});
}
}

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

@ -7,9 +7,9 @@ function test() {
let manifest = { // normal provider
name: "provider 1",
origin: "http://example.com",
sidebarURL: "http://example.com/browser/browser/base/content/test/social_sidebar.html",
workerURL: "http://example.com/browser/browser/base/content/test/social_worker.js",
origin: "https://example.com",
sidebarURL: "https://example.com/browser/browser/base/content/test/social_sidebar.html",
workerURL: "https://example.com/browser/browser/base/content/test/social_worker.js",
iconURL: "chrome://branding/content/icon48.png"
};
runSocialTestWithProvider(manifest, function (finishcb) {

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

@ -28,6 +28,9 @@
}, false)
win.close();
break;
case "test-isVisible":
port.postMessage({topic: "test-isVisible-response", result: navigator.mozSocial.isVisible});
break;
}
}
port.postMessage({topic: "sidebar-message", result: "ok"});

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

@ -49,11 +49,17 @@ onconnect = function(e) {
let icon = {
name: "testIcon",
iconURL: "chrome://branding/content/icon48.png",
contentPanel: "http://example.com/browser/browser/base/content/test/social_panel.html",
contentPanel: "https://example.com/browser/browser/base/content/test/social_panel.html",
counter: 1
};
port.postMessage({topic: "social.ambient-notification", data: icon});
break;
case "test-isVisible":
sidebarPort.postMessage({topic: "test-isVisible"});
break;
case "test-isVisible-response":
testPort.postMessage({topic: "got-isVisible-response", result: event.data.result});
break;
}
}
}

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

@ -73,42 +73,62 @@ function attachToWindow(provider, targetWindow) {
let mozSocialObj = {
// Use a method for backwards compat with existing providers, but we
// should deprecate this in favor of a simple .port getter.
getWorker: function() {
return {
port: port,
__exposedProps__: {
port: "r"
}
};
getWorker: {
enumerable: true,
configurable: true,
writable: true,
value: function() {
return {
port: port,
__exposedProps__: {
port: "r"
}
};
}
},
hasBeenIdleFor: function () {
return false;
hasBeenIdleFor: {
enumerable: true,
configurable: true,
writable: true,
value: function() {
return false;
}
},
openServiceWindow: function(toURL, name, options) {
return openServiceWindow(provider, targetWindow, toURL, name, options);
openServiceWindow: {
enumerable: true,
configurable: true,
writable: true,
value: function(toURL, name, options) {
return openServiceWindow(provider, targetWindow, toURL, name, options);
}
},
getAttention: function() {
let mainWindow = targetWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindow);
mainWindow.getAttention();
getAttention: {
enumerable: true,
configurable: true,
writable: true,
value: function() {
let mainWindow = targetWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindow);
mainWindow.getAttention();
}
},
isVisible: {
enumerable: true,
configurable: true,
get: function() {
return targetWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell).isActive;
}
}
};
let contentObj = Cu.createObjectIn(targetWindow);
let propList = {};
for (let prop in mozSocialObj) {
propList[prop] = {
enumerable: true,
configurable: true,
writable: true,
value: mozSocialObj[prop]
};
}
Object.defineProperties(contentObj, propList);
Object.defineProperties(contentObj, mozSocialObj);
Cu.makeObjectPropsNormal(contentObj);
targetWindow.navigator.wrappedJSObject.__defineGetter__("mozSocial", function() {