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 const HashSet<Page*>& pages() const { return m_pages; } 52 53 void addPage(Page*); 54 void removePage(Page*); 55 56 bool isLinkVisited(LinkHash); 57 58 void addVisitedLink(const KURL&); 59 void addVisitedLink(const UChar*, size_t); 60 void removeVisitedLinks(); 61 62 static void setShouldTrackVisitedLinks(bool); 63 static void removeAllVisitedLinks(); 64 65 const String& name() { return m_name; } 66 unsigned identifier() { return m_identifier; } 67 68 #if ENABLE(DOM_STORAGE) 69 StorageNamespace* localStorage(); 70 bool hasLocalStorage() { return m_localStorage; } 71 #endif 72 73 void addUserScriptToWorld(DOMWrapperWorld*, const String& source, const KURL&, 74 PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist, 75 UserScriptInjectionTime); 76 void addUserStyleSheetToWorld(DOMWrapperWorld*, const String& source, const KURL&, 77 PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist); 78 79 void removeUserScriptFromWorld(DOMWrapperWorld*, const KURL&); 80 void removeUserStyleSheetFromWorld(DOMWrapperWorld*, const KURL&); 81 82 void removeUserScriptsFromWorld(DOMWrapperWorld*); 83 void removeUserStyleSheetsFromWorld(DOMWrapperWorld*); 84 85 void removeAllUserContent(); 86 87 const UserScriptMap* userScripts() const { return m_userScripts.get(); } 88 const UserStyleSheetMap* userStyleSheets() const { return m_userStyleSheets.get(); } 89 90 private: 91 void addVisitedLink(LinkHash stringHash); 92 93 String m_name; 94 95 HashSet<Page*> m_pages; 96 97 HashSet<LinkHash, LinkHashHash> m_visitedLinkHashes; 98 bool m_visitedLinksPopulated; 99 100 unsigned m_identifier; 101 #if ENABLE(DOM_STORAGE) 102 RefPtr<StorageNamespace> m_localStorage; 103 #endif 104 105 OwnPtr<UserScriptMap> m_userScripts; 106 OwnPtr<UserStyleSheetMap> m_userStyleSheets; 107 }; 108 109 } // namespace WebCore 110 111 #endif // PageGroup_h 112