Bug 1254386 - Change old RDM to use emulation actor. r=jryans
authorTim Nguyen <ntim.bugs@gmail.com>
Tue, 23 Aug 2016 01:51:17 -0700
changeset 336337 6f5b69e1d1a9c8acafd059e8d221d667e86040d3
parent 336336 fec37519e65fe5d4b2e68a7f0c76bca60253a0ed
child 336338 bba8077c6c0a7d9e75f624e1b1df2bf0cbd29d2f
push id10033
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:50:26 +0000
treeherdermozilla-aurora@5dddbefdf759 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjryans
bugs1254386
milestone51.0a1
Bug 1254386 - Change old RDM to use emulation actor. r=jryans MozReview-Commit-ID: EQawVubnMAp
devtools/client/responsivedesign/responsivedesign.jsm
--- a/devtools/client/responsivedesign/responsivedesign.jsm
+++ b/devtools/client/responsivedesign/responsivedesign.jsm
@@ -14,16 +14,17 @@ var {TouchEventSimulator} = require("dev
 var {Task} = require("devtools/shared/task");
 var promise = require("promise");
 var DevToolsUtils = require("devtools/shared/DevToolsUtils");
 var flags = require("devtools/shared/flags");
 var Services = require("Services");
 var EventEmitter = require("devtools/shared/event-emitter");
 var {ViewHelpers} = require("devtools/client/shared/widgets/view-helpers");
 var { LocalizationHelper } = require("devtools/client/shared/l10n");
+var { EmulationFront } = require("devtools/shared/fronts/emulation");
 
 loader.lazyImporter(this, "SystemAppProxy",
                     "resource://gre/modules/SystemAppProxy.jsm");
 loader.lazyRequireGetter(this, "DebuggerClient",
                          "devtools/shared/client/main", true);
 loader.lazyRequireGetter(this, "DebuggerServer",
                          "devtools/server/main", true);
 
@@ -269,21 +270,18 @@ ResponsiveUI.prototype = {
   connectToServer: Task.async(function* () {
     if (!DebuggerServer.initialized) {
       DebuggerServer.init();
       DebuggerServer.addBrowserActors();
     }
     this.client = new DebuggerClient(DebuggerServer.connectPipe());
     yield this.client.connect();
     let {tab} = yield this.client.getTab();
-    let [response, tabClient] = yield this.client.attachTab(tab.actor);
-    this.tabClient = tabClient;
-    if (!tabClient) {
-      console.error(new Error("Responsive Mode: failed to attach tab"));
-    }
+    yield this.client.attachTab(tab.actor);
+    this.emulationFront = EmulationFront(this.client, tab);
   }),
 
   loadPresets: function () {
     // Try to load presets from prefs
     let presets = defaultPresets;
     if (Services.prefs.prefHasUserValue("devtools.responsiveUI.presets")) {
       try {
         presets = JSON.parse(Services.prefs.getCharPref("devtools.responsiveUI.presets"));
@@ -387,17 +385,17 @@ ResponsiveUI.prototype = {
 
     ActiveTabs.delete(this.tab);
     if (this.touchEventSimulator) {
       this.touchEventSimulator.stop();
     }
 
     yield new Promise((resolve, reject) => {
       this.client.close(resolve);
-      this.client = this.tabClient = null;
+      this.client = this.emulationFront = null;
     });
 
     this._telemetry.toolClosed("responsive");
 
     if (this.tab.linkedBrowser.messageManager) {
       let stopped = this.waitForMessage("ResponsiveMode:Stop:Done");
       this.tab.linkedBrowser.messageManager.sendAsyncMessage("ResponsiveMode:Stop");
       yield stopped;
@@ -969,28 +967,29 @@ ResponsiveUI.prototype = {
     return navigatedDeferred.promise;
   },
 
   /**
    * Change the user agent string
    */
   changeUA: Task.async(function* () {
     let value = this.userAgentInput.value;
+    let changed;
     if (value) {
+      changed = yield this.emulationFront.setUserAgentOverride(value);
       this.userAgentInput.setAttribute("attention", "true");
     } else {
+      changed = yield this.emulationFront.clearUserAgentOverride();
       this.userAgentInput.removeAttribute("attention");
     }
-
-    // Changing the UA triggers an automatic reload.  Ensure we wait for this to
-    // complete before emitting the changed event, so that tests wait for the
-    // reload.
-    let reloaded = this.waitForReload();
-    yield this.tabClient.reconfigure({customUserAgent: value});
-    yield reloaded;
+    if (changed) {
+      let reloaded = this.waitForReload();
+      this.tab.linkedBrowser.reload();
+      yield reloaded;
+    }
     ResponsiveUIManager.emit("userAgentChanged", { tab: this.tab });
   }),
 
   /**
    * Get the current width and height.
    */
   getSize() {
     let width = Number(this.stack.style.minWidth.replace("px", ""));