• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 PageGroup_h
27 #define PageGroup_h
28 
29 #include <wtf/HashSet.h>
30 #include <wtf/Noncopyable.h>
31 #include "LinkHash.h"
32 #include "UserScript.h"
33 #include "UserStyleSheet.h"
34 #include <wtf/text/StringHash.h>
35 
36 namespace WebCore {
37 
38     class KURL;
39     class GroupSettings;
40     class IDBFactoryBackendInterface;
41     class Page;
42     class SecurityOrigin;
43     class StorageNamespace;
44 
45     class PageGroup {
46         WTF_MAKE_NONCOPYABLE(PageGroup); WTF_MAKE_FAST_ALLOCATED;
47     public:
48         PageGroup(const String& name);
49         PageGroup(Page*);
50         ~PageGroup();
51 
52         static PageGroup* pageGroup(const String& groupName);
53 
54         static void closeLocalStorage();
55 
56 #if ENABLE(DOM_STORAGE)
57         static void clearLocalStorageForAllOrigins();
58         static void clearLocalStorageForOrigin(SecurityOrigin*);
59         // DumpRenderTree helper that triggers a StorageArea sync.
60         static void syncLocalStorage();
61 #endif
62         static unsigned numberOfPageGroups();
63 
64 #if ENABLE(DOM_STORAGE) && defined(ANDROID)
65         static void clearDomStorage();
66 #endif
67 
pages()68         const HashSet<Page*>& pages() const { return m_pages; }
69 
70         void addPage(Page*);
71         void removePage(Page*);
72 
73         bool isLinkVisited(LinkHash);
74 
75         void addVisitedLink(const KURL&);
76         void addVisitedLink(const UChar*, size_t);
77         void addVisitedLinkHash(LinkHash);
78         void removeVisitedLinks();
79 
80         static void setShouldTrackVisitedLinks(bool);
81         static void removeAllVisitedLinks();
82 
name()83         const String& name() { return m_name; }
identifier()84         unsigned identifier() { return m_identifier; }
85 
86 #if ENABLE(DOM_STORAGE)
87         StorageNamespace* localStorage();
hasLocalStorage()88         bool hasLocalStorage() { return m_localStorage; }
89 #endif
90 #if ENABLE(INDEXED_DATABASE)
91         IDBFactoryBackendInterface* idbFactory();
hasIDBFactory()92         bool hasIDBFactory() { return m_factoryBackend; }
93 #endif
94 
95         void addUserScriptToWorld(DOMWrapperWorld*, const String& source, const KURL&,
96                                   PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist,
97                                   UserScriptInjectionTime, UserContentInjectedFrames);
98         void addUserStyleSheetToWorld(DOMWrapperWorld*, const String& source, const KURL&,
99                                       PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist,
100                                       UserContentInjectedFrames,
101                                       UserStyleLevel level = UserStyleUserLevel,
102                                       UserStyleInjectionTime injectionTime = InjectInExistingDocuments);
103         void removeUserScriptFromWorld(DOMWrapperWorld*, const KURL&);
104         void removeUserStyleSheetFromWorld(DOMWrapperWorld*, const KURL&);
105 
106         void removeUserScriptsFromWorld(DOMWrapperWorld*);
107         void removeUserStyleSheetsFromWorld(DOMWrapperWorld*);
108 
109         void removeAllUserContent();
110 
userScripts()111         const UserScriptMap* userScripts() const { return m_userScripts.get(); }
userStyleSheets()112         const UserStyleSheetMap* userStyleSheets() const { return m_userStyleSheets.get(); }
113 
groupSettings()114         GroupSettings* groupSettings() const { return m_groupSettings.get(); }
115 
116     private:
117         void addVisitedLink(LinkHash stringHash);
118         void resetUserStyleCacheInAllFrames();
119 
120 #if ENABLE(DOM_STORAGE) && defined(ANDROID)
121         void removeLocalStorage();
122 #endif
123 
124         String m_name;
125 
126         HashSet<Page*> m_pages;
127 
128         HashSet<LinkHash, LinkHashHash> m_visitedLinkHashes;
129         bool m_visitedLinksPopulated;
130 
131         unsigned m_identifier;
132 #if ENABLE(DOM_STORAGE)
133         RefPtr<StorageNamespace> m_localStorage;
134 #endif
135 #if ENABLE(INDEXED_DATABASE)
136         RefPtr<IDBFactoryBackendInterface> m_factoryBackend;
137 #endif
138 
139         OwnPtr<UserScriptMap> m_userScripts;
140         OwnPtr<UserStyleSheetMap> m_userStyleSheets;
141 
142         OwnPtr<GroupSettings> m_groupSettings;
143     };
144 
145 } // namespace WebCore
146 
147 #endif // PageGroup_h
148