Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Firefox support #225

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
src/js/html2canvas.js
--
https://github.com/niklasvh/html2canvas
--

Copyright (c) 2012 Niklas von Hertzen

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

-------------------------------------------------------------

src/js/db.js
--
https://github.com/aaronpowell/db.js
--

The MIT License

Copyright (c) 2012 Aaron Powell

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

1 change: 1 addition & 0 deletions src/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>

<head>
<meta charset="utf-8"/>
<link type="text/css" href="css/style.css" rel="stylesheet">
<script type="text/javascript" src="js/about.js"></script>
<title data-i18n="__MSG_ext_extension_name__ - __MSG_html_about_title__"></title>
Expand Down
1 change: 1 addition & 0 deletions src/broken.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>

<head>
<meta charset="utf-8"/>
<link type="text/css" href="css/style.css" rel="stylesheet">
<script type="text/javascript" src="js/broken.js"></script>
<title data-i18n="__MSG_ext_extension_name__ __MSG_html_broken_title__"></title>
Expand Down
3 changes: 2 additions & 1 deletion src/debug.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>

<head>
<meta charset="utf-8"/>
<link type="text/css" href="css/style.css" rel="stylesheet">
<link type="text/css" href="css/debug.css" rel="stylesheet">
<script type="text/javascript" src="js/debug.js"></script>
Expand All @@ -20,7 +21,7 @@
</div>
<br />
<div>
<span>To view debug messages, go to the <a id="backgroundPage" target="_blank">chrome extensions page.</a></span>
<span>To view debug messages, go to the <span id="inspect-url" style="color:black; font-family: monospace; background-color: #d0d0d0"></span> </span>
<br />
<span>Ensure "developer mode" is checked at the top of the page, then click on the "Inspect views: background page" link for this extension.</span>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/history.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>

<head>
<meta charset="utf-8"/>
<link type='text/css' href='css/fontello.css' rel='stylesheet'>
<link type='text/css' href='css/style.css' rel='stylesheet' />
<script type='text/javascript' src='js/historyItems.js'></script>
Expand Down
94 changes: 51 additions & 43 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ var tgs = (function() {
const STATE_INITIALISE_SUSPENDED_TAB = 'initialiseSuspendedTab';
const STATE_UNLOADED_URL = 'unloadedUrl';
const STATE_HISTORY_URL_TO_REMOVE = 'historyUrlToRemove';
const STATE_SET_AUTODISCARDABLE = 'setAutodiscardable';
// const STATE_SET_AUTODISCARDABLE = 'setAutodiscardable';
const STATE_SUSPEND_REASON = 'suspendReason'; // 1=auto-suspend, 2=manual-suspend, 3=discarded
const STATE_SCROLL_POS = 'scrollPos';
const STATE_IS_UNSUSPENDING = 'currentlyUnsuspending';

const focusDelay = 500;

Expand Down Expand Up @@ -333,11 +334,11 @@ var tgs = (function() {
calculateTabStatus(tab, contentScriptStatus, function(newStatus) {
setIconStatus(newStatus, tab.id);
//This is a hotfix for issue #723
if (newStatus === 'tempWhitelist' && tab.autoDiscardable) {
chrome.tabs.update(tab.id, {
autoDiscardable: false,
});
}
// if (newStatus === 'tempWhitelist' && tab.autoDiscardable) {
// chrome.tabs.update(tab.id, {
// autoDiscardable: false,
// });
// }
if (callback) callback(newStatus);
});
});
Expand All @@ -360,12 +361,12 @@ var tgs = (function() {
calculateTabStatus(tab, contentScriptStatus, function(newStatus) {
setIconStatus(newStatus, tab.id);
//This is a hotfix for issue #723
if (newStatus !== 'tempWhitelist' && !tab.autoDiscardable) {
chrome.tabs.update(tab.id, {
//async
autoDiscardable: true,
});
}
// if (newStatus !== 'tempWhitelist' && !tab.autoDiscardable) {
// chrome.tabs.update(tab.id, {
// //async
// autoDiscardable: true,
// });
// }
if (callback) callback(newStatus);
});
});
Expand Down Expand Up @@ -613,15 +614,19 @@ var tgs = (function() {
// Reloading chrome.tabs.update causes a history item for the suspended tab
// to be made in the tab history. We clean this up on tab updated hook
setTabStatePropForTabId(tab.id, tgs.STATE_HISTORY_URL_TO_REMOVE, tab.url);
if (tab.autoDiscardable) {
setTabStatePropForTabId(tab.id, tgs.STATE_SET_AUTODISCARDABLE, tab.url);
}
// if (tab.autoDiscardable) {
// setTabStatePropForTabId(tab.id, tgs.STATE_SET_AUTODISCARDABLE, tab.url);
// }
// Handle conсurrency issue when checker trashes reloading tab
// Significant in Firefox as tabs goes to about:blank instead of originalUrl
setTabStatePropForTabId(tab.id, tgs.STATE_IS_UNSUSPENDING, true);
// NOTE: Temporarily disable autoDiscardable, as there seems to be a bug
// where discarded (and frozen?) suspended tabs will not unsuspend with
// chrome.tabs.update if this is set to true. This gets unset again after tab
// has reloaded via the STATE_SET_AUTODISCARDABLE flag.
gsUtils.log(tab.id, 'Unsuspending tab via chrome.tabs.update');
chrome.tabs.update(tab.id, { url: originalUrl, autoDiscardable: false });
// autoDiscardable is not supported in Firefox
chrome.tabs.update(tab.id, { url: originalUrl, loadReplace: true});
return;
}

Expand All @@ -645,9 +650,9 @@ var tgs = (function() {

function checkForTriggerUrls(tab, url) {
// test for a save of keyboard shortcuts (chrome://extensions/shortcuts)
if (url === 'chrome://extensions/shortcuts') {
_triggerHotkeyUpdate = true;
}
// if (url === 'chrome://extensions/shortcuts') {
// _triggerHotkeyUpdate = true;
// }
}

function handleUnsuspendedTabStateChanged(tab, changeInfo) {
Expand Down Expand Up @@ -742,18 +747,20 @@ var tgs = (function() {
tab.id,
STATE_HISTORY_URL_TO_REMOVE,
);
/*
const setAutodiscardable = getTabStatePropForTabId(
tab.id,
STATE_SET_AUTODISCARDABLE,
);
*/
clearTabStateForTabId(tab.id);

if (historyUrlToRemove) {
removeTabHistoryForUnuspendedTab(historyUrlToRemove);
}
if (setAutodiscardable) {
gsChrome.tabsUpdate(tab.id, { autoDiscardable: true });
}
// if (setAutodiscardable) {
// gsChrome.tabsUpdate(tab.id, { autoDiscardable: true });
// }

//init loaded tab
resetAutoSuspendTimerForTab(tab);
Expand Down Expand Up @@ -790,12 +797,11 @@ var tgs = (function() {
const latestVisit = visits.pop();
const previousVisit = visits.pop();
if (previousVisit) {
chrome.history.deleteRange(
browser.history.deleteRange(
{
startTime: previousVisit.visitTime - 0.1,
endTime: previousVisit.visitTime + 0.1,
},
() => {
// Firefox does not accept floats here
startTime: previousVisit.visitTime - 1,
endTime: previousVisit.visitTime + 1,
},
);
}
Expand Down Expand Up @@ -1039,9 +1045,9 @@ var tgs = (function() {
queueNewTabFocusTimer(tabId, windowId, focusedTab);

//test for a save of keyboard shortcuts (chrome://extensions/shortcuts)
if (focusedTab.url === 'chrome://extensions/shortcuts') {
_triggerHotkeyUpdate = true;
}
// if (focusedTab.url === 'chrome://extensions/shortcuts') {
// _triggerHotkeyUpdate = true;
// }

let discardAfterSuspend = gsStorage.getOption(
gsStorage.DISCARD_AFTER_SUSPEND,
Expand Down Expand Up @@ -1279,10 +1285,10 @@ var tgs = (function() {
return;
}
//check if it is a blockedFile tab (this needs to have precedence over isSpecialTab)
if (gsUtils.isBlockedFileTab(tab)) {
callback(gsUtils.STATUS_BLOCKED_FILE);
return;
}
// if (gsUtils.isBlockedFileTab(tab)) {
// callback(gsUtils.STATUS_BLOCKED_FILE);
// return;
// }
//check if it is a special tab
if (gsUtils.isSpecialTab(tab)) {
callback(gsUtils.STATUS_SPECIAL);
Expand Down Expand Up @@ -1555,14 +1561,16 @@ var tgs = (function() {
if (request.action === 'reportTabState') {
var contentScriptStatus =
request && request.status ? request.status : null;
if (
contentScriptStatus === 'formInput' ||
contentScriptStatus === 'tempWhitelist'
) {
chrome.tabs.update(sender.tab.id, { autoDiscardable: false });
} else if (!sender.tab.autoDiscardable) {
chrome.tabs.update(sender.tab.id, { autoDiscardable: true });
}

// if (
// contentScriptStatus === 'formInput' ||
// contentScriptStatus === 'tempWhitelist'
// ) {
// chrome.tabs.update(sender.tab.id, { autoDiscardable: false });
// } else if (!sender.tab.autoDiscardable) {
// chrome.tabs.update(sender.tab.id, { autoDiscardable: true });
// }

// If tab is currently visible then update popup icon
if (sender.tab && isCurrentFocusedTab(sender.tab)) {
calculateTabStatus(sender.tab, contentScriptStatus, function(status) {
Expand Down Expand Up @@ -1785,7 +1793,7 @@ var tgs = (function() {
STATE_HISTORY_URL_TO_REMOVE,
STATE_TEMP_WHITELIST_ON_RELOAD,
STATE_DISABLE_UNSUSPEND_ON_RELOAD,
STATE_SET_AUTODISCARDABLE,
// STATE_SET_AUTODISCARDABLE,
STATE_SUSPEND_REASON,
STATE_SCROLL_POS,
getTabStatePropForTabId,
Expand Down
2 changes: 1 addition & 1 deletion src/js/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
let isIgnoreForms = false;
let tempWhitelist = false;

function formInputListener(e) {
function formInputListener(event) {
if (!isReceivingFormInput && !tempWhitelist) {
if (event.keyCode >= 48 && event.keyCode <= 90 && event.target.tagName) {
if (
Expand Down
8 changes: 6 additions & 2 deletions src/js/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
favicon =
favicon && favicon.indexOf('data') === 0
? favicon
: gsFavicon.generateChromeFavIconUrlFromUrl(info.tab.url);
: chrome.extension.getURL('img/chromeDefaultFavicon.png');

html += '<tr>';
html += '<td>' + windowId + '</td>';
Expand Down Expand Up @@ -116,7 +116,7 @@
}
};

var extensionsUrl = `chrome://extensions/?id=${chrome.runtime.id}`;
var extensionsUrl = `about:devtools-toolbox?type=extension&id=${chrome.runtime.id}`;
document
.getElementById('backgroundPage')
.setAttribute('href', extensionsUrl);
Expand All @@ -136,4 +136,8 @@
});
*/
});

window.onload = function() {
document.getElementById('inspect-url').innerHTML = `about:devtools-toolbox?type=extension&id=${chrome.runtime.id}`;
}
})(this);
Loading