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

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

Issue 587803003: [Search] Add a header image to the promo flow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 6 years, 3 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 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
huangs 2014/09/23 13:44:38 #include <string> ?
Mathieu 2014/09/23 13:50:08 Done.
7 #include "base/json/json_string_value_serializer.h"
7 #include "base/memory/ref_counted_memory.h" 8 #include "base/memory/ref_counted_memory.h"
8 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
9 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
10 #include "base/values.h" 11 #include "base/values.h"
11 #include "chrome/common/url_constants.h" 12 #include "chrome/common/url_constants.h"
12 #include "chrome/grit/chromium_strings.h" 13 #include "chrome/grit/chromium_strings.h"
14 #include "components/variations/variations_associated_data.h"
13 #include "grit/browser_resources.h" 15 #include "grit/browser_resources.h"
14 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/base/webui/jstemplate_builder.h" 18 #include "ui/base/webui/jstemplate_builder.h"
17 #include "url/gurl.h" 19 #include "url/gurl.h"
18 20
19 namespace { 21 namespace {
20 22
23 const char kPromoConfigPath[] = "/config.js";
21 const char kPromoHTMLPath[] = "/promo.html"; 24 const char kPromoHTMLPath[] = "/promo.html";
22 const char kPromoCSSPath[] = "/promo.css"; 25 const char kPromoCSSPath[] = "/promo.css";
23 const char kPromoJSPath[] = "/promo.js"; 26 const char kPromoJSPath[] = "/promo.js";
24 const char kRobotoWoffPath[] = "/roboto.woff"; 27 const char kRobotoWoffPath[] = "/roboto.woff";
25 const char kRobotoWoff2Path[] = "/roboto.woff2"; 28 const char kRobotoWoff2Path[] = "/roboto.woff2";
26 29
30 // Field trial related constants.
31 const char kContextualSearchFieldTrialName[] = "ContextualSearch";
32 const char kContextualSearchHidePromoHeaderParam[] = "hide_promo_header";
33 const char kContextualSearchEnabledValue[] = "enabled";
34
35 // Returns whether we should hide the first-run promo header.
36 bool ShouldHidePromoHeader() {
37 return variations::GetVariationParamValue(
38 kContextualSearchFieldTrialName, kContextualSearchHidePromoHeaderParam) ==
39 kContextualSearchEnabledValue;
40 }
41
42 // Returns a JS dictionary of configuration data for the Contextual Search
43 // promo.
44 std::string GetConfigData() {
45 base::DictionaryValue config_data;
46 config_data.SetBoolean("hideHeader", ShouldHidePromoHeader());
47
48 // Serialize the dictionary.
49 std::string js_text;
50 JSONStringValueSerializer serializer(&js_text);
51 serializer.Serialize(config_data);
52
53 std::string config_data_js;
54 config_data_js.append("var config = ");
huangs 2014/09/23 13:44:38 Is |config| a global constant? Maybe |CONFIG| ins
Mathieu 2014/09/23 13:50:08 In this limited scope, I think it's fine.
55 config_data_js.append(js_text);
56 config_data_js.append(";");
57 return config_data_js;
58 }
59
27 } // namespace 60 } // namespace
28 61
29 ContextualSearchPromoSourceAndroid::ContextualSearchPromoSourceAndroid() {} 62 ContextualSearchPromoSourceAndroid::ContextualSearchPromoSourceAndroid() {}
30 63
31 ContextualSearchPromoSourceAndroid::~ContextualSearchPromoSourceAndroid() {} 64 ContextualSearchPromoSourceAndroid::~ContextualSearchPromoSourceAndroid() {}
32 65
33 void ContextualSearchPromoSourceAndroid::StartDataRequest( 66 void ContextualSearchPromoSourceAndroid::StartDataRequest(
34 const std::string& path_and_query, int render_process_id, 67 const std::string& path_and_query, int render_process_id,
35 int render_frame_id, 68 int render_frame_id,
36 const content::URLDataSource::GotDataCallback& callback) { 69 const content::URLDataSource::GotDataCallback& callback) {
37 GURL url(std::string(chrome::kChromeUIContextualSearchPromoURL) + "/" + 70 GURL url(std::string(chrome::kChromeUIContextualSearchPromoURL) + "/" +
38 path_and_query); 71 path_and_query);
39 std::string path(url.path()); 72 std::string path(url.path());
40 if (path == kPromoHTMLPath) { 73 if (path == kPromoHTMLPath) {
41 SendHtmlWithStrings(callback); 74 SendHtmlWithStrings(callback);
42 } else if (path == kPromoCSSPath) { 75 } else if (path == kPromoCSSPath) {
43 SendResource(IDR_CONTEXTUAL_SEARCH_PROMO_CSS, callback); 76 SendResource(IDR_CONTEXTUAL_SEARCH_PROMO_CSS, callback);
44 } else if (path == kPromoJSPath) { 77 } else if (path == kPromoJSPath) {
45 SendResource(IDR_CONTEXTUAL_SEARCH_PROMO_JS, callback); 78 SendResource(IDR_CONTEXTUAL_SEARCH_PROMO_JS, callback);
79 } else if (path == kPromoConfigPath) {
80 SendConfigResource(callback);
46 } else if (path == kRobotoWoffPath) { 81 } else if (path == kRobotoWoffPath) {
47 SendResource(IDR_ROBOTO_WOFF, callback); 82 SendResource(IDR_ROBOTO_WOFF, callback);
48 } else if (path == kRobotoWoff2Path) { 83 } else if (path == kRobotoWoff2Path) {
49 SendResource(IDR_ROBOTO_WOFF2, callback); 84 SendResource(IDR_ROBOTO_WOFF2, callback);
50 } else { 85 } else {
51 callback.Run(NULL); 86 callback.Run(NULL);
52 } 87 }
53 } 88 }
54 89
55 std::string ContextualSearchPromoSourceAndroid::GetSource() const { 90 std::string ContextualSearchPromoSourceAndroid::GetSource() const {
(...skipping 21 matching lines...) Expand all
77 return false; 112 return false;
78 } 113 }
79 114
80 void ContextualSearchPromoSourceAndroid::SendResource( 115 void ContextualSearchPromoSourceAndroid::SendResource(
81 int resource_id, const content::URLDataSource::GotDataCallback& callback) { 116 int resource_id, const content::URLDataSource::GotDataCallback& callback) {
82 scoped_refptr<base::RefCountedStaticMemory> response( 117 scoped_refptr<base::RefCountedStaticMemory> response(
83 ResourceBundle::GetSharedInstance().LoadDataResourceBytes(resource_id)); 118 ResourceBundle::GetSharedInstance().LoadDataResourceBytes(resource_id));
84 callback.Run(response.get()); 119 callback.Run(response.get());
85 } 120 }
86 121
122 void ContextualSearchPromoSourceAndroid::SendConfigResource(
123 const content::URLDataSource::GotDataCallback& callback) {
124 std::string response = GetConfigData();
125 callback.Run(base::RefCountedString::TakeString(&response));
126 }
127
87 void ContextualSearchPromoSourceAndroid::SendHtmlWithStrings( 128 void ContextualSearchPromoSourceAndroid::SendHtmlWithStrings(
88 const content::URLDataSource::GotDataCallback& callback) { 129 const content::URLDataSource::GotDataCallback& callback) {
89 base::DictionaryValue strings_data; 130 base::DictionaryValue strings_data;
90 strings_data.SetString( 131 strings_data.SetString(
91 "description", 132 "description",
92 l10n_util::GetStringUTF16(IDS_CONTEXTUAL_SEARCH_PROMO_DESCRIPTION)); 133 l10n_util::GetStringUTF16(IDS_CONTEXTUAL_SEARCH_PROMO_DESCRIPTION));
93 strings_data.SetString( 134 strings_data.SetString(
94 "heading", l10n_util::GetStringUTF16(IDS_CONTEXTUAL_SEARCH_HEADER)); 135 "heading", l10n_util::GetStringUTF16(IDS_CONTEXTUAL_SEARCH_HEADER));
95 strings_data.SetString( 136 strings_data.SetString(
96 "optIn", l10n_util::GetStringUTF16(IDS_CONTEXTUAL_SEARCH_PROMO_OPTIN)); 137 "optIn", l10n_util::GetStringUTF16(IDS_CONTEXTUAL_SEARCH_PROMO_OPTIN));
97 strings_data.SetString( 138 strings_data.SetString(
98 "optOut", l10n_util::GetStringUTF16(IDS_CONTEXTUAL_SEARCH_PROMO_OPTOUT)); 139 "optOut", l10n_util::GetStringUTF16(IDS_CONTEXTUAL_SEARCH_PROMO_OPTOUT));
99 base::StringPiece html( 140 base::StringPiece html(
100 ResourceBundle::GetSharedInstance().GetRawDataResource( 141 ResourceBundle::GetSharedInstance().GetRawDataResource(
101 IDR_CONTEXTUAL_SEARCH_PROMO_HTML)); 142 IDR_CONTEXTUAL_SEARCH_PROMO_HTML));
102 webui::UseVersion2 version; 143 webui::UseVersion2 version;
103 std::string response(webui::GetI18nTemplateHtml(html, &strings_data)); 144 std::string response(webui::GetI18nTemplateHtml(html, &strings_data));
104 callback.Run(base::RefCountedString::TakeString(&response)); 145 callback.Run(base::RefCountedString::TakeString(&response));
105 } 146 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698