Bug 1309650 - remove non remote friendly APIs from selection.js;r=pbro draft
authorJulian Descottes <jdescottes@mozilla.com>
Wed, 12 Oct 2016 20:04:17 +0200
changeset 424387 822bec09271e175ded9a4ca739a806d561f29eae
parent 423665 8654fba1417d44e510b8f2791f5ccf06c0496744
child 533670 ee69bab8cb31dff178218baef2ec7703540a535c
push id32149
push userjdescottes@mozilla.com
push dateWed, 12 Oct 2016 19:14:03 +0000
reviewerspbro
bugs1309650
milestone52.0a1
Bug 1309650 - remove non remote friendly APIs from selection.js;r=pbro MozReview-Commit-ID: 4EZIn2NWiZ5
devtools/client/framework/selection.js
--- a/devtools/client/framework/selection.js
+++ b/devtools/client/framework/selection.js
@@ -1,19 +1,17 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
 /* 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 { Cu } = require("chrome");
 const nodeConstants = require("devtools/shared/dom-node-constants");
-const { getRootBindingParent } = require("devtools/shared/layout/utils");
 var EventEmitter = require("devtools/shared/event-emitter");
 
 /**
  * API
  *
  *   new Selection(walker=null)
  *   destroy()
  *   node (readonly)
@@ -56,24 +54,22 @@ var EventEmitter = require("devtools/sha
  * A Selection object. Hold a reference to a node.
  * Includes some helpers, fire some helpful events.
  */
 function Selection(walker) {
   EventEmitter.decorate(this);
 
   this._onMutations = this._onMutations.bind(this);
   this.setWalker(walker);
-  this.setNode(null);
 }
 
 exports.Selection = Selection;
 
 Selection.prototype = {
   _walker: null,
-  _node: null,
 
   _onMutations: function (mutations) {
     let attributeChange = false;
     let pseudoChange = false;
     let detached = false;
     let parentNode = null;
 
     for (let m of mutations) {
@@ -101,69 +97,39 @@ Selection.prototype = {
       this.emit("pseudoclass");
     }
     if (detached) {
       this.emit("detached-front", parentNode);
     }
   },
 
   destroy: function () {
-    this.setNode(null);
     this.setWalker(null);
   },
 
   setWalker: function (walker) {
     if (this._walker) {
       this._walker.off("mutations", this._onMutations);
     }
     this._walker = walker;
     if (this._walker) {
       this._walker.on("mutations", this._onMutations);
     }
   },
 
-  // Not remote-safe
-  setNode: function (value, reason = "unknown") {
-    if (value) {
-      value = this._walker.frontForRawNode(value);
-    }
-    this.setNodeFront(value, reason);
-  },
-
-  // Not remote-safe
-  get node() {
-    return this._node;
-  },
-
-  // Not remote-safe
-  get document() {
-    if (this.isNode()) {
-      return this.node.ownerDocument;
-    }
-    return null;
-  },
-
   setNodeFront: function (value, reason = "unknown") {
     this.reason = reason;
 
     // If an inlineTextChild text node is being set, then set it's parent instead.
     let parentNode = value && value.parentNode();
     if (value && parentNode && parentNode.inlineTextChild === value) {
       value = parentNode;
     }
 
-    // We used to return here if the node had not changed but we now need to
-    // set the node even if it is already set otherwise it is not possible to
-    // e.g. highlight the same node twice.
-    let rawValue = null;
-    if (value && value.isLocalToBeDeprecated()) {
-      rawValue = value.rawNode();
-    }
     this.emit("before-new-node-front", value, reason);
-    this._node = rawValue;
     this._nodeFront = value;
     this.emit("new-node-front", value, this.reason);
   },
 
   get documentFront() {
     return this._walker.document(this._nodeFront);
   },
 
@@ -173,62 +139,25 @@ Selection.prototype = {
 
   isRoot: function () {
     return this.isNode() &&
            this.isConnected() &&
            this._nodeFront.isDocumentElement;
   },
 
   isNode: function () {
-    if (!this._nodeFront) {
-      return false;
-    }
-
-    // As long as tools are still accessing node.rawNode(),
-    // this needs to stay here.
-    if (this._node && Cu.isDeadWrapper(this._node)) {
-      return false;
-    }
-
-    return true;
-  },
-
-  isLocal: function () {
-    return !!this._node;
+    return !!this._nodeFront;
   },
 
   isConnected: function () {
     let node = this._nodeFront;
     if (!node || !node.actorID) {
       return false;
     }
 
-    // As long as there are still tools going around
-    // accessing node.rawNode, this needs to stay.
-    let rawNode = null;
-    if (node.isLocalToBeDeprecated()) {
-      rawNode = node.rawNode();
-    }
-    if (rawNode) {
-      try {
-        let doc = this.document;
-        if (doc && doc.defaultView) {
-          let docEl = doc.documentElement;
-          let bindingParent = getRootBindingParent(rawNode);
-
-          if (docEl.contains(bindingParent)) {
-            return true;
-          }
-        }
-      } catch (e) {
-        // "can't access dead object" error
-      }
-      return false;
-    }
-
     while (node) {
       if (node === this._walker.rootNode) {
         return true;
       }
       node = node.parentNode();
     }
     return false;
   },