Bug 1202458 - part3: rename ShortLongString to SimpleStringFront;r?pbro draft
authorJulian Descottes <jdescottes@mozilla.com>
Tue, 31 May 2016 16:51:27 +0200
changeset 374390 1bf11719e3901fe5913cabbf51ddf47ab7bbc599
parent 374389 8e8ddea83d862d94a14c9a016792ba38d793345a
child 374413 d0856bf459fc3ea6532e1585079df44d62a4cbb9
push id20004
push userjdescottes@mozilla.com
push dateThu, 02 Jun 2016 09:01:27 +0000
reviewerspbro
bugs1202458
milestone49.0a1
Bug 1202458 - part3: rename ShortLongString to SimpleStringFront;r?pbro The current name ShortLongString doesn't reflect the current usage of this class. When looking at the few clients of this class, the reason for using it is that the string is already accessible on the client and does not need to be fetched from the server, while still keeping the same interface as the LongStringFront. MozReview-Commit-ID: 7MdgH8GzC7q
devtools/client/inspector/markup/test/browser_markup_textcontent_display.js
devtools/server/actors/string.js
devtools/server/actors/styleeditor.js
devtools/server/actors/stylesheets.js
devtools/shared/fronts/inspector.js
devtools/shared/fronts/styleeditor.js
--- a/devtools/client/inspector/markup/test/browser_markup_textcontent_display.js
+++ b/devtools/client/inspector/markup/test/browser_markup_textcontent_display.js
@@ -46,17 +46,17 @@ const TEST_DATA = [{
   selector: "#shorttext-and-node",
   inline: false,
   value: "Short text",
 }, {
   desc: "Test node containing a long text and a span.",
   selector: "#longtext-and-node",
   inline: false,
   value: LONG_VALUE,
-}, ];
+}];
 
 add_task(function* () {
   let {inspector, testActor} = yield openInspectorForURL(TEST_URL);
 
   for (let data of TEST_DATA) {
     yield checkNode(inspector, testActor, data);
   }
 });
--- a/devtools/server/actors/string.js
+++ b/devtools/server/actors/string.js
@@ -47,23 +47,21 @@ exports.LongStringActor = protocol.Actor
     },
     response: { substring: RetVal() },
   }),
 
   release: method(function () { }, { release: true })
 });
 
 /**
- * When a LongString on the server is short enough to be passed
- * as a full string, the client will get a ShortLongString instead of
- * a LongStringFront.  Its API should match.
- *
- * I'm very proud of this name.
+ * When a caller is expecting a LongString actor but the string is already available on
+ * client, the SimpleStringFront can be used as it shares the same API as a
+ * LongStringFront but will not make unnecessary trips to the server.
  */
-exports.ShortLongString = Class({
+exports.SimpleStringFront = Class({
   initialize: function (str) {
     this.str = str;
   },
 
   get length() {
     return this.str.length;
   },
 
@@ -136,13 +134,13 @@ protocol.types.addType("longstring", {
     }
     return stringActorType.write(value, context, detail);
   },
   read: (value, context, detail) => {
     if (context instanceof protocol.Actor) {
       throw Error("Passing a longstring as an argument isn't supported.");
     }
     if (typeof (value) === "string") {
-      return exports.ShortLongString(value);
+      return exports.SimpleStringFront(value);
     }
     return stringActorType.read(value, context, detail);
   }
 });
--- a/devtools/server/actors/styleeditor.js
+++ b/devtools/server/actors/styleeditor.js
@@ -10,17 +10,17 @@ var Services = require("Services");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/NetUtil.jsm");
 Cu.import("resource://gre/modules/FileUtils.jsm");
 
 const promise = require("promise");
 const events = require("sdk/event/core");
 const protocol = require("devtools/shared/protocol");
 const {Arg, Option, method, RetVal, types} = protocol;
-const {LongStringActor, ShortLongString} = require("devtools/server/actors/string");
+const {LongStringActor} = require("devtools/server/actors/string");
 const {fetch} = require("devtools/shared/DevToolsUtils");
 const {OldStyleSheetFront} = require("devtools/shared/fronts/styleeditor");
 const {oldStyleSheetSpec} = require("devtools/shared/specs/styleeditor");
 
 loader.lazyGetter(this, "CssLogic", () => require("devtools/shared/inspector/css-logic").CssLogic);
 
 var TRANSITION_CLASS = "moz-styleeditor-transitioning";
 var TRANSITION_DURATION_MS = 500;
--- a/devtools/server/actors/stylesheets.js
+++ b/devtools/server/actors/stylesheets.js
@@ -11,17 +11,17 @@ Cu.import("resource://gre/modules/XPCOMU
 Cu.import("resource://gre/modules/NetUtil.jsm");
 Cu.import("resource://gre/modules/FileUtils.jsm");
 
 const promise = require("promise");
 const {Task} = require("devtools/shared/task");
 const events = require("sdk/event/core");
 const protocol = require("devtools/shared/protocol");
 const {Arg, Option, method, RetVal, types} = protocol;
-const {LongStringActor, ShortLongString} = require("devtools/server/actors/string");
+const {LongStringActor} = require("devtools/server/actors/string");
 const {fetch} = require("devtools/shared/DevToolsUtils");
 const {listenOnce} = require("devtools/shared/async-utils");
 const {originalSourceSpec, mediaRuleSpec, styleSheetSpec,
        styleSheetsSpec} = require("devtools/shared/specs/stylesheets");
 const {SourceMapConsumer} = require("source-map");
 
 loader.lazyGetter(this, "CssLogic", () => require("devtools/shared/inspector/css-logic").CssLogic);
 
--- a/devtools/shared/fronts/inspector.js
+++ b/devtools/shared/fronts/inspector.js
@@ -1,17 +1,17 @@
 /* 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";
 
 const { Ci } = require("chrome");
 require("devtools/shared/fronts/styles");
 require("devtools/shared/fronts/highlighters");
-const { ShortLongString } = require("devtools/server/actors/string");
+const { SimpleStringFront } = require("devtools/server/actors/string");
 const {
   Front,
   FrontClassWithSpec,
   custom,
   preEvent,
   types
 } = require("devtools/shared/protocol.js");
 const {
@@ -316,17 +316,17 @@ const NodeFront = FrontClassWithSpec(nod
   getNodeValue: custom(function () {
     // backward-compatibility: if nodevalue is null and shortValue is defined, the actual
     // value of the node needs to be fetched on the server.
     if (this._form.nodeValue === null && this._form.shortValue) {
       return this._getNodeValue();
     }
 
     let str = this._form.nodeValue || "";
-    return promise.resolve(new ShortLongString(str));
+    return promise.resolve(new SimpleStringFront(str));
   }, {
     impl: "_getNodeValue"
   }),
 
   // Accessors for custom form properties.
 
   getFormProperty: function (name) {
     return this._form.props ? this._form.props[name] : null;
--- a/devtools/shared/fronts/styleeditor.js
+++ b/devtools/shared/fronts/styleeditor.js
@@ -1,14 +1,14 @@
 /* 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";
 
-const { ShortLongString } = require("devtools/server/actors/string");
+const { SimpleStringFront } = require("devtools/server/actors/string");
 const { Front, FrontClassWithSpec } = require("devtools/shared/protocol");
 const { oldStyleSheetSpec } = require("devtools/shared/specs/styleeditor");
 const promise = require("promise");
 const events = require("sdk/event/core");
 
 /**
  * StyleSheetFront is the client-side counterpart to a StyleSheetActor.
  */
@@ -38,17 +38,17 @@ const OldStyleSheetFront = FrontClassWit
     this.actorID = form.actor;
     this._form = form;
   },
 
   getText: function () {
     let deferred = promise.defer();
 
     events.once(this, "source-load", (source) => {
-      let longStr = new ShortLongString(source);
+      let longStr = new SimpleStringFront(source);
       deferred.resolve(longStr);
     });
     this.fetchSource();
 
     return deferred.promise;
   },
 
   getOriginalSources: function () {