WebCore/WebCore.xcodeproj/project.pbxproj

829829 51B2417B0D931F3F00E83F5C /* LegacyWebArchiveMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51B2417A0D931F3F00E83F5C /* LegacyWebArchiveMac.mm */; };
830830 51BE37DF0DAEE00E001085FC /* StorageArea.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51BE37DD0DAEE00E001085FC /* StorageArea.cpp */; };
831831 51BE37E00DAEE00E001085FC /* StorageArea.h in Headers */ = {isa = PBXBuildFile; fileRef = 51BE37DE0DAEE00E001085FC /* StorageArea.h */; };
832  51BE38280DAEF7DA001085FC /* LocalStorage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51BE38260DAEF7DA001085FC /* LocalStorage.cpp */; };
833  51BE38290DAEF7DA001085FC /* LocalStorage.h in Headers */ = {isa = PBXBuildFile; fileRef = 51BE38270DAEF7DA001085FC /* LocalStorage.h */; };
 832 51BE38280DAEF7DA001085FC /* StorageNamespace.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51BE38260DAEF7DA001085FC /* StorageNamespace.cpp */; };
 833 51BE38290DAEF7DA001085FC /* StorageNamespace.h in Headers */ = {isa = PBXBuildFile; fileRef = 51BE38270DAEF7DA001085FC /* StorageNamespace.h */; };
834834 51C0AA390F2AA10A001648C2 /* CachedFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 51C0AA380F2AA10A001648C2 /* CachedFrame.h */; settings = {ATTRIBUTES = (Private, ); }; };
835835 51C0AA410F2AA15E001648C2 /* CachedFrame.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51C0AA400F2AA15E001648C2 /* CachedFrame.cpp */; };
836836 51C81B890C4422F70019ECE3 /* FTPDirectoryParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51C81B870C4422F70019ECE3 /* FTPDirectoryParser.cpp */; };

844844 51E0BABC0DA5547100A9E417 /* StorageEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51E0BABA0DA5547100A9E417 /* StorageEvent.cpp */; };
845845 51E0BAEA0DA55D4A00A9E417 /* JSStorageEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51E0BAE80DA55D4A00A9E417 /* JSStorageEvent.cpp */; };
846846 51E0BAEB0DA55D4A00A9E417 /* JSStorageEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 51E0BAE90DA55D4A00A9E417 /* JSStorageEvent.h */; };
847  51E0BB230DA572A600A9E417 /* SessionStorage.h in Headers */ = {isa = PBXBuildFile; fileRef = 51E0BB210DA572A600A9E417 /* SessionStorage.h */; };
848  51E0BB240DA572A600A9E417 /* SessionStorage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51E0BB220DA572A600A9E417 /* SessionStorage.cpp */; };
849847 51E0BB380DA5ACB600A9E417 /* StorageMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 51E0BB360DA5ACB600A9E417 /* StorageMap.h */; };
850848 51E0BB390DA5ACB600A9E417 /* StorageMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51E0BB370DA5ACB600A9E417 /* StorageMap.cpp */; };
851849 51E1ECAF0C91C54600DC255B /* AutodrainedPool.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51E1ECAD0C91C54600DC255B /* AutodrainedPool.mm */; };

57545752 51B2417A0D931F3F00E83F5C /* LegacyWebArchiveMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LegacyWebArchiveMac.mm; sourceTree = "<group>"; };
57555753 51BE37DD0DAEE00E001085FC /* StorageArea.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StorageArea.cpp; sourceTree = "<group>"; };
57565754 51BE37DE0DAEE00E001085FC /* StorageArea.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StorageArea.h; sourceTree = "<group>"; };
5757  51BE38260DAEF7DA001085FC /* LocalStorage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LocalStorage.cpp; sourceTree = "<group>"; };
5758  51BE38270DAEF7DA001085FC /* LocalStorage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocalStorage.h; sourceTree = "<group>"; };
 5755 51BE38260DAEF7DA001085FC /* StorageNamespace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StorageNamespace.cpp; sourceTree = "<group>"; };
 5756 51BE38270DAEF7DA001085FC /* StorageNamespace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StorageNamespace.h; sourceTree = "<group>"; };
57595757 51C0AA380F2AA10A001648C2 /* CachedFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CachedFrame.h; sourceTree = "<group>"; };
57605758 51C0AA400F2AA15E001648C2 /* CachedFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CachedFrame.cpp; sourceTree = "<group>"; };
57615759 51C81B870C4422F70019ECE3 /* FTPDirectoryParser.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = FTPDirectoryParser.cpp; sourceTree = "<group>"; };

57705768 51E0BABD0DA5548400A9E417 /* StorageEvent.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = StorageEvent.idl; sourceTree = "<group>"; };
57715769 51E0BAE80DA55D4A00A9E417 /* JSStorageEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSStorageEvent.cpp; sourceTree = "<group>"; };
57725770 51E0BAE90DA55D4A00A9E417 /* JSStorageEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSStorageEvent.h; sourceTree = "<group>"; };
5773  51E0BB210DA572A600A9E417 /* SessionStorage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SessionStorage.h; sourceTree = "<group>"; };
5774  51E0BB220DA572A600A9E417 /* SessionStorage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SessionStorage.cpp; sourceTree = "<group>"; };
57755771 51E0BB360DA5ACB600A9E417 /* StorageMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StorageMap.h; sourceTree = "<group>"; };
57765772 51E0BB370DA5ACB600A9E417 /* StorageMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StorageMap.cpp; sourceTree = "<group>"; };
57775773 51E1ECAD0C91C54600DC255B /* AutodrainedPool.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AutodrainedPool.mm; sourceTree = "<group>"; };

95999595 1AD51A130CB59CD300953D11 /* DatabaseTracker.cpp */,
96009596 1AD51A120CB59CD300953D11 /* DatabaseTracker.h */,
96019597 51FAFE330CECBF2D00BB3F24 /* DatabaseTrackerClient.h */,
9602  51BE38260DAEF7DA001085FC /* LocalStorage.cpp */,
9603  51BE38270DAEF7DA001085FC /* LocalStorage.h */,
96049598 511F23130DC160DA004F0032 /* LocalStorageTask.cpp */,
96059599 511F23140DC160DA004F0032 /* LocalStorageTask.h */,
96069600 511F23150DC160DA004F0032 /* LocalStorageThread.cpp */,

96269620 1A7CCB230CD946FD00B7B64E /* SQLTransaction.idl */,
96279621 1A7CCB170CD9469A00B7B64E /* SQLTransactionCallback.h */,
96289622 1A7CCB180CD9469A00B7B64E /* SQLTransactionErrorCallback.h */,
9629  51E0BB220DA572A600A9E417 /* SessionStorage.cpp */,
9630  51E0BB210DA572A600A9E417 /* SessionStorage.h */,
96319623 51E3F9C50DA059DC00250911 /* Storage.cpp */,
96329624 51E3F9C40DA059DC00250911 /* Storage.h */,
96339625 51E3F9D10DA05D7100250911 /* Storage.idl */,

96409632 51E0BABD0DA5548400A9E417 /* StorageEvent.idl */,
96419633 51E0BB370DA5ACB600A9E417 /* StorageMap.cpp */,
96429634 51E0BB360DA5ACB600A9E417 /* StorageMap.h */,
 9635 51BE38260DAEF7DA001085FC /* StorageNamespace.cpp */,
 9636 51BE38270DAEF7DA001085FC /* StorageNamespace.h */,
96439637 C5102D920FD9AA2D00FAFF04 /* StorageSyncManager.h */,
96449638 C5102D930FD9AA2D00FAFF04 /* StorageSyncManager.cpp */,
96459639 );

1606316057 A7AD2F880EC89D07008AB002 /* LinkHash.h in Headers */,
1606416058 656D37320ADBA5DE00A4554D /* LoaderNSURLExtras.h in Headers */,
1606516059 06E81ED70AB5D5E900C87837 /* LocalCurrentGraphicsContext.h in Headers */,
16066  51BE38290DAEF7DA001085FC /* LocalStorage.h in Headers */,
 16060 51BE38290DAEF7DA001085FC /* StorageNamespace.h in Headers */,
1606716061 511F23180DC160DA004F0032 /* LocalStorageTask.h in Headers */,
1606816062 511F231A0DC160DA004F0032 /* LocalStorageThread.h in Headers */,
1606916063 935207BE09BD410A00F2038D /* LocalizedStrings.h in Headers */,

1650316497 084AEBE50FB505FA0038483E /* SelectElement.h in Headers */,
1650416498 93309E0E099E64920056E581 /* SelectionController.h in Headers */,
1650516499 BC7FA6810D1F167900DB22A9 /* SelectorNodeList.h in Headers */,
16506  51E0BB230DA572A600A9E417 /* SessionStorage.h in Headers */,
1650716500 93309E10099E64920056E581 /* SetNodeAttributeCommand.h in Headers */,
1650816501 93F1994F08245E59001E9ABC /* Settings.h in Headers */,
1650916502 BC5EB8C40E82031B00B25965 /* ShadowData.h in Headers */,

1812618119 A7AD2F870EC89D07008AB002 /* LinkHash.cpp in Sources */,
1812718120 656D37330ADBA5DE00A4554D /* LoaderNSURLExtras.mm in Sources */,
1812818121 06E81EEC0AB5DA9700C87837 /* LocalCurrentGraphicsContext.mm in Sources */,
18129  51BE38280DAEF7DA001085FC /* LocalStorage.cpp in Sources */,
 18122 51BE38280DAEF7DA001085FC /* StorageNamespace.cpp in Sources */,
1813018123 511F23170DC160DA004F0032 /* LocalStorageTask.cpp in Sources */,
1813118124 511F23190DC160DA004F0032 /* LocalStorageThread.cpp in Sources */,
1813218125 935207C009BD412100F2038D /* LocalizedStringsMac.mm in Sources */,

1852618519 93309E0D099E64920056E581 /* SelectionController.cpp in Sources */,
1852718520 4A8C96EB0BE69032004EEFF0 /* SelectionControllerMac.mm in Sources */,
1852818521 BC7FA6820D1F167900DB22A9 /* SelectorNodeList.cpp in Sources */,
18529  51E0BB240DA572A600A9E417 /* SessionStorage.cpp in Sources */,
1853018522 93309E0F099E64920056E581 /* SetNodeAttributeCommand.cpp in Sources */,
1853118523 14C9A5EA0B3D105F005A0232 /* Settings.cpp in Sources */,
1853218524 BC5EB8C30E82031B00B25965 /* ShadowData.cpp in Sources */,

WebCore/page/Chrome.cpp

4646#include <wtf/Vector.h>
4747
4848#if ENABLE(DOM_STORAGE)
49 #include "SessionStorage.h"
 49#include "StorageNamespace.h"
5050#endif
5151
5252namespace WebCore {

@@Page* Chrome::createWindow(Frame* frame, const FrameLoadRequest& request, const
147147
148148#if ENABLE(DOM_STORAGE)
149149 if (newPage) {
150  if (SessionStorage* oldSessionStorage = m_page->sessionStorage(false))
151  newPage->setSessionStorage(oldSessionStorage->copy(newPage));
 150 if (StorageNamespace* oldSessionStorage = m_page->sessionStorage(false))
 151 newPage->setSessionStorage(oldSessionStorage->copy());
152152 }
153153#endif
154154

WebCore/page/DOMWindow.cpp

7070#endif
7171
7272#if ENABLE(DOM_STORAGE)
73 #include "LocalStorage.h"
74 #include "SessionStorage.h"
7573#include "Storage.h"
 74#include "StorageNamespace.h"
7675#include "StorageArea.h"
7776#endif
7877

@@Storage* DOMWindow::localStorage() const
564563 if (!settings || !settings->localStorageEnabled())
565564 return 0;
566565
567  LocalStorage* localStorage = page->group().localStorage();
 566 StorageNamespace* localStorage = page->group().localStorage();
568567 RefPtr<StorageArea> storageArea = localStorage ? localStorage->storageArea(document->securityOrigin()) : 0;
569568 if (storageArea) {
570569 page->inspectorController()->didUseDOMStorage(storageArea.get(), true, m_frame);

WebCore/page/DOMWindow.h

@@namespace WebCore {
6161 class WebKitPoint;
6262
6363#if ENABLE(DOM_STORAGE)
64  class SessionStorage;
6564 class Storage;
6665#endif
6766

WebCore/page/Page.cpp

5757#include <wtf/StdLibExtras.h>
5858
5959#if ENABLE(DOM_STORAGE)
60 #include "LocalStorage.h"
61 #include "SessionStorage.h"
6260#include "StorageArea.h"
 61#include "StorageNamespace.h"
6362#endif
6463
6564#if ENABLE(JAVASCRIPT_DEBUGGER)

@@void Page::setDebugger(JSC::Debugger* debugger)
548547}
549548
550549#if ENABLE(DOM_STORAGE)
551 SessionStorage* Page::sessionStorage(bool optionalCreate)
 550StorageNamespace* Page::sessionStorage(bool optionalCreate)
552551{
553552 if (!m_sessionStorage && optionalCreate)
554  m_sessionStorage = SessionStorage::create(this);
 553 m_sessionStorage = StorageNamespace::sessionStorageNamespace();
555554
556555 return m_sessionStorage.get();
557556}
558557
559 void Page::setSessionStorage(PassRefPtr<SessionStorage> newStorage)
 558void Page::setSessionStorage(PassRefPtr<StorageNamespace> newStorage)
560559{
561  ASSERT(newStorage->page() == this);
562560 m_sessionStorage = newStorage;
563561}
564562#endif

WebCore/page/Page.h

@@namespace WebCore {
6363 class VisibleSelection;
6464 class SelectionController;
6565#if ENABLE(DOM_STORAGE)
66  class SessionStorage;
 66 class StorageNamespace;
6767#endif
6868 class Settings;
6969#if ENABLE(WML)

@@namespace WebCore {
176176 static void visitedStateChanged(PageGroup*, LinkHash visitedHash);
177177
178178#if ENABLE(DOM_STORAGE)
179  SessionStorage* sessionStorage(bool optionalCreate = true);
180  void setSessionStorage(PassRefPtr<SessionStorage>);
 179 StorageNamespace* sessionStorage(bool optionalCreate = true);
 180 void setSessionStorage(PassRefPtr<StorageNamespace>);
181181#endif
182182
183183#if ENABLE(WML)

@@namespace WebCore {
248248 int m_customHTMLTokenizerChunkSize;
249249
250250#if ENABLE(DOM_STORAGE)
251  RefPtr<SessionStorage> m_sessionStorage;
 251 RefPtr<StorageNamespace> m_sessionStorage;
252252#endif
253253
254254#if PLATFORM(WIN) || (PLATFORM(WX) && defined(__WXMSW__)) || (PLATFORM(QT) && defined(Q_WS_WIN))

WebCore/page/PageGroup.cpp

3232#include "Settings.h"
3333
3434#if ENABLE(DOM_STORAGE)
35 #include "LocalStorage.h"
3635#include "StorageArea.h"
 36#include "StorageNamespace.h"
3737#endif
3838
3939#if PLATFORM(CHROMIUM)

@@void PageGroup::closeLocalStorage()
9797 PageGroupMap::iterator end = pageGroups->end();
9898
9999 for (PageGroupMap::iterator it = pageGroups->begin(); it != end; ++it) {
100  if (LocalStorage* localStorage = it->second->localStorage())
 100 if (StorageNamespace* localStorage = it->second->localStorage())
101101 localStorage->close();
102102 }
103103#endif

@@void PageGroup::addPage(Page* page)
110110 m_pages.add(page);
111111#if ENABLE(DOM_STORAGE)
112112 if (!m_localStorage)
113  m_localStorage = LocalStorage::localStorage(page->settings()->localStorageDatabasePath());
 113 m_localStorage = StorageNamespace::localStorageNamespace(page->settings()->localStorageDatabasePath());
114114#endif
115115}
116116

@@void PageGroup::setShouldTrackVisitedLinks(bool shouldTrack)
185185}
186186
187187#if ENABLE(DOM_STORAGE)
188 LocalStorage* PageGroup::localStorage()
 188StorageNamespace* PageGroup::localStorage()
189189{
190190 return m_localStorage.get();
191191}

WebCore/page/PageGroup.h

3434namespace WebCore {
3535
3636 class KURL;
37  class LocalStorage;
 37 class StorageNamespace;
3838 class Page;
3939
4040 class PageGroup : Noncopyable {

@@namespace WebCore {
6363 unsigned identifier() { return m_identifier; }
6464
6565#if ENABLE(DOM_STORAGE)
66  LocalStorage* localStorage();
 66 StorageNamespace* localStorage();
6767#endif
6868
6969 private:

@@namespace WebCore {
7878
7979 unsigned m_identifier;
8080#if ENABLE(DOM_STORAGE)
81  RefPtr<LocalStorage> m_localStorage;
 81 RefPtr<StorageNamespace> m_localStorage;
8282#endif
8383 };
8484

WebCore/storage/LocalStorage.cpp

1 /*
2  * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #include "config.h"
27 #include "LocalStorage.h"
28 
29 #include "CString.h"
30 #include "EventNames.h"
31 #include "FileSystem.h"
32 #include "Frame.h"
33 #include "FrameTree.h"
34 #include "Page.h"
35 #include "PageGroup.h"
36 #include "StorageArea.h"
37 #include "StorageSyncManager.h"
38 #include <wtf/StdLibExtras.h>
39 
40 namespace WebCore {
41 
42 typedef HashMap<String, LocalStorage*> LocalStorageMap;
43 
44 static LocalStorageMap& localStorageMap()
45 {
46  DEFINE_STATIC_LOCAL(LocalStorageMap, localStorageMap, ());
47  return localStorageMap;
48 }
49 
50 PassRefPtr<LocalStorage> LocalStorage::localStorage(const String& path)
51 {
52  const String lookupPath = path.isNull() ? String("") : path;
53  LocalStorageMap::iterator it = localStorageMap().find(lookupPath);
54  if (it == localStorageMap().end()) {
55  RefPtr<LocalStorage> localStorage = adoptRef(new LocalStorage(lookupPath));
56  localStorageMap().set(lookupPath, localStorage.get());
57  return localStorage.release();
58  }
59 
60  return it->second;
61 }
62 
63 LocalStorage::LocalStorage(const String& path)
64  : m_path(path.copy())
65  , m_syncManager(0)
66 {
67  if (!m_path.isEmpty())
68  m_syncManager = StorageSyncManager::create(m_path);
69 }
70 
71 LocalStorage::~LocalStorage()
72 {
73  ASSERT(localStorageMap().get(m_path) == this);
74  localStorageMap().remove(m_path);
75 }
76 
77 PassRefPtr<StorageArea> LocalStorage::storageArea(SecurityOrigin* origin)
78 {
79  ASSERT(isMainThread());
80 
81  // FIXME: If the security origin in question has never had a storage area established,
82  // we need to ask a client call if establishing it is okay. If the client denies the request,
83  // this method will return null.
84  // The sourceFrame argument exists for the purpose of asking a client.
85  // To know if an area has previously been established, we need to wait until this LocalStorage
86  // object has finished it's AreaImport task.
87 
88  // FIXME: If the storage area is being established for the first time here, we need to
89  // sync its existance and quota out to disk via an task of type AreaSync
90 
91  RefPtr<StorageArea> storageArea;
92  if (storageArea = m_storageAreaMap.get(origin))
93  return storageArea.release();
94 
95  storageArea = StorageArea::createLocalStorage(origin, m_syncManager);
96  m_storageAreaMap.set(origin, storageArea);
97  return storageArea.release();
98 }
99 
100 void LocalStorage::close()
101 {
102  ASSERT(isMainThread());
103 
104  LocalStorageAreaMap::iterator end = m_storageAreaMap.end();
105  for (LocalStorageAreaMap::iterator it = m_storageAreaMap.begin(); it != end; ++it)
106  it->second->scheduleFinalSync();
107 
108  m_syncManager = 0;
109 }
110 
111 } // namespace WebCore

WebCore/storage/LocalStorage.h

1 /*
2  * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef LocalStorage_h
27 #define LocalStorage_h
28 
29 #include "SecurityOriginHash.h"
30 
31 #include <wtf/HashMap.h>
32 #include <wtf/RefCounted.h>
33 
34 namespace WebCore {
35 
36  class StorageArea;
37  class StorageSyncManager;
38 
39  class LocalStorage : public RefCounted<LocalStorage> {
40  public:
41  ~LocalStorage();
42 
43  static PassRefPtr<LocalStorage> localStorage(const String& path);
44 
45  PassRefPtr<StorageArea> storageArea(SecurityOrigin*);
46 
47  void close();
48 
49  private:
50  LocalStorage(const String& path);
51 
52  typedef HashMap<RefPtr<SecurityOrigin>, RefPtr<StorageArea>, SecurityOriginHash> LocalStorageAreaMap;
53  LocalStorageAreaMap m_storageAreaMap;
54 
55  String m_path;
56  RefPtr<StorageSyncManager> m_syncManager;
57  };
58 
59 } // namespace WebCore
60 
61 #endif // LocalStorage_h

WebCore/storage/LocalStorageTask.cpp

2626#include "config.h"
2727#include "LocalStorageTask.h"
2828
29 #include "LocalStorage.h"
3029#include "LocalStorageThread.h"
3130#include "StorageAreaSync.h"
 31#include "StorageNamespace.h"
3232
3333namespace WebCore {
3434

WebCore/storage/LocalStorageThread.cpp

2626#include "config.h"
2727#include "LocalStorageThread.h"
2828
29 #include "LocalStorage.h"
3029#include "LocalStorageTask.h"
3130#include "StorageAreaSync.h"
 31#include "StorageNamespace.h"
3232
3333namespace WebCore {
3434

WebCore/storage/SessionStorage.cpp

1 /*
2  * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #include "config.h"
27 #include "SessionStorage.h"
28 
29 #include "EventNames.h"
30 #include "Frame.h"
31 #include "FrameTree.h"
32 #include "Page.h"
33 #include "SecurityOrigin.h"
34 #include "StorageArea.h"
35 #include "StorageMap.h"
36 
37 namespace WebCore {
38 
39 PassRefPtr<SessionStorage> SessionStorage::create(Page* page)
40 {
41  return adoptRef(new SessionStorage(page));
42 }
43 
44 SessionStorage::SessionStorage(Page* page)
45  : m_page(page)
46 {
47  ASSERT(m_page);
48 }
49 
50 PassRefPtr<SessionStorage> SessionStorage::copy(Page* newPage)
51 {
52  ASSERT(newPage);
53  RefPtr<SessionStorage> newSession = SessionStorage::create(newPage);
54 
55  SessionStorageAreaMap::iterator end = m_storageAreaMap.end();
56  for (SessionStorageAreaMap::iterator i = m_storageAreaMap.begin(); i != end; ++i) {
57  RefPtr<StorageArea> areaCopy = i->second->copy(i->first.get(), newPage);
58  newSession->m_storageAreaMap.set(i->first, areaCopy.release());
59  }
60 
61  return newSession.release();
62 }
63 
64 PassRefPtr<StorageArea> SessionStorage::storageArea(SecurityOrigin* origin)
65 {
66  RefPtr<StorageArea> storageArea;
67  if (storageArea = m_storageAreaMap.get(origin))
68  return storageArea.release();
69 
70  storageArea = StorageArea::createSessionStorage(origin, m_page);
71  m_storageAreaMap.set(origin, storageArea);
72  return storageArea.release();
73 }
74 
75 }

WebCore/storage/SessionStorage.h

1 /*
2  * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef SessionStorage_h
27 #define SessionStorage_h
28 
29 #include "SecurityOriginHash.h"
30 #include "StorageArea.h"
31 
32 #include <wtf/HashMap.h>
33 #include <wtf/RefCounted.h>
34 
35 namespace WebCore {
36 
37  class Page;
38 
39  class SessionStorage : public RefCounted<SessionStorage> {
40  public:
41  static PassRefPtr<SessionStorage> create(Page*);
42  PassRefPtr<SessionStorage> copy(Page*);
43 
44  PassRefPtr<StorageArea> storageArea(SecurityOrigin*);
45 
46 #ifndef NDEBUG
47  Page* page() { return m_page; }
48 #endif
49 
50  private:
51  SessionStorage(Page*);
52 
53  void dispatchStorageEvent(StorageArea*, const String& key, const String& oldValue, const String& newValue, Frame* sourceFrame);
54 
55  Page* m_page;
56 
57  typedef HashMap<RefPtr<SecurityOrigin>, RefPtr<StorageArea>, SecurityOriginHash> SessionStorageAreaMap;
58  SessionStorageAreaMap m_storageAreaMap;
59  };
60 
61 } // namespace WebCore
62 
63 #endif // SessionStorage_h

WebCore/storage/StorageArea.cpp

4040
4141namespace WebCore {
4242
43 PassRefPtr<StorageArea> StorageArea::createLocalStorage(SecurityOrigin* origin, PassRefPtr<StorageSyncManager> syncManager)
 43PassRefPtr<StorageArea> StorageArea::create(StorageType storageType, SecurityOrigin* origin, PassRefPtr<StorageSyncManager> syncManager)
4444{
45  return adoptRef(new StorageArea(origin, syncManager));
 45 return adoptRef(new StorageArea(storageType, origin, syncManager));
4646}
4747
48 StorageArea::StorageArea(SecurityOrigin* origin, PassRefPtr<StorageSyncManager> syncManager)
49  : m_securityOrigin(origin)
 48StorageArea::StorageArea(StorageType storageType, SecurityOrigin* origin, PassRefPtr<StorageSyncManager> syncManager)
 49 : m_storageType(storageType)
 50 , m_securityOrigin(origin)
5051 , m_storageMap(StorageMap::create())
5152 , m_storageAreaSync(0)
5253 , m_storageSyncManager(syncManager)
53  , m_sessionStoragePage(0)
 54#ifndef NDEBUG
 55 , m_isShutdown(false)
 56#endif
5457{
5558 ASSERT(m_securityOrigin);
5659 ASSERT(m_storageMap);

@@StorageArea::StorageArea(SecurityOrigin* origin, PassRefPtr<StorageSyncManager>
6467 }
6568}
6669
67 PassRefPtr<StorageArea> StorageArea::createSessionStorage(SecurityOrigin* origin, Page* page)
 70PassRefPtr<StorageArea> StorageArea::copy(SecurityOrigin* origin)
6871{
69  return adoptRef(new StorageArea(origin, page, 0));
 72 ASSERT(!m_isShutdown);
 73 return adoptRef(new StorageArea(origin, this));
7074}
7175
72 PassRefPtr<StorageArea> StorageArea::copy(SecurityOrigin* origin, Page* page)
73 {
74  return adoptRef(new StorageArea(origin, page, this));
75 }
76 
77 StorageArea::StorageArea(SecurityOrigin* origin, Page* page, StorageArea* area)
78  : m_securityOrigin(origin)
 76StorageArea::StorageArea(SecurityOrigin* origin, StorageArea* area)
 77 : m_storageType(area->m_storageType)
 78 , m_securityOrigin(origin)
7979 , m_storageMap(area->m_storageMap)
8080 , m_storageAreaSync(0)
81  , m_storageSyncManager(0)
82  , m_sessionStoragePage(page)
 81 , m_storageSyncManager(area->m_storageSyncManager)
 82#ifndef NDEBUG
 83 , m_isShutdown(area->m_isShutdown)
 84#endif
8385{
8486 ASSERT(m_securityOrigin);
85  ASSERT(m_sessionStoragePage);
86 
87  if (!m_storageMap) {
88  m_storageMap = StorageMap::create();
89  ASSERT(m_storageMap);
90  }
 87 ASSERT(m_storageMap);
 88 ASSERT(!m_isShutdown);
9189}
9290
9391unsigned StorageArea::length() const
9492{
 93 ASSERT(!m_isShutdown);
9594 return m_storageMap->length();
9695}
9796
9897String StorageArea::key(unsigned index, ExceptionCode& ec) const
9998{
 99 ASSERT(!m_isShutdown);
100100 blockUntilImportComplete();
101101
102102 String key;

@@String StorageArea::key(unsigned index, ExceptionCode& ec) const
111111
112112String StorageArea::getItem(const String& key) const
113113{
 114 ASSERT(!m_isShutdown);
114115 blockUntilImportComplete();
115116
116117 return m_storageMap->getItem(key);

@@String StorageArea::getItem(const String& key) const
118119
119120void StorageArea::setItem(const String& key, const String& value, ExceptionCode& ec, Frame* frame)
120121{
 122 ASSERT(!m_isShutdown);
121123 ASSERT(!value.isNull());
122124 blockUntilImportComplete();
123125

@@void StorageArea::setItem(const String& key, const String& value, ExceptionCode&
149151
150152void StorageArea::removeItem(const String& key, Frame* frame)
151153{
 154 ASSERT(!m_isShutdown);
152155 blockUntilImportComplete();
153156
154157 if (frame->page()->settings()->privateBrowsingEnabled())

@@void StorageArea::removeItem(const String& key, Frame* frame)
169172
170173void StorageArea::clear(Frame* frame)
171174{
 175 ASSERT(!m_isShutdown);
172176 blockUntilImportComplete();
173177
174178 if (frame->page()->settings()->privateBrowsingEnabled())

@@void StorageArea::clear(Frame* frame)
183187
184188bool StorageArea::contains(const String& key) const
185189{
 190 ASSERT(!m_isShutdown);
186191 blockUntilImportComplete();
187192
188193 return m_storageMap->contains(key);

@@bool StorageArea::contains(const String& key) const
190195
191196void StorageArea::importItem(const String& key, const String& value)
192197{
 198 ASSERT(!m_isShutdown);
193199 m_storageMap->importItem(key, value);
194200}
195201
196 void StorageArea::scheduleFinalSync()
 202void StorageArea::blockUntilImportComplete() const
197203{
198204 if (m_storageAreaSync)
199  m_storageAreaSync->scheduleFinalSync();
 205 m_storageAreaSync->blockUntilImportComplete();
200206}
201207
202 void StorageArea::blockUntilImportComplete() const
 208void StorageArea::close()
203209{
204210 if (m_storageAreaSync)
205  m_storageAreaSync->blockUntilImportComplete();
 211 m_storageAreaSync->scheduleFinalSync();
 212
 213#ifndef NDEBUG
 214 m_isShutdown = true;
 215#endif
206216}
207217
208218void StorageArea::dispatchStorageEvent(const String& key, const String& oldValue, const String& newValue, Frame* sourceFrame)

@@void StorageArea::dispatchStorageEvent(const String& key, const String& oldValue
211221 // of any given page in the group or mutate the page group itself.
212222 Vector<RefPtr<Frame> > frames;
213223
214  if (m_sessionStoragePage) {
 224 // FIXME: When can this occur?
 225 Page* page = sourceFrame->page();
 226 if (!page)
 227 return;
 228
 229 if (m_storageType == SessionStorage) {
215230 // Send events only to our page.
216  for (Frame* frame = m_sessionStoragePage->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
 231 for (Frame* frame = page->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
217232 if (frame->document()->securityOrigin()->equal(securityOrigin()))
218233 frames.append(frame);
219234 }
220235 } else {
221  // FIXME: When can this occur?
222  Page* page = sourceFrame->page();
223  if (!page)
224  return;
225 
226236 // Send events to every page.
227237 const HashSet<Page*>& pages = page->group().pages();
228238 HashSet<Page*>::const_iterator end = pages.end();

WebCore/storage/StorageArea.h

@@namespace WebCore {
4646 class StorageMap;
4747 class StorageSyncManager;
4848 typedef int ExceptionCode;
 49 enum StorageType { LocalStorage, SessionStorage };
4950
5051 class StorageArea : public ThreadSafeShared<StorageArea> {
5152 public:
52  static PassRefPtr<StorageArea> createLocalStorage(SecurityOrigin* origin, PassRefPtr<StorageSyncManager> syncManager);
53  static PassRefPtr<StorageArea> createSessionStorage(SecurityOrigin* origin, Page* page);
54  PassRefPtr<StorageArea> copy(SecurityOrigin*, Page*);
 53 static PassRefPtr<StorageArea> create(StorageType, SecurityOrigin*, PassRefPtr<StorageSyncManager>);
 54 PassRefPtr<StorageArea> copy(SecurityOrigin*);
5555
5656 // The HTML5 DOM Storage API
5757 unsigned length() const;

@@namespace WebCore {
6262 void clear(Frame* sourceFrame);
6363
6464 bool contains(const String& key) const;
65  void scheduleFinalSync();
 65 void close();
6666
6767 // Could be called from a background thread.
6868 void importItem(const String& key, const String& value);
6969 SecurityOrigin* securityOrigin() { return m_securityOrigin.get(); }
7070
7171 protected:
72  StorageArea(SecurityOrigin*, PassRefPtr<StorageSyncManager>);
73  StorageArea(SecurityOrigin*, Page*);
74  StorageArea(SecurityOrigin*, Page*, StorageArea*);
 72 StorageArea(StorageType, SecurityOrigin*, PassRefPtr<StorageSyncManager>);
 73 StorageArea(SecurityOrigin*, StorageArea*);
7574
7675 private:
7776 void blockUntilImportComplete() const;
7877
7978 void dispatchStorageEvent(const String& key, const String& oldValue, const String& newValue, Frame* sourceFrame);
8079
 80 StorageType m_storageType;
8181 RefPtr<SecurityOrigin> m_securityOrigin;
8282 RefPtr<StorageMap> m_storageMap;
8383
8484 RefPtr<StorageAreaSync> m_storageAreaSync;
8585 RefPtr<StorageSyncManager> m_storageSyncManager;
86  Page* m_sessionStoragePage; // NULL iff it's LocalStorage
 86
 87#ifndef NDEBUG
 88 bool m_isShutdown;
 89#endif
8790 };
8891
8992} // namespace WebCore

WebCore/storage/StorageAreaSync.cpp

@@void StorageAreaSync::scheduleFinalSync()
7474{
7575 ASSERT(isMainThread());
7676
 77 // FIXME: Avoid races without having to block on the import here.
 78 blockUntilImportComplete();
 79
7780 if (m_syncTimer.isActive())
7881 m_syncTimer.stop();
7982 else {

WebCore/storage/StorageNamespace.cpp

 1/*
 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27#include "StorageNamespace.h"
 28
 29// FIXME: Do we need all of these
 30#include "CString.h"
 31#include "EventNames.h"
 32#include "FileSystem.h"
 33#include "Frame.h"
 34#include "FrameTree.h"
 35#include "Page.h"
 36#include "PageGroup.h"
 37#include "StorageArea.h"
 38#include "StorageSyncManager.h"
 39#include <wtf/StdLibExtras.h>
 40
 41namespace WebCore {
 42
 43typedef HashMap<String, StorageNamespace*> LocalStorageNamespaceMap;
 44
 45static LocalStorageNamespaceMap& localStorageNamespaceMap()
 46{
 47 DEFINE_STATIC_LOCAL(LocalStorageNamespaceMap, localStorageNamespaceMap, ());
 48 return localStorageNamespaceMap;
 49}
 50
 51PassRefPtr<StorageNamespace> StorageNamespace::localStorageNamespace(const String& path)
 52{
 53 const String lookupPath = path.isNull() ? String("") : path;
 54 LocalStorageNamespaceMap::iterator it = localStorageNamespaceMap().find(lookupPath);
 55 if (it == localStorageNamespaceMap().end()) {
 56 RefPtr<StorageNamespace> storageNamespace = adoptRef(new StorageNamespace(LocalStorage, lookupPath));
 57 localStorageNamespaceMap().set(lookupPath, storageNamespace.get());
 58 return storageNamespace.release();
 59 }
 60
 61 return it->second;
 62}
 63
 64PassRefPtr<StorageNamespace> StorageNamespace::sessionStorageNamespace()
 65{
 66 return adoptRef(new StorageNamespace(SessionStorage, String()));
 67}
 68
 69StorageNamespace::StorageNamespace(StorageType storageType, const String& path)
 70 : m_storageType(storageType)
 71 , m_path(path.copy()) // FIXME: Is the .copy necessary?
 72 , m_syncManager(0)
 73#ifndef NDEBUG
 74 , m_isShutdown(false)
 75#endif
 76{
 77 if (m_storageType == LocalStorage && !m_path.isEmpty())
 78 m_syncManager = StorageSyncManager::create(m_path);
 79}
 80
 81StorageNamespace::~StorageNamespace()
 82{
 83 ASSERT(isMainThread());
 84
 85 if (m_storageType == LocalStorage) {
 86 ASSERT(localStorageNamespaceMap().get(m_path) == this);
 87 localStorageNamespaceMap().remove(m_path);
 88 }
 89}
 90
 91PassRefPtr<StorageNamespace> StorageNamespace::copy()
 92{
 93 ASSERT(isMainThread());
 94 ASSERT(!m_isShutdown);
 95
 96 RefPtr<StorageNamespace> newNamespace = adoptRef(new StorageNamespace(m_storageType, m_path));
 97
 98 StorageAreaMap::iterator end = m_storageAreaMap.end();
 99 for (StorageAreaMap::iterator i = m_storageAreaMap.begin(); i != end; ++i) {
 100 RefPtr<StorageArea> areaCopy = i->second->copy(i->first.get());
 101 newNamespace->m_storageAreaMap.set(i->first, areaCopy.release());
 102 }
 103
 104 return newNamespace.release();
 105}
 106
 107PassRefPtr<StorageArea> StorageNamespace::storageArea(SecurityOrigin* origin)
 108{
 109 ASSERT(isMainThread());
 110 ASSERT(!m_isShutdown);
 111
 112 RefPtr<StorageArea> storageArea;
 113 if (storageArea = m_storageAreaMap.get(origin))
 114 return storageArea.release();
 115
 116 storageArea = StorageArea::create(m_storageType, origin, m_syncManager);
 117 m_storageAreaMap.set(origin, storageArea);
 118 return storageArea.release();
 119}
 120
 121void StorageNamespace::close()
 122{
 123 ASSERT(isMainThread());
 124 ASSERT(!m_isShutdown);
 125
 126 StorageAreaMap::iterator end = m_storageAreaMap.end();
 127 for (StorageAreaMap::iterator it = m_storageAreaMap.begin(); it != end; ++it)
 128 it->second->close();
 129
 130#ifndef NDEBUG
 131 m_isShutdown = true;
 132#endif
 133}
 134
 135} // namespace WebCore

WebCore/storage/StorageNamespace.h

 1/*
 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#ifndef StorageNamespace_h
 27#define StorageNamespace_h
 28
 29#include "SecurityOriginHash.h"
 30#include "StorageArea.h"
 31
 32#include <wtf/HashMap.h>
 33#include <wtf/RefCounted.h>
 34
 35namespace WebCore {
 36
 37 class StorageArea;
 38 class StorageSyncManager;
 39
 40 class StorageNamespace : public RefCounted<StorageNamespace> {
 41 public:
 42 ~StorageNamespace();
 43
 44 static PassRefPtr<StorageNamespace> sessionStorageNamespace();
 45 static PassRefPtr<StorageNamespace> localStorageNamespace(const String& path);
 46
 47 PassRefPtr<StorageArea> storageArea(SecurityOrigin*);
 48 PassRefPtr<StorageNamespace> copy();
 49 void close();
 50
 51 private:
 52 StorageNamespace(StorageType, const String& path);
 53
 54 typedef HashMap<RefPtr<SecurityOrigin>, RefPtr<StorageArea>, SecurityOriginHash> StorageAreaMap;
 55 StorageAreaMap m_storageAreaMap;
 56
 57 StorageType m_storageType;
 58
 59 // Only used iff m_storageType == LocalStorage and we're persistent.
 60 String m_path;
 61 RefPtr<StorageSyncManager> m_syncManager;
 62
 63#ifndef NDEBUG
 64 bool m_isShutdown;
 65#endif
 66 };
 67
 68} // namespace WebCore
 69
 70#endif // StorageNamespace_h