1/*
2 * Copyright (C) 2010, 2011 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. 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.
24 */
25
26#ifndef WebPreferences_h
27#define WebPreferences_h
28
29#include "APIObject.h"
30#include "FontSmoothingLevel.h"
31#include "WebPreferencesDefinitions.h"
32#include "WebPreferencesStore.h"
33#include <wtf/HashSet.h>
34#include <wtf/PassRefPtr.h>
35#include <wtf/RefPtr.h>
36
37#define DECLARE_PREFERENCE_GETTER_AND_SETTERS(KeyUpper, KeyLower, TypeName, Type, DefaultValue) \
38    void set##KeyUpper(const Type& value); \
39    Type KeyLower() const;
40
41namespace WebKit {
42
43class WebPageProxy;
44
45class WebPreferences : public API::ObjectImpl<API::Object::Type::Preferences> {
46public:
47    static PassRefPtr<WebPreferences> create(const String& identifier, const String& keyPrefix, const String& globalDebugKeyPrefix);
48    static PassRefPtr<WebPreferences> createWithLegacyDefaults(const String& identifier, const String& keyPrefix, const String& globalDebugKeyPrefix);
49
50    virtual ~WebPreferences();
51
52    PassRefPtr<WebPreferences> copy() const;
53
54    void addPage(WebPageProxy&);
55    void removePage(WebPageProxy&);
56
57    const WebPreferencesStore& store() const { return m_store; }
58
59#define DECLARE_PREFERENCE_GETTER_AND_SETTERS(KeyUpper, KeyLower, TypeName, Type, DefaultValue) \
60    void set##KeyUpper(const Type& value); \
61    Type KeyLower() const; \
62
63    FOR_EACH_WEBKIT_PREFERENCE(DECLARE_PREFERENCE_GETTER_AND_SETTERS)
64    FOR_EACH_WEBKIT_DEBUG_PREFERENCE(DECLARE_PREFERENCE_GETTER_AND_SETTERS)
65
66#undef DECLARE_PREFERENCE_GETTER_AND_SETTERS
67
68    // Exposed for WebKitTestRunner use only.
69    void forceUpdate() { update(); }
70
71    static bool anyPagesAreUsingPrivateBrowsing();
72
73private:
74    explicit WebPreferences(const String& identifier, const String& keyPrefix, const String& globalDebugKeyPrefix);
75    WebPreferences(const WebPreferences&);
76
77    void platformInitializeStore();
78
79    void update();
80
81    void updateStringValueForKey(const String& key, const String& value);
82    void updateBoolValueForKey(const String& key, bool value);
83    void updateUInt32ValueForKey(const String& key, uint32_t value);
84    void updateDoubleValueForKey(const String& key, double value);
85    void updateFloatValueForKey(const String& key, float value);
86    void platformUpdateStringValueForKey(const String& key, const String& value);
87    void platformUpdateBoolValueForKey(const String& key, bool value);
88    void platformUpdateUInt32ValueForKey(const String& key, uint32_t value);
89    void platformUpdateDoubleValueForKey(const String& key, double value);
90    void platformUpdateFloatValueForKey(const String& key, float value);
91
92    void updatePrivateBrowsingValue(bool value);
93
94    void registerDefaultBoolValueForKey(const String&, bool);
95    void registerDefaultUInt32ValueForKey(const String&, uint32_t);
96
97    bool platformGetStringUserValueForKey(const String& key, String& userValue);
98    bool platformGetBoolUserValueForKey(const String&, bool&);
99    bool platformGetUInt32UserValueForKey(const String&, uint32_t&);
100    bool platformGetDoubleUserValueForKey(const String&, double&);
101
102    const String m_identifier;
103    const String m_keyPrefix;
104    const String m_globalDebugKeyPrefix;
105    WebPreferencesStore m_store;
106
107    HashSet<WebPageProxy*> m_pages;
108};
109
110} // namespace WebKit
111
112#endif // WebPreferences_h
113