OLD | NEW |
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_android.h" | 5 #include "chrome/browser/search/contextual_search_promo_source_android.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
10 #include "base/memory/ref_counted_memory.h" | 10 #include "base/memory/ref_counted_memory.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
15 #include "chrome/grit/chromium_strings.h" | 15 #include "chrome/grit/chromium_strings.h" |
16 #include "components/variations/variations_associated_data.h" | 16 #include "components/variations/variations_associated_data.h" |
17 #include "grit/browser_resources.h" | 17 #include "grit/browser_resources.h" |
18 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
19 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
20 #include "ui/base/webui/jstemplate_builder.h" | 20 #include "ui/base/webui/jstemplate_builder.h" |
21 #include "url/gurl.h" | 21 #include "url/gurl.h" |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 const char kPromoConfigPath[] = "/config.js"; | 25 const char kPromoConfigPath[] = "/config.js"; |
26 const char kPromoHTMLPath[] = "/promo.html"; | 26 const char kPromoHTMLPath[] = "/promo.html"; |
27 const char kPromoCSSPath[] = "/promo.css"; | 27 const char kPromoCSSPath[] = "/promo.css"; |
28 const char kPromoJSPath[] = "/promo.js"; | 28 const char kPromoJSPath[] = "/promo.js"; |
29 const char kRobotoWoffPath[] = "/roboto.woff"; | |
30 const char kRobotoWoff2Path[] = "/roboto.woff2"; | |
31 | 29 |
32 // Field trial related constants. | 30 // Field trial related constants. |
33 const char kContextualSearchFieldTrialName[] = "ContextualSearch"; | 31 const char kContextualSearchFieldTrialName[] = "ContextualSearch"; |
34 const char kContextualSearchHidePromoHeaderParam[] = "hide_promo_header"; | 32 const char kContextualSearchHidePromoHeaderParam[] = "hide_promo_header"; |
35 const char kContextualSearchEnabledValue[] = "enabled"; | 33 const char kContextualSearchEnabledValue[] = "enabled"; |
36 | 34 |
37 // Returns whether we should hide the first-run promo header. | 35 // Returns whether we should hide the first-run promo header. |
38 bool ShouldHidePromoHeader() { | 36 bool ShouldHidePromoHeader() { |
39 return variations::GetVariationParamValue( | 37 return variations::GetVariationParamValue( |
40 kContextualSearchFieldTrialName, kContextualSearchHidePromoHeaderParam) == | 38 kContextualSearchFieldTrialName, kContextualSearchHidePromoHeaderParam) == |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 path_and_query); | 71 path_and_query); |
74 std::string path(url.path()); | 72 std::string path(url.path()); |
75 if (path == kPromoHTMLPath) { | 73 if (path == kPromoHTMLPath) { |
76 SendHtmlWithStrings(callback); | 74 SendHtmlWithStrings(callback); |
77 } else if (path == kPromoCSSPath) { | 75 } else if (path == kPromoCSSPath) { |
78 SendResource(IDR_CONTEXTUAL_SEARCH_PROMO_CSS, callback); | 76 SendResource(IDR_CONTEXTUAL_SEARCH_PROMO_CSS, callback); |
79 } else if (path == kPromoJSPath) { | 77 } else if (path == kPromoJSPath) { |
80 SendResource(IDR_CONTEXTUAL_SEARCH_PROMO_JS, callback); | 78 SendResource(IDR_CONTEXTUAL_SEARCH_PROMO_JS, callback); |
81 } else if (path == kPromoConfigPath) { | 79 } else if (path == kPromoConfigPath) { |
82 SendConfigResource(callback); | 80 SendConfigResource(callback); |
83 } else if (path == kRobotoWoffPath) { | |
84 SendResource(IDR_ROBOTO_WOFF, callback); | |
85 } else if (path == kRobotoWoff2Path) { | |
86 SendResource(IDR_ROBOTO_WOFF2, callback); | |
87 } else { | 81 } else { |
88 callback.Run(NULL); | 82 callback.Run(NULL); |
89 } | 83 } |
90 } | 84 } |
91 | 85 |
92 std::string ContextualSearchPromoSourceAndroid::GetSource() const { | 86 std::string ContextualSearchPromoSourceAndroid::GetSource() const { |
93 return chrome::kChromeUIContextualSearchPromoHost; | 87 return chrome::kChromeUIContextualSearchPromoHost; |
94 } | 88 } |
95 | 89 |
96 std::string ContextualSearchPromoSourceAndroid::GetMimeType( | 90 std::string ContextualSearchPromoSourceAndroid::GetMimeType( |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 strings_data.SetString( | 140 strings_data.SetString( |
147 "optIn", l10n_util::GetStringUTF16(IDS_CONTEXTUAL_SEARCH_PROMO_OPTIN)); | 141 "optIn", l10n_util::GetStringUTF16(IDS_CONTEXTUAL_SEARCH_PROMO_OPTIN)); |
148 strings_data.SetString( | 142 strings_data.SetString( |
149 "optOut", l10n_util::GetStringUTF16(IDS_CONTEXTUAL_SEARCH_PROMO_OPTOUT)); | 143 "optOut", l10n_util::GetStringUTF16(IDS_CONTEXTUAL_SEARCH_PROMO_OPTOUT)); |
150 base::StringPiece html( | 144 base::StringPiece html( |
151 ResourceBundle::GetSharedInstance().GetRawDataResource( | 145 ResourceBundle::GetSharedInstance().GetRawDataResource( |
152 IDR_CONTEXTUAL_SEARCH_PROMO_HTML)); | 146 IDR_CONTEXTUAL_SEARCH_PROMO_HTML)); |
153 std::string response(webui::GetI18nTemplateHtml(html, &strings_data)); | 147 std::string response(webui::GetI18nTemplateHtml(html, &strings_data)); |
154 callback.Run(base::RefCountedString::TakeString(&response)); | 148 callback.Run(base::RefCountedString::TakeString(&response)); |
155 } | 149 } |
OLD | NEW |