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