From 7b8392ca48414864ac34e4feed068fcc8539073c Mon Sep 17 00:00:00 2001 From: gorhill Date: Wed, 21 Jan 2015 11:13:32 -0500 Subject: [PATCH] more fixes for #105 --- platform/firefox/vapi-background.js | 18 ++++++++++++------ src/js/messaging.js | 11 +++++++++++ src/js/popup.js | 18 ++++-------------- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index 2d8d2f270..404f8a7ba 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -308,19 +308,23 @@ var tabsProgressListener = { var tabId = vAPI.tabs.getTabId(browser); + // LOCATION_CHANGE_SAME_DOCUMENT = "did not load a new document" if ( flags & 1 ) { vAPI.tabs.onUpdated(tabId, {url: location.asciiSpec}, { frameId: 0, tabId: tabId, url: browser.currentURI.asciiSpec }); - } else if ( location.schemeIs('http') || location.schemeIs('https') ) { - vAPI.tabs.onNavigation({ - frameId: 0, - tabId: tabId, - url: location.asciiSpec - }); + return; } + + // https://github.com/gorhill/uBlock/issues/105 + // Allow any kind of pages + vAPI.tabs.onNavigation({ + frameId: 0, + tabId: tabId, + url: location.asciiSpec + }); } }; @@ -1359,6 +1363,8 @@ vAPI.contextMenu.displayMenuItem = function(e) { var menuitem = doc.getElementById(vAPI.contextMenu.menuItemId); var currentURI = gContextMenu.browser.currentURI; + // https://github.com/gorhill/uBlock/issues/105 + // TODO: Should the element picker works on any kind of pages? if ( !currentURI.schemeIs('http') && !currentURI.schemeIs('https') ) { menuitem.hidden = true; return; diff --git a/src/js/messaging.js b/src/js/messaging.js index e5aff1d02..f4e3e4142 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -197,6 +197,8 @@ var getStats = function(tabId) { r.hostnameDict = getHostnameDict(pageStore.hostnameToCountMap); r.contentLastModified = pageStore.contentLastModified; r.dynamicFilterRules = getDynamicFilterRules(pageStore.pageHostname, r.hostnameDict); + r.canElementPicker = r.pageHostname.indexOf('.') !== -1; + r.canRequestLog = canRequestLog; } else { r.hostnameDict = {}; r.dynamicFilterRules = getDynamicFilterRules(); @@ -204,9 +206,15 @@ var getStats = function(tabId) { return r; }; +// Not the most elegant approach, but it does keep everything simple: +// This will be set by getTargetTabId() and used by getStats(). +var canRequestLog = true; + /******************************************************************************/ var getTargetTabId = function(tab) { + canRequestLog = true; + if ( !tab ) { return ''; } @@ -220,11 +228,14 @@ var getTargetTabId = function(tab) { // This allows a user to actually modify filtering profile for // behind-the-scene requests. + canRequestLog = false; + // Extract the target tab id from the URL var matches = tab.url.match(/[\?&]tabId=([^&]+)/); if ( matches && matches.length === 2 ) { return matches[1]; } + return tab.id; }; diff --git a/src/js/popup.js b/src/js/popup.js index a18b03c1e..04d9a3019 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -298,23 +298,13 @@ var buildAllDynamicFilters = function() { var renderPopup = function() { uDom('#appname').text(popupData.appName); uDom('#version').text(popupData.appVersion); - - var isHTTP = /^https?:\/\/[0-9a-z]/.test(popupData.pageURL); - - // Condition for dynamic filtering toggler: - // - Advanced user uDom('body').toggleClass('advancedUser', popupData.advancedUserEnabled); - uDom('#switch').toggleClass('off', popupData.pageURL === '' || !popupData.netFilteringSwitch); - // Conditions for request log: - // - `http` or `https` scheme - uDom('#gotoLog').toggleClass('enabled', isHTTP); - uDom('#gotoLog').attr('href', 'devtools.html?tabId=' + popupData.tabId); - - // Conditions for element picker: - // - `http` or `https` scheme - uDom('#gotoPick').toggleClass('enabled', isHTTP); + // If you think the `=== true` is pointless, you are mistaken + uDom('#gotoLog').toggleClass('enabled', popupData.canRequestLog === true) + .attr('href', 'devtools.html?tabId=' + popupData.tabId); + uDom('#gotoPick').toggleClass('enabled', popupData.canElementPicker === true); var or = vAPI.i18n('popupOr'); var blocked = popupData.pageBlockedRequestCount;