Bug 1506237 - Share document fragment for search-one-offs between instances;r=dao
authorBrian Grinstead <bgrinstead@mozilla.com>
Fri, 09 Nov 2018 20:57:45 +0000
changeset 445499 9edb93a822c3c4e8b98d575c5688fc8f4dda8735
parent 445498 65a4195373c8c4a73e9835f9cd873ba49a4bfd9e
child 445500 9fce755a1262f4a2a0c2c55aa64baced6d3defb5
push id72747
push userbgrinstead@mozilla.com
push dateFri, 09 Nov 2018 21:38:43 +0000
treeherderautoland@9edb93a822c3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs1506237
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1506237 - Share document fragment for search-one-offs between instances;r=dao This avoids the cost to parse the markup for subsequent connections. Differential Revision: https://phabricator.services.mozilla.com/D11521
browser/components/search/content/search-one-offs.js
--- a/browser/components/search/content/search-one-offs.js
+++ b/browser/components/search/content/search-one-offs.js
@@ -3,16 +3,48 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 /* eslint-env mozilla/browser-window */
 
 {
 
+let sharedFragment;
+function getFragment() {
+  if (!sharedFragment) {
+    sharedFragment = MozXULElement.parseXULToFragment(`
+    <deck class="search-panel-one-offs-header search-panel-header search-panel-current-input">
+      <label class="searchbar-oneoffheader-search" value="&searchWithHeader.label;"></label>
+      <hbox class="search-panel-searchforwith search-panel-current-input">
+        <label value="&searchFor.label;"></label>
+        <label class="searchbar-oneoffheader-searchtext search-panel-input-value" flex="1" crop="end"></label>
+        <label flex="10000" value="&searchWith.label;"></label>
+      </hbox>
+      <hbox class="search-panel-searchonengine search-panel-current-input">
+        <label value="&search.label;"></label>
+        <label class="searchbar-oneoffheader-engine search-panel-input-value" flex="1" crop="end"></label>
+        <label flex="10000" value="&searchAfter.label;"></label>
+      </hbox>
+    </deck>
+    <description role="group" class="search-panel-one-offs">
+      <button oncommand="showSettings();" class="searchbar-engine-one-off-item search-setting-button-compact" tooltiptext="&changeSearchSettings.tooltip;"></button>
+    </description>
+    <vbox class="search-add-engines"></vbox>
+    <button oncommand="showSettings();" class="search-setting-button search-panel-header" label="&changeSearchSettings.button;"></button>
+    <menupopup class="search-one-offs-context-menu">
+      <menuitem class="search-one-offs-context-open-in-new-tab" label="&searchInNewTab.label;" accesskey="&searchInNewTab.accesskey;"></menuitem>
+      <menuitem class="search-one-offs-context-set-default" label="&searchSetAsDefault.label;" accesskey="&searchSetAsDefault.accesskey;"></menuitem>
+    </menupopup>
+    `, ["chrome://browser/locale/browser.dtd"]);
+  }
+
+  return document.importNode(sharedFragment, true);
+}
+
 class MozSearchOneOffs extends MozXULElement {
   constructor() {
     super();
 
     this.addEventListener("mousedown", event => {
       let target = event.originalTarget;
       if (target.classList.contains("addengine-menu-button")) {
         return;
@@ -182,41 +214,17 @@ class MozSearchOneOffs extends MozXULEle
     });
   }
 
   connectedCallback() {
     if (this.delayConnectedCallback()) {
       return;
     }
 
-    this.appendChild(MozXULElement.parseXULToFragment(`
-      <deck class="search-panel-one-offs-header search-panel-header search-panel-current-input">
-        <label class="searchbar-oneoffheader-search" value="&searchWithHeader.label;"></label>
-        <hbox class="search-panel-searchforwith search-panel-current-input">
-          <label value="&searchFor.label;"></label>
-          <label class="searchbar-oneoffheader-searchtext search-panel-input-value" flex="1" crop="end"></label>
-          <label flex="10000" value="&searchWith.label;"></label>
-        </hbox>
-        <hbox class="search-panel-searchonengine search-panel-current-input">
-          <label value="&search.label;"></label>
-          <label class="searchbar-oneoffheader-engine search-panel-input-value" flex="1" crop="end"></label>
-          <label flex="10000" value="&searchAfter.label;"></label>
-        </hbox>
-      </deck>
-      <description role="group" class="search-panel-one-offs">
-        <button oncommand="showSettings();" class="searchbar-engine-one-off-item search-setting-button-compact" tooltiptext="&changeSearchSettings.tooltip;"></button>
-      </description>
-      <vbox class="search-add-engines"></vbox>
-      <button oncommand="showSettings();" class="search-setting-button search-panel-header" label="&changeSearchSettings.button;"></button>
-      <menupopup class="search-one-offs-context-menu">
-        <menuitem class="search-one-offs-context-open-in-new-tab" label="&searchInNewTab.label;" accesskey="&searchInNewTab.accesskey;"></menuitem>
-        <menuitem class="search-one-offs-context-set-default" label="&searchSetAsDefault.label;" accesskey="&searchSetAsDefault.accesskey;"></menuitem>
-      </menupopup>
-      `, ["chrome://browser/locale/browser.dtd"])
-    );
+    this.appendChild(getFragment());
 
     this._popup = null;
 
     this._textbox = null;
 
     this._textboxWidth = 0;
 
     /**