diff --git a/modules/base.js b/modules/base.js index 3a995419..46cc235a 100644 --- a/modules/base.js +++ b/modules/base.js @@ -37,24 +37,23 @@ const EXPORTED_SYMBOLS = ['TreeStyleTabBase']; const Cc = Components.classes; const Ci = Components.interfaces; - + Components.utils.import('resource://gre/modules/XPCOMUtils.jsm'); -XPCOMUtils.defineLazyModuleGetter(this, 'Services', 'resource://gre/modules/Services.jsm'); +Components.utils.import('resource://gre/modules/Services.jsm'); -Components.utils.import('resource://treestyletab-modules/lib/prefs.js'); -Components.utils.import('resource://treestyletab-modules/lib/namespace.jsm'); -var window = getNamespaceFor('piro.sakura.ne.jp'); - -XPCOMUtils.defineLazyModuleGetter(this, 'Deferred', 'resource://treestyletab-modules/lib/jsdeferred.js'); +XPCOMUtils.defineLazyGetter(this, 'window', function() { + Cu.import('resource://treestyletab-modules/lib/namespace.jsm'); + return getNamespaceFor('piro.sakura.ne.jp'); +}); +XPCOMUtils.defineLazyGetter(this, 'prefs', function() { + Cu.import('resource://treestyletab-modules/lib/prefs.js'); + return window['piro.sakura.ne.jp'].prefs; +}); XPCOMUtils.defineLazyGetter(this, 'jstimer', function() { var jstimer = {}; Components.utils.import('resource://treestyletab-modules/lib/jstimer.jsm', jstimer); return jstimer; }); -XPCOMUtils.defineLazyGetter(this, 'boxObject', function() { - Components.utils.import('resource://treestyletab-modules/lib/boxObject.js', {}); - return window['piro.sakura.ne.jp'].boxObject; -}); XPCOMUtils.defineLazyGetter(this, 'extensions', function() { Components.utils.import('resource://treestyletab-modules/lib/extensions.js', {}); return window['piro.sakura.ne.jp'].extensions; @@ -69,9 +68,16 @@ XPCOMUtils.defineLazyGetter(this, 'autoScroll', function() { }); XPCOMUtils.defineLazyModuleGetter(this, 'UninstallationListener', 'resource://treestyletab-modules/lib/UninstallationListener.js'); +XPCOMUtils.defineLazyModuleGetter(this, 'Deferred', + 'resource://treestyletab-modules/lib/jsdeferred.js'); XPCOMUtils.defineLazyModuleGetter(this, 'confirmWithPopup', 'resource://treestyletab-modules/lib/confirmWithPopup.js'); XPCOMUtils.defineLazyModuleGetter(this, 'utils', 'resource://treestyletab-modules/utils.js', 'TreeStyleTabUtils'); +if (Services.appinfo.OS === 'WINNT') { + XPCOMUtils.defineLazyModuleGetter(this, 'AeroPeek', + 'resource://gre/modules/WindowsPreviewPerTab.jsm', 'AeroPeek'); +} + var TreeStyleTabBase = { __proto__ : window['piro.sakura.ne.jp'].prefs, @@ -290,7 +296,8 @@ var TreeStyleTabBase = { get animationManager() { return animationManager; }, get autoScroll() { return autoScroll; }, get Deferred() { return Deferred; }, - + get AeroPeek() { return AeroPeek; }, // for Windows + init : function utils_init() { if (this._initialized) return; @@ -321,14 +328,6 @@ var TreeStyleTabBase = { this.onPrefChange('extensions.treestyletab.counter.role.horizontal'); this.onPrefChange('extensions.treestyletab.counter.role.vertical'); - try { - if (Services.appinfo.OS == 'WINNT') - this.updateAeroPeek(); - } - catch(e) { - dump(e+'\n'); - } - try { this.overrideExtensions(); } @@ -511,13 +510,6 @@ var TreeStyleTabBase = { }); }, - updateAeroPeek : function utils_updateAeroPeek() - { - var ns = {}; - Components.utils.import('resource://gre/modules/WindowsPreviewPerTab.jsm', ns); - this.AeroPeek = ns.AeroPeek; - }, - overrideExtensions : function utils_overrideExtensions() { // Scriptish @@ -611,23 +603,7 @@ var TreeStyleTabBase = { }, /* utilities */ - - getBoxObjectFor : function utils_getBoxObjectFor(aNode) - { - return boxObject.getBoxObjectFor(aNode); - }, - - evalInSandbox : function utils_evalInSandbox(aCode, aOwner) - { - try { - var sandbox = new Components.utils.Sandbox(aOwner || 'about:blank'); - return Components.utils.evalInSandbox(aCode, sandbox); - } - catch(e) { - } - return void(0); - }, - + get browserWindow() { return this.topBrowserWindow; diff --git a/modules/browser.js b/modules/browser.js index e9661a69..b2e73933 100644 --- a/modules/browser.js +++ b/modules/browser.js @@ -3959,7 +3959,7 @@ TreeStyleTabBrowser.prototype = { return; var indexes = []; - var items = this.evalInSandbox('('+this.SessionStore.getClosedTabData(this.window)+')'); + var items = utils.evalInSandbox('('+this.SessionStore.getClosedTabData(this.window)+')'); for (let i = 0, maxi = items.length; i < maxi; i++) { let item = items[i]; diff --git a/modules/lib/boxObject.js b/modules/lib/boxObject.js deleted file mode 100644 index d6e7d144..00000000 --- a/modules/lib/boxObject.js +++ /dev/null @@ -1,180 +0,0 @@ -/* - "getBoxObjectFor()" compatibility library for Firefox 3.6 or later - - Usage: - // use instead of HTMLDocument.getBoxObjectFor(HTMLElement) - var boxObject = window['piro.sakura.ne.jp'] - .boxObject - .getBoxObjectFor(HTMLElement); - - license: The MIT License, Copyright (c) 2009-2010 YUKI "Piro" Hiroshi - http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/license.txt - original: - http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/boxObject.js - http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/boxObject.test.js - http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/fixtures/box.html -*/ - -/* To work as a JS Code Module */ -if (typeof window == 'undefined' || - (window && typeof window.constructor == 'function')) { - this.EXPORTED_SYMBOLS = ['boxObject']; - - // If namespace.jsm is available, export symbols to the shared namespace. - // See: http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/namespace.jsm - try { - let ns = {}; - Components.utils.import('resource://treestyletab-modules/lib/namespace.jsm', ns); - /* var */ window = ns.getNamespaceFor('piro.sakura.ne.jp'); - } - catch(e) { - window = {}; - } -} - -(function() { - const currentRevision = 6; - - if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {}; - - var loadedRevision = 'boxObject' in window['piro.sakura.ne.jp'] ? - window['piro.sakura.ne.jp'].boxObject.revision : - 0 ; - if (loadedRevision && loadedRevision > currentRevision) { - return; - } - - var Cc = Components.classes; - var Ci = Components.interfaces; - - window['piro.sakura.ne.jp'].boxObject = { - revision : currentRevision, - - getBoxObjectFor : function(aNode, aUnify) - { - return ('getBoxObjectFor' in aNode.ownerDocument) ? - this.getBoxObjectFromBoxObjectFor(aNode, aUnify) : - this.getBoxObjectFromClientRectFor(aNode, aUnify) ; - }, - - getBoxObjectFromBoxObjectFor : function(aNode, aUnify) - { - var boxObject = aNode.ownerDocument.getBoxObjectFor(aNode); - var box = { - x : boxObject.x, - y : boxObject.y, - width : boxObject.width, - height : boxObject.height, - screenX : boxObject.screenX, - screenY : boxObject.screenY, - element : aNode - }; - if (!aUnify) return box; - - var style = this._getComputedStyle(aNode); - box.left = box.x - this._getPropertyPixelValue(style, 'border-left-width'); - box.top = box.y - this._getPropertyPixelValue(style, 'border-top-width'); - if (style.getPropertyValue('position') == 'fixed') { - box.left -= frame.scrollX; - box.top -= frame.scrollY; - } - box.right = box.left + box.width; - box.bottom = box.top + box.height; - - return box; - }, - - getBoxObjectFromClientRectFor : function(aNode, aUnify) - { - var box = { - x : 0, - y : 0, - width : 0, - height : 0, - screenX : 0, - screenY : 0, - element : aNode - }; - try { - var zoom = this.getZoom(aNode.ownerDocument.defaultView); - - var rect = aNode.getBoundingClientRect(); - if (aUnify) { - box.left = rect.left; - box.top = rect.top; - box.right = rect.right; - box.bottom = rect.bottom; - } - - var style = this._getComputedStyle(aNode); - var frame = aNode.ownerDocument.defaultView; - - // "x" and "y" are offset positions of the "padding-box" from the document top-left edge. - box.x = rect.left + this._getPropertyPixelValue(style, 'border-left-width'); - box.y = rect.top + this._getPropertyPixelValue(style, 'border-top-width'); - if (style.getPropertyValue('position') != 'fixed') { - box.x += frame.scrollX; - box.y += frame.scrollY; - } - - // "width" and "height" are sizes of the "border-box". - box.width = rect.right - rect.left; - box.height = rect.bottom - rect.top; - - box.screenX = rect.left * zoom; - box.screenY = rect.top * zoom; - - box.screenX += frame.mozInnerScreenX * zoom; - box.screenY += frame.mozInnerScreenY * zoom; - } - catch(e) { - } - - 'x,y,screenX,screenY,width,height,left,top,right,bottom' - .split(',') - .forEach(function(aProperty) { - if (aProperty in box) - box[aProperty] = Math.round(box[aProperty]); - }); - - return box; - }, - - _getComputedStyle : function(aNode) - { - return aNode.ownerDocument.defaultView.getComputedStyle(aNode, null); - }, - - _getPropertyPixelValue : function(aStyle, aProperty) - { - return parseInt(aStyle.getPropertyValue(aProperty).replace('px', '')); - }, - - Prefs : Cc['@mozilla.org/preferences;1'] - .getService(Ci.nsIPrefBranch) - .QueryInterface(Ci.nsIPrefBranch2), - - getZoom : function(aFrame) - { - try { - if (!this.Prefs.getBoolPref('browser.zoom.full')) - return 1; - } - catch(e) { - return 1; - } - var markupDocumentViewer = aFrame.top - .QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIWebNavigation) - .QueryInterface(Ci.nsIDocShell) - .contentViewer - .QueryInterface(Ci.nsIMarkupDocumentViewer); - return markupDocumentViewer.fullZoom; - } - - }; -})(); - -if (window != this) { // work as a JS Code Module - this.boxObject = window['piro.sakura.ne.jp'].boxObject; -} diff --git a/modules/utils.js b/modules/utils.js index 446b9ce4..7546eb70 100644 --- a/modules/utils.js +++ b/modules/utils.js @@ -39,21 +39,22 @@ let EXPORTED_SYMBOLS = ['TreeStyleTabUtils']; const Cc = Components.classes; const Ci = Components.interfaces; +const Cu = Components.utils; -Components.utils.import('resource://gre/modules/XPCOMUtils.jsm'); +Cu.import('resource://gre/modules/XPCOMUtils.jsm'); XPCOMUtils.defineLazyGetter(this, 'window', function() { - Components.utils.import('resource://treestyletab-modules/lib/namespace.jsm'); + Cu.import('resource://treestyletab-modules/lib/namespace.jsm'); return getNamespaceFor('piro.sakura.ne.jp'); }); XPCOMUtils.defineLazyGetter(this, 'prefs', function() { - Components.utils.import('resource://treestyletab-modules/lib/prefs.js'); + Cu.import('resource://treestyletab-modules/lib/prefs.js'); return window['piro.sakura.ne.jp'].prefs; }); XPCOMUtils.defineLazyGetter(this, 'stringBundle', function() { - Components.utils.import('resource://treestyletab-modules/lib/stringBundle.js', {}); + Cu.import('resource://treestyletab-modules/lib/stringBundle.js', {}); return window['piro.sakura.ne.jp'].stringBundle; }); @@ -89,6 +90,17 @@ let TreeStyleTabUtils = { }, get tabbrowserBundle () { return stringBundle.get('chrome://browser/locale/tabbrowser.properties'); + }, + + evalInSandbox : function utils_evalInSandbox(aCode, aOwner) + { + try { + var sandbox = new Cu.Sandbox(aOwner || 'about:blank'); + return Cu.evalInSandbox(aCode, sandbox); + } + catch(e) { + } + return void(0); } };