• 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 "StringHash.h"
33 #include "UserScript.h"
34 #include "UserStyleSheet.h"
35 
36 namespace WebCore {
37 
38     class KURL;
39     class Page;
40     class StorageNamespace;
41 
42     class PageGroup : public Noncopyable {
43     public:
44         PageGroup(const String& name);
45         PageGroup(Page*);
46         ~PageGroup();
47 
48         static PageGroup* pageGroup(const String& groupName);
49         static void closeLocalStorage();
50 
51 #if ENABLE(DOM_STORAGE) && defined(ANDROID)
52         static void clearDomStorage();
53 #endif
54 
pages()55         const HashSet<Page*>& pages() const { return m_pages; }
56 
57         void addPage(Page*);
58         void removePage(Page*);
59 
60         bool isLinkVisited(LinkHash);
61 
62         void addVisitedLink(const KURL&);
63         void addVisitedLink(const UChar*, size_t);
64         void removeVisitedLinks();
65 
66         static void setShouldTrackVisitedLinks(bool);
67         static void removeAllVisitedLinks();
68 
name()69         const String& name() { return m_name; }
identifier()70         unsigned identifier() { return m_identifier; }
71 
72 #if ENABLE(DOM_STORAGE)
73         StorageNamespace* localStorage();
hasLocalStorage()74         bool hasLocalStorage() { return m_localStorage; }
75 #endif
76 
77         void addUserScriptToWorld(DOMWrapperWorld*, const String& source, const KURL&,
78                                   PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist,
79                                   UserScriptInjectionTime);
80         void addUserStyleSheetToWorld(DOMWrapperWorld*, const String& source, const KURL&,
81                                PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist);
82 
83         void removeUserScriptFromWorld(DOMWrapperWorld*, const KURL&);
84         void removeUserStyleSheetFromWorld(DOMWrapperWorld*, const KURL&);
85 
86         void removeUserScriptsFromWorld(DOMWrapperWorld*);
87         void removeUserStyleSheetsFromWorld(DOMWrapperWorld*);
88 
89         void removeAllUserContent();
90 
userScripts()91         const UserScriptMap* userScripts() const { return m_userScripts.get(); }
userStyleSheets()92         const UserStyleSheetMap* userStyleSheets() const { return m_userStyleSheets.get(); }
93 
94     private:
95         void addVisitedLink(LinkHash stringHash);
96 
97 #if ENABLE(DOM_STORAGE) && defined(ANDROID)
98         void removeLocalStorage();
99 #endif
100 
101         String m_name;
102 
103         HashSet<Page*> m_pages;
104 
105         HashSet<LinkHash, LinkHashHash> m_visitedLinkHashes;
106         bool m_visitedLinksPopulated;
107 
108         unsigned m_identifier;
109 #if ENABLE(DOM_STORAGE)
110         RefPtr<StorageNamespace> m_localStorage;
111 #endif
112 
113         OwnPtr<UserScriptMap> m_userScripts;
114         OwnPtr<UserStyleSheetMap> m_userStyleSheets;
115     };
116 
117 } // namespace WebCore
118 
119 #endif // PageGroup_h
120