Chromium Code Reviews| 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 } | |
|
Mathieu
2015/03/25 13:36:39
missing newline
huangs
2015/03/25 14:10:29
Done.
| |
| 82 // Returns whether we are in the Fast NTP experiment or not. | 87 // Returns whether we are in the Fast NTP experiment or not. |
| 83 bool IsLocalNTPFastEnabled() { | 88 bool IsLocalNTPFastEnabled() { |
| 84 return StartsWithASCII(base::FieldTrialList::FindFullName("LocalNTPFast"), | 89 return StartsWithASCII(base::FieldTrialList::FindFullName("LocalNTPFast"), |
| 85 "Enabled", true); | 90 "Enabled", true); |
| 86 } | 91 } |
| 87 | 92 |
| 88 // Serves a particular resource. | 93 // Serves a particular resource. |
| 89 // Used for bypassing the default resources when we are in an experiment. | 94 // Used for bypassing the default resources when we are in an experiment. |
| 90 void SendResource(int resource_id, | 95 void SendResource(int resource_id, |
| 91 const content::URLDataSource::GotDataCallback& callback) { | 96 const content::URLDataSource::GotDataCallback& callback) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 } | 138 } |
| 134 | 139 |
| 135 // Returns a JS dictionary of configuration data for the local NTP. | 140 // Returns a JS dictionary of configuration data for the local NTP. |
| 136 std::string GetConfigData(Profile* profile) { | 141 std::string GetConfigData(Profile* profile) { |
| 137 base::DictionaryValue config_data; | 142 base::DictionaryValue config_data; |
| 138 bool is_google = DefaultSearchProviderIsGoogle(profile) && | 143 bool is_google = DefaultSearchProviderIsGoogle(profile) && |
| 139 chrome::ShouldShowGoogleLocalNTP(); | 144 chrome::ShouldShowGoogleLocalNTP(); |
| 140 config_data.Set("translatedStrings", | 145 config_data.Set("translatedStrings", |
| 141 GetTranslatedStrings(is_google).release()); | 146 GetTranslatedStrings(is_google).release()); |
| 142 config_data.SetBoolean("isGooglePage", is_google); | 147 config_data.SetBoolean("isGooglePage", is_google); |
| 148 config_data.SetBoolean("useIcons", IsIconNTPEnabled()); | |
| 143 | 149 |
| 144 // Serialize the dictionary. | 150 // Serialize the dictionary. |
| 145 std::string js_text; | 151 std::string js_text; |
| 146 JSONStringValueSerializer serializer(&js_text); | 152 JSONStringValueSerializer serializer(&js_text); |
| 147 serializer.Serialize(config_data); | 153 serializer.Serialize(config_data); |
| 148 | 154 |
| 149 std::string config_data_js; | 155 std::string config_data_js; |
| 150 config_data_js.append("var configData = "); | 156 config_data_js.append("var configData = "); |
| 151 config_data_js.append(js_text); | 157 config_data_js.append(js_text); |
| 152 config_data_js.append(";"); | 158 config_data_js.append(";"); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 } | 238 } |
| 233 } | 239 } |
| 234 return false; | 240 return false; |
| 235 } | 241 } |
| 236 | 242 |
| 237 std::string LocalNtpSource::GetContentSecurityPolicyFrameSrc() const { | 243 std::string LocalNtpSource::GetContentSecurityPolicyFrameSrc() const { |
| 238 // Allow embedding of most visited iframes. | 244 // Allow embedding of most visited iframes. |
| 239 return base::StringPrintf("frame-src %s;", | 245 return base::StringPrintf("frame-src %s;", |
| 240 chrome::kChromeSearchMostVisitedUrl); | 246 chrome::kChromeSearchMostVisitedUrl); |
| 241 } | 247 } |
| OLD | NEW |