aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDeathamns <deathamns@gmail.com>2015-01-15 13:24:35 +0100
committerDeathamns <deathamns@gmail.com>2015-01-15 13:24:35 +0100
commit089af13e32ca7ee05ab8d82dfecc94431f565a75 (patch)
treecf51131f972aeb1e233ecf23e90391e053db06bb
parent3930be428d670a3b5d462a31e9bf561159335062 (diff)
downloaduBlock-089af13e32ca7ee05ab8d82dfecc94431f565a75.zip
uBlock-089af13e32ca7ee05ab8d82dfecc94431f565a75.tar.gz
uBlock-089af13e32ca7ee05ab8d82dfecc94431f565a75.tar.bz2
URL handling changes
-rw-r--r--platform/chromium/vapi-client.js6
-rw-r--r--platform/firefox/bootstrap.js3
-rw-r--r--platform/firefox/frameModule.js12
-rw-r--r--platform/firefox/vapi-background.js70
-rw-r--r--platform/firefox/vapi-client.js13
-rw-r--r--platform/safari/vapi-client.js6
-rw-r--r--src/js/element-picker.js2
7 files changed, 71 insertions, 41 deletions
diff --git a/platform/chromium/vapi-client.js b/platform/chromium/vapi-client.js
index 9fd6a6e..7872e79 100644
--- a/platform/chromium/vapi-client.js
+++ b/platform/chromium/vapi-client.js
@@ -156,6 +156,12 @@ vAPI.canExecuteContentScript = function() {
/******************************************************************************/
+vAPI.getUrlNormalizer = function() {
+ return document.createElement('a');
+};
+
+/******************************************************************************/
+
})();
/******************************************************************************/ \ No newline at end of file
diff --git a/platform/firefox/bootstrap.js b/platform/firefox/bootstrap.js
index 252ea62..94c59b8 100644
--- a/platform/firefox/bootstrap.js
+++ b/platform/firefox/bootstrap.js
@@ -26,6 +26,9 @@
/******************************************************************************/
+// Accessing the context of the background page from Console (e.g., about:addons):
+// var win = Services.appShell.hiddenDOMWindow.document.querySelector('iframe[src*=ublock]').contentWindow;
+
let bgProcess;
const hostName = 'ublock';
const restartListener = {
diff --git a/platform/firefox/frameModule.js b/platform/firefox/frameModule.js
index ae469a0..6f12f18 100644
--- a/platform/firefox/frameModule.js
+++ b/platform/firefox/frameModule.js
@@ -119,7 +119,7 @@ const contentObserver = {
let openerURL;
- if ( location.scheme !== 'http' && location.scheme !== 'https' ) {
+ if ( !location.schemeIs('http') && !location.schemeIs('https') ) {
if ( type !== this.MAIN_FRAME ) {
return this.ACCEPT;
}
@@ -132,7 +132,7 @@ const contentObserver = {
let isPopup = location.spec === 'about:blank' && openerURL;
- if ( location.scheme !== 'data' && !isPopup ) {
+ if ( !location.schemeIs('data') && !isPopup ) {
return this.ACCEPT;
}
} else if ( type === this.MAIN_FRAME ) {
@@ -145,8 +145,8 @@ const contentObserver = {
context = (context.ownerDocument || context).defaultView;
}
- // The context for the popups is an iframe element here,
- // so check context.top instead
+ // The context for the toolbar popup is an iframe element here,
+ // so check context.top instead of context
if ( context.top && context.location ) {
// https://bugzil.la/1092216
getMessageManager(context).sendRpcMessage(this.cpMessageName, {
@@ -192,6 +192,10 @@ const contentObserver = {
}
sandbox._sandboxId_ = sandboxId;
+ sandbox._urlNormalizer_ = function(url, baseURI) {
+ baseURI = Services.io.newURI(baseURI, null, null);
+ return Services.io.newURI(url, null, baseURI).asciiSpec;
+ };
sandbox.sendAsyncMessage = messager.sendAsyncMessage;
sandbox.addMessageListener = function(callback) {
if ( this._messageListener_ ) {
diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js
index 56f185c..2d60830 100644
--- a/platform/firefox/vapi-background.js
+++ b/platform/firefox/vapi-background.js
@@ -19,6 +19,8 @@
Home: https://github.com/gorhill/uBlock
*/
+/* global punycode */
+
// For background page
/******************************************************************************/
@@ -308,7 +310,7 @@ var tabsProgressListener = {
tabId: tabId,
url: browser.currentURI.asciiSpec
});
- } else if ( location.scheme === 'http' || location.scheme === 'https' ) {
+ } else if ( location.schemeIs('http') || location.schemeIs('https') ) {
vAPI.tabs.onNavigation({
frameId: 0,
tabId: tabId,
@@ -352,7 +354,7 @@ vAPI.tabs.registerListeners = function() {
for ( var tab of win.gBrowser.tabs ) {
var URI = tab.linkedBrowser.currentURI;
- if ( URI.scheme === 'chrome' && URI.host === location.host ) {
+ if ( URI.schemeIs('chrome') && URI.host === location.host ) {
win.gBrowser.removeTab(tab);
}
}
@@ -489,15 +491,14 @@ vAPI.tabs.open = function(details) {
var tab, tabs;
if ( details.select ) {
- var rgxHash = /#.*/;
- // this is questionable
- var url = details.url.replace(rgxHash, '');
+ var URI = Services.io.newURI(details.url, null, null);
tabs = this.getAll();
for ( tab of tabs ) {
var browser = tab.linkedBrowser;
- if ( browser.currentURI.asciiSpec.replace(rgxHash, '') === url ) {
+ // Or simply .equals if we care about the fragment
+ if ( URI.equalsExceptRef(browser.currentURI) ) {
browser.ownerDocument.defaultView.gBrowser.selectedTab = tab;
return;
}
@@ -857,7 +858,7 @@ var httpObserver = {
return false;
}
- if ( URI.scheme !== 'http' && URI.scheme !== 'https' ) {
+ if ( !URI.schemeIs('http') && !URI.schemeIs('https') ) {
return false;
}
@@ -978,8 +979,8 @@ var httpObserver = {
for ( var tab of vAPI.tabs.getAll() ) {
var tabURI = tab.linkedBrowser.currentURI;
- // Not the best approach
- if ( tabURI.asciiSpec === this.lastRequest.openerURL ) {
+ // Probably isn't the best method to identify the source tab
+ if ( tabURI.spec === this.lastRequest.openerURL ) {
sourceTabId = vAPI.tabs.getTabId(tab);
break;
}
@@ -1016,9 +1017,9 @@ var httpObserver = {
return;
}*/
- var scheme = newChannel.URI.scheme;
+ var URI = newChannel.URI;
- if ( scheme !== 'http' && scheme !== 'https' ) {
+ if ( !URI.schemeIs('http') && !URI.schemeIs('https') ) {
return;
}
@@ -1029,7 +1030,7 @@ var httpObserver = {
var channelData = oldChannel.getProperty(location.host + 'reqdata');
var [type, tabId, sourceTabId] = channelData;
- if ( this.handlePopup(newChannel.URI, tabId, sourceTabId) ) {
+ if ( this.handlePopup(URI, tabId, sourceTabId) ) {
result = this.ABORT;
return;
}
@@ -1324,8 +1325,9 @@ vAPI.contextMenu.displayMenuItem = function(e) {
}
var menuitem = doc.getElementById(vAPI.contextMenu.menuItemId);
+ var currentURI = gContextMenu.browser.currentURI;
- if ( /^https?$/.test(gContextMenu.browser.currentURI.scheme) === false) {
+ if ( !currentURI.schemeIs('http') && !currentURI.schemeIs('https') ) {
menuitem.hidden = true;
return;
}
@@ -1462,22 +1464,6 @@ vAPI.onLoadAllCompleted = function() {};
/******************************************************************************/
-// clean up when the extension is disabled
-
-window.addEventListener('unload', function() {
- for ( var cleanup of cleanupTasks ) {
- cleanup();
- }
-
- // frameModule needs to be cleared too
- var frameModule = {};
- Cu.import(vAPI.getURL('frameModule.js'), frameModule);
- frameModule.contentObserver.unregister();
- Cu.unload(vAPI.getURL('frameModule.js'));
-});
-
-/******************************************************************************/
-
// Likelihood is that we do not have to punycode: given punycode overhead,
// it's faster to check and skip than do it unconditionally all the time.
@@ -1488,19 +1474,31 @@ vAPI.punycodeHostname = function(hostname) {
return isNotASCII.test(hostname) ? punycodeHostname(hostname) : hostname;
};
-var cachedURL = self.URL;
-
vAPI.punycodeURL = function(url) {
- if ( isNotASCII.test(url) === false ) {
- return url;
+ if ( isNotASCII.test(url) ) {
+ return Services.io.newURI(url, null, null).asciiSpec;
}
- cachedURL.href = url;
- cachedURL.hostname = punycodeHostname(cachedURL.hostname);
- return urlNormalizer.href;
+ return url;
};
/******************************************************************************/
+// clean up when the extension is disabled
+
+window.addEventListener('unload', function() {
+ for ( var cleanup of cleanupTasks ) {
+ cleanup();
+ }
+
+ // frameModule needs to be cleared too
+ var frameModule = {};
+ Cu.import(vAPI.getURL('frameModule.js'), frameModule);
+ frameModule.contentObserver.unregister();
+ Cu.unload(vAPI.getURL('frameModule.js'));
+});
+
+/******************************************************************************/
+
})();
/******************************************************************************/
diff --git a/platform/firefox/vapi-client.js b/platform/firefox/vapi-client.js
index 4886bb6..42c2cdf 100644
--- a/platform/firefox/vapi-client.js
+++ b/platform/firefox/vapi-client.js
@@ -174,6 +174,19 @@ vAPI.canExecuteContentScript = function() {
/******************************************************************************/
+vAPI.getUrlNormalizer = function() {
+ return {
+ get href() {
+ return this._url || '';
+ },
+ set href(url) {
+ this._url = _urlNormalizer_(url, document.baseURI);
+ }
+ };
+};
+
+/******************************************************************************/
+
})(this);
/******************************************************************************/
diff --git a/platform/safari/vapi-client.js b/platform/safari/vapi-client.js
index 9adde80..7998bd0 100644
--- a/platform/safari/vapi-client.js
+++ b/platform/safari/vapi-client.js
@@ -182,6 +182,12 @@ vAPI.canExecuteContentScript = function() {
/******************************************************************************/
+vAPI.getUrlNormalizer = function() {
+ return document.createElement('a');
+};
+
+/******************************************************************************/
+
// This file can be included into extensin pages,
// but the following code should run only in content pages.
diff --git a/src/js/element-picker.js b/src/js/element-picker.js
index f43761b..6cd6669 100644
--- a/src/js/element-picker.js
+++ b/src/js/element-picker.js
@@ -896,7 +896,7 @@ var startPicker = function(details) {
divDialog.addEventListener('click', onDialogClicked);
taCandidate = divDialog.querySelector('textarea');
taCandidate.addEventListener('input', onCandidateChanged);
- urlNormalizer = document.createElement('a');
+ urlNormalizer = vAPI.getUrlNormalizer();
window.addEventListener('scroll', onScrolled, true);
window.addEventListener('keydown', onKeyPressed, true);