Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: chrome/browser/search/local_ntp_source.cc

Issue 12840003: Implement local NTP for fallback. (Closed) Base URL: https://git.chromium.org/chromium/src.git@master
Patch Set: Fix compile. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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";
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 }
77 return "";
78 }
79
80 bool LocalNtpSource::ShouldServiceRequest(
81 const net::URLRequest* request) const {
82 DCHECK(request->url().host() == chrome::kChromeSearchLocalNtpHost);
83
84 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) {
85 DCHECK(StartsWithASCII(request->url().path(), "/", true));
86 std::string filename = request->url().path().substr(1);
87 return filename == kHtmlFilename || filename == kJSFilename ||
88 filename == kCssFilename || filename == kCloseBarFilename ||
89 filename == kCloseBarHoverFilename ||
90 filename == kCloseBarActiveFilename;
91 }
92 return false;
93 }
OLDNEW
« no previous file with comments | « chrome/browser/search/local_ntp_source.h ('k') | chrome/browser/search/local_omnibox_popup_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698