Added: trunk/LayoutTests/storage/websql/private-browsing-open-disabled.html (0 => 214309)
--- trunk/LayoutTests/storage/websql/private-browsing-open-disabled.html (rev 0)
+++ trunk/LayoutTests/storage/websql/private-browsing-open-disabled.html 2017-03-23 19:06:31 UTC (rev 214309)
@@ -0,0 +1,23 @@
+<body>
+<div id="logger"></div>
+<script>
+
+if (window.testRunner) {
+ testRunner.dumpAsText();
+ testRunner.waitUntilDone();
+ testRunner.setPrivateBrowsingEnabled(true);
+}
+
+var logger = document.getElementById("logger");
+try {
+ openDatabase("PrivateBrowsingOpenDisabled", "1.0", "Test that you can't open databases in private browsing mode", 1);
+ logger.innerHTML = "Successfully opened a WebSQL database in private browsing"
+} catch(e) {
+ logger.innerHTML = "Caught exception opening a WebSQL database in private browsing: " + e;
+}
+
+if (window.testRunner)
+ testRunner.notifyDone();
+
+</script>
+</body>
Modified: trunk/Source/WebCore/Modules/webdatabase/DatabaseManager.cpp (214308 => 214309)
--- trunk/Source/WebCore/Modules/webdatabase/DatabaseManager.cpp 2017-03-23 18:47:49 UTC (rev 214308)
+++ trunk/Source/WebCore/Modules/webdatabase/DatabaseManager.cpp 2017-03-23 19:06:31 UTC (rev 214309)
@@ -121,10 +121,8 @@
ExceptionOr<Ref<Database>> DatabaseManager::openDatabaseBackend(ScriptExecutionContext& context, const String& name, const String& expectedVersion, const String& displayName, unsigned estimatedSize, bool setVersionInNewDatabase)
{
- auto databaseContext = this->databaseContext(context);
+ auto backend = tryToOpenDatabaseBackend(context, name, expectedVersion, displayName, estimatedSize, setVersionInNewDatabase, FirstTryToOpenDatabase);
- auto backend = tryToOpenDatabaseBackend(databaseContext, name, expectedVersion, displayName, estimatedSize, setVersionInNewDatabase, FirstTryToOpenDatabase);
-
if (backend.hasException()) {
if (backend.exception().code() == QUOTA_EXCEEDED_ERR) {
// Notify the client that we've exceeded the database quota.
@@ -133,9 +131,9 @@
{
// FIXME: What guarantees context.securityOrigin() is non-null?
ProposedDatabase proposedDatabase { *this, *context.securityOrigin(), name, displayName, estimatedSize };
- databaseContext->databaseExceededQuota(name, proposedDatabase.details());
+ this->databaseContext(context)->databaseExceededQuota(name, proposedDatabase.details());
}
- backend = tryToOpenDatabaseBackend(databaseContext, name, expectedVersion, displayName, estimatedSize, setVersionInNewDatabase, RetryOpenDatabase);
+ backend = tryToOpenDatabaseBackend(context, name, expectedVersion, displayName, estimatedSize, setVersionInNewDatabase, RetryOpenDatabase);
}
}
@@ -149,9 +147,22 @@
return backend;
}
-ExceptionOr<Ref<Database>> DatabaseManager::tryToOpenDatabaseBackend(DatabaseContext& backendContext, const String& name, const String& expectedVersion, const String& displayName, unsigned estimatedSize, bool setVersionInNewDatabase,
+ExceptionOr<Ref<Database>> DatabaseManager::tryToOpenDatabaseBackend(ScriptExecutionContext& scriptContext, const String& name, const String& expectedVersion, const String& displayName, unsigned estimatedSize, bool setVersionInNewDatabase,
OpenAttempt attempt)
{
+ if (is<Document>(&scriptContext)) {
+ auto* page = downcast<Document>(scriptContext).page();
+ if (!page || page->usesEphemeralSession())
+ return Exception { SECURITY_ERR };
+ }
+
+ if (scriptContext.isWorkerGlobalScope()) {
+ ASSERT_NOT_REACHED();
+ return Exception { SECURITY_ERR };
+ }
+
+ auto backendContext = this->databaseContext(scriptContext);
+
ExceptionOr<void> preflightResult;
switch (attempt) {
case FirstTryToOpenDatabase:
@@ -171,7 +182,7 @@
return openResult.releaseException();
// FIXME: What guarantees backendContext.securityOrigin() is non-null?
- DatabaseTracker::singleton().setDatabaseDetails(backendContext.securityOrigin(), name, displayName, estimatedSize);
+ DatabaseTracker::singleton().setDatabaseDetails(backendContext->securityOrigin(), name, displayName, estimatedSize);
return WTFMove(database);
}
Modified: trunk/Source/WebCore/Modules/webdatabase/DatabaseManager.h (214308 => 214309)
--- trunk/Source/WebCore/Modules/webdatabase/DatabaseManager.h 2017-03-23 18:47:49 UTC (rev 214308)
+++ trunk/Source/WebCore/Modules/webdatabase/DatabaseManager.h 2017-03-23 19:06:31 UTC (rev 214309)
@@ -76,7 +76,7 @@
enum OpenAttempt { FirstTryToOpenDatabase, RetryOpenDatabase };
ExceptionOr<Ref<Database>> openDatabaseBackend(ScriptExecutionContext&, const String& name, const String& expectedVersion, const String& displayName, unsigned estimatedSize, bool setVersionInNewDatabase);
- static ExceptionOr<Ref<Database>> tryToOpenDatabaseBackend(DatabaseContext&, const String& name, const String& expectedVersion, const String& displayName, unsigned estimatedSize, bool setVersionInNewDatabase, OpenAttempt);
+ ExceptionOr<Ref<Database>> tryToOpenDatabaseBackend(ScriptExecutionContext&, const String& name, const String& expectedVersion, const String& displayName, unsigned estimatedSize, bool setVersionInNewDatabase, OpenAttempt);
class ProposedDatabase;
void addProposedDatabase(ProposedDatabase&);