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

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

Issue 450543002: Make ContextualSearchPromoSource Android-only. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/contextual_search_promo_source.h" 5 #include "chrome/browser/search/contextual_search_promo_source_android.h"
6 6
7 #include "base/memory/ref_counted_memory.h" 7 #include "base/memory/ref_counted_memory.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/common/url_constants.h" 11 #include "chrome/common/url_constants.h"
12 #include "grit/browser_resources.h" 12 #include "grit/browser_resources.h"
13 #include "grit/chromium_strings.h" 13 #include "grit/chromium_strings.h"
14 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
15 #include "ui/base/l10n/l10n_util.h" 15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/resource/resource_bundle.h" 16 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/base/webui/jstemplate_builder.h" 17 #include "ui/base/webui/jstemplate_builder.h"
18 #include "url/gurl.h" 18 #include "url/gurl.h"
19 19
20 namespace { 20 namespace {
21 21
22 const char kPromoHTMLPath[] = "/promo.html"; 22 const char kPromoHTMLPath[] = "/promo.html";
23 const char kPromoCSSPath[] = "/promo.css"; 23 const char kPromoCSSPath[] = "/promo.css";
24 const char kPromoJSPath[] = "/promo.js"; 24 const char kPromoJSPath[] = "/promo.js";
25 const char kPromoRobotoPath[] = "/roboto.woff"; 25 const char kPromoRobotoPath[] = "/roboto.woff";
26 26
27 } // namespace 27 } // namespace
28 28
29 ContextualSearchPromoSource::ContextualSearchPromoSource() {} 29 ContextualSearchPromoSourceAndroid::ContextualSearchPromoSourceAndroid() {}
30 30
31 ContextualSearchPromoSource::~ContextualSearchPromoSource() {} 31 ContextualSearchPromoSourceAndroid::~ContextualSearchPromoSourceAndroid() {}
32 32
33 void ContextualSearchPromoSource::StartDataRequest( 33 void ContextualSearchPromoSourceAndroid::StartDataRequest(
34 const std::string& path_and_query, int render_process_id, 34 const std::string& path_and_query, int render_process_id,
35 int render_frame_id, 35 int render_frame_id,
36 const content::URLDataSource::GotDataCallback& callback) { 36 const content::URLDataSource::GotDataCallback& callback) {
37 GURL url(std::string(chrome::kChromeUIContextualSearchPromoURL) + "/" + 37 GURL url(std::string(chrome::kChromeUIContextualSearchPromoURL) + "/" +
38 path_and_query); 38 path_and_query);
39 std::string path(url.path()); 39 std::string path(url.path());
40 if (path == kPromoHTMLPath) { 40 if (path == kPromoHTMLPath) {
41 SendHtmlWithStrings(callback); 41 SendHtmlWithStrings(callback);
42 } else if (path == kPromoCSSPath) { 42 } else if (path == kPromoCSSPath) {
43 SendResource(IDR_CONTEXTUAL_SEARCH_PROMO_CSS, callback); 43 SendResource(IDR_CONTEXTUAL_SEARCH_PROMO_CSS, callback);
Lei Zhang 2014/08/06 23:47:23 FYI, these should not exist on non-Android builds.
Mathieu 2014/08/07 13:41:14 Acknowledged.
44 } else if (path == kPromoJSPath) { 44 } else if (path == kPromoJSPath) {
45 SendResource(IDR_CONTEXTUAL_SEARCH_PROMO_JS, callback); 45 SendResource(IDR_CONTEXTUAL_SEARCH_PROMO_JS, callback);
46 } else if (path == kPromoRobotoPath) { 46 } else if (path == kPromoRobotoPath) {
47 SendResource(IDR_CONTEXTUAL_SEARCH_ROBOTO_WOFF, callback); 47 SendResource(IDR_CONTEXTUAL_SEARCH_ROBOTO_WOFF, callback);
48 } else { 48 } else {
49 callback.Run(NULL); 49 callback.Run(NULL);
50 } 50 }
51 } 51 }
52 52
53 std::string ContextualSearchPromoSource::GetSource() const { 53 std::string ContextualSearchPromoSourceAndroid::GetSource() const {
54 return chrome::kChromeUIContextualSearchPromoHost; 54 return chrome::kChromeUIContextualSearchPromoHost;
55 } 55 }
56 56
57 std::string ContextualSearchPromoSource::GetMimeType( 57 std::string ContextualSearchPromoSourceAndroid::GetMimeType(
58 const std::string& path_and_query) const { 58 const std::string& path_and_query) const {
59 std::string path(GURL("chrome://host/" + path_and_query).path()); 59 std::string path(GURL("chrome://host/" + path_and_query).path());
60 if (EndsWith(path, ".js", false)) return "application/javascript"; 60 if (EndsWith(path, ".js", false)) return "application/javascript";
61 if (EndsWith(path, ".png", false)) return "image/png"; 61 if (EndsWith(path, ".png", false)) return "image/png";
62 if (EndsWith(path, ".css", false)) return "text/css"; 62 if (EndsWith(path, ".css", false)) return "text/css";
63 if (EndsWith(path, ".html", false)) return "text/html"; 63 if (EndsWith(path, ".html", false)) return "text/html";
64 if (EndsWith(path, ".woff", false)) return "font/woff"; 64 if (EndsWith(path, ".woff", false)) return "font/woff";
65 return ""; 65 return "";
66 } 66 }
67 67
68 bool ContextualSearchPromoSource::ShouldDenyXFrameOptions() const { 68 bool ContextualSearchPromoSourceAndroid::ShouldDenyXFrameOptions() const {
69 return false; 69 return false;
70 } 70 }
71 71
72 bool ContextualSearchPromoSource::ShouldAddContentSecurityPolicy() const { 72 bool
73 ContextualSearchPromoSourceAndroid::ShouldAddContentSecurityPolicy() const {
73 return false; 74 return false;
74 } 75 }
75 76
76 void ContextualSearchPromoSource::SendResource( 77 void ContextualSearchPromoSourceAndroid::SendResource(
77 int resource_id, const content::URLDataSource::GotDataCallback& callback) { 78 int resource_id, const content::URLDataSource::GotDataCallback& callback) {
78 scoped_refptr<base::RefCountedStaticMemory> response( 79 scoped_refptr<base::RefCountedStaticMemory> response(
79 ResourceBundle::GetSharedInstance().LoadDataResourceBytes(resource_id)); 80 ResourceBundle::GetSharedInstance().LoadDataResourceBytes(resource_id));
80 callback.Run(response.get()); 81 callback.Run(response.get());
81 } 82 }
82 83
83 void ContextualSearchPromoSource::SendHtmlWithStrings( 84 void ContextualSearchPromoSourceAndroid::SendHtmlWithStrings(
84 const content::URLDataSource::GotDataCallback& callback) { 85 const content::URLDataSource::GotDataCallback& callback) {
85 base::DictionaryValue strings_data; 86 base::DictionaryValue strings_data;
86 strings_data.SetString( 87 strings_data.SetString(
87 "description", 88 "description",
88 l10n_util::GetStringUTF16(IDS_CONTEXTUAL_SEARCH_PROMO_DESCRIPTION)); 89 l10n_util::GetStringUTF16(IDS_CONTEXTUAL_SEARCH_PROMO_DESCRIPTION));
89 strings_data.SetString( 90 strings_data.SetString(
90 "optIn", l10n_util::GetStringUTF16(IDS_CONTEXTUAL_SEARCH_PROMO_OPTIN)); 91 "optIn", l10n_util::GetStringUTF16(IDS_CONTEXTUAL_SEARCH_PROMO_OPTIN));
91 strings_data.SetString( 92 strings_data.SetString(
92 "optOut", l10n_util::GetStringUTF16(IDS_CONTEXTUAL_SEARCH_PROMO_OPTOUT)); 93 "optOut", l10n_util::GetStringUTF16(IDS_CONTEXTUAL_SEARCH_PROMO_OPTOUT));
93 base::StringPiece html( 94 base::StringPiece html(
94 ResourceBundle::GetSharedInstance().GetRawDataResource( 95 ResourceBundle::GetSharedInstance().GetRawDataResource(
95 IDR_CONTEXTUAL_SEARCH_PROMO_HTML)); 96 IDR_CONTEXTUAL_SEARCH_PROMO_HTML));
96 webui::UseVersion2 version; 97 webui::UseVersion2 version;
97 std::string response(webui::GetI18nTemplateHtml(html, &strings_data)); 98 std::string response(webui::GetI18nTemplateHtml(html, &strings_data));
98 callback.Run(base::RefCountedString::TakeString(&response)); 99 callback.Run(base::RefCountedString::TakeString(&response));
99 } 100 }
OLDNEW
« no previous file with comments | « chrome/browser/search/contextual_search_promo_source_android.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698