Merge branch 'master' of github.com:standardnotes/web

This commit is contained in:
Mo Bitar
2017-01-16 18:13:56 -06:00
7 changed files with 30 additions and 13 deletions

View File

@@ -2,7 +2,11 @@
var Neeto = Neeto || {}; var Neeto = Neeto || {};
if(window.crypto.subtle) { // detect IE8 and above, and edge.
// IE and Edge do not support pbkdf2 in WebCrypto, therefore we need to use CryptoJS
var IEOrEdge = document.documentMode || /Edge/.test(navigator.userAgent);
if(!IEOrEdge && (window.crypto && window.crypto.subtle)) {
Neeto.crypto = new SNCryptoWeb(); Neeto.crypto = new SNCryptoWeb();
} else { } else {
Neeto.crypto = new SNCryptoJS(); Neeto.crypto = new SNCryptoJS();

View File

@@ -27,7 +27,12 @@ class Item {
return this.content; return this.content;
} }
return JSON.parse(this.content); try {
return JSON.parse(this.content);
} catch (e) {
console.log("Error parsing json", e);
return {};
}
} }
updateFromJSON(json) { updateFromJSON(json) {

View File

@@ -90,7 +90,7 @@ angular.module('app.frontend')
// if user has high password cost and is using browser that doesn't support WebCrypto, // if user has high password cost and is using browser that doesn't support WebCrypto,
// we want to tell them that they can't login with this browser. // we want to tell them that they can't login with this browser.
if(cost > 5000) { if(cost > 5000) {
return window.crypto.subtle ? true : false; return Neeto.crypto instanceof SNCryptoWeb ? true : false;
} else { } else {
return true; return true;
} }
@@ -581,7 +581,7 @@ angular.module('app.frontend')
item.content = Neeto.crypto.base64Decode(item.content.substring(3, item.content.length)) item.content = Neeto.crypto.base64Decode(item.content.substring(3, item.content.length))
} }
} catch (e) { } catch (e) {
console.log("Error decrypting item", item); console.log("Error decrypting item", item, e);
continue; continue;
} }
} }

View File

@@ -13,7 +13,7 @@ class ExtensionManager {
ext.encrypted = this.extensionUsesEncryptedData(ext); ext.encrypted = this.extensionUsesEncryptedData(ext);
for (var action of ext.actions) { for (var action of ext.actions) {
if(this.enabledRepeatActionUrls.includes(action.url)) { if(_.includes(this.enabledRepeatActionUrls, action.url)) {
this.enableRepeatAction(action, ext); this.enableRepeatAction(action, ext);
} }
} }
@@ -38,7 +38,7 @@ class ExtensionManager {
} }
extensionUsesEncryptedData(extension) { extensionUsesEncryptedData(extension) {
return !this.decryptedExtensions.includes(extension.url); return !_.includes(this.decryptedExtensions, extension.url);
} }
changeExtensionEncryptionFormat(encrypted, extension) { changeExtensionEncryptionFormat(encrypted, extension) {
@@ -174,7 +174,7 @@ class ExtensionManager {
} }
isRepeatActionEnabled(action) { isRepeatActionEnabled(action) {
return this.enabledRepeatActionUrls.includes(action.url); return _.includes(this.enabledRepeatActionUrls, action.url);
} }
disableRepeatAction(action, extension) { disableRepeatAction(action, extension) {

View File

@@ -1,4 +1,4 @@
var subtleCrypto = window.crypto.subtle; var subtleCrypto = window.crypto ? window.crypto.subtle : null;
class SNCryptoWeb extends SNCrypto { class SNCryptoWeb extends SNCrypto {
@@ -89,8 +89,16 @@ class SNCryptoWeb extends SNCrypto {
} }
stringToArrayBuffer(string) { stringToArrayBuffer(string) {
var encoder = new TextEncoder("utf-8"); // not available on Edge/IE
return encoder.encode(string); // var encoder = new TextEncoder("utf-8");
// var result = encoder.encode(string);
var buf = new ArrayBuffer(string.length);
var bufView = new Uint8Array(buf);
for (var i=0, strLen=string.length; i<strLen; i++) {
bufView[i] = string.charCodeAt(i);
}
return buf;
} }
arrayBufferToHexString(arrayBuffer) { arrayBufferToHexString(arrayBuffer) {

View File

@@ -24,7 +24,7 @@ class ModelManager {
allItemsMatchingTypes(contentTypes) { allItemsMatchingTypes(contentTypes) {
return this.items.filter(function(item){ return this.items.filter(function(item){
return (contentTypes.includes(item.content_type) || contentTypes.includes("*")) && !item.dummy; return (_.includes(contentTypes, item.content_type) || _.includes(contentTypes, "*")) && !item.dummy;
}) })
} }
@@ -83,7 +83,7 @@ class ModelManager {
notifyItemChangeObserversOfModels(models) { notifyItemChangeObserversOfModels(models) {
for(var observer of this.itemChangeObservers) { for(var observer of this.itemChangeObservers) {
var relevantItems = models.filter(function(item){ var relevantItems = models.filter(function(item){
return observer.content_types.includes(item.content_type) || observer.content_types.includes("*"); return _.includes(observer.content_types, item.content_type) || _.includes(observer.content_types, "*");
}); });
if(relevantItems.length > 0) { if(relevantItems.length > 0) {

View File

@@ -1,4 +1,4 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!DOCTYPE html>
<html ng-app="app.frontend" ng-controller="BaseCtrl"> <html ng-app="app.frontend" ng-controller="BaseCtrl">
<head> <head>
<meta charset="utf-8"/> <meta charset="utf-8"/>