OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_THEMES_THEME_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_THEMES_THEME_SERVICE_H_ |
6 #define CHROME_BROWSER_THEMES_THEME_SERVICE_H_ | 6 #define CHROME_BROWSER_THEMES_THEME_SERVICE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 #include <utility> | 12 #include <utility> |
13 | 13 |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
18 #include "base/sequence_checker.h" | 18 #include "base/sequence_checker.h" |
19 #include "base/task/cancelable_task_tracker.h" | |
20 #include "build/build_config.h" | 19 #include "build/build_config.h" |
21 #include "chrome/common/features.h" | 20 #include "chrome/common/features.h" |
22 #include "components/keyed_service/core/keyed_service.h" | 21 #include "components/keyed_service/core/keyed_service.h" |
23 #include "content/public/browser/notification_observer.h" | 22 #include "content/public/browser/notification_observer.h" |
24 #include "content/public/browser/notification_registrar.h" | 23 #include "content/public/browser/notification_registrar.h" |
25 #include "extensions/common/extension_id.h" | |
26 #include "extensions/features/features.h" | 24 #include "extensions/features/features.h" |
27 #include "ui/base/theme_provider.h" | 25 #include "ui/base/theme_provider.h" |
28 | 26 |
29 class BrowserThemePack; | |
30 class CustomThemeSupplier; | 27 class CustomThemeSupplier; |
31 class ThemeSyncableService; | 28 class ThemeSyncableService; |
32 class Profile; | 29 class Profile; |
33 | 30 |
34 namespace base { | 31 namespace base { |
35 class FilePath; | 32 class FilePath; |
36 } | 33 } |
37 | 34 |
38 namespace color_utils { | 35 namespace color_utils { |
39 struct HSL; | 36 struct HSL; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 // Overridden from content::NotificationObserver: | 75 // Overridden from content::NotificationObserver: |
79 void Observe(int type, | 76 void Observe(int type, |
80 const content::NotificationSource& source, | 77 const content::NotificationSource& source, |
81 const content::NotificationDetails& details) override; | 78 const content::NotificationDetails& details) override; |
82 | 79 |
83 // Set the current theme to the theme defined in |extension|. | 80 // Set the current theme to the theme defined in |extension|. |
84 // |extension| must already be added to this profile's | 81 // |extension| must already be added to this profile's |
85 // ExtensionService. | 82 // ExtensionService. |
86 virtual void SetTheme(const extensions::Extension* extension); | 83 virtual void SetTheme(const extensions::Extension* extension); |
87 | 84 |
88 // Similar to SetTheme, but doesn't show an undo infobar. | |
89 void RevertToTheme(const extensions::Extension* extension); | |
90 | |
91 // Reset the theme to default. | 85 // Reset the theme to default. |
92 virtual void UseDefaultTheme(); | 86 virtual void UseDefaultTheme(); |
93 | 87 |
94 // Set the current theme to the system theme. On some platforms, the system | 88 // Set the current theme to the system theme. On some platforms, the system |
95 // theme is the default theme. | 89 // theme is the default theme. |
96 virtual void UseSystemTheme(); | 90 virtual void UseSystemTheme(); |
97 | 91 |
98 // Returns true if the default theme and system theme are not the same on | 92 // Returns true if the default theme and system theme are not the same on |
99 // this platform. | 93 // this platform. |
100 virtual bool IsSystemThemeDistinctFromDefaultTheme() const; | 94 virtual bool IsSystemThemeDistinctFromDefaultTheme() const; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 // Computes the "toolbar top separator" color. This color is drawn atop the | 223 // Computes the "toolbar top separator" color. This color is drawn atop the |
230 // frame to separate it from tabs, the toolbar, and the new tab button, as | 224 // frame to separate it from tabs, the toolbar, and the new tab button, as |
231 // well as atop background tabs to separate them from other tabs or the | 225 // well as atop background tabs to separate them from other tabs or the |
232 // toolbar. We use semitransparent black or white so as to darken or lighten | 226 // toolbar. We use semitransparent black or white so as to darken or lighten |
233 // the frame, with the goal of contrasting with both the frame color and the | 227 // the frame, with the goal of contrasting with both the frame color and the |
234 // active tab (i.e. toolbar) color. (It's too difficult to try to find colors | 228 // active tab (i.e. toolbar) color. (It's too difficult to try to find colors |
235 // that will contrast with both of these as well as the background tab color, | 229 // that will contrast with both of these as well as the background tab color, |
236 // and contrasting with the foreground tab is the most important). | 230 // and contrasting with the foreground tab is the most important). |
237 static SkColor GetSeparatorColor(SkColor tab_color, SkColor frame_color); | 231 static SkColor GetSeparatorColor(SkColor tab_color, SkColor frame_color); |
238 | 232 |
239 void DoSetTheme(const extensions::Extension* extension, | |
240 bool suppress_infobar); | |
241 | |
242 // These methods provide the implementation for ui::ThemeProvider (exposed | 233 // These methods provide the implementation for ui::ThemeProvider (exposed |
243 // via BrowserThemeProvider). | 234 // via BrowserThemeProvider). |
244 gfx::ImageSkia* GetImageSkiaNamed(int id, bool incognito) const; | 235 gfx::ImageSkia* GetImageSkiaNamed(int id, bool incognito) const; |
245 SkColor GetColor(int id, bool incognito) const; | 236 SkColor GetColor(int id, bool incognito) const; |
246 int GetDisplayProperty(int id) const; | 237 int GetDisplayProperty(int id) const; |
247 base::RefCountedMemory* GetRawData(int id, | 238 base::RefCountedMemory* GetRawData(int id, |
248 ui::ScaleFactor scale_factor) const; | 239 ui::ScaleFactor scale_factor) const; |
249 #if defined(OS_MACOSX) | 240 #if defined(OS_MACOSX) |
250 NSImage* GetNSImageNamed(int id, bool incognito) const; | 241 NSImage* GetNSImageNamed(int id, bool incognito) const; |
251 NSColor* GetNSImageColorNamed(int id, bool incognito) const; | 242 NSColor* GetNSImageColorNamed(int id, bool incognito) const; |
(...skipping 20 matching lines...) Expand all Loading... |
272 // StopUsingTheme() or StartUsingTheme() as appropriate. | 263 // StopUsingTheme() or StartUsingTheme() as appropriate. |
273 void SwapThemeSupplier(scoped_refptr<CustomThemeSupplier> theme_supplier); | 264 void SwapThemeSupplier(scoped_refptr<CustomThemeSupplier> theme_supplier); |
274 | 265 |
275 // Saves the filename of the cached theme pack. | 266 // Saves the filename of the cached theme pack. |
276 void SavePackName(const base::FilePath& pack_path); | 267 void SavePackName(const base::FilePath& pack_path); |
277 | 268 |
278 // Save the id of the last theme installed. | 269 // Save the id of the last theme installed. |
279 void SaveThemeID(const std::string& id); | 270 void SaveThemeID(const std::string& id); |
280 | 271 |
281 // Implementation of SetTheme() (and the fallback from LoadThemePrefs() in | 272 // Implementation of SetTheme() (and the fallback from LoadThemePrefs() in |
282 // case we don't have a theme pack). |new_theme| indicates whether this is a | 273 // case we don't have a theme pack). |
283 // newly installed theme or a migration. | 274 void BuildFromExtension(const extensions::Extension* extension); |
284 void BuildFromExtension(const extensions::Extension* extension, | |
285 bool new_theme); | |
286 | |
287 // Callback when |pack| has finished or failed building. | |
288 void OnThemeBuiltFromExtension(const extensions::ExtensionId& extension_id, | |
289 scoped_refptr<BrowserThemePack> pack, | |
290 bool new_theme); | |
291 | 275 |
292 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) | 276 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
293 // Returns true if the profile belongs to a supervised user. | 277 // Returns true if the profile belongs to a supervised user. |
294 bool IsSupervisedUser() const; | 278 bool IsSupervisedUser() const; |
295 | 279 |
296 // Sets the current theme to the supervised user theme. Should only be used | 280 // Sets the current theme to the supervised user theme. Should only be used |
297 // for supervised user profiles. | 281 // for supervised user profiles. |
298 void SetSupervisedUserTheme(); | 282 void SetSupervisedUserTheme(); |
299 #endif | 283 #endif |
300 | 284 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 #if BUILDFLAG(ENABLE_EXTENSIONS) | 321 #if BUILDFLAG(ENABLE_EXTENSIONS) |
338 class ThemeObserver; | 322 class ThemeObserver; |
339 std::unique_ptr<ThemeObserver> theme_observer_; | 323 std::unique_ptr<ThemeObserver> theme_observer_; |
340 #endif | 324 #endif |
341 | 325 |
342 BrowserThemeProvider original_theme_provider_; | 326 BrowserThemeProvider original_theme_provider_; |
343 BrowserThemeProvider incognito_theme_provider_; | 327 BrowserThemeProvider incognito_theme_provider_; |
344 | 328 |
345 SEQUENCE_CHECKER(sequence_checker_); | 329 SEQUENCE_CHECKER(sequence_checker_); |
346 | 330 |
347 // Allows us to cancel building a theme pack from an extension. | |
348 base::CancelableTaskTracker build_extension_task_tracker_; | |
349 | |
350 // The ID of the theme that's currently being built on a different thread. | |
351 // We hold onto this just to be sure not to uninstall the extension view | |
352 // RemoveUnusedThemes while it's still being built. | |
353 std::string building_extension_id_; | |
354 | |
355 base::WeakPtrFactory<ThemeService> weak_ptr_factory_; | 331 base::WeakPtrFactory<ThemeService> weak_ptr_factory_; |
356 | 332 |
357 DISALLOW_COPY_AND_ASSIGN(ThemeService); | 333 DISALLOW_COPY_AND_ASSIGN(ThemeService); |
358 }; | 334 }; |
359 | 335 |
360 #endif // CHROME_BROWSER_THEMES_THEME_SERVICE_H_ | 336 #endif // CHROME_BROWSER_THEMES_THEME_SERVICE_H_ |
OLD | NEW |