OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/dom_ui/dom_ui_theme_source.h" | 5 #include "chrome/browser/dom_ui/dom_ui_theme_source.h" |
6 | 6 |
7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
8 #include "app/theme_provider.h" | 8 #include "app/theme_provider.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/ref_counted_memory.h" |
10 #include "chrome/browser/browser_theme_provider.h" | 11 #include "chrome/browser/browser_theme_provider.h" |
11 #include "chrome/browser/chrome_thread.h" | 12 #include "chrome/browser/chrome_thread.h" |
12 #include "chrome/browser/dom_ui/ntp_resource_cache.h" | 13 #include "chrome/browser/dom_ui/ntp_resource_cache.h" |
13 #include "chrome/browser/profile.h" | 14 #include "chrome/browser/profile.h" |
14 #include "chrome/browser/resources_util.h" | 15 #include "chrome/browser/resources_util.h" |
15 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
16 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
17 | 18 |
18 // use a resource map rather than hard-coded strings. | 19 // use a resource map rather than hard-coded strings. |
19 static const char* kNewTabCSSPath = "css/newtab.css"; | 20 static const char* kNewTabCSSPath = "css/newtab.css"; |
20 static const char* kNewIncognitoTabCSSPath = "css/newincognitotab.css"; | 21 static const char* kNewIncognitoTabCSSPath = "css/newincognitotab.css"; |
21 | 22 |
22 static std::string StripQueryParams(const std::string& path) { | 23 static std::string StripQueryParams(const std::string& path) { |
23 GURL path_url = GURL(std::string(chrome::kChromeUIScheme) + "://" + | 24 GURL path_url = GURL(std::string(chrome::kChromeUIScheme) + "://" + |
24 std::string(chrome::kChromeUIThemePath) + "/" + path); | 25 std::string(chrome::kChromeUIThemePath) + "/" + path); |
25 return path_url.path().substr(1); // path() always includes a leading '/'. | 26 return path_url.path().substr(1); // path() always includes a leading '/'. |
26 } | 27 } |
27 | 28 |
28 //////////////////////////////////////////////////////////////////////////////// | 29 //////////////////////////////////////////////////////////////////////////////// |
29 // DOMUIThemeSource, public: | 30 // DOMUIThemeSource, public: |
30 | 31 |
31 DOMUIThemeSource::DOMUIThemeSource(Profile* profile) | 32 DOMUIThemeSource::DOMUIThemeSource(Profile* profile) |
32 : DataSource(chrome::kChromeUIThemePath, MessageLoop::current()), | 33 : DataSource(chrome::kChromeUIThemePath, MessageLoop::current()), |
33 profile_(profile->GetOriginalProfile()) { | 34 profile_(profile->GetOriginalProfile()) { |
34 css_bytes_ = profile_->GetNTPResourceCache()->GetNewTabCSS( | 35 css_bytes_ = profile_->GetNTPResourceCache()->GetNewTabCSS( |
35 profile->IsOffTheRecord()); | 36 profile->IsOffTheRecord()); |
36 } | 37 } |
37 | 38 |
| 39 DOMUIThemeSource::~DOMUIThemeSource() { |
| 40 } |
| 41 |
38 void DOMUIThemeSource::StartDataRequest(const std::string& path, | 42 void DOMUIThemeSource::StartDataRequest(const std::string& path, |
39 bool is_off_the_record, | 43 bool is_off_the_record, |
40 int request_id) { | 44 int request_id) { |
41 // Our path may include cachebuster arguments, so trim them off. | 45 // Our path may include cachebuster arguments, so trim them off. |
42 std::string uncached_path = StripQueryParams(path); | 46 std::string uncached_path = StripQueryParams(path); |
43 | 47 |
44 if (uncached_path == kNewTabCSSPath || | 48 if (uncached_path == kNewTabCSSPath || |
45 uncached_path == kNewIncognitoTabCSSPath) { | 49 uncached_path == kNewIncognitoTabCSSPath) { |
46 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 50 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
47 DCHECK((uncached_path == kNewTabCSSPath && !is_off_the_record) || | 51 DCHECK((uncached_path == kNewTabCSSPath && !is_off_the_record) || |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 DCHECK(tp); | 104 DCHECK(tp); |
101 | 105 |
102 scoped_refptr<RefCountedMemory> image_data(tp->GetRawData(resource_id)); | 106 scoped_refptr<RefCountedMemory> image_data(tp->GetRawData(resource_id)); |
103 SendResponse(request_id, image_data); | 107 SendResponse(request_id, image_data); |
104 } else { | 108 } else { |
105 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 109 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
106 const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 110 const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
107 SendResponse(request_id, rb.LoadDataResourceBytes(resource_id)); | 111 SendResponse(request_id, rb.LoadDataResourceBytes(resource_id)); |
108 } | 112 } |
109 } | 113 } |
OLD | NEW |