Chromium Code Reviews| 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 <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/macros.h" | |
| 14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 17 #include "base/threading/non_thread_safe.h" | 18 #include "base/threading/non_thread_safe.h" |
| 18 #include "components/keyed_service/core/keyed_service.h" | 19 #include "components/keyed_service/core/keyed_service.h" |
| 19 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
| 20 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" |
| 21 #include "ui/base/theme_provider.h" | 22 #include "ui/base/theme_provider.h" |
| 22 | 23 |
| 23 class CustomThemeSupplier; | 24 class CustomThemeSupplier; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 51 | 52 |
| 52 #ifdef __OBJC__ | 53 #ifdef __OBJC__ |
| 53 @class NSString; | 54 @class NSString; |
| 54 // Sent whenever the browser theme changes. Object => NSValue wrapping the | 55 // Sent whenever the browser theme changes. Object => NSValue wrapping the |
| 55 // ThemeService that changed. | 56 // ThemeService that changed. |
| 56 extern "C" NSString* const kBrowserThemeDidChangeNotification; | 57 extern "C" NSString* const kBrowserThemeDidChangeNotification; |
| 57 #endif // __OBJC__ | 58 #endif // __OBJC__ |
| 58 | 59 |
| 59 class ThemeService : public base::NonThreadSafe, | 60 class ThemeService : public base::NonThreadSafe, |
| 60 public content::NotificationObserver, | 61 public content::NotificationObserver, |
| 61 public KeyedService, | 62 public KeyedService { |
| 62 public ui::ThemeProvider { | |
| 63 public: | 63 public: |
| 64 // Public constants used in ThemeService and its subclasses: | 64 // Public constants used in ThemeService and its subclasses: |
| 65 static const char* kDefaultThemeID; | 65 static const char* kDefaultThemeID; |
| 66 | 66 |
| 67 ThemeService(); | 67 ThemeService(); |
| 68 ~ThemeService() override; | 68 ~ThemeService() override; |
| 69 | 69 |
| 70 virtual void Init(Profile* profile); | 70 virtual void Init(Profile* profile); |
| 71 | 71 |
| 72 // Returns a cross platform image for an id. | |
| 73 // | |
| 74 // TODO(erg): Make this part of the ui::ThemeProvider and the main way to get | |
| 75 // theme properties out of the theme provider since it's cross platform. | |
| 76 virtual gfx::Image GetImageNamed(int id) const; | |
| 77 | |
| 78 // Overridden from ui::ThemeProvider: | |
| 79 bool UsingSystemTheme() const override; | |
| 80 gfx::ImageSkia* GetImageSkiaNamed(int id) const override; | |
| 81 SkColor GetColor(int id) const override; | |
| 82 int GetDisplayProperty(int id) const override; | |
| 83 bool ShouldUseNativeFrame() const override; | |
| 84 bool HasCustomImage(int id) const override; | |
| 85 base::RefCountedMemory* GetRawData(int id, ui::ScaleFactor scale_factor) | |
| 86 const override; | |
| 87 #if defined(OS_MACOSX) | |
| 88 NSImage* GetNSImageNamed(int id) const override; | |
| 89 NSColor* GetNSImageColorNamed(int id) const override; | |
| 90 NSColor* GetNSColor(int id) const override; | |
| 91 NSColor* GetNSColorTint(int id) const override; | |
| 92 NSGradient* GetNSGradient(int id) const override; | |
| 93 #endif | |
| 94 | |
| 95 // KeyedService: | 72 // KeyedService: |
| 96 void Shutdown() override; | 73 void Shutdown() override; |
| 97 | 74 |
| 98 // Overridden from content::NotificationObserver: | 75 // Overridden from content::NotificationObserver: |
| 99 void Observe(int type, | 76 void Observe(int type, |
| 100 const content::NotificationSource& source, | 77 const content::NotificationSource& source, |
| 101 const content::NotificationDetails& details) override; | 78 const content::NotificationDetails& details) override; |
| 102 | 79 |
| 103 // Set the current theme to the theme defined in |extension|. | 80 // Set the current theme to the theme defined in |extension|. |
| 104 // |extension| must already be added to this profile's | 81 // |extension| must already be added to this profile's |
| 105 // ExtensionService. | 82 // ExtensionService. |
| 106 virtual void SetTheme(const extensions::Extension* extension); | 83 virtual void SetTheme(const extensions::Extension* extension); |
| 107 | 84 |
| 108 // Reset the theme to default. | 85 // Reset the theme to default. |
| 109 virtual void UseDefaultTheme(); | 86 virtual void UseDefaultTheme(); |
| 110 | 87 |
| 111 // 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 |
| 112 // theme is the default theme. | 89 // theme is the default theme. |
| 113 virtual void UseSystemTheme(); | 90 virtual void UseSystemTheme(); |
| 114 | 91 |
| 115 // 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 |
| 116 // this platform. | 93 // this platform. |
| 117 virtual bool IsSystemThemeDistinctFromDefaultTheme() const; | 94 virtual bool IsSystemThemeDistinctFromDefaultTheme() const; |
| 118 | 95 |
| 119 // Whether we're using the chrome default theme. Virtual so linux can check | 96 // Whether we're using the chrome default theme. Virtual so linux can check |
| 120 // if we're using the GTK theme. | 97 // if we're using the GTK theme. |
| 121 virtual bool UsingDefaultTheme() const; | 98 virtual bool UsingDefaultTheme() const; |
| 122 | 99 |
| 100 // Also overridden for GTK. | |
|
pkotwicz
2015/12/04 23:16:49
How about: "Whether we are using the system theme.
Evan Stade
2015/12/09 00:57:11
Done.
| |
| 101 virtual bool UsingSystemTheme() const; | |
| 102 | |
| 123 // Gets the id of the last installed theme. (The theme may have been further | 103 // Gets the id of the last installed theme. (The theme may have been further |
| 124 // locally customized.) | 104 // locally customized.) |
| 125 virtual std::string GetThemeID() const; | 105 virtual std::string GetThemeID() const; |
| 126 | 106 |
| 127 // This class needs to keep track of the number of theme infobars so that we | 107 // This class needs to keep track of the number of theme infobars so that we |
| 128 // clean up unused themes. | 108 // clean up unused themes. |
| 129 void OnInfobarDisplayed(); | 109 void OnInfobarDisplayed(); |
| 130 | 110 |
| 131 // Decrements the number of theme infobars. If the last infobar has been | 111 // Decrements the number of theme infobars. If the last infobar has been |
| 132 // destroyed, uninstalls all themes that aren't the currently selected. | 112 // destroyed, uninstalls all themes that aren't the currently selected. |
| 133 void OnInfobarDestroyed(); | 113 void OnInfobarDestroyed(); |
| 134 | 114 |
| 135 // Uninstall theme extensions which are no longer in use. |ignore_infobars| is | 115 // Uninstall theme extensions which are no longer in use. |ignore_infobars| is |
| 136 // whether unused themes should be removed despite a theme infobar being | 116 // whether unused themes should be removed despite a theme infobar being |
| 137 // visible. | 117 // visible. |
| 138 void RemoveUnusedThemes(bool ignore_infobars); | 118 void RemoveUnusedThemes(bool ignore_infobars); |
| 139 | 119 |
| 140 // Returns the syncable service for syncing theme. The returned service is | 120 // Returns the syncable service for syncing theme. The returned service is |
| 141 // owned by |this| object. | 121 // owned by |this| object. |
| 142 virtual ThemeSyncableService* GetThemeSyncableService() const; | 122 virtual ThemeSyncableService* GetThemeSyncableService() const; |
| 143 | 123 |
| 144 // Save the images to be written to disk, mapping file path to id. | 124 static const ui::ThemeProvider& GetThemeProviderForProfile(Profile* profile); |
|
pkotwicz
2015/12/04 23:16:50
Is returning a const reference from a static metho
Evan Stade
2015/12/09 00:57:11
a new pattern? No, it has existed for a while. The
| |
| 145 typedef std::map<base::FilePath, int> ImagesDiskCache; | |
| 146 | 125 |
| 147 protected: | 126 protected: |
| 148 // Set a custom default theme instead of the normal default theme. | 127 // Set a custom default theme instead of the normal default theme. |
| 149 virtual void SetCustomDefaultTheme( | 128 virtual void SetCustomDefaultTheme( |
| 150 scoped_refptr<CustomThemeSupplier> theme_supplier); | 129 scoped_refptr<CustomThemeSupplier> theme_supplier); |
| 151 | 130 |
| 152 // Returns true if the ThemeService should use the system theme on startup. | 131 // Returns true if the ThemeService should use the system theme on startup. |
| 153 virtual bool ShouldInitWithSystemTheme() const; | 132 virtual bool ShouldInitWithSystemTheme() const; |
| 154 | 133 |
| 155 // Get the specified tint - |id| is one of the TINT_* enum values. | 134 // Get the specified tint - |id| is one of the TINT_* enum values. |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 182 } | 161 } |
| 183 | 162 |
| 184 // True if the theme service is ready to be used. | 163 // True if the theme service is ready to be used. |
| 185 // TODO(pkotwicz): Add DCHECKS to the theme service's getters once | 164 // TODO(pkotwicz): Add DCHECKS to the theme service's getters once |
| 186 // ThemeSource no longer uses the ThemeService when it is not ready. | 165 // ThemeSource no longer uses the ThemeService when it is not ready. |
| 187 bool ready_; | 166 bool ready_; |
| 188 | 167 |
| 189 private: | 168 private: |
| 190 friend class theme_service_internal::ThemeServiceTest; | 169 friend class theme_service_internal::ThemeServiceTest; |
| 191 | 170 |
| 171 // This class serves to isolate the ThemeProvider methods that are implemented | |
| 172 // by ThemeService, and handles modifications based on whether the profile is | |
| 173 // incognito (otr) or normal. | |
|
pkotwicz
2015/12/04 23:16:50
How about: "This class implements ui::ThemeProvide
Evan Stade
2015/12/09 00:57:11
adjusted
| |
| 174 class BrowserThemeProvider : public ui::ThemeProvider { | |
| 175 public: | |
| 176 BrowserThemeProvider(const ThemeService& theme_service, bool otr); | |
| 177 ~BrowserThemeProvider() override; | |
| 178 | |
| 179 // Overridden from ui::ThemeProvider: | |
| 180 gfx::ImageSkia* GetImageSkiaNamed(int id) const override; | |
| 181 SkColor GetColor(int id) const override; | |
| 182 int GetDisplayProperty(int id) const override; | |
| 183 bool ShouldUseNativeFrame() const override; | |
| 184 bool HasCustomImage(int id) const override; | |
| 185 base::RefCountedMemory* GetRawData(int id, ui::ScaleFactor scale_factor) | |
| 186 const override; | |
| 187 #if defined(OS_MACOSX) | |
| 188 bool UsingSystemTheme() const override; | |
| 189 NSImage* GetNSImageNamed(int id) const override; | |
| 190 NSColor* GetNSImageColorNamed(int id) const override; | |
| 191 NSColor* GetNSColor(int id) const override; | |
| 192 NSColor* GetNSColorTint(int id) const override; | |
| 193 NSGradient* GetNSGradient(int id) const override; | |
| 194 #endif | |
| 195 | |
| 196 private: | |
| 197 const ThemeService& theme_service_; | |
|
pkotwicz
2015/12/04 23:16:49
Nit: Make this a const pointer (const ThemeService
Evan Stade
2015/12/09 00:57:11
why? It should never be null and this makes that c
| |
| 198 bool otr_; | |
|
pkotwicz
2015/12/04 23:16:50
Might as well name this variable |off_the_record_|
Evan Stade
2015/12/09 00:57:11
Done.
| |
| 199 | |
| 200 DISALLOW_COPY_AND_ASSIGN(BrowserThemeProvider); | |
| 201 }; | |
| 202 friend class BrowserThemeProvider; | |
| 203 | |
| 204 const ui::ThemeProvider& GetOrCreateThemeProviderForProfile(Profile* profile); | |
| 205 | |
| 206 // These methods provide the implementation for ui::ThemeProvider (exposed | |
| 207 // via BrowserThemeProvider). | |
| 208 gfx::ImageSkia* GetImageSkiaNamed(int id) const; | |
| 209 SkColor GetColor(int id) const; | |
| 210 int GetDisplayProperty(int id) const; | |
| 211 bool ShouldUseNativeFrame() const; | |
| 212 bool HasCustomImage(int id) const; | |
| 213 base::RefCountedMemory* GetRawData(int id, | |
| 214 ui::ScaleFactor scale_factor) const; | |
| 215 #if defined(OS_MACOSX) | |
| 216 bool UsingSystemTheme() const; | |
|
pkotwicz
2015/12/04 23:16:50
UsingSystemTheme() should not be present twice in
Evan Stade
2015/12/09 00:57:11
Done.
| |
| 217 NSImage* GetNSImageNamed(int id) const; | |
| 218 NSColor* GetNSImageColorNamed(int id) const; | |
| 219 NSColor* GetNSColor(int id) const; | |
| 220 NSColor* GetNSColorTint(int id) const; | |
| 221 NSGradient* GetNSGradient(int id) const; | |
| 222 #endif | |
| 223 | |
| 224 // Returns a cross platform image for an id. | |
| 225 // | |
| 226 // TODO(erg): Make this part of the ui::ThemeProvider and the main way to get | |
| 227 // theme properties out of the theme provider since it's cross platform. | |
| 228 virtual gfx::Image GetImageNamed(int id) const; | |
| 229 | |
| 192 // Called when the extension service is ready. | 230 // Called when the extension service is ready. |
| 193 void OnExtensionServiceReady(); | 231 void OnExtensionServiceReady(); |
| 194 | 232 |
| 195 // Migrate the theme to the new theme pack schema by recreating the data pack | 233 // Migrate the theme to the new theme pack schema by recreating the data pack |
| 196 // from the extension. | 234 // from the extension. |
| 197 void MigrateTheme(); | 235 void MigrateTheme(); |
| 198 | 236 |
| 199 // Replaces the current theme supplier with a new one and calls | 237 // Replaces the current theme supplier with a new one and calls |
| 200 // StopUsingTheme() or StartUsingTheme() as appropriate. | 238 // StopUsingTheme() or StartUsingTheme() as appropriate. |
| 201 void SwapThemeSupplier(scoped_refptr<CustomThemeSupplier> theme_supplier); | 239 void SwapThemeSupplier(scoped_refptr<CustomThemeSupplier> theme_supplier); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 | 287 |
| 250 content::NotificationRegistrar registrar_; | 288 content::NotificationRegistrar registrar_; |
| 251 | 289 |
| 252 scoped_ptr<ThemeSyncableService> theme_syncable_service_; | 290 scoped_ptr<ThemeSyncableService> theme_syncable_service_; |
| 253 | 291 |
| 254 #if defined(ENABLE_EXTENSIONS) | 292 #if defined(ENABLE_EXTENSIONS) |
| 255 class ThemeObserver; | 293 class ThemeObserver; |
| 256 scoped_ptr<ThemeObserver> theme_observer_; | 294 scoped_ptr<ThemeObserver> theme_observer_; |
| 257 #endif | 295 #endif |
| 258 | 296 |
| 297 BrowserThemeProvider original_theme_provider_; | |
| 298 BrowserThemeProvider otr_theme_provider_; | |
| 299 | |
| 259 base::WeakPtrFactory<ThemeService> weak_ptr_factory_; | 300 base::WeakPtrFactory<ThemeService> weak_ptr_factory_; |
| 260 | 301 |
| 261 DISALLOW_COPY_AND_ASSIGN(ThemeService); | 302 DISALLOW_COPY_AND_ASSIGN(ThemeService); |
| 262 }; | 303 }; |
| 263 | 304 |
| 264 #endif // CHROME_BROWSER_THEMES_THEME_SERVICE_H_ | 305 #endif // CHROME_BROWSER_THEMES_THEME_SERVICE_H_ |
| OLD | NEW |