| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/ui/webui/theme_source.h" | 5 #include "chrome/browser/ui/webui/theme_source.h" |
| 6 | 6 |
| 7 #include "base/memory/ref_counted_memory.h" | 7 #include "base/memory/ref_counted_memory.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/resources_util.h" | 10 #include "chrome/browser/resources_util.h" |
| 11 #include "chrome/browser/themes/theme_service.h" | 11 #include "chrome/browser/themes/theme_service.h" |
| 12 #include "chrome/browser/themes/theme_service_factory.h" | 12 #include "chrome/browser/themes/theme_service_factory.h" |
| 13 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" | 13 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" |
| 14 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" |
| 14 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
| 15 #include "content/browser/browser_thread.h" | 16 #include "content/browser/browser_thread.h" |
| 16 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 17 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 18 #include "ui/base/theme_provider.h" | 19 #include "ui/base/theme_provider.h" |
| 19 | 20 |
| 20 // use a resource map rather than hard-coded strings. | 21 // use a resource map rather than hard-coded strings. |
| 21 static const char* kNewTabCSSPath = "css/newtab.css"; | 22 static const char* kNewTabCSSPath = "css/newtab.css"; |
| 22 static const char* kNewIncognitoTabCSSPath = "css/newincognitotab.css"; | 23 static const char* kNewIncognitoTabCSSPath = "css/newincognitotab.css"; |
| 23 | 24 |
| 24 static std::string StripQueryParams(const std::string& path) { | 25 static std::string StripQueryParams(const std::string& path) { |
| 25 GURL path_url = GURL(std::string(chrome::kChromeUIScheme) + "://" + | 26 GURL path_url = GURL(std::string(chrome::kChromeUIScheme) + "://" + |
| 26 std::string(chrome::kChromeUIThemePath) + "/" + path); | 27 std::string(chrome::kChromeUIThemePath) + "/" + path); |
| 27 return path_url.path().substr(1); // path() always includes a leading '/'. | 28 return path_url.path().substr(1); // path() always includes a leading '/'. |
| 28 } | 29 } |
| 29 | 30 |
| 30 //////////////////////////////////////////////////////////////////////////////// | 31 //////////////////////////////////////////////////////////////////////////////// |
| 31 // ThemeSource, public: | 32 // ThemeSource, public: |
| 32 | 33 |
| 33 ThemeSource::ThemeSource(Profile* profile) | 34 ThemeSource::ThemeSource(Profile* profile) |
| 34 : DataSource(chrome::kChromeUIThemePath, MessageLoop::current()), | 35 : DataSource(chrome::kChromeUIThemePath, MessageLoop::current()), |
| 35 profile_(profile->GetOriginalProfile()) { | 36 profile_(profile->GetOriginalProfile()) { |
| 36 css_bytes_ = profile_->GetNTPResourceCache()->GetNewTabCSS( | 37 css_bytes_ = NTPResourceCacheFactory::GetForProfile(profile)->GetNewTabCSS( |
| 37 profile->IsOffTheRecord()); | 38 profile->IsOffTheRecord()); |
| 38 } | 39 } |
| 39 | 40 |
| 40 ThemeSource::~ThemeSource() { | 41 ThemeSource::~ThemeSource() { |
| 41 } | 42 } |
| 42 | 43 |
| 43 void ThemeSource::StartDataRequest(const std::string& path, | 44 void ThemeSource::StartDataRequest(const std::string& path, |
| 44 bool is_incognito, | 45 bool is_incognito, |
| 45 int request_id) { | 46 int request_id) { |
| 46 // Our path may include cachebuster arguments, so trim them off. | 47 // Our path may include cachebuster arguments, so trim them off. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 DCHECK(tp); | 112 DCHECK(tp); |
| 112 | 113 |
| 113 scoped_refptr<RefCountedMemory> image_data(tp->GetRawData(resource_id)); | 114 scoped_refptr<RefCountedMemory> image_data(tp->GetRawData(resource_id)); |
| 114 SendResponse(request_id, image_data); | 115 SendResponse(request_id, image_data); |
| 115 } else { | 116 } else { |
| 116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 117 const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 118 const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 118 SendResponse(request_id, rb.LoadDataResourceBytes(resource_id)); | 119 SendResponse(request_id, rb.LoadDataResourceBytes(resource_id)); |
| 119 } | 120 } |
| 120 } | 121 } |
| OLD | NEW |