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