1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-25 03:43:25 +01:00

Safari: slightly better pop-up blocking

This commit is contained in:
Deathamns 2014-12-01 20:45:00 +01:00
parent d93d70b4ae
commit 2a26448734
7 changed files with 48 additions and 67 deletions

1
.gitignore vendored
View File

@ -1,4 +1,3 @@
*.bak
*.pem
/meta/safariextz/certs/
/dist/build/

View File

@ -13,7 +13,7 @@
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleShortVersionString</key>
<string>0.7.0.11</string>
<string>0.7.2.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>Chrome</key>

View File

@ -36,6 +36,13 @@ vAPI.safari = true;
/******************************************************************************/
vAPI.app = {
name: 'µBlock',
version: '0.7.2.0'
};
/******************************************************************************/
// addContentScriptFromURL allows whitelisting,
// so load sitepaching this way, instead of adding it to the Info.plist
@ -568,10 +575,32 @@ vAPI.messaging.broadcast = function(message) {
/******************************************************************************/
vAPI.net = {}
safari.application.addEventListener('beforeNavigate', function(e) {
if (!vAPI.tabs.expectPopUpFrom || e.url === 'about:blank') {
return;
}
var details = {
url: e.url,
tabId: vAPI.tabs.getTabId(e.target),
sourceTabId: vAPI.tabs.expectPopUpFrom
};
vAPI.tabs.expectPopUpFrom = null;
if (vAPI.tabs.onPopup(details)) {
e.preventDefault();
if (vAPI.tabs.stack[details.sourceTabId]) {
vAPI.tabs.stack[details.sourceTabId].activate();
}
}
}, true);
/******************************************************************************/
vAPI.net = {}
vAPI.net.registerListeners = function() {
var onBeforeRequest = this.onBeforeRequest;
@ -611,17 +640,17 @@ vAPI.net.registerListeners = function() {
}
// blocking unwanted pop-ups
else if (e.message.type === 'popup') {
if (typeof vAPI.tabs.onPopup === 'function') {
e.message.type = 'main_frame';
e.message.sourceTabId = vAPI.tabs.getTabId(e.target);
if (vAPI.tabs.onPopup(e.message)) {
e.message = false;
return;
}
if (e.message.url === 'about:blank') {
vAPI.tabs.expectPopUpFrom = vAPI.tabs.getTabId(e.target);
e.message = true;
return;
}
e.message = true;
e.message = !vAPI.tabs.onPopup({
url: e.message.url,
tabId: 0,
sourceTabId: vAPI.tabs.getTabId(e.target)
});
return;
}
@ -637,7 +666,7 @@ vAPI.net.registerListeners = function() {
// truthy return value will allow the request,
// except when redirectUrl is present
if (block && typeof block === 'object') {
if (block.cancel) {
if (block.cancel === true) {
e.message = false;
}
else if (e.message.type === 'script'

View File

@ -220,7 +220,7 @@ var onBeforeLoad = function(e, details) {
linkHelper.href = details ? details.url : e.url;
if (!/^https?:/.test(linkHelper.protocol)) {
if (!(/^https?:/.test(linkHelper.protocol) || (details && details.type === 'popup'))) {
return;
}

View File

@ -1,43 +0,0 @@
/*******************************************************************************
µBlock - a Chromium browser extension to block requests.
Copyright (C) 2014 The µBlock authors
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
*/
// Can be included anywhere if it's needed
/* global self */
/******************************************************************************/
(function(){
'use strict';
/******************************************************************************/
self.vAPI = self.vAPI || {};
self.vAPI.app = {
name: 'µBlock',
version: '0.7.2.0'
};
/******************************************************************************/
})();

View File

@ -80,15 +80,12 @@ vAPI.tabs.onPopup = function(details) {
// Blocked
// Safari blocks before the pop-up opens, so there is no window to remove.
// TODO: Can't this test be done within the platform-specific code?
if ( vAPI.safari ) {
return true;
}
// It is a popup, block and remove the tab.
µBlock.unbindTabFromPageStats(details.tabId);
vAPI.tabs.remove(details.tabId);
// for Safari
return true;
};
vAPI.tabs.registerListeners();

View File

@ -15,8 +15,7 @@ cp -R src/lib $DES/
cp -R src/_locales $DES/
cp src/*.html $DES/
cp src/img/icon_128.png $DES/Icon.png
cp platform/vapi-appinfo.js $DES/js/
cp platform/safariextz/*.js $DES/js/
cp platform/safariextz/Info.plist $DES/
cp platform/safariextz/Settings.plist $DES/
cp platform/safari/*.js $DES/js/
cp platform/safari/Info.plist $DES/
cp platform/safari/Settings.plist $DES/
echo "*** uBlock.safariextension: Package done."