2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include "WebPageGroup.h"
29 #include "WebPageProxy.h"
30 #include "WebPreferences.h"
31 #include <wtf/HashMap.h>
32 #include <wtf/text/StringConcatenate.h>
36 static uint64_t generatePageGroupID()
38 static uint64_t uniquePageGroupID = 1;
39 return uniquePageGroupID++;
42 typedef HashMap<uint64_t, WebPageGroup*> WebPageGroupMap;
44 static WebPageGroupMap& webPageGroupMap()
46 DEFINE_STATIC_LOCAL(WebPageGroupMap, map, ());
50 PassRefPtr<WebPageGroup> WebPageGroup::create(const String& identifier, bool visibleToInjectedBundle, bool visibleToHistoryClient)
52 RefPtr<WebPageGroup> pageGroup = adoptRef(new WebPageGroup(identifier, visibleToInjectedBundle, visibleToHistoryClient));
54 webPageGroupMap().set(pageGroup->pageGroupID(), pageGroup.get());
56 return pageGroup.release();
59 WebPageGroup* WebPageGroup::get(uint64_t pageGroupID)
61 return webPageGroupMap().get(pageGroupID);
64 WebPageGroup::WebPageGroup(const String& identifier, bool visibleToInjectedBundle, bool visibleToHistoryClient)
66 m_data.pageGroupID = generatePageGroupID();
68 if (!identifier.isNull())
69 m_data.identifer = identifier;
71 m_data.identifer = m_data.identifer = makeString("__uniquePageGroupID-", String::number(m_data.pageGroupID));
73 m_data.visibleToInjectedBundle = visibleToInjectedBundle;
74 m_data.visibleToHistoryClient = visibleToHistoryClient;
77 WebPageGroup::~WebPageGroup()
80 m_preferences->removePageGroup(this);
81 webPageGroupMap().remove(pageGroupID());
84 void WebPageGroup::addPage(WebPageProxy* page)
89 void WebPageGroup::removePage(WebPageProxy* page)
94 void WebPageGroup::setPreferences(WebPreferences* preferences)
96 if (preferences == m_preferences)
100 m_preferences = preferences;
101 m_preferences->addPageGroup(this);
103 m_preferences->removePageGroup(this);
104 m_preferences = preferences;
105 m_preferences->addPageGroup(this);
107 preferencesDidChange();
111 WebPreferences* WebPageGroup::preferences() const
113 if (!m_preferences) {
114 if (!m_data.identifer.isNull())
115 m_preferences = WebPreferences::create(m_data.identifer);
117 m_preferences = WebPreferences::create();
118 m_preferences->addPageGroup(const_cast<WebPageGroup*>(this));
120 return m_preferences.get();
123 void WebPageGroup::preferencesDidChange()
125 for (HashSet<WebPageProxy*>::iterator it = m_pages.begin(), end = m_pages.end(); it != end; ++it) {
126 WebPageProxy* page = *it;
127 page->preferencesDidChange();
131 } // namespace WebKit