summaryrefslogtreecommitdiffstats
path: root/Source/WebKit/mac/Storage
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebKit/mac/Storage')
-rw-r--r--Source/WebKit/mac/Storage/WebDatabaseManager.mm149
-rw-r--r--Source/WebKit/mac/Storage/WebDatabaseManagerInternal.h33
-rw-r--r--Source/WebKit/mac/Storage/WebDatabaseManagerPrivate.h68
-rw-r--r--Source/WebKit/mac/Storage/WebDatabaseQuotaManager.h32
-rw-r--r--Source/WebKit/mac/Storage/WebDatabaseQuotaManager.mm78
-rw-r--r--Source/WebKit/mac/Storage/WebDatabaseTrackerClient.h44
-rw-r--r--Source/WebKit/mac/Storage/WebDatabaseTrackerClient.mm112
-rw-r--r--Source/WebKit/mac/Storage/WebStorageManager.mm113
-rw-r--r--Source/WebKit/mac/Storage/WebStorageManagerInternal.h30
-rw-r--r--Source/WebKit/mac/Storage/WebStorageManagerPrivate.h45
-rw-r--r--Source/WebKit/mac/Storage/WebStorageTrackerClient.h45
-rw-r--r--Source/WebKit/mac/Storage/WebStorageTrackerClient.mm82
12 files changed, 831 insertions, 0 deletions
diff --git a/Source/WebKit/mac/Storage/WebDatabaseManager.mm b/Source/WebKit/mac/Storage/WebDatabaseManager.mm
new file mode 100644
index 0000000..8c5e8a2
--- /dev/null
+++ b/Source/WebKit/mac/Storage/WebDatabaseManager.mm
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "WebDatabaseManagerPrivate.h"
+#import "WebDatabaseManagerInternal.h"
+
+#if ENABLE(DATABASE)
+
+#import "WebDatabaseTrackerClient.h"
+#import "WebSecurityOriginInternal.h"
+
+#import <WebCore/DatabaseTracker.h>
+#import <WebCore/SecurityOrigin.h>
+
+using namespace WebCore;
+
+NSString *WebDatabaseDirectoryDefaultsKey = @"WebDatabaseDirectory";
+
+NSString *WebDatabaseDisplayNameKey = @"WebDatabaseDisplayNameKey";
+NSString *WebDatabaseExpectedSizeKey = @"WebDatabaseExpectedSizeKey";
+NSString *WebDatabaseUsageKey = @"WebDatabaseUsageKey";
+
+NSString *WebDatabaseDidModifyOriginNotification = @"WebDatabaseDidModifyOriginNotification";
+NSString *WebDatabaseDidModifyDatabaseNotification = @"WebDatabaseDidModifyDatabaseNotification";
+NSString *WebDatabaseIdentifierKey = @"WebDatabaseIdentifierKey";
+
+static NSString *databasesDirectoryPath();
+
+@implementation WebDatabaseManager
+
++ (WebDatabaseManager *) sharedWebDatabaseManager
+{
+ static WebDatabaseManager *sharedManager = [[WebDatabaseManager alloc] init];
+ return sharedManager;
+}
+
+- (NSArray *)origins
+{
+ Vector<RefPtr<SecurityOrigin> > coreOrigins;
+ DatabaseTracker::tracker().origins(coreOrigins);
+ NSMutableArray *webOrigins = [[NSMutableArray alloc] initWithCapacity:coreOrigins.size()];
+
+ for (unsigned i = 0; i < coreOrigins.size(); ++i) {
+ WebSecurityOrigin *webOrigin = [[WebSecurityOrigin alloc] _initWithWebCoreSecurityOrigin:coreOrigins[i].get()];
+ [webOrigins addObject:webOrigin];
+ [webOrigin release];
+ }
+
+ return [webOrigins autorelease];
+}
+
+- (NSArray *)databasesWithOrigin:(WebSecurityOrigin *)origin
+{
+ Vector<String> nameVector;
+ if (!DatabaseTracker::tracker().databaseNamesForOrigin([origin _core], nameVector))
+ return nil;
+
+ NSMutableArray *names = [[NSMutableArray alloc] initWithCapacity:nameVector.size()];
+
+ for (unsigned i = 0; i < nameVector.size(); ++i)
+ [names addObject:(NSString *)nameVector[i]];
+
+ return [names autorelease];
+}
+
+- (NSDictionary *)detailsForDatabase:(NSString *)databaseIdentifier withOrigin:(WebSecurityOrigin *)origin
+{
+ static id keys[3] = {WebDatabaseDisplayNameKey, WebDatabaseExpectedSizeKey, WebDatabaseUsageKey};
+
+ DatabaseDetails details = DatabaseTracker::tracker().detailsForNameAndOrigin(databaseIdentifier, [origin _core]);
+ if (details.name().isNull())
+ return nil;
+
+ id objects[3];
+ objects[0] = details.displayName().isEmpty() ? databaseIdentifier : (NSString *)details.displayName();
+ objects[1] = [NSNumber numberWithUnsignedLongLong:details.expectedUsage()];
+ objects[2] = [NSNumber numberWithUnsignedLongLong:details.currentUsage()];
+
+ return [[[NSDictionary alloc] initWithObjects:objects forKeys:keys count:3] autorelease];
+}
+
+- (void)deleteAllDatabases
+{
+ DatabaseTracker::tracker().deleteAllDatabases();
+}
+
+- (BOOL)deleteOrigin:(WebSecurityOrigin *)origin
+{
+ return DatabaseTracker::tracker().deleteOrigin([origin _core]);
+}
+
+- (BOOL)deleteDatabase:(NSString *)databaseIdentifier withOrigin:(WebSecurityOrigin *)origin
+{
+ return DatabaseTracker::tracker().deleteDatabase([origin _core], databaseIdentifier);
+}
+
+@end
+
+static NSString *databasesDirectoryPath()
+{
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+ NSString *databasesDirectory = [defaults objectForKey:WebDatabaseDirectoryDefaultsKey];
+ if (!databasesDirectory || ![databasesDirectory isKindOfClass:[NSString class]])
+ databasesDirectory = @"~/Library/WebKit/Databases";
+
+ return [databasesDirectory stringByStandardizingPath];
+}
+
+void WebKitInitializeDatabasesIfNecessary()
+{
+ static BOOL initialized = NO;
+ if (initialized)
+ return;
+
+ // Set the database root path in WebCore
+ DatabaseTracker::initializeTracker(databasesDirectoryPath());
+
+ // Set the DatabaseTrackerClient
+ DatabaseTracker::tracker().setClient(WebDatabaseTrackerClient::sharedWebDatabaseTrackerClient());
+
+ initialized = YES;
+}
+
+#endif
diff --git a/Source/WebKit/mac/Storage/WebDatabaseManagerInternal.h b/Source/WebKit/mac/Storage/WebDatabaseManagerInternal.h
new file mode 100644
index 0000000..6a4ad1d
--- /dev/null
+++ b/Source/WebKit/mac/Storage/WebDatabaseManagerInternal.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2007 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if ENABLE(DATABASE)
+
+void WebKitInitializeDatabasesIfNecessary();
+
+#endif
diff --git a/Source/WebKit/mac/Storage/WebDatabaseManagerPrivate.h b/Source/WebKit/mac/Storage/WebDatabaseManagerPrivate.h
new file mode 100644
index 0000000..94d8109
--- /dev/null
+++ b/Source/WebKit/mac/Storage/WebDatabaseManagerPrivate.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if ENABLE(DATABASE)
+
+extern NSString *WebDatabaseDirectoryDefaultsKey;
+
+extern NSString *WebDatabaseDisplayNameKey;
+extern NSString *WebDatabaseExpectedSizeKey;
+extern NSString *WebDatabaseUsageKey;
+
+// Posted with an origin is created from scratch, gets a new database, has a database deleted, has a quota change, etc
+// The notification object will be a WebSecurityOrigin object corresponding to the origin.
+extern NSString *WebDatabaseDidModifyOriginNotification;
+
+// Posted when a database is created, its size increases, its display name changes, or its estimated size changes, or the database is removed
+// The notification object will be a WebSecurityOrigin object corresponding to the origin.
+// The notification userInfo will have a WebDatabaseNameKey whose value is the database name.
+extern NSString *WebDatabaseDidModifyDatabaseNotification;
+extern NSString *WebDatabaseIdentifierKey;
+
+@class WebSecurityOrigin;
+
+@interface WebDatabaseManager : NSObject
+
++ (WebDatabaseManager *)sharedWebDatabaseManager;
+
+// Will return an array of WebSecurityOrigin objects.
+- (NSArray *)origins;
+
+// Will return an array of strings, the identifiers of each database in the given origin.
+- (NSArray *)databasesWithOrigin:(WebSecurityOrigin *)origin;
+
+// Will return the dictionary describing everything about the database for the passed identifier and origin.
+- (NSDictionary *)detailsForDatabase:(NSString *)databaseIdentifier withOrigin:(WebSecurityOrigin *)origin;
+
+- (void)deleteAllDatabases; // Deletes all databases and all origins.
+- (BOOL)deleteOrigin:(WebSecurityOrigin *)origin;
+- (BOOL)deleteDatabase:(NSString *)databaseIdentifier withOrigin:(WebSecurityOrigin *)origin;
+
+@end
+
+#endif
diff --git a/Source/WebKit/mac/Storage/WebDatabaseQuotaManager.h b/Source/WebKit/mac/Storage/WebDatabaseQuotaManager.h
new file mode 100644
index 0000000..8219da4
--- /dev/null
+++ b/Source/WebKit/mac/Storage/WebDatabaseQuotaManager.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "WebQuotaManager.h"
+
+@interface WebDatabaseQuotaManager : NSObject <WebQuotaManager> {
+ WebSecurityOrigin *_origin;
+}
+
+@end
diff --git a/Source/WebKit/mac/Storage/WebDatabaseQuotaManager.mm b/Source/WebKit/mac/Storage/WebDatabaseQuotaManager.mm
new file mode 100644
index 0000000..e26ae33
--- /dev/null
+++ b/Source/WebKit/mac/Storage/WebDatabaseQuotaManager.mm
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2007, 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "WebDatabaseQuotaManager.h"
+
+#import "WebSecurityOriginInternal.h"
+#import <WebCore/DatabaseTracker.h>
+
+using namespace WebCore;
+
+@implementation WebDatabaseQuotaManager
+
+- (id)initWithOrigin:(WebSecurityOrigin *)origin
+{
+ self = [super init];
+ if (!self)
+ return nil;
+
+ _origin = origin;
+ return self;
+}
+
+- (WebSecurityOrigin *)origin
+{
+ return _origin;
+}
+
+- (unsigned long long)usage
+{
+#if ENABLE(DATABASE)
+ return DatabaseTracker::tracker().usageForOrigin([_origin _core]);
+#else
+ return 0;
+#endif
+}
+
+- (unsigned long long)quota
+{
+#if ENABLE(DATABASE)
+ return DatabaseTracker::tracker().quotaForOrigin([_origin _core]);
+#else
+ return 0;
+#endif
+}
+
+// If the quota is set to a value lower than the current usage, that quota will
+// "stick" but no data will be purged to meet the new quota. This will simply
+// prevent new data from being added to databases in that origin.
+- (void)setQuota:(unsigned long long)quota
+{
+#if ENABLE(DATABASE)
+ DatabaseTracker::tracker().setQuota([_origin _core], quota);
+#endif
+}
+
+@end
diff --git a/Source/WebKit/mac/Storage/WebDatabaseTrackerClient.h b/Source/WebKit/mac/Storage/WebDatabaseTrackerClient.h
new file mode 100644
index 0000000..cbb5eb7
--- /dev/null
+++ b/Source/WebKit/mac/Storage/WebDatabaseTrackerClient.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2007 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if ENABLE(DATABASE)
+
+#import <WebCore/DatabaseTrackerClient.h>
+
+class WebDatabaseTrackerClient : public WebCore::DatabaseTrackerClient {
+public:
+ static WebDatabaseTrackerClient* sharedWebDatabaseTrackerClient();
+
+ virtual ~WebDatabaseTrackerClient();
+ virtual void dispatchDidModifyOrigin(WebCore::SecurityOrigin*);
+ virtual void dispatchDidModifyDatabase(WebCore::SecurityOrigin*, const WTF::String& databaseIdentifier);
+private:
+ WebDatabaseTrackerClient();
+};
+
+#endif
diff --git a/Source/WebKit/mac/Storage/WebDatabaseTrackerClient.mm b/Source/WebKit/mac/Storage/WebDatabaseTrackerClient.mm
new file mode 100644
index 0000000..65aba43
--- /dev/null
+++ b/Source/WebKit/mac/Storage/WebDatabaseTrackerClient.mm
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2007 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "WebDatabaseTrackerClient.h"
+
+#if ENABLE(DATABASE)
+
+#import "WebDatabaseManagerPrivate.h"
+#import "WebSecurityOriginInternal.h"
+#import <wtf/MainThread.h>
+#import <wtf/RetainPtr.h>
+#import <WebCore/SecurityOrigin.h>
+
+using namespace WebCore;
+
+WebDatabaseTrackerClient* WebDatabaseTrackerClient::sharedWebDatabaseTrackerClient()
+{
+ static WebDatabaseTrackerClient* sharedClient = new WebDatabaseTrackerClient();
+ return sharedClient;
+}
+
+WebDatabaseTrackerClient::WebDatabaseTrackerClient()
+{
+}
+
+WebDatabaseTrackerClient::~WebDatabaseTrackerClient()
+{
+}
+
+class DidModifyOriginData {
+ WTF_MAKE_NONCOPYABLE(DidModifyOriginData);
+public:
+ static void dispatchToMainThread(WebDatabaseTrackerClient* client, SecurityOrigin* origin)
+ {
+ DidModifyOriginData* context = new DidModifyOriginData(client, origin->threadsafeCopy());
+ callOnMainThread(&DidModifyOriginData::dispatchDidModifyOriginOnMainThread, context);
+ }
+
+private:
+ DidModifyOriginData(WebDatabaseTrackerClient* client, PassRefPtr<SecurityOrigin> origin)
+ : client(client)
+ , origin(origin)
+ {
+ }
+
+ static void dispatchDidModifyOriginOnMainThread(void* context)
+ {
+ ASSERT(isMainThread());
+ DidModifyOriginData* info = static_cast<DidModifyOriginData*>(context);
+ info->client->dispatchDidModifyOrigin(info->origin.get());
+ delete info;
+ }
+
+ WebDatabaseTrackerClient* client;
+ RefPtr<SecurityOrigin> origin;
+};
+
+void WebDatabaseTrackerClient::dispatchDidModifyOrigin(SecurityOrigin* origin)
+{
+ if (!isMainThread()) {
+ DidModifyOriginData::dispatchToMainThread(this, origin);
+ return;
+ }
+
+ RetainPtr<WebSecurityOrigin> webSecurityOrigin(AdoptNS, [[WebSecurityOrigin alloc] _initWithWebCoreSecurityOrigin:origin]);
+
+ [[NSNotificationCenter defaultCenter] postNotificationName:WebDatabaseDidModifyOriginNotification
+ object:webSecurityOrigin.get()];
+}
+
+void WebDatabaseTrackerClient::dispatchDidModifyDatabase(SecurityOrigin* origin, const String& databaseIdentifier)
+{
+ if (!isMainThread()) {
+ DidModifyOriginData::dispatchToMainThread(this, origin);
+ return;
+ }
+
+ RetainPtr<WebSecurityOrigin> webSecurityOrigin(AdoptNS, [[WebSecurityOrigin alloc] _initWithWebCoreSecurityOrigin:origin]);
+ RetainPtr<NSDictionary> userInfo(AdoptNS, [[NSDictionary alloc]
+ initWithObjectsAndKeys:(NSString *)databaseIdentifier, WebDatabaseIdentifierKey, nil]);
+
+ [[NSNotificationCenter defaultCenter] postNotificationName:WebDatabaseDidModifyDatabaseNotification
+ object:webSecurityOrigin.get()
+ userInfo:userInfo.get()];
+}
+
+#endif
diff --git a/Source/WebKit/mac/Storage/WebStorageManager.mm b/Source/WebKit/mac/Storage/WebStorageManager.mm
new file mode 100644
index 0000000..23f699f
--- /dev/null
+++ b/Source/WebKit/mac/Storage/WebStorageManager.mm
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if ENABLE(DOM_STORAGE)
+
+#import "WebSecurityOriginInternal.h"
+#import "WebStorageManagerPrivate.h"
+#import "WebStorageManagerInternal.h"
+#import "WebStorageTrackerClient.h"
+
+#import <WebCore/SecurityOrigin.h>
+#import <WebCore/StorageTracker.h>
+
+using namespace WebCore;
+
+NSString * const WebStorageDirectoryDefaultsKey = @"WebKitLocalStorageDatabasePathPreferenceKey";
+NSString * const WebStorageDidModifyOriginNotification = @"WebStorageDidModifyOriginNotification";
+
+static NSString *storageDirectoryPath();
+
+@implementation WebStorageManager
+
++ (WebStorageManager *)sharedWebStorageManager
+{
+ static WebStorageManager *sharedManager = [[WebStorageManager alloc] init];
+ return sharedManager;
+}
+
+- (NSArray *)origins
+{
+ Vector<RefPtr<SecurityOrigin> > coreOrigins;
+
+ StorageTracker::tracker().origins(coreOrigins);
+
+ NSMutableArray *webOrigins = [[NSMutableArray alloc] initWithCapacity:coreOrigins.size()];
+
+ for (size_t i = 0; i < coreOrigins.size(); ++i) {
+ WebSecurityOrigin *webOrigin = [[WebSecurityOrigin alloc] _initWithWebCoreSecurityOrigin:coreOrigins[i].get()];
+ [webOrigins addObject:webOrigin];
+ [webOrigin release];
+ }
+
+ return [webOrigins autorelease];
+}
+
+- (void)deleteAllOrigins
+{
+ StorageTracker::tracker().deleteAllOrigins();
+}
+
+- (void)deleteOrigin:(WebSecurityOrigin *)origin
+{
+ StorageTracker::tracker().deleteOrigin([origin _core]);
+}
+
+- (void)syncLocalStorage
+{
+ StorageTracker::tracker().syncLocalStorage();
+}
+
+- (void)syncFileSystemAndTrackerDatabase
+{
+ StorageTracker::tracker().syncFileSystemAndTrackerDatabase();
+}
+
+static NSString *storageDirectoryPath()
+{
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+ NSString *storageDirectory = [defaults objectForKey:WebStorageDirectoryDefaultsKey];
+ if (!storageDirectory || ![storageDirectory isKindOfClass:[NSString class]])
+ storageDirectory = @"~/Library/WebKit/LocalStorage";
+
+ return [storageDirectory stringByStandardizingPath];
+}
+
+void WebKitInitializeStorageIfNecessary()
+{
+ static BOOL initialized = NO;
+ if (initialized)
+ return;
+
+ StorageTracker::initializeTracker(storageDirectoryPath());
+
+ StorageTracker::tracker().setClient(WebStorageTrackerClient::sharedWebStorageTrackerClient());
+
+ initialized = YES;
+}
+
+@end
+
+#endif
diff --git a/Source/WebKit/mac/Storage/WebStorageManagerInternal.h b/Source/WebKit/mac/Storage/WebStorageManagerInternal.h
new file mode 100644
index 0000000..d3d3604
--- /dev/null
+++ b/Source/WebKit/mac/Storage/WebStorageManagerInternal.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if ENABLE(DOM_STORAGE)
+
+void WebKitInitializeStorageIfNecessary();
+
+#endif
diff --git a/Source/WebKit/mac/Storage/WebStorageManagerPrivate.h b/Source/WebKit/mac/Storage/WebStorageManagerPrivate.h
new file mode 100644
index 0000000..34db3f6
--- /dev/null
+++ b/Source/WebKit/mac/Storage/WebStorageManagerPrivate.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+extern NSString * const WebStorageDirectoryDefaultsKey;
+extern NSString * const WebStorageDidModifyOriginNotification;
+
+@class WebSecurityOrigin;
+
+@interface WebStorageManager : NSObject
+
++ (WebStorageManager *)sharedWebStorageManager;
+
+// Returns an array of WebSecurityOrigin objects that have LocalStorage.
+- (NSArray *)origins;
+
+- (void)deleteAllOrigins;
+- (void)deleteOrigin:(WebSecurityOrigin *)origin;
+
+- (void)syncLocalStorage;
+- (void)syncFileSystemAndTrackerDatabase;
+
+@end
+
diff --git a/Source/WebKit/mac/Storage/WebStorageTrackerClient.h b/Source/WebKit/mac/Storage/WebStorageTrackerClient.h
new file mode 100644
index 0000000..d3c190c
--- /dev/null
+++ b/Source/WebKit/mac/Storage/WebStorageTrackerClient.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if ENABLE(DOM_STORAGE)
+
+#import <WebCore/SecurityOrigin.h>
+#import <WebCore/StorageTrackerClient.h>
+
+using namespace WebCore;
+
+class WebStorageTrackerClient : public WebCore::StorageTrackerClient {
+public:
+ static WebStorageTrackerClient* sharedWebStorageTrackerClient();
+ static void dispatchDidModifyOriginOnMainThread(void* context);
+
+ virtual ~WebStorageTrackerClient();
+ virtual void dispatchDidModifyOrigin(const String& originIdentifier);
+ virtual void dispatchDidModifyOrigin(PassRefPtr<SecurityOrigin>);
+private:
+ WebStorageTrackerClient();
+};
+
+#endif
diff --git a/Source/WebKit/mac/Storage/WebStorageTrackerClient.mm b/Source/WebKit/mac/Storage/WebStorageTrackerClient.mm
new file mode 100644
index 0000000..01bb981
--- /dev/null
+++ b/Source/WebKit/mac/Storage/WebStorageTrackerClient.mm
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if ENABLE(DOM_STORAGE)
+
+#import "WebStorageTrackerClient.h"
+
+#import "WebSecurityOriginInternal.h"
+#import "WebStorageManagerPrivate.h"
+#import <WebCore/PlatformString.h>
+#import <WebCore/SecurityOrigin.h>
+#import <wtf/MainThread.h>
+#import <wtf/RetainPtr.h>
+
+using namespace WebCore;
+
+WebStorageTrackerClient* WebStorageTrackerClient::sharedWebStorageTrackerClient()
+{
+ static WebStorageTrackerClient* sharedClient = new WebStorageTrackerClient();
+ return sharedClient;
+}
+
+WebStorageTrackerClient::WebStorageTrackerClient()
+{
+}
+
+WebStorageTrackerClient::~WebStorageTrackerClient()
+{
+}
+
+void WebStorageTrackerClient::dispatchDidModifyOriginOnMainThread(void* context)
+{
+ ASSERT(isMainThread());
+ // adoptRef is balanced by leakRef in dispatchDidModifyOrigin.
+ RefPtr<SecurityOrigin> origin = adoptRef(static_cast<SecurityOrigin*>(context));
+ WebStorageTrackerClient::sharedWebStorageTrackerClient()->dispatchDidModifyOrigin(origin.get());
+}
+
+void WebStorageTrackerClient::dispatchDidModifyOrigin(PassRefPtr<SecurityOrigin> origin)
+{
+ RetainPtr<WebSecurityOrigin> webSecurityOrigin(AdoptNS, [[WebSecurityOrigin alloc] _initWithWebCoreSecurityOrigin:origin.get()]);
+
+ [[NSNotificationCenter defaultCenter] postNotificationName:WebStorageDidModifyOriginNotification
+ object:webSecurityOrigin.get()];
+}
+
+void WebStorageTrackerClient::dispatchDidModifyOrigin(const String& originIdentifier)
+{
+ PassRefPtr<SecurityOrigin> origin = SecurityOrigin::createFromDatabaseIdentifier(originIdentifier);
+
+ if (!isMainThread()) {
+ // leakRef is balanced by adoptRef in dispatchDidModifyOriginOnMainThread.
+ callOnMainThread(dispatchDidModifyOriginOnMainThread, origin.leakRef());
+ return;
+ }
+
+ dispatchDidModifyOrigin(origin);
+}
+
+#endif