| 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 #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 "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "chrome/browser/instant/instant_io_context.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/resources_util.h" | 12 #include "chrome/browser/resources_util.h" |
| 12 #include "chrome/browser/themes/theme_properties.h" | 13 #include "chrome/browser/themes/theme_properties.h" |
| 13 #include "chrome/browser/themes/theme_service.h" | 14 #include "chrome/browser/themes/theme_service.h" |
| 14 #include "chrome/browser/themes/theme_service_factory.h" | 15 #include "chrome/browser/themes/theme_service_factory.h" |
| 15 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" | 16 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" |
| 16 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" | 17 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" |
| 17 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
| 18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 19 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
| 21 #include "net/url_request/url_request.h" |
| 20 #include "ui/base/layout.h" | 22 #include "ui/base/layout.h" |
| 21 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
| 22 #include "ui/webui/web_ui_util.h" | 24 #include "ui/webui/web_ui_util.h" |
| 23 | 25 |
| 24 using content::BrowserThread; | 26 using content::BrowserThread; |
| 25 | 27 |
| 26 namespace { | 28 namespace { |
| 27 | 29 |
| 28 std::string GetThemePath() { | 30 std::string GetThemePath() { |
| 29 return std::string(chrome::kChromeUIScheme) + | 31 return std::string(chrome::kChromeUIScheme) + |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 117 |
| 116 return content::URLDataSource::MessageLoopForRequestPath(path); | 118 return content::URLDataSource::MessageLoopForRequestPath(path); |
| 117 } | 119 } |
| 118 | 120 |
| 119 bool ThemeSource::ShouldReplaceExistingSource() const { | 121 bool ThemeSource::ShouldReplaceExistingSource() const { |
| 120 // We currently get the css_bytes_ in the ThemeSource constructor, so we need | 122 // We currently get the css_bytes_ in the ThemeSource constructor, so we need |
| 121 // to recreate the source itself when a theme changes. | 123 // to recreate the source itself when a theme changes. |
| 122 return true; | 124 return true; |
| 123 } | 125 } |
| 124 | 126 |
| 127 bool ThemeSource::ShouldServiceRequest(const net::URLRequest* request) const { |
| 128 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) |
| 129 return InstantIOContext::ShouldServiceRequest(request); |
| 130 return URLDataSource::ShouldServiceRequest(request); |
| 131 } |
| 132 |
| 125 //////////////////////////////////////////////////////////////////////////////// | 133 //////////////////////////////////////////////////////////////////////////////// |
| 126 // ThemeSource, private: | 134 // ThemeSource, private: |
| 127 | 135 |
| 128 void ThemeSource::SendThemeBitmap( | 136 void ThemeSource::SendThemeBitmap( |
| 129 const content::URLDataSource::GotDataCallback& callback, | 137 const content::URLDataSource::GotDataCallback& callback, |
| 130 int resource_id, | 138 int resource_id, |
| 131 ui::ScaleFactor scale_factor) { | 139 ui::ScaleFactor scale_factor) { |
| 132 if (ThemeProperties::IsThemeableImage(resource_id)) { | 140 if (ThemeProperties::IsThemeableImage(resource_id)) { |
| 133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 134 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_); | 142 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_); |
| 135 DCHECK(tp); | 143 DCHECK(tp); |
| 136 | 144 |
| 137 scoped_refptr<base::RefCountedMemory> image_data(tp->GetRawData( | 145 scoped_refptr<base::RefCountedMemory> image_data(tp->GetRawData( |
| 138 resource_id, scale_factor)); | 146 resource_id, scale_factor)); |
| 139 callback.Run(image_data); | 147 callback.Run(image_data); |
| 140 } else { | 148 } else { |
| 141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 149 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 142 const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 150 const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 143 callback.Run(rb.LoadDataResourceBytesForScale(resource_id, scale_factor)); | 151 callback.Run(rb.LoadDataResourceBytesForScale(resource_id, scale_factor)); |
| 144 } | 152 } |
| 145 } | 153 } |
| OLD | NEW |