Skip to content

Commit

Permalink
Merge m-c to b2g-inbound.
Browse files Browse the repository at this point in the history
  • Loading branch information
rvandermeulen committed May 20, 2014
2 parents 8c46824 + b2cdbab commit 2a34efc
Show file tree
Hide file tree
Showing 157 changed files with 11,279 additions and 2,214 deletions.
2 changes: 2 additions & 0 deletions browser/app/profile/firefox.js
Original file line number Diff line number Diff line change
Expand Up @@ -1330,9 +1330,11 @@ pref("devtools.tilt.outro_transition", true);
// 'Open Recent'-menu.
// - showTrailingSpace: Whether to highlight trailing space or not.
// - enableCodeFolding: Whether to enable code folding or not.
// - enableAutocompletion: Whether to enable JavaScript autocompletion.
pref("devtools.scratchpad.recentFilesMax", 10);
pref("devtools.scratchpad.showTrailingSpace", false);
pref("devtools.scratchpad.enableCodeFolding", true);
pref("devtools.scratchpad.enableAutocompletion", true);

// Enable the Style Editor.
pref("devtools.styleeditor.enabled", true);
Expand Down
2 changes: 2 additions & 0 deletions browser/base/content/browser-fullScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,8 @@ var FullScreen = {
navbar.appendChild(fullscreenctls);
}
fullscreenctls.hidden = aShow;

ToolbarIconColor.inferFromText();
}
};
XPCOMUtils.defineLazyGetter(FullScreen, "useLionFullScreen", function() {
Expand Down
44 changes: 31 additions & 13 deletions browser/base/content/browser-social.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ SocialUI = {
Services.prefs.addObserver("social.toast-notifications.enabled", this, false);

gBrowser.addEventListener("ActivateSocialFeature", this._activationEventHandler.bind(this), true, true);
document.getElementById("PanelUI-popup").addEventListener("popupshown", SocialMarks.updatePanelButtons, true);
PanelUI.panel.addEventListener("popupshown", SocialUI.updateState, true);

// menupopups that list social providers. we only populate them when shown,
// and if it has not been done already.
Expand Down Expand Up @@ -102,7 +102,7 @@ SocialUI = {

Services.prefs.removeObserver("social.toast-notifications.enabled", this);

document.getElementById("PanelUI-popup").removeEventListener("popupshown", SocialMarks.updatePanelButtons, true);
PanelUI.panel.removeEventListener("popupshown", SocialUI.updateState, true);
document.getElementById("viewSidebarMenu").removeEventListener("popupshowing", SocialSidebar.populateSidebarMenu, true);
document.getElementById("social-statusarea-popup").removeEventListener("popupshowing", SocialSidebar.populateSidebarMenu, true);

Expand Down Expand Up @@ -288,7 +288,7 @@ SocialUI = {
// called on tab/urlbar/location changes and after customization. Update
// anything that is tab specific.
updateState: function() {
if (!this.enabled)
if (!SocialUI.enabled)
return;
SocialMarks.update();
SocialShare.update();
Expand Down Expand Up @@ -432,6 +432,12 @@ SocialFlyout = {
}

SocialShare = {
// Share panel may be attached to the overflow or menu button depending on
// customization, we need to manage open state of the anchor.
get anchor() {
let widget = CustomizableUI.getWidget("social-share-button");
return widget.forWindow(window).anchor;
},
get panel() {
return document.getElementById("social-share-panel");
},
Expand Down Expand Up @@ -523,7 +529,15 @@ SocialShare = {
},

get shareButton() {
return document.getElementById("social-share-button");
// web-panels (bookmark/sidebar) don't include customizableui, so
// nsContextMenu fails when accessing shareButton, breaking
// browser_bug409481.js.
if (!window.CustomizableUI)
return null;
let widget = CustomizableUI.getWidget("social-share-button");
if (!widget || !widget.areaType)
return null;
return widget.forWindow(window).node;
},

canSharePage: function(aURI) {
Expand All @@ -540,23 +554,29 @@ SocialShare = {
let shareButton = this.shareButton;
shareButton.hidden = !SocialUI.enabled ||
[p for (p of Social.providers) if (p.shareURL)].length == 0;
shareButton.disabled = shareButton.hidden || !this.canSharePage(gBrowser.currentURI);
let disabled = shareButton.hidden || !this.canSharePage(gBrowser.currentURI);

// also update the relevent command's disabled state so the keyboard
// 1. update the relevent command's disabled state so the keyboard
// shortcut only works when available.
// 2. If the button has been relocated to a place that is not visible by
// default (e.g. menu panel) then the disabled attribute will not update
// correctly based on the command, so we update the attribute directly as.
let cmd = document.getElementById("Social:SharePage");
if (shareButton.disabled)
if (disabled) {
cmd.setAttribute("disabled", "true");
else
shareButton.setAttribute("disabled", "true");
} else {
cmd.removeAttribute("disabled");
shareButton.removeAttribute("disabled");
}
},

onShowing: function() {
this.shareButton.setAttribute("open", "true");
this.anchor.setAttribute("open", "true");
},

onHidden: function() {
this.shareButton.removeAttribute("open");
this.anchor.removeAttribute("open");
this.iframe.setAttribute("src", "data:text/plain;charset=utf8,");
this.currentShare = null;
},
Expand Down Expand Up @@ -670,8 +690,7 @@ SocialShare = {
iframe.setAttribute("origin", provider.origin);
iframe.setAttribute("src", shareEndpoint);

let navBar = document.getElementById("nav-bar");
let anchor = document.getAnonymousElementByAttribute(this.shareButton, "class", "toolbarbutton-icon");
let anchor = document.getAnonymousElementByAttribute(this.anchor, "class", "toolbarbutton-icon");
this.panel.openPopup(anchor, "bottomcenter topright", 0, 0, false, false);
Social.setErrorListener(iframe, this.setErrorMessage.bind(this));
}
Expand Down Expand Up @@ -1357,7 +1376,6 @@ SocialMarks = {
// querySelectorAll does not work on the menu panel the panel, so we have to
// do this the hard way.
let providers = SocialMarks.getProviders();
let panel = document.getElementById("PanelUI-popup");
for (let p of providers) {
let widgetId = SocialMarks._toolbarHelper.idFromOrigin(p.origin);
let widget = CustomizableUI.getWidget(widgetId);
Expand Down
76 changes: 76 additions & 0 deletions browser/base/content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,8 @@ var gBrowserInit = {
}
#endif

ToolbarIconColor.init();

// Wait until chrome is painted before executing code not critical to making the window visible
this._boundDelayedStartup = this._delayedStartup.bind(this, mustLoadSidebar);
window.addEventListener("MozAfterPaint", this._boundDelayedStartup);
Expand Down Expand Up @@ -1283,6 +1285,8 @@ var gBrowserInit = {

TabsInTitlebar.uninit();

ToolbarIconColor.uninit();

var enumerator = Services.wm.getEnumerator(null);
enumerator.getNext();
if (!enumerator.hasMoreElements()) {
Expand Down Expand Up @@ -4296,6 +4300,8 @@ function setToolbarVisibility(toolbar, isVisible, persist=true) {
PlacesToolbarHelper.init();
BookmarkingUI.onToolbarVisibilityChange();
gBrowser.updateWindowResizers();
if (isVisible)
ToolbarIconColor.inferFromText();
}

var TabsInTitlebar = {
Expand Down Expand Up @@ -4540,6 +4546,8 @@ var TabsInTitlebar = {
titlebar.style.marginBottom = "";
menubar.style.paddingBottom = "";
}

ToolbarIconColor.inferFromText();
},

_sizePlaceholder: function (type, width) {
Expand Down Expand Up @@ -7192,3 +7200,71 @@ function BrowserOpenNewTabOrWindow(event) {
BrowserOpenTab();
}
}

let ToolbarIconColor = {
init: function () {
this._initialized = true;

window.addEventListener("activate", this);
window.addEventListener("deactivate", this);
Services.obs.addObserver(this, "lightweight-theme-styling-update", false);

// If the window isn't active now, we assume that it has never been active
// before and will soon become active such that inferFromText will be
// called from the initial activate event.
if (Services.focus.activeWindow == window)
this.inferFromText();
},

uninit: function () {
this._initialized = false;

window.removeEventListener("activate", this);
window.removeEventListener("deactivate", this);
Services.obs.removeObserver(this, "lightweight-theme-styling-update");
},

handleEvent: function (event) {
switch (event.type) {
case "activate":
case "deactivate":
this.inferFromText();
break;
}
},

observe: function (aSubject, aTopic, aData) {
switch (aTopic) {
case "lightweight-theme-styling-update":
// inferFromText needs to run after LightweightThemeConsumer.jsm's
// lightweight-theme-styling-update observer.
setTimeout(() => { this.inferFromText(); }, 0);
break;
}
},

inferFromText: function () {
if (!this._initialized)
return;

function parseRGB(aColorString) {
let rgb = aColorString.match(/^rgba?\((\d+), (\d+), (\d+)/);
rgb.shift();
return rgb.map(x => parseInt(x));
}

let toolbarSelector = "#navigator-toolbox > toolbar:not([collapsed=true]):not(#addon-bar)";
#ifdef XP_MACOSX
toolbarSelector += ":not([type=menubar])";
#endif

for (let toolbar of document.querySelectorAll(toolbarSelector)) {
let [r, g, b] = parseRGB(getComputedStyle(toolbar).color);
let luminance = 0.2125 * r + 0.7154 * g + 0.0721 * b;
if (luminance <= 110)
toolbar.removeAttribute("brighttext");
else
toolbar.setAttribute("brighttext", "true");
}
}
}
2 changes: 1 addition & 1 deletion browser/base/content/browser.xul
Original file line number Diff line number Diff line change
Expand Up @@ -899,10 +899,10 @@
<toolbarbutton id="social-share-button"
class="toolbarbutton-1 chromeclass-toolbar-additional"
hidden="true"
overflows="false"
label="&sharePageCmd.label;"
tooltiptext="&sharePageCmd.label;"
cui-areatype="toolbar"
removable="true"
command="Social:SharePage"/>
</hbox>

Expand Down
56 changes: 6 additions & 50 deletions browser/base/content/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Cu.import("resource://gre/modules/Services.jsm");

XPCOMUtils.defineLazyModuleGetter(this, "ContentLinkHandler",
"resource:///modules/ContentLinkHandler.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "LanguageDetector",
"resource:///modules/translation/LanguageDetector.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "LoginManagerContent",
"resource://gre/modules/LoginManagerContent.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "InsecurePasswordUtils",
Expand Down Expand Up @@ -442,51 +440,9 @@ let PageStyleHandler = {
};
PageStyleHandler.init();

let TranslationHandler = {
init: function() {
let webProgress = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebProgress);
webProgress.addProgressListener(this, Ci.nsIWebProgress.NOTIFY_STATE_DOCUMENT);
},

/* nsIWebProgressListener implementation */
onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus) {
// Don't bother if we're not a toplevel document, if this isn't the 'stop'
// notification, or if the content document has gone away
if (!aWebProgress.isTopLevel ||
!(aStateFlags & Ci.nsIWebProgressListener.STATE_STOP) ||
!content)
return;

let url = aRequest.name;
if (!url.startsWith("http://") && !url.startsWith("https://"))
return;

// Grab a 60k sample of text from the page.
let encoder = Cc["@mozilla.org/layout/documentEncoder;1?type=text/plain"]
.createInstance(Ci.nsIDocumentEncoder);
encoder.init(content.document, "text/plain", encoder.SkipInvisibleContent);
let string = encoder.encodeToStringWithMaxLength(60 * 1024);

// Language detection isn't reliable on very short strings.
if (string.length < 100)
return;

LanguageDetector.detectLanguage(string).then(result => {
if (result.confident)
sendAsyncMessage("LanguageDetection:Result", result.language);
});
},

// Unused methods.
onProgressChange: function() {},
onLocationChange: function() {},
onStatusChange: function() {},
onSecurityChange: function() {},

QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener,
Ci.nsISupportsWeakReference])
};

if (Services.prefs.getBoolPref("browser.translation.detectLanguage"))
TranslationHandler.init();
// Keep a reference to the translation content handler to avoid it it being GC'ed.
let trHandler = null;
if (Services.prefs.getBoolPref("browser.translation.detectLanguage")) {
Cu.import("resource:///modules/translation/TranslationContentHandler.jsm");
trHandler = new TranslationContentHandler(global, docShell);
}
2 changes: 1 addition & 1 deletion browser/components/sessionstore/src/SessionStore.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -3414,7 +3414,7 @@ let SessionStoreInternal = {
* with respect to |browser|.
*/
isCurrentEpoch: function (browser, epoch) {
return this._browserEpochs.get(browser.permanentKey, 0) == epoch;
return (this._browserEpochs.get(browser.permanentKey) || 0) == epoch;
},

};
Expand Down
Loading

0 comments on commit 2a34efc

Please sign in to comment.