[Pkg-mozext-commits] [greasemonkey] 33/41: GM_openInTab: Background/position features.
David Prévot
taffit at moszumanska.debian.org
Thu Apr 30 22:06:36 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository greasemonkey.
commit 8b2ccf0dc710cbfc062e31696be7aa5231f3662e
Author: Anthony Lieuallen <arantius at gmail.com>
Date: Tue Apr 28 12:13:23 2015 -0400
GM_openInTab: Background/position features.
Mostly restore details broken in 3.0. Set fore/back ground appropriately, and position related to the _script_ (not current) tab, consistently.
Fixes #2105
---
content/browser.js | 26 ++++++++++++++++++--------
content/framescript.js | 14 ++++++++++----
modules/miscapis.js | 12 ------------
modules/sandbox.js | 3 +--
4 files changed, 29 insertions(+), 26 deletions(-)
diff --git a/content/browser.js b/content/browser.js
index 996fb51..6fc341e 100644
--- a/content/browser.js
+++ b/content/browser.js
@@ -1,3 +1,4 @@
+Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import('resource://greasemonkey/prefmanager.js');
Components.utils.import('resource://greasemonkey/util.js');
@@ -67,14 +68,23 @@ GM_BrowserUI.openTab = function(url) {
GM_BrowserUI.openInTab = function(aMessage) {
var browser = aMessage.target;
var tabBrowser = browser.getTabBrowser();
-
- var newTab = tabBrowser.loadOneTab(aMessage.data.url, {
- 'inBackground': aMessage.data.inBackground,
- 'relatedToCurrent': true
- });
-
- // TODO: obviously can't return a window here...
- return /* tabBrowser.getBrowserForTab(newTab).contentWindow */ null;
+ var scriptTab = tabBrowser.getTabForBrowser(browser);
+ var scriptTabIsCurrentTab = scriptTab == tabBrowser.mCurrentTab;
+ var newTab = tabBrowser.addTab(
+ aMessage.data.url,
+ {
+ 'ownerTab': scriptTab,
+ 'relatedToCurrent': scriptTabIsCurrentTab,
+ });
+
+ var getBool = Services.prefs.getBoolPref;
+
+ var prefBg = getBool('browser.tabs.loadInBackground');
+ prefBg |= aMessage.data.inBackground;
+ if (scriptTabIsCurrentTab && !prefBg) tabBrowser.selectedTab = newTab;
+
+ var prefRel = getBool('browser.tabs.insertRelatedAfterCurrent');
+ if (prefRel) tabBrowser.moveTabTo(newTab, scriptTab._tPos + 1);
};
/**
diff --git a/content/framescript.js b/content/framescript.js
index 0fb8213..24addd7 100644
--- a/content/framescript.js
+++ b/content/framescript.js
@@ -60,11 +60,17 @@ ScriptRunner.prototype.injectScripts = function(aScripts) {
};
ScriptRunner.prototype.openInTab = function(aUrl, aInBackground) {
- var response = sendSyncMessage('greasemonkey:open-in-tab', {
- inBackground: aInBackground,
- url: aUrl
+ var loadInBackground = ('undefined' == typeof aInBackground)
+ ? null : !!aInBackground;
+
+ // Resolve URL relative to the location of the content window.
+ var baseUri = Services.io.newURI(this.window.location.href, null, null);
+ var uri = Services.io.newURI(aUrl, null, baseUri);
+
+ sendAsyncMessage('greasemonkey:open-in-tab', {
+ inBackground: loadInBackground,
+ url: uri.spec,
});
- return response ? response[0] : null;
};
diff --git a/modules/miscapis.js b/modules/miscapis.js
index c5a92d9..011cda7 100644
--- a/modules/miscapis.js
+++ b/modules/miscapis.js
@@ -105,15 +105,3 @@ function GM_console(script) {
GM_console.prototype.log = function() {
};
-
-// \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ //
-
-function GM_openInTab(aScriptRunner, aUrl, aLoadInBackground) {
- if ('undefined' == typeof aLoadInBackground) aLoadInBackground = null;
-
- // Resolve URL relative to the location of the content window.
- var baseUri = Services.io.newURI(aScriptRunner.window.location.href, null, null);
- var uri = Services.io.newURI(aUrl, null, baseUri);
-
- return aScriptRunner.openInTab(uri.spec, !!aLoadInBackground);
-};
diff --git a/modules/sandbox.js b/modules/sandbox.js
index 274aa1d..99e1e14 100644
--- a/modules/sandbox.js
+++ b/modules/sandbox.js
@@ -120,8 +120,7 @@ function createSandbox(aScript, aScriptRunner) {
}
if (GM_util.inArray(aScript.grants, 'GM_openInTab')) {
- sandbox.GM_openInTab = GM_util.hitch(
- null, GM_openInTab, aScriptRunner);
+ sandbox.GM_openInTab = GM_util.hitch(aScriptRunner, 'openInTab');
}
if (GM_util.inArray(aScript.grants, 'GM_xmlhttpRequest')) {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/greasemonkey.git
More information about the Pkg-mozext-commits
mailing list