Bug 1314361: Part 7a - Strip addonId from existing DOMStorage origin attributes. r=mayhemer
MozReview-Commit-ID: 3c0n7DxDBch
--- a/dom/storage/StorageDBThread.cpp
+++ b/dom/storage/StorageDBThread.cpp
@@ -33,17 +33,17 @@
// before they are flushed to the database
// In milliseconds.
#define FLUSHING_INTERVAL_MS 5000
// Write Ahead Log's maximum size is 512KB
#define MAX_WAL_SIZE_BYTES 512 * 1024
// Current version of the database schema
-#define CURRENT_SCHEMA_VERSION 1
+#define CURRENT_SCHEMA_VERSION 2
namespace mozilla {
namespace dom {
namespace { // anon
// This is only a compatibility code for schema version 0. Returns the 'scope'
// key in the schema version 0 format for the scope column.
--- a/dom/storage/StorageDBUpdater.cpp
+++ b/dom/storage/StorageDBUpdater.cpp
@@ -11,17 +11,17 @@
#include "mozIStorageValueArray.h"
#include "mozIStorageFunction.h"
#include "mozilla/BasePrincipal.h"
#include "nsVariant.h"
#include "mozilla/Services.h"
#include "mozilla/Tokenizer.h"
// Current version of the database schema
-#define CURRENT_SCHEMA_VERSION 1
+#define CURRENT_SCHEMA_VERSION 2
namespace mozilla {
namespace dom {
extern void
ReverseString(const nsCSubstring& aSource, nsCSubstring& aResult);
namespace {
@@ -192,16 +192,57 @@ GetOriginParticular::OnFunctionCall(
}
NS_ENSURE_SUCCESS(rv, rv);
outVar.forget(aResult);
return NS_OK;
}
+class StripOriginAddonId final : public mozIStorageFunction
+{
+public:
+ explicit StripOriginAddonId() {}
+
+private:
+ ~StripOriginAddonId() {}
+
+ NS_DECL_ISUPPORTS
+ NS_DECL_MOZISTORAGEFUNCTION
+};
+
+NS_IMPL_ISUPPORTS(StripOriginAddonId, mozIStorageFunction)
+
+NS_IMETHODIMP
+StripOriginAddonId::OnFunctionCall(
+ mozIStorageValueArray* aFunctionArguments, nsIVariant** aResult)
+{
+ nsresult rv;
+
+ nsAutoCString suffix;
+ rv = aFunctionArguments->GetUTF8String(0, suffix);
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ // Deserialize and re-serialize to automatically drop any obsolete origin
+ // attributes.
+ OriginAttributes oa;
+ bool ok = oa.PopulateFromSuffix(suffix);
+ NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);
+
+ nsAutoCString newSuffix;
+ oa.CreateSuffix(newSuffix);
+
+ nsCOMPtr<nsIWritableVariant> outVar = new nsVariant();
+ rv = outVar->SetAsAUTF8String(newSuffix);
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ outVar.forget(aResult);
+ return NS_OK;
+}
+
} // namespace
namespace StorageDBUpdater {
nsresult CreateSchema1Tables(mozIStorageConnection *aWorkerConnection)
{
nsresult rv;
@@ -386,16 +427,35 @@ nsresult Update(mozIStorageConnection *a
aWorkerConnection->RemoveFunction(NS_LITERAL_CSTRING("GET_ORIGIN_SUFFIX"));
aWorkerConnection->RemoveFunction(NS_LITERAL_CSTRING("GET_ORIGIN_KEY"));
rv = aWorkerConnection->SetSchemaVersion(1);
NS_ENSURE_SUCCESS(rv, rv);
MOZ_FALLTHROUGH;
}
+ case 1: {
+ nsCOMPtr<mozIStorageFunction> oaStripAddonId(
+ new StripOriginAddonId());
+ rv = aWorkerConnection->CreateFunction(NS_LITERAL_CSTRING("STRIP_ADDON_ID"), 1, oaStripAddonId);
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ rv = aWorkerConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+ "UPDATE webappsstore2 "
+ "SET originAttributes = STRIP_ADDON_ID(originAttributes) "
+ "WHERE originAttributes LIKE '^%'"));
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ aWorkerConnection->RemoveFunction(NS_LITERAL_CSTRING("STRIP_ADDON_ID"));
+
+ rv = aWorkerConnection->SetSchemaVersion(2);
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ MOZ_FALLTHROUGH;
+ }
case CURRENT_SCHEMA_VERSION:
// Ensure the tables and indexes are up. This is mostly a no-op
// in common scenarios.
rv = CreateSchema1Tables(aWorkerConnection);
NS_ENSURE_SUCCESS(rv, rv);
// Nothing more to do here, this is the current schema version
break;