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

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: 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
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 config_data.SetBoolean("hideHeader", true);
48
49 // Serialize the dictionary.
50 std::string js_text;
51 JSONStringValueSerializer serializer(&js_text);
52 serializer.Serialize(config_data);
53
54 std::string config_data_js;
55 config_data_js.append("var config = ");
56 config_data_js.append(js_text);
57 config_data_js.append(";");
58 return config_data_js;
59 }
60
27 } // namespace 61 } // namespace
28 62
29 ContextualSearchPromoSourceAndroid::ContextualSearchPromoSourceAndroid() {} 63 ContextualSearchPromoSourceAndroid::ContextualSearchPromoSourceAndroid() {}
30 64
31 ContextualSearchPromoSourceAndroid::~ContextualSearchPromoSourceAndroid() {} 65 ContextualSearchPromoSourceAndroid::~ContextualSearchPromoSourceAndroid() {}
32 66
33 void ContextualSearchPromoSourceAndroid::StartDataRequest( 67 void ContextualSearchPromoSourceAndroid::StartDataRequest(
34 const std::string& path_and_query, int render_process_id, 68 const std::string& path_and_query, int render_process_id,
35 int render_frame_id, 69 int render_frame_id,
36 const content::URLDataSource::GotDataCallback& callback) { 70 const content::URLDataSource::GotDataCallback& callback) {
37 GURL url(std::string(chrome::kChromeUIContextualSearchPromoURL) + "/" + 71 GURL url(std::string(chrome::kChromeUIContextualSearchPromoURL) + "/" +
38 path_and_query); 72 path_and_query);
39 std::string path(url.path()); 73 std::string path(url.path());
40 if (path == kPromoHTMLPath) { 74 if (path == kPromoHTMLPath) {
41 SendHtmlWithStrings(callback); 75 SendHtmlWithStrings(callback);
42 } else if (path == kPromoCSSPath) { 76 } else if (path == kPromoCSSPath) {
43 SendResource(IDR_CONTEXTUAL_SEARCH_PROMO_CSS, callback); 77 SendResource(IDR_CONTEXTUAL_SEARCH_PROMO_CSS, callback);
44 } else if (path == kPromoJSPath) { 78 } else if (path == kPromoJSPath) {
45 SendResource(IDR_CONTEXTUAL_SEARCH_PROMO_JS, callback); 79 SendResource(IDR_CONTEXTUAL_SEARCH_PROMO_JS, callback);
80 } else if (path == kPromoConfigPath) {
81 SendConfigResource(callback);
46 } else if (path == kRobotoWoffPath) { 82 } else if (path == kRobotoWoffPath) {
47 SendResource(IDR_ROBOTO_WOFF, callback); 83 SendResource(IDR_ROBOTO_WOFF, callback);
48 } else if (path == kRobotoWoff2Path) { 84 } else if (path == kRobotoWoff2Path) {
49 SendResource(IDR_ROBOTO_WOFF2, callback); 85 SendResource(IDR_ROBOTO_WOFF2, callback);
50 } else { 86 } else {
51 callback.Run(NULL); 87 callback.Run(NULL);
52 } 88 }
53 } 89 }
54 90
55 std::string ContextualSearchPromoSourceAndroid::GetSource() const { 91 std::string ContextualSearchPromoSourceAndroid::GetSource() const {
(...skipping 21 matching lines...) Expand all
77 return false; 113 return false;
78 } 114 }
79 115
80 void ContextualSearchPromoSourceAndroid::SendResource( 116 void ContextualSearchPromoSourceAndroid::SendResource(
81 int resource_id, const content::URLDataSource::GotDataCallback& callback) { 117 int resource_id, const content::URLDataSource::GotDataCallback& callback) {
82 scoped_refptr<base::RefCountedStaticMemory> response( 118 scoped_refptr<base::RefCountedStaticMemory> response(
83 ResourceBundle::GetSharedInstance().LoadDataResourceBytes(resource_id)); 119 ResourceBundle::GetSharedInstance().LoadDataResourceBytes(resource_id));
84 callback.Run(response.get()); 120 callback.Run(response.get());
85 } 121 }
86 122
123 void ContextualSearchPromoSourceAndroid::SendConfigResource(
124 const content::URLDataSource::GotDataCallback& callback) {
125 std::string response = GetConfigData();
126 callback.Run(base::RefCountedString::TakeString(&response));
127 }
128
87 void ContextualSearchPromoSourceAndroid::SendHtmlWithStrings( 129 void ContextualSearchPromoSourceAndroid::SendHtmlWithStrings(
88 const content::URLDataSource::GotDataCallback& callback) { 130 const content::URLDataSource::GotDataCallback& callback) {
89 base::DictionaryValue strings_data; 131 base::DictionaryValue strings_data;
90 strings_data.SetString( 132 strings_data.SetString(
91 "description", 133 "description",
92 l10n_util::GetStringUTF16(IDS_CONTEXTUAL_SEARCH_PROMO_DESCRIPTION)); 134 l10n_util::GetStringUTF16(IDS_CONTEXTUAL_SEARCH_PROMO_DESCRIPTION));
93 strings_data.SetString( 135 strings_data.SetString(
94 "heading", l10n_util::GetStringUTF16(IDS_CONTEXTUAL_SEARCH_HEADER)); 136 "heading", l10n_util::GetStringUTF16(IDS_CONTEXTUAL_SEARCH_HEADER));
95 strings_data.SetString( 137 strings_data.SetString(
96 "optIn", l10n_util::GetStringUTF16(IDS_CONTEXTUAL_SEARCH_PROMO_OPTIN)); 138 "optIn", l10n_util::GetStringUTF16(IDS_CONTEXTUAL_SEARCH_PROMO_OPTIN));
97 strings_data.SetString( 139 strings_data.SetString(
98 "optOut", l10n_util::GetStringUTF16(IDS_CONTEXTUAL_SEARCH_PROMO_OPTOUT)); 140 "optOut", l10n_util::GetStringUTF16(IDS_CONTEXTUAL_SEARCH_PROMO_OPTOUT));
99 base::StringPiece html( 141 base::StringPiece html(
100 ResourceBundle::GetSharedInstance().GetRawDataResource( 142 ResourceBundle::GetSharedInstance().GetRawDataResource(
101 IDR_CONTEXTUAL_SEARCH_PROMO_HTML)); 143 IDR_CONTEXTUAL_SEARCH_PROMO_HTML));
102 webui::UseVersion2 version; 144 webui::UseVersion2 version;
103 std::string response(webui::GetI18nTemplateHtml(html, &strings_data)); 145 std::string response(webui::GetI18nTemplateHtml(html, &strings_data));
104 callback.Run(base::RefCountedString::TakeString(&response)); 146 callback.Run(base::RefCountedString::TakeString(&response));
105 } 147 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698