aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--eval_test.js195
-rw-r--r--html/display_panel/content/main_panel.js11
-rw-r--r--main_background.js55
-rw-r--r--manifest.json5
4 files changed, 185 insertions, 81 deletions
diff --git a/eval_test.js b/eval_test.js
index d0de7e5..e930a48 100644
--- a/eval_test.js
+++ b/eval_test.js
@@ -50,17 +50,17 @@ var licenses = {
'URL': 'http://www.apache.org/licenses/LICENSE-2.0',
'Magnet link': 'magnet:?xt=urn:btih:8e4f440f4c65981c5bf93c76d35135ba5064d8b7&dn=apache-2.0.txt'
},
- // No identifier was present
+ // No identifier was present in documentation
'Artistic-2.0':{
'URL': 'http://www.perlfoundation.org/artistic_license_2_0',
'Magnet link': 'magnet:?xt=urn:btih:54fd2283f9dbdf29466d2df1a98bf8f65cafe314&dn=artistic-2.0.txt'
},
- // No identifier was present
+ // No identifier was present in documentation
'Boost':{
'URL': 'http://www.boost.org/LICENSE_1_0.txt',
'Magnet link': 'magnet:?xt=urn:btih:89a97c535628232f2f3888c2b7b8ffd4c078cec0&dn=Boost-1.0.txt'
},
- // No identifier was present
+ // No identifier was present in documentation
'BSD-3-Clause':{
'URL': 'http://opensource.org/licenses/BSD-3-Clause',
'Magnet link': 'magnet:?xt=urn:btih:c80d50af7d3db9be66a4d0a86db0286e4fd33292&dn=bsd-3-clause.txt',
@@ -131,7 +131,7 @@ var licenses = {
'URL': 'http://unlicense.org/UNLICENSE',
'Magnet link': 'magnet:?xt=urn:btih:5ac446d35272cc2e4e85e4325b146d0b7ca8f50c&dn=unlicense.txt'
},
- // No identifier was present
+ // No identifier was present in documentation
'X11':{
'URL': 'http://www.xfree86.org/3.3.6/COPYRIGHT2.html#3',
'Magnet link': 'magnet:?xt=urn:btih:5305d91886084f776adcf57509a648432709a7c7&dn=x11.txt'
@@ -143,79 +143,206 @@ var licenses = {
}
}
-var license_regexes = {
- // Comments on a single line only
- "JScomment": /(\/\/.*\n)|(\/\*.*\*\/)/g,
- "JSallcomment": /(\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/)|(\/\/.*)/g,
- // "@license [magnet link] [identifier]"
- "license_start": /@license[^\S\n]+magnet:\S+[^\S\n]+\S+/g,
- // "@license-end"
- "license_end": /\/\/\s*@license\-end/g
-}
-
/**
*
* Runs regexes to search for explicit delcarations of script
-* licenses on the argument. (// @license, //@license-end)
-*
-* Returns the identifier string or "fail".
+* licenses on the argument.
+* It detects:
+* // @license, //@license-end
+* // licstart, //licend
+* Returns the identifier string of the license or "fail".
*
*/
function license_read(script_src){
+ if(typeof(script_src) != "string"){
+ return "fail"
+ }
var license_attempts = [];
- var comment_regex = new RegExp(license_regexes["JSallcomment"]);
- var comments = script_src.match(comment_regex);
+ // comment regex
+ var comments = script_src.match(/(\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/)|(\/\/.*)/g);
if(comments == null){
comments = [];
}
console.log("%c comments:","color:green;")
console.log(comments);
+
+ // Not sure if there is any better way to do this.
for(var i = 0; i < comments.length; i++){
if(comments[i] !== undefined){
- if(comments[i].match(license_regexes["license_start"]) != null){
- console.log("License start:");
- console.log(comments[i])
+ // license_start regex
+ if(comments[i].match(/@license[^\S\n]+magnet:\S+[^\S\n]+\S+/g) != null){
+ console.log("License start detected.");
+ var content = comments[i].match(/(?:magnet:\S+)(\s+.+)/g);
+ if(content != null){
+ content[0].replace(/\s+/g," ");
+ content = content[0].split(" ");
+ var magnet = content[0];
+ var identifier = "";
+ for(var i = 1; i < content.length; i++){
+ if(i == 1){
+ identifier = identifier + content[i];
+ } else{
+ identifier = identifier + "-" + content[i];
+ }
+ }
+ var valid = true;
+ if(licenses[identifier]["Magnet link"] != magnet){
+ valid = false;
+ }
+ if((identifier in licenses) == false){
+ valid = false;
+ }
+ console.log("Valid? "+ valid);
+ } else{
+ console.log("Valid? false");
+ }
}
-
- if(comments[i].match(license_regexes["license_end"]) != null){
+ // license-end regex
+ if(comments[i].match(/\/\/\s*@license\-end/g) != null){
console.log("License end:");
console.log(comments[i])
}
}
}
+ //console.log("VERDICT: probably nonfree");
+ //console.log("VERDICT: probably free");
+}
+
+/**
+*
+* Checks the whitelist in storage
+* (Not the comma seperated whitelist from settings)
+*
+*/
+function is_whitelisted(){
+ // TODO: implement
+ return false;
+
}
-// The Javascript evaluation can be tested as a content script until we have
-// the API features we need to make it run before the page's scripts do.
-// To run this, set it as a content script active on all URLs in the manifest.json.
+/**
+* Parses the weblabels table from a DOM object
+*
+*/
+function read_weblabels_table(weblabel){
+ var tbody = weblabel.getElementsByTagName("td");
+ for(var i = 0; i < tbody.length; i++){
+ var link = tbody[i].getElementsByTagName("a")[0];
+ console.log(link.href);
+ console.log(link.innerText);
+ }
+}
+
+/**
+* Reads the weblabels table from a link.
+*
+*/
+function get_table(url){
+ var xml = new XMLHttpRequest();
+ xml.open("get",url)
+ xml.onload = function(){
+ var a = new DOMParser()
+ var doc = a.parseFromString(this.responseText,"text/html");
+ var web_label = doc.getElementById("jslicense-labels1");
+ if(web_label != null){
+ read_weblabels_table(web_label);
+ }
+ }
+ xml.send();
+}
// called when invoked by the button
-function handler(){
+function analyze(){
+ // TODO: Call get_whitelisted_status on this page's URL
+
+ // Test "the first piece of Javascript available to the page" for the license comment
+ // TODO: Is this supposed to test if the license is free or just assume that it is?
+ if(document.scripts[0] !== undefined){
+ if(document.scripts[0].src != ""){
+ var name = document.scripts[0].src;
+ var xml = new XMLHttpRequest();
+ xml.open("get", document.scripts[0].src);
+ xml.onload = function(response){
+ var matches = this.responseText.match(/@licstart[\s\S]+@licend/g);
+ if(matches != null){
+ console.log("License comment found:");
+ console.log(matches[0]);
+ }
+ }
+ xml.send();
+ } else{
+ console.log("%c Script " + i + ": (src: inline)","color:red;");
+ var matches = document.scripts[0].innerText.match(/@licstart[\s\S]+@licend/g);
+ if(matches != null){
+ console.log("License comment found:");
+ console.log(matches[0]);
+ }
+ }
+ }
+ // Test for the link that has rel="jslicense", data-jslicense="1"
+ for(var i = 0; i < document.links.length; i++){
+ // TODO: also check if data-jslicense == "1". (how?)
+ if(document.links[i].rel == "jslicense"){
+ console.log("Found HTML table link:");
+ get_table(document.links[i].href);
+ break;
+ }
+ }
+ // Test for the JavaScript Web Labels table
+ var weblabel = document.getElementById("jslicense-labels1");
+ if(weblabel !== undefined && weblabel != null){
+ console.log("Found web labels table");
+ read_weblabels_table(weblabel);
+ }
+
+ // Call license_read on all the document's scripts
+ // This is done just to debug before we can implement this in a background script,
+ // where it will have access to the individual script requests and HTML document.
for(var i = 0; i < document.scripts.length; i++){
if(document.scripts[i].src != ""){
+ // it is a remote script ("<script src='/script.js'></script>")
var name = document.scripts[i].src;
var xml = new XMLHttpRequest();
xml.open("get", document.scripts[i].src);
xml.onload = function(response){
- console.log("%c Script " + i + ": (src: " + name + ")","color:red;");
+ console.log("%c Script " + i + ":","color:red;");
+ console.log(name);
license_read(this.responseText);
}
xml.send();
} else{
- name = "inline";
- source = document.scripts[i].innerText;
+ // it is an inline script ("<script>console.log('test');</script>")
console.log("%c Script " + i + ": (src: inline)","color:red;");
- license_read(document.scripts[i]);
+ //console.log(document.scripts[i].innerText);
+ license_read(document.scripts[i].innerText);
}
}
+ // Find all the document's elements with intrinsic events
+ for(var i = 0; i < document.all.length; i++){
+ for(var j = 0; j < intrinsicEvents.length; j++){
+ if(intrinsicEvents[j] in document.all[i].attributes){
+ console.log("intrinsic event JS found in element:");
+ console.log(document.all[i][intrinsicEvents[j]].toString());
+ }
+ }
+
+ }
+
+
}
+
+/**
+* Makes a button appear that calls a function when you press it.
+*
+* I copied and pasted this from something else I wrote. It's quite useful.
+*
+*/
var button_i = 0;
if(document.getElementById("abc123_main_div") !== null){
document.getElementById("abc123_main_div").remove();
}
-
function new_debug_button(name_text,callback){
if(document.getElementById("abc123_main_div") === null){
var to_insert = '<div style="opacity: 0.5; font-size: small; z-index: 2147483647; position: fixed; right: 1%; top: 4%;" id="abc123_main_div"></div>';
@@ -227,7 +354,7 @@ function new_debug_button(name_text,callback){
button_i = button_i + 1;
}
-new_debug_button("Evaluate scripts",handler);
+new_debug_button("Evaluate scripts",analyze);
new_debug_button("Remove these buttons",function(){
if(document.getElementById("abc123_main_div") !== null){
document.getElementById("abc123_main_div").remove();
diff --git a/html/display_panel/content/main_panel.js b/html/display_panel/content/main_panel.js
index 3848a2e..c6d2059 100644
--- a/html/display_panel/content/main_panel.js
+++ b/html/display_panel/content/main_panel.js
@@ -1,3 +1,6 @@
+//TODO: there is a known bug involving "forget preference" not working correctly.
+
+
/**
*
* Sets global variable "webex" to either "chrome" or "browser" for
@@ -114,6 +117,9 @@ var template = '<tr><td id="c1"></td><td id="c2"></td></tr>';
var lr_flag = true;
var button_num = 0;
function write_button(button,callback){
+ if(document.getElementById("buttons_table").innerHTML.indexOf(button) != -1){
+ return;
+ }
var id = "buttonno_"+button_num;
if(lr_flag){
document.getElementById("buttons_table").insertAdjacentHTML("beforeend",template);
@@ -161,6 +167,8 @@ function generate_HTML(blocked_data){
for(var i = 0; i < to_clr.length; i++){
to_clr[i].innerHTML = "";
}
+ console.log("REGEN HTML:");
+ console.log(blocked_data);
write_elements(blocked_data,"accepted","green");
write_elements(blocked_data,"whitelisted","green");
write_elements(blocked_data,"blocked","red");
@@ -181,8 +189,7 @@ function generate_HTML(blocked_data){
myPort.postMessage({"open_popup_tab": blocked_data});
});
} else{
- write_button(button_new_tab,"l",function(){
- // NOTE: does not
+ write_button(button_new_tab,function(){
myPort.postMessage({"open_popup_tab": blocked_data});
});
}
diff --git a/main_background.js b/main_background.js
index 1e31d64..cf8ca80 100644
--- a/main_background.js
+++ b/main_background.js
@@ -37,7 +37,7 @@ function options_listener(changes, area){
function flushed(){
console.log("cache flushed");
}
- var flushingCache = webex.webRequest.handlerBehaviorChanged(flushed);
+ //var flushingCache = webex.webRequest.handlerBehaviorChanged(flushed);
console.log("Items updated in area" + area +": ");
@@ -108,6 +108,10 @@ function debug_print_local(){
* "url": "example.com"
* }
*
+* NOTE: This WILL break if you provide inconsistent URLs to it.
+* Make sure it will use the right URL when refering to a certain script.
+*
+*
*/
function update_popup(tab_id,blocked_info_arg,update=false){
var new_blocked_data;
@@ -168,12 +172,12 @@ function update_popup(tab_id,blocked_info_arg,update=false){
for(var script_arr in blocked_info[type]){
if(is_bl(blocked_info[type][script_arr][0])){
new_blocked_data["blacklisted"].push(blocked_info[type][script_arr]);
- //console.log("Script " + blocked_info[type][script_arr][0] + " is blacklisted");
+ console.log("Script " + blocked_info[type][script_arr][0] + " is blacklisted");
continue;
}
if(is_wl(blocked_info[type][script_arr][0])){
new_blocked_data["whitelisted"].push(blocked_info[type][script_arr]);
- //console.log("Script " + blocked_info[type][script_arr][0] + " is whitelisted");
+ console.log("Script " + blocked_info[type][script_arr][0] + " is whitelisted");
continue;
}
if(type == "url"){
@@ -181,9 +185,10 @@ function update_popup(tab_id,blocked_info_arg,update=false){
}
// either "blocked" or "accepted"
new_blocked_data[type].push(blocked_info[type][script_arr]);
- //console.log("Script " + blocked_info[type][script_arr][0] + " isn't whitelisted or blacklisted");
+ console.log("Script " + blocked_info[type][script_arr][0] + " isn't whitelisted or blacklisted");
}
}
+ console.log(new_blocked_data);
//***********************************************************************************************//
// store the blocked info until it is opened and needed
if(update == false && active_connections[tab_id] === undefined){
@@ -221,16 +226,13 @@ function connected(p) {
current_url = tabs[0]["url"];
// The space char is a valid delimiter because encodeURI() replaces it with %20
-
var scriptkey = encodeURI(current_url)+" "+encodeURI(script);
-
if(val == "forget"){
var prom = webex.storage.local.remove(scriptkey);
// TODO: This should produce a "Refresh the page for this change to take effect" message
} else{
var newitem = {};
newitem[scriptkey] = val;
-
webex.storage.local.set(newitem);
}
}
@@ -275,15 +277,9 @@ function connected(p) {
inject_contact_finder(tabs[0]["id"]);
}
if(update){
- // TODO: check the Firefox equivalent reserved URL pattern
- if(typeof(tabs[0]["url"].match(/chrome\-extension:\/\/.*display-panel\.html/g)) == "object"){
- console.log("%c Not updating popup because this is a reserved page","color: red;");
- return;
- } else{
- console.log("%c updating tab "+tabs[0]["id"],"color: red;");
- update_popup(tabs[0]["id"],unused_data[tabs[0]["id"]],true);
- active_connections[tabs[0]["id"]] = p;
- }
+ console.log("%c updating tab "+tabs[0]["id"],"color: red;");
+ update_popup(tabs[0]["id"],unused_data[tabs[0]["id"]],true);
+ active_connections[tabs[0]["id"]] = p;
}
for(var i = 0; i < tabs.length; i++) {
var tab = tabs[i];
@@ -331,33 +327,6 @@ function init_addon(){
webex.runtime.onConnect.addListener(connected);
webex.storage.onChanged.addListener(options_listener);
webex.tabs.onRemoved.addListener(delete_removed_tab_info);
-
- /**
- * Callback for request traffic.
- *
- */
- /*
- function script_request(details){
- console.log("Request:"+details.type)
- //return {redirectUrl: "about:blank"};
- return true;
- }
- webex.webRequest.onResponseStarted.addListener(script_request,{
- urls:["<all_urls>"]
- });
- */
-
- /**************** some debugging: ***************************/
- // Valid input for update_popup
- var example_input = {
- "accepted": [["FILENAME 1","REASON 1"],["FILENAME 2","REASON 2"]],
- "blocked": [["FILENAME 3","REASON 1"],["FILENAME 4","REASON 2"]],
- "url":"chrome://extensions/"
- };
- // To test the default text
- update_popup(4,example_input);
- console.log("Set the browser action contents");
- /*****************************************************************/
}
/**
diff --git a/manifest.json b/manifest.json
index 9586586..bcf91f1 100644
--- a/manifest.json
+++ b/manifest.json
@@ -21,7 +21,8 @@
"activeTab",
"notifications",
"storage",
- "tabs"
+ "tabs",
+ "<all_urls>"
],
"browser_action": {
"browser_style": true,
@@ -40,5 +41,5 @@
"background": {
"scripts": ["main_background.js"]
},
- "content_scripts": [{"matches": ["<all_urls>"],"js": ["contact_finder.js"]}]
+ "content_scripts": [{"matches": ["<all_urls>"],"js": ["eval_test.js"]}]
}