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

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

Issue 12840003: Implement local NTP for fallback. (Closed) Base URL: https://git.chromium.org/chromium/src.git@master
Patch Set: Respond. 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
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_omnibox_popup_source.h" 5 #include "chrome/browser/search/local_omnibox_popup_source.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/ref_counted_memory.h" 8 #include "base/memory/ref_counted_memory.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "chrome/common/url_constants.h" 10 #include "chrome/common/url_constants.h"
11 #include "content/public/common/content_client.h" 11 #include "content/public/common/content_client.h"
12 #include "googleurl/src/gurl.h" 12 #include "googleurl/src/gurl.h"
13 #include "grit/browser_resources.h" 13 #include "grit/browser_resources.h"
14 #include "net/url_request/url_request.h" 14 #include "net/url_request/url_request.h"
15 15
16 namespace { 16 namespace {
17 17
18 const char kHTMLFilename[] = "local-omnibox-popup.html"; 18 const char kHTMLFilename[] = "local-omnibox-popup.html";
19 const char kJsFilename[] = "local-omnibox-popup.js"; 19 const char kJSFilename[] = "local-omnibox-popup.js";
Dan Beam 2013/03/25 18:13:49 I'd rather you just change everything else to kHtm
jeremycho 2013/03/25 21:27:16 Done.
20 const char kCSSFilename[] = "local-omnibox-popup.css"; 20 const char kCSSFilename[] = "local-omnibox-popup.css";
21 const char kPageIconFilename[] = "images/page_icon.png"; 21 const char kPageIconFilename[] = "images/page_icon.png";
22 const char kPageIcon2xFilename[] = "images/2x/page_icon.png"; 22 const char kPageIcon2xFilename[] = "images/2x/page_icon.png";
23 const char kSearchIconFilename[] = "images/search_icon.png"; 23 const char kSearchIconFilename[] = "images/search_icon.png";
24 const char kSearchIcon2xFilename[] = "images/2x/search_icon.png"; 24 const char kSearchIcon2xFilename[] = "images/2x/search_icon.png";
25 25
26 } // namespace 26 } // namespace
27 27
28 LocalOmniboxPopupSource::LocalOmniboxPopupSource() { 28 LocalOmniboxPopupSource::LocalOmniboxPopupSource() {
29 } 29 }
30 30
31 LocalOmniboxPopupSource::~LocalOmniboxPopupSource() { 31 LocalOmniboxPopupSource::~LocalOmniboxPopupSource() {
32 } 32 }
33 33
34 std::string LocalOmniboxPopupSource::GetSource() { 34 std::string LocalOmniboxPopupSource::GetSource() {
35 return chrome::kChromeSearchLocalOmniboxPopupHost; 35 return chrome::kChromeSearchLocalOmniboxPopupHost;
36 } 36 }
37 37
38 void LocalOmniboxPopupSource::StartDataRequest( 38 void LocalOmniboxPopupSource::StartDataRequest(
39 const std::string& path, 39 const std::string& path,
40 bool is_incognito, 40 bool is_incognito,
41 const content::URLDataSource::GotDataCallback& callback) { 41 const content::URLDataSource::GotDataCallback& callback) {
42 int identifier = -1; 42 int identifier = -1;
43 if (path == kHTMLFilename) { 43 if (path == kHTMLFilename) {
44 identifier = IDR_LOCAL_OMNIBOX_POPUP_HTML; 44 identifier = IDR_LOCAL_OMNIBOX_POPUP_HTML;
45 } else if (path == kJsFilename) { 45 } else if (path == kJSFilename) {
46 identifier = IDR_LOCAL_OMNIBOX_POPUP_JS; 46 identifier = IDR_LOCAL_OMNIBOX_POPUP_JS;
47 } else if (path == kCSSFilename) { 47 } else if (path == kCSSFilename) {
48 identifier = IDR_LOCAL_OMNIBOX_POPUP_CSS; 48 identifier = IDR_LOCAL_OMNIBOX_POPUP_CSS;
49 } else if (path == kPageIconFilename) { 49 } else if (path == kPageIconFilename) {
50 identifier = IDR_LOCAL_OMNIBOX_POPUP_IMAGES_PAGE_ICON_PNG; 50 identifier = IDR_LOCAL_OMNIBOX_POPUP_IMAGES_PAGE_ICON_PNG;
51 } else if (path == kPageIcon2xFilename) { 51 } else if (path == kPageIcon2xFilename) {
52 identifier = IDR_LOCAL_OMNIBOX_POPUP_IMAGES_2X_PAGE_ICON_PNG; 52 identifier = IDR_LOCAL_OMNIBOX_POPUP_IMAGES_2X_PAGE_ICON_PNG;
53 } else if (path == kSearchIconFilename) { 53 } else if (path == kSearchIconFilename) {
54 identifier = IDR_LOCAL_OMNIBOX_POPUP_IMAGES_SEARCH_ICON_PNG; 54 identifier = IDR_LOCAL_OMNIBOX_POPUP_IMAGES_SEARCH_ICON_PNG;
55 } else if (path == kSearchIcon2xFilename) { 55 } else if (path == kSearchIcon2xFilename) {
56 identifier = IDR_LOCAL_OMNIBOX_POPUP_IMAGES_2X_SEARCH_ICON_PNG; 56 identifier = IDR_LOCAL_OMNIBOX_POPUP_IMAGES_2X_SEARCH_ICON_PNG;
57 } else { 57 } else {
58 callback.Run(NULL); 58 callback.Run(NULL);
59 return; 59 return;
60 } 60 }
61 61
62 scoped_refptr<base::RefCountedStaticMemory> response( 62 scoped_refptr<base::RefCountedStaticMemory> response(
63 content::GetContentClient()->GetDataResourceBytes(identifier)); 63 content::GetContentClient()->GetDataResourceBytes(identifier));
64 callback.Run(response); 64 callback.Run(response);
65 } 65 }
66 66
67 std::string LocalOmniboxPopupSource::GetMimeType( 67 std::string LocalOmniboxPopupSource::GetMimeType(
68 const std::string& path) const { 68 const std::string& path) const {
69 if (path == kHTMLFilename) 69 if (path == kHTMLFilename)
70 return "text/html"; 70 return "text/html";
71 if (path == kJsFilename) 71 if (path == kJSFilename)
72 return "application/javascript"; 72 return "application/javascript";
73 if (path == kCSSFilename) 73 if (path == kCSSFilename)
74 return "text/css"; 74 return "text/css";
75 if (path == kPageIconFilename || path == kPageIcon2xFilename || 75 if (path == kPageIconFilename || path == kPageIcon2xFilename ||
76 path == kSearchIconFilename || path == kSearchIcon2xFilename) 76 path == kSearchIconFilename || path == kSearchIcon2xFilename)
77 return "image/png"; 77 return "image/png";
78 return ""; 78 return "";
79 } 79 }
80 80
81 bool LocalOmniboxPopupSource::ShouldServiceRequest( 81 bool LocalOmniboxPopupSource::ShouldServiceRequest(
82 const net::URLRequest* request) const { 82 const net::URLRequest* request) const {
83 DCHECK(request->url().host() == chrome::kChromeSearchLocalOmniboxPopupHost); 83 DCHECK(request->url().host() == chrome::kChromeSearchLocalOmniboxPopupHost);
84 84
85 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) { 85 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) {
86 DCHECK(StartsWithASCII(request->url().path(), "/", true)); 86 DCHECK(StartsWithASCII(request->url().path(), "/", true));
87 std::string filename = request->url().path().substr(1); 87 std::string filename = request->url().path().substr(1);
88 return filename == kHTMLFilename || filename == kJsFilename || 88 return filename == kHTMLFilename || filename == kJSFilename ||
89 filename == kCSSFilename || filename == kPageIconFilename || 89 filename == kCSSFilename || filename == kPageIconFilename ||
90 filename == kPageIcon2xFilename || filename == kSearchIconFilename || 90 filename == kPageIcon2xFilename || filename == kSearchIconFilename ||
91 filename == kSearchIcon2xFilename; 91 filename == kSearchIcon2xFilename;
92 } 92 }
93 return false; 93 return false;
94 } 94 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698