Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/search/local_ntp_source.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/memory/ref_counted_memory.h" | |
| 9 #include "base/string_util.h" | |
| 10 #include "chrome/common/url_constants.h" | |
| 11 #include "content/public/common/content_client.h" | |
| 12 #include "googleurl/src/gurl.h" | |
| 13 #include "grit/browser_resources.h" | |
| 14 #include "grit/ui_resources.h" | |
| 15 #include "net/url_request/url_request.h" | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 const char kHTMLFilename[] = "local-ntp.html"; | |
|
Dan Beam
2013/03/25 18:13:49
generally when abbreviations are over 2 chars, we
jeremycho
2013/03/25 21:27:16
Done.
| |
| 20 const char kJSFilename[] = "local-ntp.js"; | |
| 21 const char kCSSFilename[] = "local-ntp.css"; | |
| 22 const char kCloseBarFilename[] = "images/close_bar.png"; | |
| 23 const char kCloseBarHoverFilename[] = "images/close_bar_hover.png"; | |
| 24 const char kCloseBarActiveFilename[] = "images/close_bar_active.png"; | |
| 25 | |
| 26 } // namespace | |
| 27 | |
| 28 LocalNTPSource::LocalNTPSource() { | |
| 29 } | |
| 30 | |
| 31 LocalNTPSource::~LocalNTPSource() { | |
| 32 } | |
| 33 | |
| 34 std::string LocalNTPSource::GetSource() { | |
| 35 return chrome::kChromeSearchLocalNTPHost; | |
| 36 } | |
| 37 | |
| 38 void LocalNTPSource::StartDataRequest( | |
| 39 const std::string& path, | |
| 40 bool is_incognito, | |
| 41 const content::URLDataSource::GotDataCallback& callback) { | |
| 42 int identifier = -1; | |
| 43 if (path == kHTMLFilename) { | |
| 44 identifier = IDR_LOCAL_NTP_HTML; | |
| 45 } else if (path == kJSFilename) { | |
| 46 identifier = IDR_LOCAL_NTP_JS; | |
| 47 } else if (path == kCSSFilename) { | |
| 48 identifier = IDR_LOCAL_NTP_CSS; | |
| 49 } else if (path == kCloseBarFilename) { | |
| 50 identifier = IDR_CLOSE_BAR; | |
| 51 } else if (path == kCloseBarHoverFilename) { | |
| 52 identifier = IDR_CLOSE_BAR_H; | |
| 53 } else if (path == kCloseBarActiveFilename) { | |
| 54 identifier = IDR_CLOSE_BAR_P; | |
| 55 } else { | |
| 56 callback.Run(NULL); | |
| 57 return; | |
| 58 } | |
| 59 | |
| 60 scoped_refptr<base::RefCountedStaticMemory> response( | |
| 61 content::GetContentClient()->GetDataResourceBytes(identifier)); | |
| 62 callback.Run(response); | |
| 63 } | |
| 64 | |
| 65 std::string LocalNTPSource::GetMimeType( | |
| 66 const std::string& path) const { | |
| 67 if (path == kHTMLFilename) | |
| 68 return "text/html"; | |
| 69 if (path == kJSFilename) | |
| 70 return "application/javascript"; | |
| 71 if (path == kCSSFilename) | |
| 72 return "text/css"; | |
| 73 if (path == kCloseBarFilename || path == kCloseBarHoverFilename || | |
| 74 path == kCloseBarActiveFilename) | |
| 75 return "image/png"; | |
| 76 return ""; | |
| 77 } | |
| 78 | |
| 79 bool LocalNTPSource::ShouldServiceRequest( | |
| 80 const net::URLRequest* request) const { | |
| 81 DCHECK_EQ(request->url().host(), chrome::kChromeSearchLocalNTPHost); | |
| 82 | |
| 83 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) { | |
| 84 DCHECK(StartsWithASCII(request->url().path(), "/", true)); | |
| 85 std::string filename = request->url().path().substr(1); | |
| 86 return filename == kHTMLFilename || filename == kJSFilename || | |
| 87 filename == kCSSFilename || filename == kCloseBarFilename || | |
| 88 filename == kCloseBarHoverFilename || | |
| 89 filename == kCloseBarActiveFilename; | |
|
Dan Beam
2013/03/25 18:13:49
nit:
return filename == kHTMLFilename || filename
jeremycho
2013/03/25 21:27:16
Done.
| |
| 90 } | |
| 91 return false; | |
| 92 } | |
| OLD | NEW |