Merge branch 'develop' into bwindels/bacat-scrolling-merged-develop
This commit is contained in:
commit
adf263c4af
26 changed files with 641 additions and 54 deletions
101
src/utils/StorageManager.js
Normal file
101
src/utils/StorageManager.js
Normal file
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
Copyright 2019 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import Matrix from 'matrix-js-sdk';
|
||||
import Analytics from '../Analytics';
|
||||
|
||||
const localStorage = window.localStorage;
|
||||
|
||||
// just *accessing* indexedDB throws an exception in firefox with
|
||||
// indexeddb disabled.
|
||||
let indexedDB;
|
||||
try {
|
||||
indexedDB = window.indexedDB;
|
||||
} catch (e) {}
|
||||
|
||||
// The JS SDK will add a prefix of "matrix-js-sdk:" to the sync store name.
|
||||
const SYNC_STORE_NAME = "riot-web-sync";
|
||||
const CRYPTO_STORE_NAME = "matrix-js-sdk:crypto";
|
||||
|
||||
function log(msg) {
|
||||
console.log(`StorageManager: ${msg}`);
|
||||
}
|
||||
|
||||
function error(msg) {
|
||||
console.error(`StorageManager: ${msg}`);
|
||||
}
|
||||
|
||||
function track(action) {
|
||||
Analytics.trackEvent("StorageManager", action);
|
||||
}
|
||||
|
||||
export async function checkConsistency() {
|
||||
log("Checking storage consistency");
|
||||
log(`Local storage supported? ${!!localStorage}`);
|
||||
log(`IndexedDB supported? ${!!indexedDB}`);
|
||||
|
||||
let dataInLocalStorage = false;
|
||||
let dataInCryptoStore = false;
|
||||
let healthy = true;
|
||||
|
||||
if (localStorage) {
|
||||
dataInLocalStorage = localStorage.length > 0;
|
||||
log(`Local storage contains data? ${dataInLocalStorage}`);
|
||||
} else {
|
||||
healthy = false;
|
||||
error("Local storage cannot be used on this browser");
|
||||
track("Local storage disabled");
|
||||
}
|
||||
|
||||
if (indexedDB && localStorage) {
|
||||
const dataInSyncStore = await Matrix.IndexedDBStore.exists(
|
||||
indexedDB, SYNC_STORE_NAME,
|
||||
);
|
||||
log(`Sync store contains data? ${dataInSyncStore}`);
|
||||
} else {
|
||||
healthy = false;
|
||||
error("Sync store cannot be used on this browser");
|
||||
track("Sync store disabled");
|
||||
}
|
||||
|
||||
if (indexedDB) {
|
||||
dataInCryptoStore = await Matrix.IndexedDBCryptoStore.exists(
|
||||
indexedDB, CRYPTO_STORE_NAME,
|
||||
);
|
||||
log(`Crypto store contains data? ${dataInCryptoStore}`);
|
||||
} else {
|
||||
healthy = false;
|
||||
error("Crypto store cannot be used on this browser");
|
||||
track("Crypto store disabled");
|
||||
}
|
||||
|
||||
if (dataInLocalStorage && !dataInCryptoStore) {
|
||||
healthy = false;
|
||||
error(
|
||||
"Data exists in local storage but not in crypto store. " +
|
||||
"IndexedDB storage has likely been evicted by the browser!",
|
||||
);
|
||||
track("Crypto store evicted");
|
||||
}
|
||||
|
||||
if (healthy) {
|
||||
log("Storage consistency checks passed");
|
||||
track("Consistency checks passed");
|
||||
} else {
|
||||
error("Storage consistency checks failed");
|
||||
track("Consistency checks failed");
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
Copyright 2017 Vector Creations Ltd
|
||||
Copyright 2018 New Vector Ltd
|
||||
Copyright 2019 Travis Ralston
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -25,6 +26,7 @@ import WidgetEchoStore from '../stores/WidgetEchoStore';
|
|||
// before waitFor[Room/User]Widget rejects its promise
|
||||
const WIDGET_WAIT_TIME = 20000;
|
||||
import SettingsStore from "../settings/SettingsStore";
|
||||
import ActiveWidgetStore from "../stores/ActiveWidgetStore";
|
||||
|
||||
/**
|
||||
* Encodes a URI according to a set of template variables. Variables will be
|
||||
|
@ -396,4 +398,25 @@ export default class WidgetUtils {
|
|||
|
||||
return capWhitelist;
|
||||
}
|
||||
|
||||
static getWidgetSecurityKey(widgetId, widgetUrl, isUserWidget) {
|
||||
let widgetLocation = ActiveWidgetStore.getRoomId(widgetId);
|
||||
|
||||
if (isUserWidget) {
|
||||
const userWidget = WidgetUtils.getUserWidgetsArray()
|
||||
.find((w) => w.id === widgetId && w.content && w.content.url === widgetUrl);
|
||||
|
||||
if (!userWidget) {
|
||||
throw new Error("No matching user widget to form security key");
|
||||
}
|
||||
|
||||
widgetLocation = userWidget.sender;
|
||||
}
|
||||
|
||||
if (!widgetLocation) {
|
||||
throw new Error("Failed to locate where the widget resides");
|
||||
}
|
||||
|
||||
return encodeURIComponent(`${widgetLocation}::${widgetUrl}`);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,27 +32,18 @@ try {
|
|||
* @param {Object} opts options to pass to Matrix.createClient. This will be
|
||||
* extended with `sessionStore` and `store` members.
|
||||
*
|
||||
* @param {bool} useIndexedDb True to attempt to use indexeddb, or false to force
|
||||
* use of the memory store. Default: true.
|
||||
*
|
||||
* @property {string} indexedDbWorkerScript Optional URL for a web worker script
|
||||
* for IndexedDB store operations. By default, indexeddb ops are done on
|
||||
* the main thread.
|
||||
*
|
||||
* @returns {MatrixClient} the newly-created MatrixClient
|
||||
*/
|
||||
export default function createMatrixClient(opts, useIndexedDb) {
|
||||
if (useIndexedDb === undefined) useIndexedDb = true;
|
||||
|
||||
export default function createMatrixClient(opts) {
|
||||
const storeOpts = {
|
||||
useAuthorizationHeader: true,
|
||||
};
|
||||
|
||||
if (localStorage) {
|
||||
storeOpts.sessionStore = new Matrix.WebStorageSessionStore(localStorage);
|
||||
}
|
||||
|
||||
if (indexedDB && localStorage && useIndexedDb) {
|
||||
if (indexedDB && localStorage) {
|
||||
storeOpts.store = new Matrix.IndexedDBStore({
|
||||
indexedDB: indexedDB,
|
||||
dbName: "riot-web-sync",
|
||||
|
@ -61,6 +52,16 @@ export default function createMatrixClient(opts, useIndexedDb) {
|
|||
});
|
||||
}
|
||||
|
||||
if (localStorage) {
|
||||
storeOpts.sessionStore = new Matrix.WebStorageSessionStore(localStorage);
|
||||
}
|
||||
|
||||
if (indexedDB) {
|
||||
storeOpts.cryptoStore = new Matrix.IndexedDBCryptoStore(
|
||||
indexedDB, "matrix-js-sdk:crypto",
|
||||
);
|
||||
}
|
||||
|
||||
opts = Object.assign(storeOpts, opts);
|
||||
|
||||
return Matrix.createClient(opts);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue