Bug 942622 - Invalidate TabStateCache when .userTypedValue changes r=yoric,dao
authorTim Taubert <ttaubert@mozilla.com>
Mon, 25 Nov 2013 21:01:43 +0100
changeset 172685 662e8032dccec26c23af53aaa6883178f27e4cc0
parent 172684 9edf20552d79e2bc4e7a281f8839fa85bdaaac9c
child 172686 e193c7a76f4f341ebf14c40226b61a21152778c4
push id3224
push userlsblakk@mozilla.com
push dateTue, 04 Feb 2014 01:06:49 +0000
treeherdermozilla-beta@60c04d0987f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyoric, dao
bugs942622
milestone28.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 942622 - Invalidate TabStateCache when .userTypedValue changes r=yoric,dao From 087412c836ecf1412325942e20c1fd9559d8f20a Mon Sep 17 00:00:00 2001
browser/components/sessionstore/src/SessionStore.jsm
browser/components/sessionstore/src/TabStateCache.jsm
toolkit/content/widgets/browser.xml
--- a/browser/components/sessionstore/src/SessionStore.jsm
+++ b/browser/components/sessionstore/src/SessionStore.jsm
@@ -645,16 +645,26 @@ let SessionStoreInternal = {
         this.onTabLoad(win, browser);
         break;
       case "SwapDocShells":
         browser = aEvent.currentTarget;
         let otherBrowser = aEvent.detail;
         TabState.onBrowserContentsSwapped(browser, otherBrowser);
         TabStateCache.onBrowserContentsSwapped(browser, otherBrowser);
         break;
+      case "UserTypedValueChanged":
+        browser = aEvent.currentTarget;
+        if (browser.userTypedValue) {
+          TabStateCache.updateField(browser, "userTypedValue", browser.userTypedValue);
+          TabStateCache.updateField(browser, "userTypedClear", browser.userTypedClear);
+        } else {
+          TabStateCache.removeField(browser, "userTypedValue");
+          TabStateCache.removeField(browser, "userTypedClear");
+        }
+        break;
       case "TabOpen":
         this.onTabAdd(win, aEvent.originalTarget);
         break;
       case "TabClose":
         // aEvent.detail determines if the tab was closed by moving to a different window
         if (!aEvent.detail)
           this.onTabClose(win, aEvent.originalTarget);
         this.onTabRemove(win, aEvent.originalTarget);
@@ -1230,16 +1240,17 @@ let SessionStoreInternal = {
    *        Tab reference
    * @param aNoNotification
    *        bool Do not save state if we're updating an existing tab
    */
   onTabAdd: function ssi_onTabAdd(aWindow, aTab, aNoNotification) {
     let browser = aTab.linkedBrowser;
     browser.addEventListener("load", this, true);
     browser.addEventListener("SwapDocShells", this, true);
+    browser.addEventListener("UserTypedValueChanged", this, true);
 
     let mm = browser.messageManager;
     MESSAGES.forEach(msg => mm.addMessageListener(msg, this));
 
     // Load the frame script after registering listeners.
     mm.loadFrameScript("chrome://browser/content/content-sessionStore.js", false);
 
     if (!aNoNotification) {
@@ -1257,16 +1268,17 @@ let SessionStoreInternal = {
    *        Tab reference
    * @param aNoNotification
    *        bool Do not save state if we're updating an existing tab
    */
   onTabRemove: function ssi_onTabRemove(aWindow, aTab, aNoNotification) {
     let browser = aTab.linkedBrowser;
     browser.removeEventListener("load", this, true);
     browser.removeEventListener("SwapDocShells", this, true);
+    browser.removeEventListener("UserTypedValueChanged", this, true);
 
     let mm = browser.messageManager;
     MESSAGES.forEach(msg => mm.removeMessageListener(msg, this));
 
     delete browser.__SS_data;
 
     // If this tab was in the middle of restoring or still needs to be restored,
     // we need to reset that state. If the tab was restoring, we will attempt to
--- a/browser/components/sessionstore/src/TabStateCache.jsm
+++ b/browser/components/sessionstore/src/TabStateCache.jsm
@@ -231,33 +231,31 @@ let TabStateCacheInternal = {
    * @param {*} aValue The new value to place in the field.
    */
   updateField: function(aKey, aField, aValue) {
     let key = this._normalizeToBrowser(aKey);
     let data = this._data.get(key);
     if (data) {
       data[aField] = aValue;
     }
-    TabStateCacheTelemetry.recordAccess(!!data);
   },
 
   /**
    * Remove a given field from a cached tab state.
    *
    * @param {XULElement} aKey The tab or the associated browser.
    * If the tab/browser is not present, do nothing.
    * @param {string} aField The field to remove.
    */
   removeField: function(aKey, aField) {
     let key = this._normalizeToBrowser(aKey);
     let data = this._data.get(key);
     if (data && aField in data) {
       delete data[aField];
     }
-    TabStateCacheTelemetry.recordAccess(!!data);
   },
 
   /**
    * Swap cached data for two given browsers.
    *
    * @param {xul:browser} browser
    *        The first of the two browsers that swapped docShells.
    * @param {xul:browser} otherBrowser
--- a/toolkit/content/widgets/browser.xml
+++ b/toolkit/content/widgets/browser.xml
@@ -668,18 +668,27 @@
         1
       </field>
 
       <field name="_userTypedValue">
         null
       </field>
 
       <property name="userTypedValue"
-                onget="return this._userTypedValue;"
-                onset="this.userTypedClear = 0; return this._userTypedValue = val;"/>
+                onget="return this._userTypedValue;">
+        <setter><![CDATA[
+          this.userTypedClear = 0;
+          this._userTypedValue = val;
+
+          let event = new CustomEvent("UserTypedValueChanged");
+          this.dispatchEvent(event);
+
+          return val;
+        ]]></setter>
+      </property>
 
       <field name="mFormFillAttached">
         false
       </field>
 
       <field name="isShowingMessage">
         false
       </field>