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/instant/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 "net/url_request/url_request.h" |
| 15 |
| 16 namespace { |
| 17 |
| 18 const char kHTMLFilename[] = "local-ntp.html"; |
| 19 const char kJsFilename[] = "local-ntp.js"; |
| 20 const char kCSSFilename[] = "local-ntp.css"; |
| 21 |
| 22 } // namespace |
| 23 |
| 24 LocalNTPSource::LocalNTPSource() { |
| 25 } |
| 26 |
| 27 LocalNTPSource::~LocalNTPSource() { |
| 28 } |
| 29 |
| 30 std::string LocalNTPSource::GetSource() { |
| 31 return chrome::kChromeSearchLocalNTPHost; |
| 32 } |
| 33 |
| 34 void LocalNTPSource::StartDataRequest( |
| 35 const std::string& path, |
| 36 bool is_incognito, |
| 37 const content::URLDataSource::GotDataCallback& callback) { |
| 38 int identifier = -1; |
| 39 if (path == kHTMLFilename) { |
| 40 identifier = IDR_LOCAL_NTP_HTML; |
| 41 } else if (path == kJsFilename) { |
| 42 identifier = IDR_LOCAL_NTP_JS; |
| 43 } else if (path == kCSSFilename) { |
| 44 identifier = IDR_LOCAL_NTP_CSS; |
| 45 } else { |
| 46 callback.Run(NULL); |
| 47 return; |
| 48 } |
| 49 |
| 50 scoped_refptr<base::RefCountedStaticMemory> response( |
| 51 content::GetContentClient()->GetDataResourceBytes(identifier)); |
| 52 callback.Run(response); |
| 53 } |
| 54 |
| 55 std::string LocalNTPSource::GetMimeType( |
| 56 const std::string& path) const { |
| 57 if (path == kHTMLFilename) |
| 58 return "text/html"; |
| 59 if (path == kJsFilename) |
| 60 return "application/javascript"; |
| 61 if (path == kCSSFilename) |
| 62 return "text/css"; |
| 63 return ""; |
| 64 } |
| 65 |
| 66 bool LocalNTPSource::ShouldServiceRequest( |
| 67 const net::URLRequest* request) const { |
| 68 DCHECK_EQ(request->url().host(), chrome::kChromeSearchLocalNTPHost); |
| 69 |
| 70 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) { |
| 71 DCHECK(StartsWithASCII(request->url().path(), "/", true)); |
| 72 std::string filename = request->url().path().substr(1); |
| 73 return filename == kHTMLFilename || filename == kJsFilename || |
| 74 filename == kCSSFilename; |
| 75 } |
| 76 return false; |
| 77 } |
OLD | NEW |