1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
|
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Defines the classes to realize the Font Settings Extension API as specified
// in the extension API JSON.
#ifndef CHROME_BROWSER_EXTENSIONS_API_FONT_SETTINGS_FONT_SETTINGS_API_H_
#define CHROME_BROWSER_EXTENSIONS_API_FONT_SETTINGS_FONT_SETTINGS_API_H_
#include <memory>
#include <string>
#include "base/memory/raw_ptr.h"
#include "base/values.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/extension_function.h"
namespace content {
class BrowserContext;
}
namespace extensions {
class FontSettingsEventRouter;
// The profile-keyed service that manages the font_settings extension API.
// This is not an EventRouter::Observer (and does not lazily initialize) because
// doing so caused a regression in perf tests. See crbug.com/163466.
class FontSettingsAPI : public BrowserContextKeyedAPI {
public:
explicit FontSettingsAPI(content::BrowserContext* context);
~FontSettingsAPI() override;
// BrowserContextKeyedAPI implementation.
static BrowserContextKeyedAPIFactory<FontSettingsAPI>* GetFactoryInstance();
private:
friend class BrowserContextKeyedAPIFactory<FontSettingsAPI>;
// BrowserContextKeyedAPI implementation.
static const char* service_name() {
return "FontSettingsAPI";
}
static const bool kServiceIsNULLWhileTesting = true;
std::unique_ptr<FontSettingsEventRouter> font_settings_event_router_;
};
// fontSettings.clearFont API function.
class FontSettingsClearFontFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fontSettings.clearFont", FONTSETTINGS_CLEARFONT)
protected:
// RefCounted types have non-public destructors, as with all extension
// functions in this file.
~FontSettingsClearFontFunction() override = default;
// ExtensionFunction:
ResponseAction Run() override;
};
// fontSettings.getFont API function.
class FontSettingsGetFontFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fontSettings.getFont", FONTSETTINGS_GETFONT)
protected:
~FontSettingsGetFontFunction() override = default;
// ExtensionFunction:
ResponseAction Run() override;
};
// fontSettings.setFont API function.
class FontSettingsSetFontFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fontSettings.setFont", FONTSETTINGS_SETFONT)
protected:
~FontSettingsSetFontFunction() override = default;
// ExtensionFunction:
ResponseAction Run() override;
};
// fontSettings.getFontList API function.
class FontSettingsGetFontListFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fontSettings.getFontList",
FONTSETTINGS_GETFONTLIST)
protected:
~FontSettingsGetFontListFunction() override = default;
// ExtensionFunction:
ResponseAction Run() override;
private:
void FontListHasLoaded(base::Value::List list);
ResponseValue CopyFontsToResult(const base::Value::List& fonts);
};
// Base class for extension API functions that clear a browser font pref.
class ClearFontPrefExtensionFunction : public ExtensionFunction {
protected:
~ClearFontPrefExtensionFunction() override = default;
// ExtensionFunction:
ResponseAction Run() override;
// Implementations should return the name of the preference to clear, like
// "webkit.webprefs.default_font_size".
virtual const char* GetPrefName() = 0;
};
// Base class for extension API functions that get a browser font pref.
class GetFontPrefExtensionFunction : public ExtensionFunction {
protected:
~GetFontPrefExtensionFunction() override = default;
// ExtensionFunction:
ResponseAction Run() override;
// Implementations should return the name of the preference to get, like
// "webkit.webprefs.default_font_size".
virtual const char* GetPrefName() = 0;
// Implementations should return the key for the value in the extension API,
// like "pixelSize".
virtual const char* GetKey() = 0;
};
// Base class for extension API functions that set a browser font pref.
class SetFontPrefExtensionFunction : public ExtensionFunction {
protected:
~SetFontPrefExtensionFunction() override = default;
// ExtensionFunction:
ResponseAction Run() override;
// Implementations should return the name of the preference to set, like
// "webkit.webprefs.default_font_size".
virtual const char* GetPrefName() = 0;
// Implementations should return the key for the value in the extension API,
// like "pixelSize".
virtual const char* GetKey() = 0;
};
// The following are get/set/clear API functions that act on a browser font
// pref.
class FontSettingsClearDefaultFontSizeFunction
: public ClearFontPrefExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fontSettings.clearDefaultFontSize",
FONTSETTINGS_CLEARDEFAULTFONTSIZE)
protected:
~FontSettingsClearDefaultFontSizeFunction() override = default;
// ClearFontPrefExtensionFunction:
const char* GetPrefName() override;
};
class FontSettingsGetDefaultFontSizeFunction
: public GetFontPrefExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fontSettings.getDefaultFontSize",
FONTSETTINGS_GETDEFAULTFONTSIZE)
protected:
~FontSettingsGetDefaultFontSizeFunction() override = default;
// GetFontPrefExtensionFunction:
const char* GetPrefName() override;
const char* GetKey() override;
};
class FontSettingsSetDefaultFontSizeFunction
: public SetFontPrefExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fontSettings.setDefaultFontSize",
FONTSETTINGS_SETDEFAULTFONTSIZE)
protected:
~FontSettingsSetDefaultFontSizeFunction() override = default;
// SetFontPrefExtensionFunction:
const char* GetPrefName() override;
const char* GetKey() override;
};
class FontSettingsClearDefaultFixedFontSizeFunction
: public ClearFontPrefExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fontSettings.clearDefaultFixedFontSize",
FONTSETTINGS_CLEARDEFAULTFIXEDFONTSIZE)
protected:
~FontSettingsClearDefaultFixedFontSizeFunction() override = default;
// ClearFontPrefExtensionFunction:
const char* GetPrefName() override;
};
class FontSettingsGetDefaultFixedFontSizeFunction
: public GetFontPrefExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fontSettings.getDefaultFixedFontSize",
FONTSETTINGS_GETDEFAULTFIXEDFONTSIZE)
protected:
~FontSettingsGetDefaultFixedFontSizeFunction() override = default;
// GetFontPrefExtensionFunction:
const char* GetPrefName() override;
const char* GetKey() override;
};
class FontSettingsSetDefaultFixedFontSizeFunction
: public SetFontPrefExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fontSettings.setDefaultFixedFontSize",
FONTSETTINGS_SETDEFAULTFIXEDFONTSIZE)
protected:
~FontSettingsSetDefaultFixedFontSizeFunction() override = default;
// SetFontPrefExtensionFunction:
const char* GetPrefName() override;
const char* GetKey() override;
};
class FontSettingsClearMinimumFontSizeFunction
: public ClearFontPrefExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fontSettings.clearMinimumFontSize",
FONTSETTINGS_CLEARMINIMUMFONTSIZE)
protected:
~FontSettingsClearMinimumFontSizeFunction() override = default;
// ClearFontPrefExtensionFunction:
const char* GetPrefName() override;
};
class FontSettingsGetMinimumFontSizeFunction
: public GetFontPrefExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fontSettings.getMinimumFontSize",
FONTSETTINGS_GETMINIMUMFONTSIZE)
protected:
~FontSettingsGetMinimumFontSizeFunction() override = default;
// GetFontPrefExtensionFunction:
const char* GetPrefName() override;
const char* GetKey() override;
};
class FontSettingsSetMinimumFontSizeFunction
: public SetFontPrefExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fontSettings.setMinimumFontSize",
FONTSETTINGS_SETMINIMUMFONTSIZE)
protected:
~FontSettingsSetMinimumFontSizeFunction() override = default;
// SetFontPrefExtensionFunction:
const char* GetPrefName() override;
const char* GetKey() override;
};
} // namespace extensions
#endif // CHROME_BROWSER_EXTENSIONS_API_FONT_SETTINGS_FONT_SETTINGS_API_H_
|