Bug 1196975 - part3: GetTabForContentWindowNoShim. r=billm
authorGabor Krizsanits <gkrizsanits>
Fri, 09 Oct 2015 06:06:00 +0200
changeset 293023 088a84f0a1ad2e89bf147412f550c5fc9d463ac2
parent 293022 a4e71f016f2726fbd1aec892774c57f1577553f4
child 293024 8674d248140d4aeae853ad03fc5e47c1d3c395c0
push id8824
push userraliiev@mozilla.com
push dateMon, 14 Dec 2015 20:18:56 +0000
treeherdermozilla-aurora@e2031358e2a6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm
bugs1196975
milestone45.0a1
Bug 1196975 - part3: GetTabForContentWindowNoShim. r=billm
addon-sdk/source/lib/sdk/content/page-mod.js
addon-sdk/source/lib/sdk/content/sandbox.js
addon-sdk/source/lib/sdk/content/worker.js
addon-sdk/source/lib/sdk/loader/sandbox.js
addon-sdk/source/lib/sdk/selection.js
addon-sdk/source/lib/sdk/tabs/helpers.js
addon-sdk/source/lib/sdk/tabs/utils.js
--- a/addon-sdk/source/lib/sdk/content/page-mod.js
+++ b/addon-sdk/source/lib/sdk/content/page-mod.js
@@ -13,18 +13,17 @@ const { Disposable } = require('../core/
 const { WeakReference } = require('../core/reference');
 const { WorkerChild } = require('./worker-child');
 const { EventTarget } = require('../event/target');
 const { on, emit, once, setListeners } = require('../event/core');
 const { on: domOn, removeListener: domOff } = require('../dom/events');
 const { isRegExp, isUndefined } = require('../lang/type');
 const { merge } = require('../util/object');
 const { isBrowser, getFrames } = require('../window/utils');
-const { getTabs, getTabContentWindow, getTabForContentWindow,
-        getURI: getTabURI } = require('../tabs/utils');
+const { getTabs, getURI: getTabURI } = require('../tabs/utils');
 const { ignoreWindow } = require('../private-browsing/utils');
 const { Style } = require("../stylesheet/style");
 const { attach, detach } = require("../content/mod");
 const { has, hasAny } = require("../util/array");
 const { Rules } = require("../util/rules");
 const { List, addListItem, removeListItem } = require('../util/list');
 const { when } = require("../system/unload");
 const { uuid } = require('../util/uuid');
--- a/addon-sdk/source/lib/sdk/content/sandbox.js
+++ b/addon-sdk/source/lib/sdk/content/sandbox.js
@@ -13,17 +13,17 @@ const { on, off, emit } = require('../ev
 const { events } = require('./sandbox/events');
 const { requiresAddonGlobal } = require('./utils');
 const { delay: async } = require('../lang/functional');
 const { Ci, Cu, Cc } = require('chrome');
 const timer = require('../timers');
 const { URL } = require('../url');
 const { sandbox, evaluate, load } = require('../loader/sandbox');
 const { merge } = require('../util/object');
-const { getTabForContentWindow } = require('../tabs/utils');
+const { getTabForContentWindowNoShim } = require('../tabs/utils');
 const { getInnerId } = require('../window/utils');
 const { PlainTextConsole } = require('../console/plain-text');
 const { data } = require('../self');const { isChildLoader } = require('../remote/core');
 // WeakMap of sandboxes so we can access private values
 const sandboxes = new WeakMap();
 
 /* Trick the linker in order to ensure shipping these files in the XPI.
   require('./content-worker.js');
@@ -52,17 +52,17 @@ const JS_VERSION = '1.8';
 function isWindowInTab(window) {
   if (isChildLoader) {
     let { frames } = require('../remote/child');
     let frame = frames.getFrameForWindow(window.top);
     return frame && frame.isTab;
   }
   else {
     // The deprecated sync worker API still does everything in the main process
-    return getTabForContentWindow(window);
+    return getTabForContentWindowNoShim(window);
   }
 }
 
 const WorkerSandbox = Class({
   implements: [ EventTarget ],
 
   /**
    * Emit a message to the worker content sandbox
--- a/addon-sdk/source/lib/sdk/content/worker.js
+++ b/addon-sdk/source/lib/sdk/content/worker.js
@@ -9,21 +9,21 @@ module.metadata = {
 
 const { emit } = require('../event/core');
 const { omit, merge } = require('../util/object');
 const { Class } = require('../core/heritage');
 const { method } = require('../lang/functional');
 const { getInnerId } = require('../window/utils');
 const { EventTarget } = require('../event/target');
 const { isPrivate } = require('../private-browsing/utils');
-const { getTabForBrowser, getTabForContentWindow, getBrowserForTab } = require('../tabs/utils');
+const { getTabForBrowser, getTabForContentWindowNoShim, getBrowserForTab } = require('../tabs/utils');
 const { attach, connect, detach, destroy, makeChildOptions } = require('./utils');
 const { ensure } = require('../system/unload');
 const { on: observe } = require('../system/events');
-const { Ci } = require('chrome');
+const { Ci, Cu } = require('chrome');
 const { modelFor: tabFor } = require('sdk/model/core');
 const { remoteRequire, processes, frames } = require('../remote/parent');
 remoteRequire('sdk/content/worker-child');
 
 const workers = new WeakMap();
 var modelFor = (worker) => workers.get(worker);
 
 const ERR_DESTROYED = "Couldn't find the worker to receive this message. " +
@@ -118,17 +118,17 @@ exports.Worker = Worker;
 attach.define(Worker, function(worker, window) {
   // This method of attaching should be deprecated
   let model = modelFor(worker);
   if (model.attached)
     detach(worker);
 
   model.window = window;
   let frame = null;
-  let tab = getTabForContentWindow(window.top);
+  let tab = getTabForContentWindowNoShim(window);
   if (tab)
     frame = frames.getFrameForBrowser(getBrowserForTab(tab));
 
   let childOptions = makeChildOptions(model.options);
   childOptions.windowId = getInnerId(window);
 
   processes.port.emit('sdk/worker/create', childOptions);
 
--- a/addon-sdk/source/lib/sdk/loader/sandbox.js
+++ b/addon-sdk/source/lib/sdk/loader/sandbox.js
@@ -7,17 +7,17 @@ module.metadata = {
   "stability": "experimental"
 };
 
 const { Cc, Ci, CC, Cu } = require('chrome');
 const systemPrincipal = CC('@mozilla.org/systemprincipal;1', 'nsIPrincipal')();
 const scriptLoader = Cc['@mozilla.org/moz/jssubscript-loader;1'].
                      getService(Ci.mozIJSSubScriptLoader);
 const self = require('sdk/self');
-const { getTabId, getTabForContentWindow } = require('../tabs/utils');
+const { getTabId } = require('../tabs/utils');
 const { getInnerId } = require('../window/utils');
 
 const { devtools } = Cu.import("resource://devtools/shared/Loader.jsm", {});
 const { require: devtoolsRequire } = devtools;
 const { addContentGlobal, removeContentGlobal } = devtoolsRequire("devtools/server/content-globals");
 
 /**
  * Make a new sandbox that inherits given `source`'s principals. Source can be
--- a/addon-sdk/source/lib/sdk/selection.js
+++ b/addon-sdk/source/lib/sdk/selection.js
@@ -15,17 +15,17 @@ module.metadata = {
 const { Ci, Cc } = require("chrome"),
     { setTimeout } = require("./timers"),
     { emit, off } = require("./event/core"),
     { Class, obscure } = require("./core/heritage"),
     { EventTarget } = require("./event/target"),
     { ns } = require("./core/namespace"),
     { when: unload } = require("./system/unload"),
     { ignoreWindow } = require('./private-browsing/utils'),
-    { getTabs, getTabContentWindow, getTabForContentWindow,
+    { getTabs, getTabForContentWindow,
       getAllTabContentWindows } = require('./tabs/utils'),
     winUtils = require("./window/utils"),
     events = require("./system/events");
 
 // The selection types
 const HTML = 0x01,
       TEXT = 0x02,
       DOM  = 0x03; // internal use only
--- a/addon-sdk/source/lib/sdk/tabs/helpers.js
+++ b/addon-sdk/source/lib/sdk/tabs/helpers.js
@@ -6,17 +6,17 @@
 module.metadata = {
   'stability': 'unstable'
 };
 
 
 // NOTE: This file should only export Tab instances
 
 
-const { getTabForContentWindow, getTabForBrowser: getRawTabForBrowser } = require('./utils');
+const { getTabForBrowser: getRawTabForBrowser } = require('./utils');
 const { modelFor } = require('../model/core');
 
 exports.getTabForRawTab = modelFor;
 
 function getTabForBrowser(browser) {
   return modelFor(getRawTabForBrowser(browser)) || null;
 }
 exports.getTabForBrowser = getTabForBrowser;
--- a/addon-sdk/source/lib/sdk/tabs/utils.js
+++ b/addon-sdk/source/lib/sdk/tabs/utils.js
@@ -6,20 +6,21 @@
 module.metadata = {
   'stability': 'unstable'
 };
 
 
 // NOTE: This file should only deal with xul/native tabs
 
 
-const { Ci } = require('chrome');
+const { Ci, Cu } = require('chrome');
 const { defer } = require("../lang/functional");
 const { windows, isBrowser } = require('../window/utils');
 const { isPrivateBrowsingSupported } = require('../self');
+const { ShimWaiver } = Cu.import("resource://gre/modules/ShimWaiver.jsm");
 
 // Bug 834961: ignore private windows when they are not supported
 function getWindows() {
   return windows(null, { includePrivate: isPrivateBrowsingSupported });
 }
 
 const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 
@@ -257,16 +258,26 @@ function getAllTabContentWindows() {
 exports.getAllTabContentWindows = getAllTabContentWindows;
 
 // gets the tab containing the provided window
 function getTabForContentWindow(window) {
   return getTabs().find(tab => getTabContentWindow(tab) === window.top) || null;
 }
 exports.getTabForContentWindow = getTabForContentWindow;
 
+// only sdk/selection.js is relying on shims
+function getTabForContentWindowNoShim(window) {
+  function getTabContentWindowNoShim(tab) {
+    let browser = getBrowserForTab(tab);
+    return ShimWaiver.getProperty(browser, "contentWindow");
+  }
+  return getTabs().find(tab => getTabContentWindowNoShim(tab) === window.top) || null;
+}
+exports.getTabForContentWindowNoShim = getTabForContentWindowNoShim;
+
 function getTabURL(tab) {
   return String(getBrowserForTab(tab).currentURI.spec);
 }
 exports.getTabURL = getTabURL;
 
 function setTabURL(tab, url) {
   let browser = getBrowserForTab(tab);
   browser.loadURI(String(url));