diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index de3686e..ea37bf7 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -572,6 +572,22 @@ "description": "Message asking user to confirm reset" }, + "mainBlockedPrompt1": { + "message": "uMatrix has prevented the following page from loading:", + "description": "English: uMatrix has prevented the following page from loading:" + }, + "mainBlockedPrompt2": { + "message": "Because of the following rule", + "description": "English: Because of the following rule" + }, + "mainBlockedBack" : { + "message": "Go back", + "description": "English: Go back" + }, + "mainBlockedClose" : { + "message": "Close", + "description": "English: Close" + }, "commandRevertAll" : { "message": "Remove all temporary changes", diff --git a/src/css/noop.css b/src/css/noop.css deleted file mode 100644 index e69de29..0000000 diff --git a/src/js/background.js b/src/js/background.js index fba362f..0d8cb5e 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -123,8 +123,6 @@ return { behindTheSceneScope: 'behind-the-scene', // Commonly encountered strings - chromeExtensionURLPrefix: 'chrome-extension://', - noopCSSURL: vAPI.getURL('css/noop.css'), fontCSSURL: vAPI.getURL('css/fonts/Roboto_Condensed/RobotoCondensed-Regular.ttf'), noopFunc: function(){}, diff --git a/src/js/main-blocked.js b/src/js/main-blocked.js new file mode 100644 index 0000000..eed66bf --- /dev/null +++ b/src/js/main-blocked.js @@ -0,0 +1,76 @@ +/******************************************************************************* + + µMatrix - a browser extension to block requests. + Copyright (C) 2015 Raymond Hill + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see {http://www.gnu.org/licenses/}. + + Home: https://github.com/gorhill/uBlock +*/ + +/* global uDom */ + +/******************************************************************************/ + +(function() { + +'use strict'; + +/******************************************************************************/ + +var details = {}; + +(function() { + var matches = /details=([^&]+)/.exec(window.location.search); + if ( matches === null ) { + return; + } + details = JSON.parse(atob(matches[1])); +})(); + +/******************************************************************************/ + +uDom('.what').text(details.url); +uDom('#why').text(details.why.slice(3)); + +if ( window.history.length > 1 ) { + uDom('#back').on('click', function() { window.history.back(); }); + uDom('#bye').css('display', 'none'); +} else { + uDom('#bye').on('click', function() { window.close(); }); + uDom('#back').css('display', 'none'); +} + +/******************************************************************************/ + +// See if the target hostname is still blacklisted, and if not, navigate to it. + +var messager = vAPI.messaging.channel('main-blocked.js'); + +messager.send({ + what: 'mustBlock', + scope: details.hn, + hostname: details.hn, + type: 'doc' +}, function(response) { + if ( response === false ) { + window.location.replace(details.url); + } +}); + +/******************************************************************************/ + +})(); + +/******************************************************************************/ diff --git a/src/js/messaging.js b/src/js/messaging.js index e59a6c1..205fe26 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -71,6 +71,14 @@ function onMessage(request, sender, callback) { µm.utils.gotoURL(request); break; + case 'mustBlock': + response = µm.mustBlock( + request.scope, + request.hostname, + request.type + ); + break; + case 'reloadHostsFiles': µm.reloadHostsFiles(); break; @@ -168,7 +176,7 @@ var matrixSnapshot = function(tabId, details) { // Allow examination of behind-the-scene requests if ( - tabContext.rawURL.lastIndexOf(vAPI.getURL(''), 0) === 0 || + tabContext.rawURL.lastIndexOf(vAPI.getURL('dashboard.html'), 0) === 0 || tabContext.rawURL === µm.behindTheSceneURL ) { tabId = µm.behindTheSceneTabId; diff --git a/src/js/tab.js b/src/js/tab.js index ac88ac5..ce0dbc0 100644 --- a/src/js/tab.js +++ b/src/js/tab.js @@ -49,6 +49,20 @@ var µm = µMatrix; if ( vAPI.isBehindTheSceneTabId(tabId) ) { return 'http://behind-the-scene/'; } + + // If the URL is that of our "blocked page" document, return the URL of + // the blocked page. + if ( pageURL.lastIndexOf(vAPI.getURL('main-blocked.html'), 0) === 0 ) { + var matches = /main-blocked\.html\?details=([^&]+)/.exec(pageURL); + if ( matches && matches.length === 2 ) { + try { + var details = JSON.parse(atob(matches[1])); + pageURL = details.url; + } catch (e) { + } + } + } + var uri = this.URI.set(pageURL); var scheme = uri.scheme; if ( scheme === 'https' || scheme === 'http' ) { @@ -453,13 +467,6 @@ vAPI.tabs.registerListeners(); return this.pageStores[tabId]; } - // https://github.com/gorhill/httpswitchboard/issues/303 - // Don't rebind pages blocked by µMatrix. - var blockedRootFramePrefix = this.webRequest.blockedRootFramePrefix; - if ( tabContext.rawURL.lastIndexOf(blockedRootFramePrefix, 0) === 0 ) { - return null; - } - var normalURL = tabContext.normalURL; var pageStore = this.pageStores[tabId] || null; diff --git a/src/js/traffic.js b/src/js/traffic.js index 9b99130..c0dd4f8 100644 --- a/src/js/traffic.js +++ b/src/js/traffic.js @@ -33,65 +33,6 @@ // The `id='uMatrix'` is important, it allows µMatrix to detect whether a // specific data URI originates from itself. -var rootFrameReplacement = [ - '', - '
', - '', - '', - '', - '+
+