Bug 1529969 - Only request info about the current engine to the parent; r=adw,Mardak

This patch adds a new ContentSearchHandoffUI class to be used when search
handoff is enabled in the newtab page, avoiding the much more complex
ContentSearchUI. This also reduces the amount of unnecessary information being
sent across processes.

Differential Revision: https://phabricator.services.mozilla.com/D48776

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jim Porter 2019-12-17 21:02:52 +00:00
Родитель b06ed766ee
Коммит 9c55da7d77
12 изменённых файлов: 124 добавлений и 36 удалений

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

@ -0,0 +1,79 @@
/* 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/. */
"use strict";
function ContentSearchHandoffUIController() {
this._isPrivateWindow = false;
this._engineIcon = null;
window.addEventListener("ContentSearchService", this);
this._sendMsg("GetEngine");
}
ContentSearchHandoffUIController.prototype = {
handleEvent(event) {
let methodName = "_onMsg" + event.detail.type;
if (methodName in this) {
this[methodName](event.detail.data);
}
},
_onMsgEngine({ isPrivateWindow, engine }) {
this._isPrivateWindow = isPrivateWindow;
this._updateEngineIcon(engine);
},
_onMsgCurrentEngine(engine) {
if (!this._isPrivateWindow) {
this._updateEngineIcon(engine);
}
},
_onMsgCurrentPrivateEngine(engine) {
if (this._isPrivateWindow) {
this._updateEngineIcon(engine);
}
},
_updateEngineIcon(engine) {
if (this._engineIcon) {
URL.revokeObjectURL(this._engineIcon);
}
if (engine.iconData) {
this._engineIcon = this._getFaviconURIFromIconData(engine.iconData);
} else {
this._engineIcon = "chrome://mozapps/skin/places/defaultFavicon.svg";
}
document.body.style.setProperty(
"--newtab-search-icon",
"url(" + this._engineIcon + ")"
);
},
// If the favicon is an array buffer, convert it into a Blob URI.
// Otherwise just return the plain URI.
_getFaviconURIFromIconData(data) {
if (typeof data === "string") {
return data;
}
// If typeof(data) != "string", we assume it's an ArrayBuffer
let blob = new Blob([data]);
return URL.createObjectURL(blob);
},
_sendMsg(type, data = null) {
dispatchEvent(
new CustomEvent("ContentSearchClient", {
detail: {
type,
data,
},
})
);
},
};

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

@ -94,6 +94,7 @@ browser.jar:
content/browser/sanitizeDialog.js (content/sanitizeDialog.js)
content/browser/sanitizeDialog.css (content/sanitizeDialog.css)
content/browser/contentSearchUI.js (content/contentSearchUI.js)
content/browser/contentSearchHandoffUI.js (content/contentSearchHandoffUI.js)
content/browser/contentSearchUI.css (content/contentSearchUI.css)
content/browser/tabbrowser.css (content/tabbrowser.css)
content/browser/tabbrowser.js (content/tabbrowser.js)

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

@ -28,6 +28,7 @@ function templateHTML(options) {
const debugString = options.debug ? "-dev" : "";
const scripts = [
"chrome://browser/content/contentSearchUI.js",
"chrome://browser/content/contentSearchHandoffUI.js",
"chrome://browser/content/contentTheme.js",
`${options.baseUrl}vendor/react${debugString}.js`,
`${options.baseUrl}vendor/react-dom${debugString}.js`,

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

@ -2,7 +2,7 @@
* 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 ContentSearchUIController */
/* globals ContentSearchUIController, ContentSearchHandoffUIController */
"use strict";
import { actionCreators as ac, actionTypes as at } from "common/Actions.jsm";
@ -18,6 +18,7 @@ export class _Search extends React.PureComponent {
this.onSearchHandoffPaste = this.onSearchHandoffPaste.bind(this);
this.onSearchHandoffDrop = this.onSearchHandoffDrop.bind(this);
this.onInputMount = this.onInputMount.bind(this);
this.onInputMountHandoff = this.onInputMountHandoff.bind(this);
this.onSearchHandoffButtonMount = this.onSearchHandoffButtonMount.bind(
this
);
@ -103,6 +104,14 @@ export class _Search extends React.PureComponent {
}
}
onInputMountHandoff(input) {
if (input) {
// The handoff UI controller helps usset the search icon and reacts to
// changes to default engine to keep everything in sync.
this._handoffSearchController = new ContentSearchHandoffUIController();
}
}
onSearchHandoffButtonMount(button) {
// Keep a reference to the button for use during "paste" event handling.
this._searchHandoffButton = button;
@ -167,18 +176,10 @@ export class _Search extends React.PureComponent {
aria-hidden="true"
onDrop={this.onSearchHandoffDrop}
onPaste={this.onSearchHandoffPaste}
ref={this.onInputMountHandoff}
/>
<div className="fake-caret" />
</button>
{/*
This dummy and hidden input below is so we can load ContentSearchUIController.
Why? It sets --newtab-search-icon for us and it isn't trivial to port over.
*/}
<input
type="search"
style={{ display: "none" }}
ref={this.onInputMount}
/>
</div>
)}
</div>

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

@ -10286,7 +10286,7 @@ __webpack_require__.r(__webpack_exports__);
* 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 ContentSearchUIController */
/* globals ContentSearchUIController, ContentSearchHandoffUIController */
@ -10301,6 +10301,7 @@ class _Search extends react__WEBPACK_IMPORTED_MODULE_3___default.a.PureComponent
this.onSearchHandoffPaste = this.onSearchHandoffPaste.bind(this);
this.onSearchHandoffDrop = this.onSearchHandoffDrop.bind(this);
this.onInputMount = this.onInputMount.bind(this);
this.onInputMountHandoff = this.onInputMountHandoff.bind(this);
this.onSearchHandoffButtonMount = this.onSearchHandoffButtonMount.bind(this);
}
@ -10390,6 +10391,14 @@ class _Search extends react__WEBPACK_IMPORTED_MODULE_3___default.a.PureComponent
}
}
onInputMountHandoff(input) {
if (input) {
// The handoff UI controller helps usset the search icon and reacts to
// changes to default engine to keep everything in sync.
this._handoffSearchController = new ContentSearchHandoffUIController();
}
}
onSearchHandoffButtonMount(button) {
// Keep a reference to the button for use during "paste" event handling.
this._searchHandoffButton = button;
@ -10441,16 +10450,11 @@ class _Search extends react__WEBPACK_IMPORTED_MODULE_3___default.a.PureComponent
tabIndex: "-1",
"aria-hidden": "true",
onDrop: this.onSearchHandoffDrop,
onPaste: this.onSearchHandoffPaste
onPaste: this.onSearchHandoffPaste,
ref: this.onInputMountHandoff
}), react__WEBPACK_IMPORTED_MODULE_3___default.a.createElement("div", {
className: "fake-caret"
})), react__WEBPACK_IMPORTED_MODULE_3___default.a.createElement("input", {
type: "search",
style: {
display: "none"
},
ref: this.onInputMount
})));
}))));
}
}

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

@ -20,6 +20,7 @@
<div id="root"></div>
<div id="footer-asrouter-container" role="presentation"></div>
<script src="chrome://browser/content/contentSearchUI.js"></script>
<script src="chrome://browser/content/contentSearchHandoffUI.js"></script>
<script src="chrome://browser/content/contentTheme.js"></script>
<script src="resource://activity-stream/vendor/react-dev.js"></script>
<script src="resource://activity-stream/vendor/react-dom-dev.js"></script>

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

@ -20,6 +20,7 @@
<div id="root"></div>
<div id="footer-asrouter-container" role="presentation"></div>
<script src="chrome://browser/content/contentSearchUI.js"></script>
<script src="chrome://browser/content/contentSearchHandoffUI.js"></script>
<script src="chrome://browser/content/contentTheme.js"></script>
<script src="resource://activity-stream/vendor/react.js"></script>
<script src="resource://activity-stream/vendor/react-dom.js"></script>

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

@ -73,8 +73,11 @@ const TEST_GLOBAL = {
},
isSuccessCode: () => true,
},
// NB: These are functions/constructors
// eslint-disable-next-line object-shorthand
ContentSearchUIController: function() {}, // NB: This is a function/constructor
ContentSearchUIController: function() {},
// eslint-disable-next-line object-shorthand
ContentSearchHandoffUIController: function() {},
Cc: {
"@mozilla.org/browser/nav-bookmarks-service;1": {
addObserver() {},

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

@ -118,14 +118,5 @@ document.addEventListener("DOMContentLoaded", function() {
});
// Load contentSearchUI so it sets the search engine icon for us.
// TODO: FIXME. We should eventually refector contentSearchUI to do only what
// we need and have it do the common search handoff work for
// about:newtab and about:privatebrowsing.
let input = document.getElementById("dummy-input");
new window.ContentSearchUIController(
input,
input.parentNode,
"aboutprivatebrowsing",
"aboutprivatebrowsing"
);
new window.ContentSearchHandoffUIController();
});

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

@ -15,7 +15,7 @@
<link rel="localization" href="branding/brand.ftl"/>
<link rel="localization" href="browser/aboutPrivateBrowsing.ftl"/>
<script src="chrome://browser/content/aboutPrivateBrowsing.js"></script>
<script src="chrome://browser/content/contentSearchUI.js"></script>
<script src="chrome://browser/content/contentSearchHandoffUI.js"></script>
</head>
<body>
@ -50,7 +50,6 @@
<input id="fake-editable" class="fake-editable" tabindex="-1" aria-hidden="true" />
<div class="fake-caret" />
</button>
<input id="dummy-input" class="dummy-input" type="search" />
</div>
<div class="info">
<h1 data-l10n-id="about-private-browsing-info-title"></h1>

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

@ -453,6 +453,17 @@ var ContentSearch = {
});
},
_onMessageGetEngine(msg, data) {
return this.currentStateObj(msg.target.ownerGlobal).then(state => {
this._reply(msg, "Engine", {
isPrivateWindow: state.isPrivateWindow,
engine: state.isPrivateWindow
? state.currentPrivateEngine
: state.currentEngine,
});
});
},
_onMessageGetStrings(msg, data) {
this._reply(msg, "Strings", this.searchSuggestionUIStrings);
},

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

@ -163,10 +163,6 @@ p {
width: 1px;
}
.dummy-input {
display: none;
}
.search-banner {
width: 100%;
background-color: var(--in-content-banner-background);