Bug 1202458 - part3: rename ShortLongString to SimpleStringFront;r=pbro
authorJulian Descottes <jdescottes@mozilla.com>
Tue, 31 May 2016 16:51:27 +0200
changeset 375179 96f3ba6f40966164d51a040b8c8eb25c80ff07ed
parent 375178 e3622cb1ef4266152f887583a621df599452905f
child 375180 c60e3877ccf650d0b665b2395c9dc9794ff820a5
push id20186
push userrhelmer@mozilla.com
push dateFri, 03 Jun 2016 16:55:36 +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 {oldStyleSheetSpec, styleEditorSpec} = 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;
 var TRANSITION_RULE = "\
--- 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,16 +1,16 @@
 /* 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";
 
 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,
   styleEditorSpec
 } = require("devtools/shared/specs/styleeditor");
 const promise = require("promise");
 const events = require("sdk/event/core");
 
@@ -41,17 +41,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 () {