mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 08:15:31 +00:00
Bug 1210936 - Remote New Tab Content Frame and AboutRedirector location r=mconley
--HG-- extra : commitid : 5I9gHJn4LxX
This commit is contained in:
parent
be3bd61d57
commit
5634b62e5d
@ -1657,6 +1657,9 @@ pref("browser.newtabpage.directory.source", "https://tiles.services.mozilla.com/
|
||||
// endpoint to send newtab click and view pings
|
||||
pref("browser.newtabpage.directory.ping", "https://tiles.services.mozilla.com/v3/links/");
|
||||
|
||||
// activates the remote-hosted newtab page
|
||||
pref("browser.newtabpage.remote", false);
|
||||
|
||||
// Enable the DOM fullscreen API.
|
||||
pref("full-screen-api.enabled", true);
|
||||
|
||||
|
@ -34,6 +34,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "GMPInstallManager",
|
||||
"resource://gre/modules/GMPInstallManager.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "NewTabUtils",
|
||||
"resource://gre/modules/NewTabUtils.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "RemoteNewTabUtils",
|
||||
"resource:///modules/RemoteNewTabUtils.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "ContentSearch",
|
||||
"resource:///modules/ContentSearch.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "AboutHome",
|
||||
@ -3518,8 +3520,11 @@ const BrowserSearch = {
|
||||
if (!aSearchBar || document.activeElement != aSearchBar.textbox.inputField) {
|
||||
let url = gBrowser.currentURI.spec.toLowerCase();
|
||||
let mm = gBrowser.selectedBrowser.messageManager;
|
||||
let newTabRemoted = Services.prefs.getBoolPref("browser.newtabpage.remote");
|
||||
if (url === "about:home" ||
|
||||
(url === "about:newtab" && NewTabUtils.allPages.enabled)) {
|
||||
(url === "about:newtab" &&
|
||||
((!newTabRemoted && NewTabUtils.allPages.enabled) ||
|
||||
(newTabRemoted && RemoteNewTabUtils.allPages.enabled)))) {
|
||||
ContentSearch.focusInput(mm);
|
||||
} else {
|
||||
openUILinkIn("about:home", "current");
|
||||
|
23
browser/base/content/remote-newtab/newTab.css
Normal file
23
browser/base/content/remote-newtab/newTab.css
Normal file
@ -0,0 +1,23 @@
|
||||
/* 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/. */
|
||||
|
||||
html {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
#remotedoc {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border: none;
|
||||
position: absolute;
|
||||
}
|
126
browser/base/content/remote-newtab/newTab.js
Normal file
126
browser/base/content/remote-newtab/newTab.js
Normal file
@ -0,0 +1,126 @@
|
||||
/* 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/. */
|
||||
/*globals XPCOMUtils, Components, sendAsyncMessage, addMessageListener, removeMessageListener,
|
||||
Services, PrivateBrowsingUtils*/
|
||||
"use strict";
|
||||
|
||||
const {utils: Cu, interfaces: Ci} = Components;
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
|
||||
"resource://gre/modules/PrivateBrowsingUtils.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "Services",
|
||||
"resource://gre/modules/Services.jsm");
|
||||
|
||||
(function() {
|
||||
let remoteNewTabLocation;
|
||||
let remoteIFrame;
|
||||
|
||||
/**
|
||||
* Attempts to handle commands sent from the remote IFrame within this content frame.
|
||||
* Expected commands below, with data types explained.
|
||||
*
|
||||
* @returns {Boolean} whether or not the command was handled
|
||||
* @param {String} command
|
||||
* The command passed from the remote IFrame
|
||||
* @param {Object} data
|
||||
* Parameters to the command
|
||||
*/
|
||||
function handleCommand(command, data) {
|
||||
let commandHandled = true;
|
||||
switch (command) {
|
||||
case "NewTab:UpdateTelemetryProbe":
|
||||
/**
|
||||
* Update a given Telemetry histogram
|
||||
*
|
||||
* @param {String} data.probe
|
||||
* Probe name to update
|
||||
* @param {Number} data.value
|
||||
* Value to update histogram by
|
||||
*/
|
||||
Services.telemetry.getHistogramById(data.probe).add(data.value);
|
||||
break;
|
||||
case "NewTab:Register":
|
||||
registerEvent(data.type);
|
||||
break;
|
||||
case "NewTab:GetInitialState":
|
||||
getInitialState();
|
||||
break;
|
||||
default:
|
||||
commandHandled = false;
|
||||
}
|
||||
return commandHandled;
|
||||
}
|
||||
|
||||
function initRemotePage(initData) {
|
||||
// Messages that the iframe sends the browser will be passed onto
|
||||
// the privileged parent process
|
||||
remoteNewTabLocation = initData;
|
||||
remoteIFrame = document.querySelector("#remotedoc");
|
||||
|
||||
let loadHandler = () => {
|
||||
if (remoteIFrame.src !== remoteNewTabLocation.href) {
|
||||
return;
|
||||
}
|
||||
|
||||
remoteIFrame.removeEventListener("load", loadHandler);
|
||||
|
||||
remoteIFrame.contentDocument.addEventListener("NewTabCommand", (e) => {
|
||||
// If the commands are not handled within this content frame, the command will be
|
||||
// passed on to main process, in RemoteAboutNewTab.jsm
|
||||
let handled = handleCommand(e.detail.command, e.detail.data);
|
||||
if (!handled) {
|
||||
sendAsyncMessage(e.detail.command, e.detail.data);
|
||||
}
|
||||
});
|
||||
registerEvent("NewTab:Observe");
|
||||
let ev = new CustomEvent("NewTabCommandReady");
|
||||
remoteIFrame.contentDocument.dispatchEvent(ev);
|
||||
};
|
||||
|
||||
remoteIFrame.src = remoteNewTabLocation.href;
|
||||
remoteIFrame.addEventListener("load", loadHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows the content IFrame to register a listener to an event sent by
|
||||
* the privileged parent process, in RemoteAboutNewTab.jsm
|
||||
*
|
||||
* @param {String} eventName
|
||||
* Event name to listen to
|
||||
*/
|
||||
function registerEvent(eventName) {
|
||||
addMessageListener(eventName, (message) => {
|
||||
remoteIFrame.contentWindow.postMessage(message, remoteNewTabLocation.origin);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the initial data payload to a content IFrame so it can bootstrap
|
||||
*/
|
||||
function getInitialState() {
|
||||
let prefs = Services.prefs;
|
||||
let isPrivate = PrivateBrowsingUtils.isContentWindowPrivate(window);
|
||||
let state = {
|
||||
enabled: prefs.getBoolPref("browser.newtabpage.enabled"),
|
||||
enhanced: prefs.getBoolPref("browser.newtabpage.enhanced"),
|
||||
rows: prefs.getIntPref("browser.newtabpage.rows"),
|
||||
columns: prefs.getIntPref("browser.newtabpage.columns"),
|
||||
introShown: prefs.getBoolPref("browser.newtabpage.introShown"),
|
||||
windowID: window.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIDOMWindowUtils).outerWindowID,
|
||||
privateBrowsingMode: isPrivate
|
||||
};
|
||||
remoteIFrame.contentWindow.postMessage({
|
||||
name: "NewTab:State",
|
||||
data: state
|
||||
}, remoteNewTabLocation.origin);
|
||||
}
|
||||
|
||||
addMessageListener("NewTabFrame:Init", function loadHandler(message) {
|
||||
// Everything is loaded. Initialize the New Tab Page.
|
||||
removeMessageListener("NewTabFrame:Init", loadHandler);
|
||||
initRemotePage(message.data);
|
||||
});
|
||||
sendAsyncMessage("NewTabFrame:GetInit");
|
||||
}());
|
24
browser/base/content/remote-newtab/newTab.xhtml
Normal file
24
browser/base/content/remote-newtab/newTab.xhtml
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!-- 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/. -->
|
||||
|
||||
<!DOCTYPE html [
|
||||
<!ENTITY % newTabDTD SYSTEM "chrome://browser/locale/newTab.dtd">
|
||||
%newTabDTD;
|
||||
]>
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title>&newtab.pageTitle;</title>
|
||||
<link rel="stylesheet" href="chrome://browser/content/remote-newtab/newTab.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<iframe id="remotedoc"/>
|
||||
<script type="text/javascript;version=1.8"
|
||||
src="chrome://browser/content/remote-newtab/newTab.js">
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -109,6 +109,9 @@ browser.jar:
|
||||
* content/browser/newtab/newTab.js (content/newtab/newTab.js)
|
||||
content/browser/newtab/newTab.css (content/newtab/newTab.css)
|
||||
content/browser/newtab/newTab.inadjacent.json (content/newtab/newTab.inadjacent.json)
|
||||
content/browser/remote-newtab/newTab.xhtml (content/remote-newtab/newTab.xhtml)
|
||||
* content/browser/remote-newtab/newTab.js (content/remote-newtab/newTab.js)
|
||||
content/browser/remote-newtab/newTab.css (content/remote-newtab/newTab.css)
|
||||
* content/browser/pageinfo/pageInfo.xul (content/pageinfo/pageInfo.xul)
|
||||
content/browser/pageinfo/pageInfo.js (content/pageinfo/pageInfo.js)
|
||||
content/browser/pageinfo/pageInfo.css (content/pageinfo/pageInfo.css)
|
||||
|
@ -87,6 +87,9 @@ static RedirEntry kRedirMap[] = {
|
||||
nsIAboutModule::ENABLE_INDEXED_DB },
|
||||
{ "newtab", "chrome://browser/content/newtab/newTab.xhtml",
|
||||
nsIAboutModule::ALLOW_SCRIPT },
|
||||
{ "remote-newtab", "chrome://browser/content/remote-newtab/newTab.xhtml",
|
||||
nsIAboutModule::URI_MUST_LOAD_IN_CHILD |
|
||||
nsIAboutModule::ALLOW_SCRIPT },
|
||||
{ "permissions", "chrome://browser/content/preferences/aboutPermissions.xul",
|
||||
nsIAboutModule::ALLOW_SCRIPT },
|
||||
{ "preferences", "chrome://browser/content/preferences/in-content/preferences.xul",
|
||||
|
@ -107,6 +107,7 @@ static const mozilla::Module::ContractIDEntry kBrowserContracts[] = {
|
||||
#endif
|
||||
{ NS_ABOUT_MODULE_CONTRACTID_PREFIX "home", &kNS_BROWSER_ABOUT_REDIRECTOR_CID },
|
||||
{ NS_ABOUT_MODULE_CONTRACTID_PREFIX "newtab", &kNS_BROWSER_ABOUT_REDIRECTOR_CID },
|
||||
{ NS_ABOUT_MODULE_CONTRACTID_PREFIX "remote-newtab", &kNS_BROWSER_ABOUT_REDIRECTOR_CID },
|
||||
{ NS_ABOUT_MODULE_CONTRACTID_PREFIX "permissions", &kNS_BROWSER_ABOUT_REDIRECTOR_CID },
|
||||
{ NS_ABOUT_MODULE_CONTRACTID_PREFIX "preferences", &kNS_BROWSER_ABOUT_REDIRECTOR_CID },
|
||||
{ NS_ABOUT_MODULE_CONTRACTID_PREFIX "downloads", &kNS_BROWSER_ABOUT_REDIRECTOR_CID },
|
||||
|
Loading…
Reference in New Issue
Block a user