From daf890406cdc68c98e304bf241357928f107a080 Mon Sep 17 00:00:00 2001 From: George Hafiz Date: Sun, 3 Nov 2013 22:54:41 +0000 Subject: [PATCH 1/8] Start moving of options into tabs. Signed-off-by: George Hafiz --- extension/options.html | 98 ++++++++++++++++++++++++------------------ extension/options.js | 13 +++--- 2 files changed, 64 insertions(+), 47 deletions(-) diff --git a/extension/options.html b/extension/options.html index ac83787..277d3c3 100644 --- a/extension/options.html +++ b/extension/options.html @@ -185,47 +185,63 @@ WebPG Options -
-
-    -    -    -    - - - -
-
    -

    -
    - - -
    -
    -
    -
    -
    -
    - - Your system appears to be configured correctly for WebPG -
    - -
    -
    -
    -
    -
    -

    -
    -
    +
    +
    +
    +
    +
    + + Your system appears to be configured correctly for WebPG +
    + +
    +
    +
    +
    + + + +
    +
    +
    +    +    +    +    + + + +
    +
      +

      +
      +
      + +
      +

      +
      +
      +
      +
      +

      + Here's filter text +

      +
      +
      +
      +    +    +    +    +
      +
      diff --git a/extension/options.js b/extension/options.js index 8324cb2..0bbc993 100644 --- a/extension/options.js +++ b/extension/options.js @@ -23,9 +23,16 @@ webpg.options = { document.title = _("WebPG Options"); document.dir = (webpg.utils.isRTL() ? 'rtl' : 'ltr'); if (webpg.utils.detectedBrowser['vendor'] == "mozilla") + { webpg.plugin = browserWindow.webpg.plugin; + } else if (webpg.utils.detectedBrowser['product'] == "chrome") + { webpg.plugin = chrome.extension.getBackgroundPage().webpg.plugin; + } + + // jQuery UI elements + webpg.jq('#tabs').tabs(); webpg.jq('#step-1').ready(function() { doSystemCheck(); @@ -177,8 +184,6 @@ webpg.options = { webpg.xoauth2.requestCode(); }); - webpg.jq("#advanced-options-link").text(_("Advanced Options")); - webpg.jq("#gnupg-path-select").find(".webpg-options-text"). text(_("GnuPG home directory")); @@ -531,10 +536,6 @@ webpg.options = { })[0].value = webpg.plugin.gpgGetPreference("keyserver").value; webpg.jq("#gnupg-keyserver-input")[0].dir = "ltr"; - - webpg.jq("#advanced-options-link").click(function(e) { - webpg.jq("#advanced-options").toggle("slide"); - }); } } From 82a9f7dfa2ba488f3c1aa2aedd1b1e4c5d28c168 Mon Sep 17 00:00:00 2001 From: George Hafiz Date: Tue, 3 Dec 2013 21:17:29 +0000 Subject: [PATCH 2/8] Don't scroll the browser when resizing the inline results, after asking to 'hide original'. Signed-off-by: George Hafiz --- extension/webpg_results.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension/webpg_results.js b/extension/webpg_results.js index fbe00c5..72dab5f 100644 --- a/extension/webpg_results.js +++ b/extension/webpg_results.js @@ -636,7 +636,7 @@ webpg.inline_results = { this.textContent = _("DISPLAY ORIGINAL"); webpg.jq('#signature_text').show(); webpg.jq('#original_text').hide(); - webpg.inline_results.doResize(true) + webpg.inline_results.doResize() } }); webpg.jq('.copy_to_clipboard').click(function(){ From 53c7ae9ced845242cb7b00858bc74f223a0046c8 Mon Sep 17 00:00:00 2001 From: George Hafiz Date: Mon, 23 Dec 2013 23:51:55 +0000 Subject: [PATCH 3/8] Adjust styling of the browser action menu, reduce whitespace and make more central. Signed-off-by: George Hafiz --- extension/browser_action_menu.html | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/extension/browser_action_menu.html b/extension/browser_action_menu.html index c2719df..08537a2 100644 --- a/extension/browser_action_menu.html +++ b/extension/browser_action_menu.html @@ -5,9 +5,13 @@ -
      +
      From fc2ac43a7ccbb12d88f11777e58955fd0b0b97b1 Mon Sep 17 00:00:00 2001 From: George Hafiz Date: Tue, 25 Mar 2014 20:28:33 +0000 Subject: [PATCH 4/8] Partially working site white and blacklisting. Signed-off-by: George Hafiz --- extension/jquery/js/URI.js | 58 +++++++++++++ extension/options.html | 162 ++++++++++++++++++++++++------------- extension/options.js | 76 +++++++++++++---- extension/preferences.js | 43 ++++++++++ extension/utils.js | 18 +++++ 5 files changed, 287 insertions(+), 70 deletions(-) create mode 100644 extension/jquery/js/URI.js diff --git a/extension/jquery/js/URI.js b/extension/jquery/js/URI.js new file mode 100644 index 0000000..2b2c774 --- /dev/null +++ b/extension/jquery/js/URI.js @@ -0,0 +1,58 @@ +/*! URI.js v1.11.2 http://medialize.github.com/URI.js/ */ +/* build contains: IPv6.js, URI.js, jquery.URI.js */ +(function(f,k){"object"===typeof exports?module.exports=k():"function"===typeof define&&define.amd?define(k):f.IPv6=k(f)})(this,function(f){var k=f&&f.IPv6;return{best:function(g){g=g.toLowerCase().split(":");var f=g.length,d=8;""===g[0]&&""===g[1]&&""===g[2]?(g.shift(),g.shift()):""===g[0]&&""===g[1]?g.shift():""===g[f-1]&&""===g[f-2]&&g.pop();f=g.length;-1!==g[f-1].indexOf(".")&&(d=7);var l;for(l=0;lk;k++)if("0"===f[0]&&1k&&(f=r,k=n)):"0"==g[l]&&(s=!0,r=l,n=1);n>k&&(f=r,k=n);1]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u2018\u2019]))/ig;d.defaultPorts={http:"80",https:"443",ftp:"21",gopher:"70",ws:"80",wss:"443"};d.invalid_hostname_characters=/[^a-zA-Z0-9\.-]/;d.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href", +iframe:"src",embed:"src",source:"src",track:"src",input:"src"};d.getDomAttribute=function(a){if(a&&a.nodeName){var b=a.nodeName.toLowerCase();return"input"===b&&"image"!==a.type?void 0:d.domAttributes[b]}};d.encode=h;d.decode=decodeURIComponent;d.iso8859=function(){d.encode=escape;d.decode=unescape};d.unicode=function(){d.encode=h;d.decode=decodeURIComponent};d.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/ig,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=", +"%3A":":","%40":"@"}},decode:{expression:/[\/\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/ig,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@","%21":"!","%24":"$","%26":"&","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"="}}}};d.encodeQuery=function(a,b){var c=d.encode(a+"");return b?c.replace(/%20/g,"+"):c};d.decodeQuery=function(a,b){a+="";try{return d.decode(b? +a.replace(/\+/g,"%20"):a)}catch(c){return a}};d.recodePath=function(a){a=(a+"").split("/");for(var b=0,c=a.length;bd)return a.charAt(0)===b.charAt(0)&&"/"===a.charAt(0)?"/":"";if("/"!==a.charAt(d)||"/"!==b.charAt(d))d=a.substring(0,d).lastIndexOf("/");return a.substring(0,d+1)};d.withinString=function(a,b){return a.replace(d.find_uri_expression,b)};d.ensureValidHostname=function(a){if(a.match(d.invalid_hostname_characters)){if(!f)throw new TypeError("Hostname '"+a+"' contains characters other than [A-Z0-9.-] and Punycode.js is not available");if(f.toASCII(a).match(d.invalid_hostname_characters))throw new TypeError("Hostname '"+ +a+"' contains characters other than [A-Z0-9.-]");}};d.noConflict=function(a){if(a)return a={URI:this.noConflict()},URITemplate&&"function"==typeof URITemplate.noConflict&&(a.URITemplate=URITemplate.noConflict()),k&&"function"==typeof k.noConflict&&(a.IPv6=k.noConflict()),SecondLevelDomains&&"function"==typeof SecondLevelDomains.noConflict&&(a.SecondLevelDomains=SecondLevelDomains.noConflict()),a;w.URI===this&&(w.URI=t);return this};e.build=function(a){if(!0===a)this._deferred_build=!0;else if(void 0=== +a||this._deferred_build)this._string=d.build(this._parts),this._deferred_build=!1;return this};e.clone=function(){return new d(this)};e.valueOf=e.toString=function(){return this.build(!1)._string};q={protocol:"protocol",username:"username",password:"password",hostname:"hostname",port:"port"};v=function(a){return function(b,c){if(void 0===b)return this._parts[a]||"";this._parts[a]=b||null;this.build(!c);return this}};for(p in q)e[p]=v(q[p]);q={query:"?",fragment:"#"};v=function(a,b){return function(c, +d){if(void 0===c)return this._parts[a]||"";null!==c&&(c+="",c.charAt(0)===b&&(c=c.substring(1)));this._parts[a]=c;this.build(!d);return this}};for(p in q)e[p]=v(p,q[p]);q={search:["?","query"],hash:["#","fragment"]};v=function(a,b){return function(c,d){var e=this[a](c,d);return"string"===typeof e&&e.length?b+e:e}};for(p in q)e[p]=v(q[p][1],q[p][0]);e.pathname=function(a,b){if(void 0===a||!0===a){var c=this._parts.path||(this._parts.hostname?"/":"");return a?d.decodePath(c):c}this._parts.path=a?d.recodePath(a): +"/";this.build(!b);return this};e.path=e.pathname;e.href=function(a,b){var c;if(void 0===a)return this.toString();this._string="";this._parts=d._parts();var m=a instanceof d,e="object"===typeof a&&(a.hostname||a.path||a.pathname);a.nodeName&&(e=d.getDomAttribute(a),a=a[e]||"",e=!1);!m&&e&&void 0!==a.pathname&&(a=a.toString());if("string"===typeof a)this._parts=d.parse(a,this._parts);else if(m||e)for(c in m=m?a._parts:a,m)u.call(this._parts,c)&&(this._parts[c]=m[c]);else throw new TypeError("invalid input"); +this.build(!b);return this};e.is=function(a){var b=!1,c=!1,e=!1,f=!1,h=!1,t=!1,k=!1,l=!this._parts.urn;this._parts.hostname&&(l=!1,c=d.ip4_expression.test(this._parts.hostname),e=d.ip6_expression.test(this._parts.hostname),b=c||e,h=(f=!b)&&g&&g.has(this._parts.hostname),t=f&&d.idn_expression.test(this._parts.hostname),k=f&&d.punycode_expression.test(this._parts.hostname));switch(a.toLowerCase()){case "relative":return l;case "absolute":return!l;case "domain":case "name":return f;case "sld":return h; +case "ip":return b;case "ip4":case "ipv4":case "inet4":return c;case "ip6":case "ipv6":case "inet6":return e;case "idn":return t;case "url":return!this._parts.urn;case "urn":return!!this._parts.urn;case "punycode":return k}return null};var z=e.protocol,A=e.port,B=e.hostname;e.protocol=function(a,b){if(void 0!==a&&a&&(a=a.replace(/:(\/\/)?$/,""),a.match(/[^a-zA-z0-9\.+-]/)))throw new TypeError("Protocol '"+a+"' contains characters other than [A-Z0-9.+-]");return z.call(this,a,b)};e.scheme=e.protocol; +e.port=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0!==a&&(0===a&&(a=null),a&&(a+="",":"===a.charAt(0)&&(a=a.substring(1)),a.match(/[^0-9]/))))throw new TypeError("Port '"+a+"' contains characters other than [0-9]");return A.call(this,a,b)};e.hostname=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0!==a){var c={};d.parseHost(a,c);a=c.hostname}return B.call(this,a,b)};e.host=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a)return this._parts.hostname? +d.buildHost(this._parts):"";d.parseHost(a,this._parts);this.build(!b);return this};e.authority=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a)return this._parts.hostname?d.buildAuthority(this._parts):"";d.parseAuthority(a,this._parts);this.build(!b);return this};e.userinfo=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){if(!this._parts.username)return"";var c=d.buildUserinfo(this._parts);return c.substring(0,c.length-1)}"@"!==a[a.length-1]&&(a+= +"@");d.parseUserinfo(a,this._parts);this.build(!b);return this};e.resource=function(a,b){var c;if(void 0===a)return this.path()+this.search()+this.hash();c=d.parse(a);this._parts.path=c.path;this._parts.query=c.query;this._parts.fragment=c.fragment;this.build(!b);return this};e.subdomain=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var c=this._parts.hostname.length-this.domain().length-1;return this._parts.hostname.substring(0, +c)||""}c=this._parts.hostname.length-this.domain().length;c=this._parts.hostname.substring(0,c);c=RegExp("^"+l(c));a&&"."!==a.charAt(a.length-1)&&(a+=".");a&&d.ensureValidHostname(a);this._parts.hostname=this._parts.hostname.replace(c,a);this.build(!b);return this};e.domain=function(a,b){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(b=a,a=void 0);if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var c=this._parts.hostname.match(/\./g);if(c&&2>c.length)return this._parts.hostname; +c=this._parts.hostname.length-this.tld(b).length-1;c=this._parts.hostname.lastIndexOf(".",c-1)+1;return this._parts.hostname.substring(c)||""}if(!a)throw new TypeError("cannot set domain empty");d.ensureValidHostname(a);!this._parts.hostname||this.is("IP")?this._parts.hostname=a:(c=RegExp(l(this.domain())+"$"),this._parts.hostname=this._parts.hostname.replace(c,a));this.build(!b);return this};e.tld=function(a,b){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(b=a,a=void 0);if(void 0=== +a){if(!this._parts.hostname||this.is("IP"))return"";var c=this._parts.hostname.lastIndexOf("."),c=this._parts.hostname.substring(c+1);return!0!==b&&g&&g.list[c.toLowerCase()]?g.get(this._parts.hostname)||c:c}if(a)if(a.match(/[^a-zA-Z0-9-]/))if(g&&g.is(a))c=RegExp(l(this.tld())+"$"),this._parts.hostname=this._parts.hostname.replace(c,a);else throw new TypeError("TLD '"+a+"' contains characters other than [A-Z0-9]");else{if(!this._parts.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host"); +c=RegExp(l(this.tld())+"$");this._parts.hostname=this._parts.hostname.replace(c,a)}else throw new TypeError("cannot set TLD empty");this.build(!b);return this};e.directory=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path&&!this._parts.hostname)return"";if("/"===this._parts.path)return"/";var c=this._parts.path.length-this.filename().length-1,c=this._parts.path.substring(0,c)||(this._parts.hostname?"/":"");return a?d.decodePath(c):c}c=this._parts.path.length- +this.filename().length;c=this._parts.path.substring(0,c);c=RegExp("^"+l(c));this.is("relative")||(a||(a="/"),"/"!==a.charAt(0)&&(a="/"+a));a&&"/"!==a.charAt(a.length-1)&&(a+="/");a=d.recodePath(a);this._parts.path=this._parts.path.replace(c,a);this.build(!b);return this};e.filename=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path||"/"===this._parts.path)return"";var c=this._parts.path.lastIndexOf("/"),c=this._parts.path.substring(c+1);return a? +d.decodePathSegment(c):c}c=!1;"/"===a.charAt(0)&&(a=a.substring(1));a.match(/\.?\//)&&(c=!0);var e=RegExp(l(this.filename())+"$");a=d.recodePath(a);this._parts.path=this._parts.path.replace(e,a);c?this.normalizePath(b):this.build(!b);return this};e.suffix=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path||"/"===this._parts.path)return"";var c=this.filename(),e=c.lastIndexOf(".");if(-1===e)return"";c=c.substring(e+1);c=/^[a-z0-9%]+$/i.test(c)?c: +"";return a?d.decodePathSegment(c):c}"."===a.charAt(0)&&(a=a.substring(1));if(c=this.suffix())e=a?RegExp(l(c)+"$"):RegExp(l("."+c)+"$");else{if(!a)return this;this._parts.path+="."+d.recodePath(a)}e&&(a=d.recodePath(a),this._parts.path=this._parts.path.replace(e,a));this.build(!b);return this};e.segment=function(a,b,c){var d=this._parts.urn?":":"/",e=this.path(),f="/"===e.substring(0,1),e=e.split(d);void 0!==a&&"number"!==typeof a&&(c=b,b=a,a=void 0);if(void 0!==a&&"number"!==typeof a)throw Error("Bad segment '"+ +a+"', must be 0-based integer");f&&e.shift();0>a&&(a=Math.max(e.length+a,0));if(void 0===b)return void 0===a?e:e[a];if(null===a||void 0===e[a])if(n(b)){e=[];a=0;for(var h=b.length;a + @@ -185,63 +186,112 @@ WebPG Options
      -
      -
      -
      -
      -
      - - Your system appears to be configured correctly for WebPG -
      - -
      -
      -
      -
      - - - -
      -
      -
      -    -    -    -    - - - -
      -
        -

        -
        -
        +
        +
        +
        +
        +
        + + Your system appears to be configured correctly for WebPG +
        + +
        +
        +
        +
        + + + +
        +
        +
        + +    + + + + + +    + + + + +    + + + + +    + + + + +
        +
          +

          +
          +
          -
          -

          -
          -
          -
          -
          -

          - Here's filter text -

          -
          -
          -
          -    -    -    -    -
          -
          +
          +

          +
          +
          +
          +
          +
          +
          + Whitelist + + + + +
          +
          + Blacklist + + + + +
          +
          +
          + +
          +
          + +    + + + + + +    + + + + + +    + + + + + +    + + + + +
          +
          diff --git a/extension/options.js b/extension/options.js index 35b1f0b..eef5186 100644 --- a/extension/options.js +++ b/extension/options.js @@ -23,16 +23,16 @@ webpg.options = { document.title = _("WebPG Options"); document.dir = (webpg.utils.isRTL() ? 'rtl' : 'ltr'); if (webpg.utils.detectedBrowser['vendor'] == "mozilla") - { + { webpg.plugin = browserWindow.webpg.plugin; - } + } else if (webpg.utils.detectedBrowser['product'] == "chrome") - { + { webpg.plugin = chrome.extension.getBackgroundPage().webpg.plugin; - } - - // jQuery UI elements - webpg.jq('#tabs').tabs(); + } + + // jQuery UI elements + webpg.jq('#tabs').tabs(); webpg.jq('#step-1').ready(function() { doSystemCheck(); @@ -186,22 +186,22 @@ webpg.options = { webpg.jq("#gnupg-path-select").find(".webpg-options-text"). text(_("GnuPG home directory")); - webpg.jq("#gnupg-path-select").find("input:button").val(_("Save")) + webpg.jq("#gnupg-path-input").attr('placeholder', '~/.gnupg'); webpg.jq("#gnupg-binary-select").find(".webpg-options-text"). - text(_("GnuPG binary") + " (i.e. /usr/bin/gpg)"); - + text(_("GnuPG binary")); + webpg.jq("#gnupg-binary-input").attr('placeholder', '/usr/bin/gpg'); webpg.jq("#gnupg-binary-select").find("input:button").val(_("Save")); webpg.jq("#gpgconf-binary-select").find(".webpg-options-text"). - text(_("GPGCONF binary") + " (i.e. /usr/bin/gpgconf)"); - + text(_("GPGCONF binary")); + webpg.jq("#gpgconf-binary-input").attr('placeholder', '/usr/bin/gpgconf'); webpg.jq("#gpgconf-binary-select").find("input:button").val(_("Save")); webpg.jq("#gnupg-keyserver-select").find(".webpg-options-text"). - text(_("Keyserver") + " (i.e. hkp://subkeys.pgp.net)"); - + text(_("Keyserver")); + webpg.jq("#gnupg-keyserver-input").attr('placeholder', 'hkp://subkeys.pgp.net'); webpg.jq("#gnupg-keyserver-select").find("input:button").val(_("Save")); webpg.jq("#system-good").find(".trust-desc").text(_("Your system appears to be configured correctly for WebPG")); @@ -542,6 +542,54 @@ webpg.options = { })[0].value = webpg.plugin.gpgGetPreference("keyserver").value; webpg.jq("#gnupg-keyserver-input")[0].dir = "ltr"; + + // Site exceptions stuff + + /* webpg.jq("#site-whitelist-list").html( + '' + ); + webpg.jq("#site-blacklist-list").html( + '' + ); */ + + webpg.jq("#site-whitelist-add").click(function() { + var site_input = webpg.jq(this).siblings('input[type=text]'); + if (site_input.val() != "") { + var site_URI = new URI(site_input.val()); + webpg.preferences.site_exceptions.add('whitelist', site_input.val()); + var site_exceptions = webpg.preferences.site_exceptions.get(); + webpg.jq('#site-whitelist-list').html(''); + } + site_input.val(''); + site_input.focus(); + }); + webpg.jq("#site-blacklist-add").click(function() { + var site_input = webpg.jq(this).siblings('input[type=text]'); + if (site_input.val() != "") { + webpg.preferences.site_exceptions.add('blacklist', site_input.val()); + var site_exceptions = webpg.preferences.site_exceptions.get(); + webpg.jq('#site-blacklist-list').html(''); + } + site_input.val(''); + site_input.focus(); + }); + + webpg.jq("#site-whitelist-remove").click(function() { + var sites = webpg.jq('#site-whitelist-list').val(); + webpg.jq.each(sites, function(index, site) { + webpg.preferences.site_exceptions.remove('whitelist', site); + var site_exceptions = webpg.preferences.site_exceptions.get(); + webpg.jq('#site-whitelist-list').html(''); + }); + }); + webpg.jq("#site-blacklist-remove").click(function() { + var sites = webpg.jq('#site-blacklist-list').val(); + webpg.jq.each(sites, function(index, site) { + webpg.preferences.site_exceptions.remove('blacklist', site); + var site_exceptions = webpg.preferences.site_exceptions.get(); + webpg.jq('#site-blacklist-list').html(''); + }); + }); } } diff --git a/extension/preferences.js b/extension/preferences.js index 9263ad4..f7627af 100644 --- a/extension/preferences.js +++ b/extension/preferences.js @@ -658,6 +658,49 @@ webpg.preferences = { webpg.localStorage.setItem('xoauth2_data', JSON.stringify(data)); } }, + + /* + Class: webpg.preferences.site_exceptions + Provides methods to get/set the "site_exceptions" user white & blacklists. + */ + site_exceptions: { + get: function() { + var stored_data = webpg.localStorage.getItem('site_exceptions'); + return (stored_data && stored_data.length > 1) ? JSON.parse(stored_data) : { whitelist: [], blacklist: [] }; + }, + + add: function(type, site) { + var site_exceptions = webpg.preferences.site_exceptions.get(); + if (type == "whitelist") { + site_exceptions.whitelist.push(site); + } + else if (type == "blacklist") { + site_exceptions.blacklist.push(site); + } + else + { + alert("Code error in site_exceptions preference handler."); + } + + return webpg.localStorage.setItem('site_exceptions', JSON.stringify(webpg.utils.unique(site_exceptions))); + }, + + remove: function(type, site) { + var site_exceptions = webpg.preferences.site_exceptions.get(); + if (type == "whitelist") { + site_exceptions.whitelist.splice(webpg.jq.inArray(site, site_exceptions), 1); + } + else if (type == "blacklist") { + site_exceptions.blacklist.splice(webpg.jq.inArray(site, site_exceptions), 1); + } + else + { + alert("Code error in site_exceptions preference handler."); + } + + return webpg.localStorage.setItem('site_exceptions', JSON.stringify(webpg.utils.unique(site_exceptions))); + }, + }, }; diff --git a/extension/utils.js b/extension/utils.js index 6ad404d..1b0ea17 100644 --- a/extension/utils.js +++ b/extension/utils.js @@ -187,6 +187,24 @@ webpg.utils = { 'anchor': result[12] } }, + + /* + Function: unique + Returns a copy of a string array without any duplicate values + + Parameters: + array - string[] The array to unique + + Returns: + string[] - The copy without duplicates + */ + unique: function(list) { + var result = []; + webpg.jq.each(list, function(i, e) { + if (webpg.jq.inArray(e, result) == -1) result.push(e); + }); + return result; + }, formatSearchParameter: function(item) { var pParam = item.split(":")[0]; From 3e95ed541f43b52d701247d2fca83554edfd1d9e Mon Sep 17 00:00:00 2001 From: George Hafiz Date: Tue, 25 Mar 2014 21:19:53 +0000 Subject: [PATCH 5/8] Fixes to incorrect merge handling (basically missing commas needed to continue method definitions). Signed-off-by: George Hafiz --- extension/options.js | 6 +++++- extension/preferences.js | 2 +- extension/{ => resources}/jquery/js/URI.js | 0 3 files changed, 6 insertions(+), 2 deletions(-) rename extension/{ => resources}/jquery/js/URI.js (100%) diff --git a/extension/options.js b/extension/options.js index e904100..f8bf305 100644 --- a/extension/options.js +++ b/extension/options.js @@ -18,13 +18,17 @@ webpg.options = { browserWindow - The Window object housing firefoxOverlay.xul or thunderbirdOverlay.xul in Mozilla applications - not passed in Google Chrome */ - init: function(browserWindow) { + init: function(browserWindow) + { var _ = webpg.utils.i18n.gettext; document.title = _("WebPG Options"); document.dir = (webpg.utils.isRTL() ? 'rtl' : 'ltr'); if (webpg.utils.detectedBrowser.vendor == "mozilla") + { webpg.plugin = browserWindow.webpg.plugin; + } else if (webpg.utils.detectedBrowser.product == "chrome") + { webpg.plugin = chrome.extension.getBackgroundPage().webpg.plugin; } diff --git a/extension/preferences.js b/extension/preferences.js index cf2e8e3..18df886 100644 --- a/extension/preferences.js +++ b/extension/preferences.js @@ -695,7 +695,7 @@ webpg.preferences = { set: function(data) { webpg.localStorage.setItem('xoauth2_data', JSON.stringify(data)); } - } + }, /* Class: webpg.preferences.site_exceptions diff --git a/extension/jquery/js/URI.js b/extension/resources/jquery/js/URI.js similarity index 100% rename from extension/jquery/js/URI.js rename to extension/resources/jquery/js/URI.js From b5ae703515d5cae8efe204f9ee440fdfab8fbb94 Mon Sep 17 00:00:00 2001 From: George Hafiz Date: Tue, 25 Mar 2014 21:43:30 +0000 Subject: [PATCH 6/8] Moved URI.js If test logic - platform should be set exclusively. Signed-off-by: George Hafiz --- extension/options.html | 2 +- extension/options.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extension/options.html b/extension/options.html index ee410e0..bdc4e21 100644 --- a/extension/options.html +++ b/extension/options.html @@ -5,7 +5,7 @@ - + diff --git a/extension/options.js b/extension/options.js index f8bf305..0715c95 100644 --- a/extension/options.js +++ b/extension/options.js @@ -49,7 +49,7 @@ webpg.options = { if (pf == "Win") { platform = "-mswindows"; } - if (pf == "Mac") { + else if (pf == "Mac") { platform = "-macosx"; } if (webpg.plugin && webpg.plugin.valid) { From 3bc0eefbe23c8c9f7c6ac908002e59cd8a5f12ab Mon Sep 17 00:00:00 2001 From: George Hafiz Date: Wed, 26 Mar 2014 22:05:41 +0000 Subject: [PATCH 7/8] - Add new tryParseJSON utility, which unpacks a JSON string or false. - Don't auto unique the exceptions lists, let the user worry about that. - Validate the URI a bit, reject nonsense URIs (eg ftp://). - Load existing user exceptions when starting up. Signed-off-by: George Hafiz --- extension/options.js | 23 ++++++++++++++++++++--- extension/preferences.js | 7 ++++--- extension/utils.js | 25 +++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/extension/options.js b/extension/options.js index 0715c95..8161e80 100644 --- a/extension/options.js +++ b/extension/options.js @@ -555,18 +555,35 @@ webpg.options = { // Site exceptions stuff - /* webpg.jq("#site-whitelist-list").html( + webpg.jq("#site-whitelist-list").html( '' ); webpg.jq("#site-blacklist-list").html( '' - ); */ + ); webpg.jq("#site-whitelist-add").click(function() { var site_input = webpg.jq(this).siblings('input[type=text]'); if (site_input.val() != "") { + // Validate before adding var site_URI = new URI(site_input.val()); - webpg.preferences.site_exceptions.add('whitelist', site_input.val()); + if (site_URI.scheme().length == 0) + site_URI.scheme('http'); + + // At least path (eg google.com) and http(s) is expected of the URI + if (site_URI.scheme() != "http" && site_URI.scheme() != "https") + { + alert('Invalid URI scheme'); + return; + } + + if (site_URI.path().length == 0) + { + alert('Invalid URI'); + return; + } + + webpg.preferences.site_exceptions.add('whitelist', site_URI.toString()); var site_exceptions = webpg.preferences.site_exceptions.get(); webpg.jq('#site-whitelist-list').html(''); } diff --git a/extension/preferences.js b/extension/preferences.js index 18df886..d3c485f 100644 --- a/extension/preferences.js +++ b/extension/preferences.js @@ -704,7 +704,8 @@ webpg.preferences = { site_exceptions: { get: function() { var stored_data = webpg.localStorage.getItem('site_exceptions'); - return (stored_data && stored_data.length > 1) ? JSON.parse(stored_data) : { whitelist: [], blacklist: [] }; + var site_exceptions = webpg.utils.tryParseJSON(stored_data); + return (site_exceptions) ? site_exceptions : { whitelist: [], blacklist: [] }; }, add: function(type, site) { @@ -720,7 +721,7 @@ webpg.preferences = { alert("Code error in site_exceptions preference handler."); } - return webpg.localStorage.setItem('site_exceptions', JSON.stringify(webpg.utils.unique(site_exceptions))); + return webpg.localStorage.setItem('site_exceptions', JSON.stringify(site_exceptions)); }, remove: function(type, site) { @@ -736,7 +737,7 @@ webpg.preferences = { alert("Code error in site_exceptions preference handler."); } - return webpg.localStorage.setItem('site_exceptions', JSON.stringify(webpg.utils.unique(site_exceptions))); + return webpg.localStorage.setItem('site_exceptions', JSON.stringify(site_exceptions)); }, }, diff --git a/extension/utils.js b/extension/utils.js index 41f7bd6..d005518 100644 --- a/extension/utils.js +++ b/extension/utils.js @@ -187,6 +187,31 @@ webpg.utils = { 'anchor': result[12] }; }, + + /* + Function: tryParseJSON + Returns an object containing parsed JSON, false otherwise + + Parameters: + json - The JSON to try and parse + + Returns: + - An object of the parsed JSON (false on failure) + */ + tryParseJSON: function(jsonString){ + try { + var o = JSON.parse(jsonString); + + // Handle non-exception-throwing cases: + //JSON.parse(null) returns 'null', and typeof null === "object" + if (o && typeof o === "object" && o !== null) { + return o; + } + } + catch (e) { } + + return false; + }, /* Function: unique From 823e2183f5e5494961a754359d04a7763c61cb19 Mon Sep 17 00:00:00 2001 From: George Hafiz Date: Thu, 27 Mar 2014 20:24:33 +0000 Subject: [PATCH 8/8] Whitelisting is functional. REGRESSION WARNING: WebPG no longer rechecks the page for PGP to parse on SCROLL event. The way it's currently implemented makes it bypass exceptions checking. Signed-off-by: George Hafiz --- extension/background.js | 2 ++ extension/inline.js | 2 +- extension/options.html | 9 +++++++++ extension/options.js | 9 +++++++++ extension/preferences.js | 7 +++++++ extension/webpg_overlay.js | 31 ++++++++++++++++++++++++++----- 6 files changed, 54 insertions(+), 6 deletions(-) diff --git a/extension/background.js b/extension/background.js index c27abfa..12a717d 100644 --- a/extension/background.js +++ b/extension/background.js @@ -187,6 +187,8 @@ webpg.background = { webpg.preferences.decorate_inline.get(), 'mode': webpg.preferences.decorate_inline.mode(), 'render_toolbar': (webpg.preferences.render_toolbar.get() === "true"), + 'filtering_mode': webpg.preferences.site_exceptions.mode(), + 'site_exceptions': webpg.preferences.site_exceptions.get(), }; break; diff --git a/extension/inline.js b/extension/inline.js index 7994669..5190e7c 100644 --- a/extension/inline.js +++ b/extension/inline.js @@ -248,7 +248,7 @@ webpg.inline = { } return true; }); - + if (!proceed) return false; diff --git a/extension/options.html b/extension/options.html index bdc4e21..36885cf 100644 --- a/extension/options.html +++ b/extension/options.html @@ -275,6 +275,15 @@
          +
          + Filtering Mode + + + + + + +
          Whitelist diff --git a/extension/options.js b/extension/options.js index 8161e80..1ad6160 100644 --- a/extension/options.js +++ b/extension/options.js @@ -562,6 +562,15 @@ webpg.options = { '' ); + webpg.jq("input[name=site-filtering-mode]") + .filter('[value=' + webpg.preferences.site_exceptions.mode() + ']') + .attr('checked', 'checked'); + + webpg.jq("input[name=site-filtering-mode]").change(function() { + var filter_mode = webpg.jq("input[name=site-filtering-mode]:checked").val(); + webpg.preferences.site_exceptions.mode(filter_mode); + }); + webpg.jq("#site-whitelist-add").click(function() { var site_input = webpg.jq(this).siblings('input[type=text]'); if (site_input.val() != "") { diff --git a/extension/preferences.js b/extension/preferences.js index d3c485f..bbea8b9 100644 --- a/extension/preferences.js +++ b/extension/preferences.js @@ -739,6 +739,13 @@ webpg.preferences = { return webpg.localStorage.setItem('site_exceptions', JSON.stringify(site_exceptions)); }, + + mode: function(value) { + if (!value) + return webpg.localStorage.getItem('site_filtering_mode'); + + return webpg.localStorage.setItem('site_filtering_mode', value); + } }, }; diff --git a/extension/webpg_overlay.js b/extension/webpg_overlay.js index 21ba75e..bb4d289 100644 --- a/extension/webpg_overlay.js +++ b/extension/webpg_overlay.js @@ -119,15 +119,36 @@ webpg.overlay = { } }; // Check if inline formatting is enabled and setup - // required parsers + // required parsers webpg.utils.sendRequest({ 'msg': "decorate_inline" }, function(response) { webpg.overlay.decorate_inline = response.result.decorate_inline; - if (webpg.overlay.decorate_inline === 'true') { + if (webpg.overlay.decorate_inline === 'true') + { + var filtering_mode = response.result.filtering_mode; + if (filtering_mode != "off") + { + var site_exceptions = response.result.site_exceptions; + var this_uri = webpg.doc.location.href; + //this_uri.normalize(); + + if (filtering_mode == "deny-allow") { + // Must be in the whitelist to continue + if (!(site_exceptions.whitelist.indexOf(this_uri) > -1)) + return; + } + else if (filtering_mode == "allow-deny") { + // Only stop if in blacklist + if (site_exceptions.blacklist.indexOf(this_uri) > -1) + return; + } + } + webpg.inline.mode = response.result.mode; webpg.inline.render_toolbar = response.result.render_toolbar; - if (webpg.utils.detectedBrowser.vendor === 'mozilla') { + if (webpg.utils.detectedBrowser.vendor === 'mozilla') + { if (typeof(browserWindow)==='undefined') browserWindow = webpg.utils.mozilla.getChromeWindow(); if (!webpg.plugin) @@ -642,10 +663,10 @@ if (webpg.utils.detectedBrowser.vendor === 'mozilla') { } else { webpg.appcontent = document.getElementById("appcontent") || document; webpg.appcontent.addEventListener("DOMContentLoaded", webpg.overlay.init, false); - webpg.appcontent.addEventListener("scroll", webpg.overlay.executeInline, true); + //webpg.appcontent.addEventListener("scroll", webpg.overlay.executeInline, true); } } else { webpg.overlay.init(); - window.addEventListener("scroll", webpg.overlay.executeInline, true); + //window.addEventListener("scroll", webpg.overlay.executeInline, true); } /* ]]> */