Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
this fixes #1013, #1062 (draft)
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Mar 27, 2015
1 parent 5f8fd22 commit f2ff0ed
Show file tree
Hide file tree
Showing 18 changed files with 496 additions and 124 deletions.
46 changes: 42 additions & 4 deletions platform/chromium/vapi-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ vAPI.app.restart = function() {

/******************************************************************************/

// chrome.storage.local.get(null, function(bin){ console.debug('%o', bin); });

vAPI.storage = chrome.storage.local;

/******************************************************************************/
Expand All @@ -74,6 +76,7 @@ vAPI.noTabId = '-1';
vAPI.tabs.registerListeners = function() {
var onNavigationClient = this.onNavigation || noopFunc;
var onPopupClient = this.onPopup || noopFunc;
var onUpdatedClient = this.onUpdated || noopFunc;

// https://developer.chrome.com/extensions/webNavigation
// [onCreatedNavigationTarget ->]
Expand Down Expand Up @@ -160,6 +163,13 @@ vAPI.tabs.registerListeners = function() {
popupCandidateTest(details);
};

var onUpdated = function(tabId, changeInfo, tab) {
if ( changeInfo.url && popupCandidateTest({ tabId: tabId, url: changeInfo.url }) ) {
return;
}
onUpdatedClient(tabId, changeInfo, tab);
};

var onCommitted = function(details) {
if ( details.frameId !== 0 ) {
return;
Expand All @@ -175,10 +185,7 @@ vAPI.tabs.registerListeners = function() {
chrome.webNavigation.onCreatedNavigationTarget.addListener(onCreatedNavigationTarget);
chrome.webNavigation.onBeforeNavigate.addListener(onBeforeNavigate);
chrome.webNavigation.onCommitted.addListener(onCommitted);

if ( typeof this.onUpdated === 'function' ) {
chrome.tabs.onUpdated.addListener(this.onUpdated);
}
chrome.tabs.onUpdated.addListener(onUpdated);

if ( typeof this.onClosed === 'function' ) {
chrome.tabs.onRemoved.addListener(this.onClosed);
Expand Down Expand Up @@ -308,6 +315,37 @@ vAPI.tabs.open = function(details) {

/******************************************************************************/

// Replace the URL of a tab. Noop if the tab does not exist.

vAPI.tabs.replace = function(tabId, url) {
var targetURL = url;
if ( typeof targetURL !== 'string' || targetURL === '' ) {
return;
}

// extension pages
if ( /^[\w-]{2,}:/.test(targetURL) !== true ) {
targetURL = vAPI.getURL(targetURL);
}

if ( typeof tabId !== 'number' ) {
tabId = parseInt(tabId, 10);
if ( isNaN(tabId) ) {
return;
}
}

chrome.tabs.update(tabId, { url: targetURL }, function() {
// this prevent console error
if ( chrome.runtime.lastError ) {
return;
}

});
};

/******************************************************************************/

vAPI.tabs.remove = function(tabId) {
var onTabRemoved = function() {
if ( vAPI.lastError() ) {
Expand Down
31 changes: 22 additions & 9 deletions platform/firefox/vapi-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,24 @@ vAPI.tabs.open = function(details) {

/******************************************************************************/

// Replace the URL of a tab. Noop if the tab does not exist.

vAPI.tabs.replace = function(tabId, url) {
var targetURL = url;

// extension pages
if ( /^[\w-]{2,}:/.test(targetURL) !== true ) {
targetURL = vAPI.getURL(targetURL);
}

var tab = this.getTabsForIds(tabId);
if ( tab ) {
getBrowserForTab(tab).loadURI(targetURL);
}
};

/******************************************************************************/

vAPI.tabs._remove = function(tab, tabBrowser) {
if ( vAPI.fennec ) {
tabBrowser.closeTab(tab);
Expand Down Expand Up @@ -1138,18 +1156,13 @@ var httpObserver = {
return true;
}

if ( result.redirectUrl ) {
if ( type === 'main_frame' ) {
channel.cancel(this.ABORT);
vAPI.tabs.open({ tabId: details.tabId, url: result.redirectUrl });
return true;
}
/*channel.redirectionLimit = 1;
/*if ( result.redirectUrl ) {
channel.redirectionLimit = 1;
channel.redirectTo(
Services.io.newURI(result.redirectUrl, null, null)
);
return true;*/
}
return true;
}*/

return false;
},
Expand Down
84 changes: 6 additions & 78 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,85 +75,13 @@
"message":"Go to request log",
"description":"English: Go to request log"
},
"popupSiteInlineScriptEnabled":{
"message":"Inline <code>script<\/code> tags are <b>allowed<\/b> on this site",
"description":""
},
"popupSiteInlineScriptDisabled":{
"message":"Inline <code>script<\/code> tags are <b>blocked<\/b> on this site",
"description":""
},
"popupSite1pScriptEnabled":{
"message":"1st-party scripts are <b>allowed<\/b> on this site",
"description":""
},
"popupSite1pScriptDisabled":{
"message":"1st-party scripts are <b>blocked<\/b> on this site",
"description":""
},
"popupSite3pScriptEnabled":{
"message":"3rd-party scripts are <b>allowed<\/b> on this site",
"description":""
},
"popupSite3pScriptDisabled":{
"message":"3rd-party scripts are <b>blocked<\/b> on this site",
"description":""
},
"popupSite1pFrameEnabled":{
"message":"1st-party frames are <b>allowed<\/b> on this site",
"description":""
},
"popupSite1pFrameDisabled":{
"message":"1st-party frames are <b>blocked<\/b> on this site",
"description":""
},
"popupSite3pFrameEnabled":{
"message":"3rd-party frames are <b>allowed<\/b> on this site",
"description":""
},
"popupSite3pFrameDisabled":{
"message":"3rd-party frames are <b>blocked<\/b> on this site",
"description":""
"popupTipDoBlockAllPopups":{
"message":"Block all popups for this site",
"description":"English: Block all popups for this site"
},
"popupDefaultInlineScriptEnabled":{
"message":"Inline <code>script</code> tags are <b>allowed<\/b> everywhere by default",
"description":""
},
"popupDefaultInlineScriptDisabled":{
"message":"Inline <code>script</code> tags are <b>blocked<\/b> everywhere by default",
"description":""
},
"popupDefault1pScriptEnabled":{
"message":"1st-party scripts are <b>allowed<\/b> everywhere by default",
"description":""
},
"popupDefault1pScriptDisabled":{
"message":"1st-party scripts are <b>blocked<\/b> everywhere by default",
"description":""
},
"popupDefault3pScriptEnabled":{
"message":"3rd-party scripts are <b>allowed<\/b> everywhere by default",
"description":""
},
"popupDefault3pScriptDisabled":{
"message":"3rd-party scripts are <b>blocked<\/b> everywhere by default",
"description":""
},
"popupDefault1pFrameEnabled":{
"message":"1st-party frames are <b>allowed<\/b> everywhere by default",
"description":""
},
"popupDefault1pFrameDisabled":{
"message":"1st-party frames are <b>blocked<\/b> everywhere by default",
"description":""
},
"popupDefault3pFrameEnabled":{
"message":"3rd-party frames are <b>allowed<\/b> everywhere by default",
"description":""
},
"popupDefault3pFrameDisabled":{
"message":"3rd-party frames are <b>blocked<\/b> everywhere by default",
"description":""
"popupTipDontBlockDoc":{
"message":"Disable strict blocking for this site",
"description":"English: Disable strict blocking for this site"
},
"popupAnyRulePrompt":{
"message":"all",
Expand Down
1 change: 1 addition & 0 deletions src/background.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<script src="js/dynamic-net-filtering.js"></script>
<script src="js/static-net-filtering.js"></script>
<script src="js/cosmetic-filtering.js"></script>
<script src="js/hnswitches.js"></script>
<script src="js/ublock.js"></script>
<script src="js/messaging.js"></script>
<script src="js/profiler.js"></script>
Expand Down
11 changes: 10 additions & 1 deletion src/css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ body:not(.advancedUser) [data-tip]:after {
box-shadow: 1px 1px 3px gray;
color: black;
content: attr(data-tip);
display: none;
font: 12px sans-serif;
left: 0;
line-height: 130%;
Expand All @@ -38,7 +39,8 @@ body:not(.advancedUser) [data-tip]:after {
pointer-events: none;
opacity: 0;
}
[data-tip]:hover:after {
body [data-tip]:hover:after {
display: initial;
opacity: 1 !important;
-webkit-transition: opacity 0.2s 0.4s;
transition: opacity 0.2s 0.4s;
Expand All @@ -60,6 +62,13 @@ body[dir=rtl] [data-tip][data-tip-anchor="top"]:hover:after {
right: -500%;
}

body [data-tip][data-tip-anchor="topcenter"]:hover:after {
bottom: 140%;
left: -225%;
right: -225%;
top: auto;
}

.hiddenFileInput {
visibility: hidden;
width: 0;
Expand Down
29 changes: 28 additions & 1 deletion src/css/popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ body[dir="rtl"] #panes > div:nth-of-type(2) {
}
#panes > div:nth-of-type(1) {
min-width: 150px;
padding: 4px 1px;
padding: 0;
}
p {
text-align: center;
Expand Down Expand Up @@ -131,6 +131,33 @@ body.off #switch .fa {
.tool:hover {
color: #444;
}
#extraTools {
background-color: #eee;
border: 0;
color: #aaa;
font-weight: normal;
margin: 1em 0 0 0;
padding: 4px 0 2px 0;
text-align: center;
}
#extraTools > span {
cursor: pointer;
font-size: 18px;
margin: 0 0.5em;
position: relative;
}
#extraTools > span.on > span {
color: #e00;
font-size: 20px;
left: 0;
position: absolute;
text-align: center;
top: 0;
width: 100%;
}
#extraTools > span.on > span:after {
content: '\2715';
}

body.advancedUser h2 {
cursor: pointer;
Expand Down
18 changes: 10 additions & 8 deletions src/document-blocked.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<title></title>
<link rel="stylesheet" href="css/common.css" type="text/css">
<style>
body {
font-family: sans-serif;
Expand Down Expand Up @@ -33,21 +34,22 @@
padding: 0.25em 0.5em;
font-size: inherit;
}
img {
height: 60vh;
left: 10vw;
opacity: 0.05;
#warningSign {
margin: 1e, 0;
opacity: 1;
pointer-events: none;
position: fixed;
bottom: 5vh;
width: 80vw;
width: 100%;
}
#warningSign > span {
color: #f2a500;
font-size: 180px;
}
</style>
</head>
<body>
<!-- http://commons.wikimedia.org/wiki/File:Caution_sign_used_on_roads_pn.svg
Public domain. I removed the shadow.
--><img src="img/Caution_sign_used_on_roads_pn.svg" />
--><div id="warningSign"><span class="fa">&#xf071;</span></div>
<div>
<p data-i18n="docblockedPrompt1"></p>
<p class="what code"></p>
Expand Down
3 changes: 1 addition & 2 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ return {
autoUpdate: true,
collapseBlocked: true,
contextMenuEnabled: true,
dynamicFilteringString: '',
dynamicFilteringEnabled: false,
experimentalEnabled: false,
externalLists: defaultExternalLists,
Expand Down Expand Up @@ -88,7 +87,7 @@ return {

// read-only
systemSettings: {
compiledMagic: 'squafjaywuba',
compiledMagic: 'perhodsoahya',
selfieMagic: 'spqmeuaftfra'
},

Expand Down
Loading

0 comments on commit f2ff0ed

Please sign in to comment.