From 94067b8bf87e8576ea5535a83658c6a948df22ee Mon Sep 17 00:00:00 2001 From: saneyuki_s Date: Fri, 4 Jan 2013 12:32:05 +0900 Subject: [PATCH 1/8] Add the constant to cache 'Components.utils' to modules/utils.js. --- modules/utils.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/utils.js b/modules/utils.js index 446b9ce4..95a2b9ce 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; }); From 665cb5668f67bd7aacd85f1d715788d2de6276c3 Mon Sep 17 00:00:00 2001 From: saneyuki_s Date: Fri, 4 Jan 2013 12:39:58 +0900 Subject: [PATCH 2/8] Move TreeStyleTabBase.evalInSandbox() to TreeStyleTabUtils. --- modules/base.js | 13 +------------ modules/browser.js | 2 +- modules/utils.js | 11 +++++++++++ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/modules/base.js b/modules/base.js index 3a995419..937c5f56 100644 --- a/modules/base.js +++ b/modules/base.js @@ -616,18 +616,7 @@ var TreeStyleTabBase = { { 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/utils.js b/modules/utils.js index 95a2b9ce..7546eb70 100644 --- a/modules/utils.js +++ b/modules/utils.js @@ -90,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); } }; From 9921ea22466f3b676e4fe9fbe55e068f92ff0070 Mon Sep 17 00:00:00 2001 From: saneyuki_s Date: Fri, 4 Jan 2013 12:43:32 +0900 Subject: [PATCH 3/8] Remove TreeStyleTabBase.getBoxObjectFor(). At this time, this method is not used in this addon. --- modules/base.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/modules/base.js b/modules/base.js index 937c5f56..8f8186bb 100644 --- a/modules/base.js +++ b/modules/base.js @@ -611,11 +611,6 @@ var TreeStyleTabBase = { }, /* utilities */ - - getBoxObjectFor : function utils_getBoxObjectFor(aNode) - { - return boxObject.getBoxObjectFor(aNode); - }, get browserWindow() { From efd07b5e7e6ef2842cc66fbbb5759f29c9f12334 Mon Sep 17 00:00:00 2001 From: saneyuki_s Date: Fri, 4 Jan 2013 12:46:28 +0900 Subject: [PATCH 4/8] Remove modules/lib/boxObject,js. At this time, this module is not used in this addon. --- modules/base.js | 4 - modules/lib/boxObject.js | 180 --------------------------------------- 2 files changed, 184 deletions(-) delete mode 100644 modules/lib/boxObject.js diff --git a/modules/base.js b/modules/base.js index 8f8186bb..a9d90c33 100644 --- a/modules/base.js +++ b/modules/base.js @@ -51,10 +51,6 @@ XPCOMUtils.defineLazyGetter(this, 'jstimer', function() { 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; 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; -} From 94d46878fa09f0157d2c5df25d91822080087b9d Mon Sep 17 00:00:00 2001 From: saneyuki_s Date: Fri, 4 Jan 2013 12:59:45 +0900 Subject: [PATCH 5/8] Add the simple getter 'TreeStyleTabBase.AeroPeek' & Remove TreeStyleTabBase.updateAeroPeek(). --- modules/base.js | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/modules/base.js b/modules/base.js index a9d90c33..5c07fc6f 100644 --- a/modules/base.js +++ b/modules/base.js @@ -68,6 +68,11 @@ XPCOMUtils.defineLazyModuleGetter(this, 'UninstallationListener', 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, @@ -286,7 +291,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; @@ -317,14 +323,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(); } @@ -507,13 +505,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 From 6361cd71a167641532a88ff1521f79a9973f521b Mon Sep 17 00:00:00 2001 From: saneyuki_s Date: Fri, 4 Jan 2013 13:04:02 +0900 Subject: [PATCH 6/8] Simple loading Services.jsm. --- modules/base.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/base.js b/modules/base.js index 5c07fc6f..e3401f75 100644 --- a/modules/base.js +++ b/modules/base.js @@ -37,9 +37,9 @@ 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'); From ce9bd03e3c2e258714517af7e22dc0f0b0d303f1 Mon Sep 17 00:00:00 2001 From: saneyuki_s Date: Fri, 4 Jan 2013 13:06:20 +0900 Subject: [PATCH 7/8] Load namespace.jsm & pref.js as lazy getter. --- modules/base.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/base.js b/modules/base.js index e3401f75..3be99a2a 100644 --- a/modules/base.js +++ b/modules/base.js @@ -41,11 +41,15 @@ const Ci = Components.interfaces; Components.utils.import('resource://gre/modules/XPCOMUtils.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); From e06bbe785d0c772b4b95210fba82829cf027aab4 Mon Sep 17 00:00:00 2001 From: saneyuki_s Date: Fri, 4 Jan 2013 13:07:32 +0900 Subject: [PATCH 8/8] Change the loading point of jsdeferred.js. --- modules/base.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/base.js b/modules/base.js index 3be99a2a..46cc235a 100644 --- a/modules/base.js +++ b/modules/base.js @@ -41,7 +41,6 @@ const Ci = Components.interfaces; Components.utils.import('resource://gre/modules/XPCOMUtils.jsm'); Components.utils.import('resource://gre/modules/Services.jsm'); -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'); @@ -69,6 +68,8 @@ 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');