addon-sdk/source/lib/sdk/panel/window.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/addon-sdk/source/lib/sdk/panel/window.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,61 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +'use strict';
     1.8 +
     1.9 +// The panel module currently supports only Firefox.
    1.10 +// See: https://bugzilla.mozilla.org/show_bug.cgi?id=jetpack-panel-apps
    1.11 +module.metadata = {
    1.12 +  'stability': 'unstable',
    1.13 +  'engines': {
    1.14 +    'Firefox': '*'
    1.15 +  }
    1.16 +};
    1.17 +
    1.18 +const { getMostRecentBrowserWindow, windows: getWindows } = require('../window/utils');
    1.19 +const { ignoreWindow } = require('../private-browsing/utils');
    1.20 +const { isPrivateBrowsingSupported } = require('../self');
    1.21 +const { isGlobalPBSupported } = require('../private-browsing/utils');
    1.22 +
    1.23 +function getWindow(anchor) {
    1.24 +  let window;
    1.25 +  let windows = getWindows("navigator:browser", {
    1.26 +    includePrivate: isPrivateBrowsingSupported || isGlobalPBSupported
    1.27 +  });
    1.28 +
    1.29 +  if (anchor) {
    1.30 +    let anchorWindow = anchor.ownerDocument.defaultView.top;
    1.31 +    let anchorDocument = anchorWindow.document;
    1.32 +
    1.33 +    // loop thru supported windows
    1.34 +    for each(let enumWindow in windows) {
    1.35 +      // Check if the anchor is in this browser window.
    1.36 +      if (enumWindow == anchorWindow) {
    1.37 +        window = anchorWindow;
    1.38 +        break;
    1.39 +      }
    1.40 +
    1.41 +      // Check if the anchor is in a browser tab in this browser window.
    1.42 +      let browser = enumWindow.gBrowser.getBrowserForDocument(anchorDocument);
    1.43 +      if (browser) {
    1.44 +        window = enumWindow;
    1.45 +        break;
    1.46 +      }
    1.47 +
    1.48 +      // Look in other subdocuments (sidebar, etc.)?
    1.49 +    }
    1.50 +  }
    1.51 +
    1.52 +  // If we didn't find the anchor's window (or we have no anchor),
    1.53 +  // return the most recent browser window.
    1.54 +  if (!window)
    1.55 +    window = getMostRecentBrowserWindow();
    1.56 +
    1.57 +  // if the window is not supported, then it should be ignored
    1.58 +  if (ignoreWindow(window)) {
    1.59 +  	return null;
    1.60 +  }
    1.61 +
    1.62 +  return window;
    1.63 +}
    1.64 +exports.getWindow = getWindow;

mercurial