Index: chrome/browser/search/local_ntp_source.cc |
diff --git a/chrome/browser/search/local_ntp_source.cc b/chrome/browser/search/local_ntp_source.cc |
index 38cbd7a2e2e5dad40a4098a53bd482dc6fd9b1e5..4ff5b3328a58bf5222875aa87f128643fb442cdb 100644 |
--- a/chrome/browser/search/local_ntp_source.cc |
+++ b/chrome/browser/search/local_ntp_source.cc |
@@ -16,12 +16,33 @@ |
namespace { |
-const char kHtmlFilename[] = "local-ntp.html"; |
-const char kJSFilename[] = "local-ntp.js"; |
-const char kCssFilename[] = "local-ntp.css"; |
-const char kCloseBarFilename[] = "images/close_2.png"; |
-const char kCloseBarHoverFilename[] = "images/close_2_hover.png"; |
-const char kCloseBarActiveFilename[] = "images/close_2_active.png"; |
+const struct Resource{ |
+ const char* filename; |
+ int identifier; |
+ const char* mime_type; |
+} kResources[] = { |
+ { "local-ntp.html", IDR_LOCAL_NTP_HTML, "text/html" }, |
+ { "local-ntp.js", IDR_LOCAL_NTP_JS, "application/javascript" }, |
+ { "local-ntp.css", IDR_LOCAL_NTP_CSS, "text/css" }, |
+ { "images/close_2.png", IDR_CLOSE_2, "image/png" }, |
+ { "images/close_2_hover.png", IDR_CLOSE_2_H, "image/png" }, |
+ { "images/close_2_active.png", IDR_CLOSE_2_P, "image/png" }, |
+ { "images/page_icon.png", IDR_LOCAL_OMNIBOX_POPUP_IMAGES_PAGE_ICON_PNG, |
+ "image/png" }, |
+ { "images/2x/page_icon.png", |
+ IDR_LOCAL_OMNIBOX_POPUP_IMAGES_2X_PAGE_ICON_PNG, "image/png" }, |
+ { "images/search_icon.png", |
+ IDR_LOCAL_OMNIBOX_POPUP_IMAGES_SEARCH_ICON_PNG, "image/png" }, |
+ { "images/2x/search_icon.png", |
+ IDR_LOCAL_OMNIBOX_POPUP_IMAGES_2X_SEARCH_ICON_PNG, "image/png" }, |
+ { "images/google_logo.png", IDR_LOCAL_NTP_IMAGES_LOGO_PNG, "image/png" }, |
+ { "images/2x/google_logo.png", |
+ IDR_LOCAL_NTP_IMAGES_2X_LOGO_PNG, "image/png" }, |
+ { "images/white_google_logo.png", |
+ IDR_LOCAL_NTP_IMAGES_WHITE_LOGO_PNG, "image/png" }, |
+ { "images/2x/white_google_logo.png", |
+ IDR_LOCAL_NTP_IMAGES_2X_WHITE_LOGO_PNG, "image/png" }, |
+}; |
} // namespace |
@@ -40,39 +61,27 @@ void LocalNtpSource::StartDataRequest( |
bool is_incognito, |
const content::URLDataSource::GotDataCallback& callback) { |
int identifier = -1; |
- if (path == kHtmlFilename) { |
- identifier = IDR_LOCAL_NTP_HTML; |
- } else if (path == kJSFilename) { |
- identifier = IDR_LOCAL_NTP_JS; |
- } else if (path == kCssFilename) { |
- identifier = IDR_LOCAL_NTP_CSS; |
- } else if (path == kCloseBarFilename) { |
- identifier = IDR_CLOSE_2; |
- } else if (path == kCloseBarHoverFilename) { |
- identifier = IDR_CLOSE_2_H; |
- } else if (path == kCloseBarActiveFilename) { |
- identifier = IDR_CLOSE_2_P; |
- } else { |
- callback.Run(NULL); |
- return; |
+ std::string stripped_path = StripParameters(path); |
samarth
2013/04/16 16:55:10
const std::string
jeremycho
2013/04/16 20:39:09
Done.
|
+ for (size_t i = 0; i < arraysize(kResources); ++i) { |
+ if (stripped_path == kResources[i].filename) { |
+ identifier = kResources[i].identifier; |
samarth
2013/04/16 16:55:10
You can just declare identifier here (or skip that
jeremycho
2013/04/16 20:39:09
Done.
|
+ scoped_refptr<base::RefCountedStaticMemory> response( |
+ ResourceBundle::GetSharedInstance().LoadDataResourceBytes( |
+ identifier)); |
+ callback.Run(response); |
+ return; |
+ } |
} |
- |
- scoped_refptr<base::RefCountedStaticMemory> response( |
- ResourceBundle::GetSharedInstance().LoadDataResourceBytes(identifier)); |
- callback.Run(response); |
-} |
+ callback.Run(NULL); |
+}; |
std::string LocalNtpSource::GetMimeType( |
const std::string& path) const { |
- if (path == kHtmlFilename) |
- return "text/html"; |
- if (path == kJSFilename) |
- return "application/javascript"; |
- if (path == kCssFilename) |
- return "text/css"; |
- if (path == kCloseBarFilename || path == kCloseBarHoverFilename || |
- path == kCloseBarActiveFilename) { |
- return "image/png"; |
+ std::string stripped_path = StripParameters(path); |
samarth
2013/04/16 16:55:10
const
jeremycho
2013/04/16 20:39:09
Done.
|
+ for (size_t i = 0; i < arraysize(kResources); ++i) { |
+ if (stripped_path == kResources[i].filename) { |
samarth
2013/04/16 16:55:10
nit: no braces
jeremycho
2013/04/16 20:39:09
Done.
|
+ return kResources[i].mime_type; |
+ } |
} |
return std::string(); |
} |
@@ -84,10 +93,15 @@ bool LocalNtpSource::ShouldServiceRequest( |
if (request->url().SchemeIs(chrome::kChromeSearchScheme)) { |
DCHECK(StartsWithASCII(request->url().path(), "/", true)); |
std::string filename = request->url().path().substr(1); |
samarth
2013/04/16 16:55:10
How come you don't need to strip the query params
jeremycho
2013/04/16 20:39:09
The request doesn't contain them, unlike the path
|
- return filename == kHtmlFilename || filename == kJSFilename || |
- filename == kCssFilename || filename == kCloseBarFilename || |
- filename == kCloseBarHoverFilename || |
- filename == kCloseBarActiveFilename; |
+ for (size_t i = 0; i < arraysize(kResources); ++i) { |
+ if (filename == kResources[i].filename) { |
samarth
2013/04/16 16:55:10
nit: no braces (It's chrome C++ style to omit brac
jeremycho
2013/04/16 20:39:09
Done.
|
+ return true; |
+ } |
+ } |
} |
return false; |
} |
+ |
+std::string LocalNtpSource::StripParameters(const std::string& path) const{ |
samarth
2013/04/16 16:55:10
Instead of a private method, just define this at t
jeremycho
2013/04/16 20:39:09
Done.
|
+ return path.substr(0, path.find("?")); |
+} |