OLD | NEW |
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_ntp_source.h" | 5 #include "chrome/browser/search/local_ntp_source.h" |
6 | 6 |
7 #include "base/json/json_string_value_serializer.h" | 7 #include "base/json/json_string_value_serializer.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 return false; | 72 return false; |
73 | 73 |
74 const TemplateURL* default_provider = | 74 const TemplateURL* default_provider = |
75 template_url_service->GetDefaultSearchProvider(); | 75 template_url_service->GetDefaultSearchProvider(); |
76 return default_provider && | 76 return default_provider && |
77 (TemplateURLPrepopulateData::GetEngineType( | 77 (TemplateURLPrepopulateData::GetEngineType( |
78 *default_provider, template_url_service->search_terms_data()) == | 78 *default_provider, template_url_service->search_terms_data()) == |
79 SEARCH_ENGINE_GOOGLE); | 79 SEARCH_ENGINE_GOOGLE); |
80 } | 80 } |
81 | 81 |
| 82 // Returns whether icon NTP is enabled. |
| 83 bool IsIconNTPEnabled() { |
| 84 return StartsWithASCII(base::FieldTrialList::FindFullName("IconNTP"), |
| 85 "Enabled", true); |
| 86 } |
| 87 |
82 // Returns whether we are in the Fast NTP experiment or not. | 88 // Returns whether we are in the Fast NTP experiment or not. |
83 bool IsLocalNTPFastEnabled() { | 89 bool IsLocalNTPFastEnabled() { |
84 return StartsWithASCII(base::FieldTrialList::FindFullName("LocalNTPFast"), | 90 return StartsWithASCII(base::FieldTrialList::FindFullName("LocalNTPFast"), |
85 "Enabled", true); | 91 "Enabled", true); |
86 } | 92 } |
87 | 93 |
88 // Serves a particular resource. | 94 // Serves a particular resource. |
89 // Used for bypassing the default resources when we are in an experiment. | 95 // Used for bypassing the default resources when we are in an experiment. |
90 void SendResource(int resource_id, | 96 void SendResource(int resource_id, |
91 const content::URLDataSource::GotDataCallback& callback) { | 97 const content::URLDataSource::GotDataCallback& callback) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 } | 139 } |
134 | 140 |
135 // Returns a JS dictionary of configuration data for the local NTP. | 141 // Returns a JS dictionary of configuration data for the local NTP. |
136 std::string GetConfigData(Profile* profile) { | 142 std::string GetConfigData(Profile* profile) { |
137 base::DictionaryValue config_data; | 143 base::DictionaryValue config_data; |
138 bool is_google = DefaultSearchProviderIsGoogle(profile) && | 144 bool is_google = DefaultSearchProviderIsGoogle(profile) && |
139 chrome::ShouldShowGoogleLocalNTP(); | 145 chrome::ShouldShowGoogleLocalNTP(); |
140 config_data.Set("translatedStrings", | 146 config_data.Set("translatedStrings", |
141 GetTranslatedStrings(is_google).release()); | 147 GetTranslatedStrings(is_google).release()); |
142 config_data.SetBoolean("isGooglePage", is_google); | 148 config_data.SetBoolean("isGooglePage", is_google); |
| 149 config_data.SetBoolean("useIcons", IsIconNTPEnabled()); |
143 | 150 |
144 // Serialize the dictionary. | 151 // Serialize the dictionary. |
145 std::string js_text; | 152 std::string js_text; |
146 JSONStringValueSerializer serializer(&js_text); | 153 JSONStringValueSerializer serializer(&js_text); |
147 serializer.Serialize(config_data); | 154 serializer.Serialize(config_data); |
148 | 155 |
149 std::string config_data_js; | 156 std::string config_data_js; |
150 config_data_js.append("var configData = "); | 157 config_data_js.append("var configData = "); |
151 config_data_js.append(js_text); | 158 config_data_js.append(js_text); |
152 config_data_js.append(";"); | 159 config_data_js.append(";"); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 } | 239 } |
233 } | 240 } |
234 return false; | 241 return false; |
235 } | 242 } |
236 | 243 |
237 std::string LocalNtpSource::GetContentSecurityPolicyFrameSrc() const { | 244 std::string LocalNtpSource::GetContentSecurityPolicyFrameSrc() const { |
238 // Allow embedding of most visited iframes. | 245 // Allow embedding of most visited iframes. |
239 return base::StringPrintf("frame-src %s;", | 246 return base::StringPrintf("frame-src %s;", |
240 chrome::kChromeSearchMostVisitedUrl); | 247 chrome::kChromeSearchMostVisitedUrl); |
241 } | 248 } |
OLD | NEW |