Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/search/local_ntp_source.h" | 5 #include "chrome/browser/search/local_ntp_source.h" |
| 6 | 6 |
| 7 #include "base/json/json_string_value_serializer.h" | 7 #include "base/json/json_string_value_serializer.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 { "local-ntp.js", IDR_LOCAL_NTP_JS, "application/javascript" }, | 54 { "local-ntp.js", IDR_LOCAL_NTP_JS, "application/javascript" }, |
| 55 { kConfigDataFilename, kLocalResource, "application/javascript" }, | 55 { kConfigDataFilename, kLocalResource, "application/javascript" }, |
| 56 { "local-ntp.css", IDR_LOCAL_NTP_CSS, "text/css" }, | 56 { "local-ntp.css", IDR_LOCAL_NTP_CSS, "text/css" }, |
| 57 { "images/close_2.png", IDR_CLOSE_2, "image/png" }, | 57 { "images/close_2.png", IDR_CLOSE_2, "image/png" }, |
| 58 { "images/close_2_hover.png", IDR_CLOSE_2_H, "image/png" }, | 58 { "images/close_2_hover.png", IDR_CLOSE_2_H, "image/png" }, |
| 59 { "images/close_2_active.png", IDR_CLOSE_2_P, "image/png" }, | 59 { "images/close_2_active.png", IDR_CLOSE_2_P, "image/png" }, |
| 60 { "images/close_2_white.png", IDR_CLOSE_2_MASK, "image/png" }, | 60 { "images/close_2_white.png", IDR_CLOSE_2_MASK, "image/png" }, |
| 61 { "images/google_logo.png", IDR_LOCAL_NTP_IMAGES_LOGO_PNG, "image/png" }, | 61 { "images/google_logo.png", IDR_LOCAL_NTP_IMAGES_LOGO_PNG, "image/png" }, |
| 62 { "images/white_google_logo.png", | 62 { "images/white_google_logo.png", |
| 63 IDR_LOCAL_NTP_IMAGES_WHITE_LOGO_PNG, "image/png" }, | 63 IDR_LOCAL_NTP_IMAGES_WHITE_LOGO_PNG, "image/png" }, |
| 64 { "roboto.woff", IDR_ROBOTO_WOFF, "font/woff" }, | |
| 65 { "roboto.woff2", IDR_ROBOTO_WOFF2, "font/woff2" }, | |
| 64 }; | 66 }; |
| 65 | 67 |
| 66 // Strips any query parameters from the specified path. | 68 // Strips any query parameters from the specified path. |
| 67 std::string StripParameters(const std::string& path) { | 69 std::string StripParameters(const std::string& path) { |
| 68 return path.substr(0, path.find("?")); | 70 return path.substr(0, path.find("?")); |
| 69 } | 71 } |
| 70 | 72 |
| 71 bool DefaultSearchProviderIsGoogle(Profile* profile) { | 73 bool DefaultSearchProviderIsGoogle(Profile* profile) { |
| 72 if (!profile) | 74 if (!profile) |
| 73 return false; | 75 return false; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 const content::URLDataSource::GotDataCallback& callback) { | 183 const content::URLDataSource::GotDataCallback& callback) { |
| 182 const std::string stripped_path = StripParameters(path); | 184 const std::string stripped_path = StripParameters(path); |
| 183 if (stripped_path == kConfigDataFilename) { | 185 if (stripped_path == kConfigDataFilename) { |
| 184 std::string config_data_js = GetConfigData(profile_); | 186 std::string config_data_js = GetConfigData(profile_); |
| 185 callback.Run(base::RefCountedString::TakeString(&config_data_js)); | 187 callback.Run(base::RefCountedString::TakeString(&config_data_js)); |
| 186 return; | 188 return; |
| 187 } | 189 } |
| 188 if (stripped_path == kLocalNTPFilename) { | 190 if (stripped_path == kLocalNTPFilename) { |
| 189 SendResourceWithClass( | 191 SendResourceWithClass( |
| 190 IDR_LOCAL_NTP_HTML, | 192 IDR_LOCAL_NTP_HTML, |
| 191 IsMaterialDesignEnabled() ? kMaterialDesignNTPName : "", | 193 IsMaterialDesignEnabled() ? kMaterialDesignNTPName : "", |
|
Mathieu
2014/08/13 20:09:30
Change/use this here.
huangs
2014/08/13 21:34:09
Done.
| |
| 192 callback); | 194 callback); |
| 193 return; | 195 return; |
| 194 } | 196 } |
| 195 float scale = 1.0f; | 197 float scale = 1.0f; |
| 196 std::string filename; | 198 std::string filename; |
| 197 webui::ParsePathAndScale( | 199 webui::ParsePathAndScale( |
| 198 GURL(GetLocalNtpPath() + stripped_path), &filename, &scale); | 200 GURL(GetLocalNtpPath() + stripped_path), &filename, &scale); |
| 199 ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactor(scale); | 201 ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactor(scale); |
| 200 for (size_t i = 0; i < arraysize(kResources); ++i) { | 202 for (size_t i = 0; i < arraysize(kResources); ++i) { |
| 201 if (filename == kResources[i].filename) { | 203 if (filename == kResources[i].filename) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 void LocalNtpSource::SendResourceWithClass( | 247 void LocalNtpSource::SendResourceWithClass( |
| 246 int resource_id, | 248 int resource_id, |
| 247 const std::string& class_name, | 249 const std::string& class_name, |
| 248 const content::URLDataSource::GotDataCallback& callback) { | 250 const content::URLDataSource::GotDataCallback& callback) { |
| 249 base::StringPiece resource_data = | 251 base::StringPiece resource_data = |
| 250 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id); | 252 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id); |
| 251 std::string response(resource_data.as_string()); | 253 std::string response(resource_data.as_string()); |
| 252 ReplaceFirstSubstringAfterOffset(&response, 0, "{{CLASS}}", class_name); | 254 ReplaceFirstSubstringAfterOffset(&response, 0, "{{CLASS}}", class_name); |
| 253 callback.Run(base::RefCountedString::TakeString(&response)); | 255 callback.Run(base::RefCountedString::TakeString(&response)); |
| 254 } | 256 } |
| OLD | NEW |