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

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

Issue 996313002: Serve fast NTP when experiment is enabled (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/metrics/field_trial.h"
11 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
12 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
13 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
14 #include "base/values.h" 15 #include "base/values.h"
15 #include "chrome/browser/search/instant_io_context.h" 16 #include "chrome/browser/search/instant_io_context.h"
16 #include "chrome/browser/search/search.h" 17 #include "chrome/browser/search/search.h"
17 #include "chrome/browser/search_engines/template_url_service_factory.h" 18 #include "chrome/browser/search_engines/template_url_service_factory.h"
18 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
19 #include "chrome/grit/generated_resources.h" 20 #include "chrome/grit/generated_resources.h"
20 #include "components/search_engines/template_url_prepopulate_data.h" 21 #include "components/search_engines/template_url_prepopulate_data.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 return false; 72 return false;
72 73
73 const TemplateURL* default_provider = 74 const TemplateURL* default_provider =
74 template_url_service->GetDefaultSearchProvider(); 75 template_url_service->GetDefaultSearchProvider();
75 return default_provider && 76 return default_provider &&
76 (TemplateURLPrepopulateData::GetEngineType( 77 (TemplateURLPrepopulateData::GetEngineType(
77 *default_provider, template_url_service->search_terms_data()) == 78 *default_provider, template_url_service->search_terms_data()) ==
78 SEARCH_ENGINE_GOOGLE); 79 SEARCH_ENGINE_GOOGLE);
79 } 80 }
80 81
82 bool IsLocalNTPFastEnabled() {
Mathieu 2015/03/14 19:58:27 Can you 1-line comment these functions?
fserb 2015/03/16 19:52:27 Done.
83 return StartsWithASCII(base::FieldTrialList::FindFullName("LocalNTPFast"),
84 "Enabled", true);
85 }
86
87 void SendResource(int resource_id,
88 const content::URLDataSource::GotDataCallback& callback) {
89 scoped_refptr<base::RefCountedStaticMemory> response(
90 ResourceBundle::GetSharedInstance().LoadDataResourceBytes(resource_id));
91 callback.Run(response.get());
92 }
93
81 // Adds a localized string keyed by resource id to the dictionary. 94 // Adds a localized string keyed by resource id to the dictionary.
82 void AddString(base::DictionaryValue* dictionary, 95 void AddString(base::DictionaryValue* dictionary,
83 const std::string& key, 96 const std::string& key,
84 int resource_id) { 97 int resource_id) {
85 dictionary->SetString(key, l10n_util::GetStringUTF16(resource_id)); 98 dictionary->SetString(key, l10n_util::GetStringUTF16(resource_id));
86 } 99 }
87 100
88 // Adds a localized string for the Google searchbox placeholder text. 101 // Adds a localized string for the Google searchbox placeholder text.
89 void AddGoogleSearchboxPlaceholderString(base::DictionaryValue* dictionary) { 102 void AddGoogleSearchboxPlaceholderString(base::DictionaryValue* dictionary) {
90 base::string16 placeholder = l10n_util::GetStringFUTF16( 103 base::string16 placeholder = l10n_util::GetStringFUTF16(
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 const std::string& path, 171 const std::string& path,
159 int render_process_id, 172 int render_process_id,
160 int render_frame_id, 173 int render_frame_id,
161 const content::URLDataSource::GotDataCallback& callback) { 174 const content::URLDataSource::GotDataCallback& callback) {
162 const std::string stripped_path = StripParameters(path); 175 const std::string stripped_path = StripParameters(path);
163 if (stripped_path == kConfigDataFilename) { 176 if (stripped_path == kConfigDataFilename) {
164 std::string config_data_js = GetConfigData(profile_); 177 std::string config_data_js = GetConfigData(profile_);
165 callback.Run(base::RefCountedString::TakeString(&config_data_js)); 178 callback.Run(base::RefCountedString::TakeString(&config_data_js));
166 return; 179 return;
167 } 180 }
181 if (IsLocalNTPFastEnabled()) {
182 if (stripped_path == "local-ntp.html") {
183 return SendResource(IDR_LOCAL_NTP_FAST_HTML, callback);
184 } else if (stripped_path == "local-ntp.js") {
185 return SendResource(IDR_LOCAL_NTP_FAST_JS, callback);
186 } else if (stripped_path == "local-ntp.css") {
187 return SendResource(IDR_LOCAL_NTP_FAST_CSS, callback);
188 }
189 }
168 float scale = 1.0f; 190 float scale = 1.0f;
169 std::string filename; 191 std::string filename;
170 webui::ParsePathAndScale( 192 webui::ParsePathAndScale(
171 GURL(GetLocalNtpPath() + stripped_path), &filename, &scale); 193 GURL(GetLocalNtpPath() + stripped_path), &filename, &scale);
172 ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactor(scale); 194 ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactor(scale);
173 for (size_t i = 0; i < arraysize(kResources); ++i) { 195 for (size_t i = 0; i < arraysize(kResources); ++i) {
174 if (filename == kResources[i].filename) { 196 if (filename == kResources[i].filename) {
175 scoped_refptr<base::RefCountedStaticMemory> response( 197 scoped_refptr<base::RefCountedStaticMemory> response(
176 ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( 198 ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale(
177 kResources[i].identifier, scale_factor)); 199 kResources[i].identifier, scale_factor));
(...skipping 17 matching lines...) Expand all
195 bool LocalNtpSource::ShouldServiceRequest( 217 bool LocalNtpSource::ShouldServiceRequest(
196 const net::URLRequest* request) const { 218 const net::URLRequest* request) const {
197 DCHECK(request->url().host() == chrome::kChromeSearchLocalNtpHost); 219 DCHECK(request->url().host() == chrome::kChromeSearchLocalNtpHost);
198 if (!InstantIOContext::ShouldServiceRequest(request)) 220 if (!InstantIOContext::ShouldServiceRequest(request))
199 return false; 221 return false;
200 222
201 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) { 223 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) {
202 std::string filename; 224 std::string filename;
203 webui::ParsePathAndScale(request->url(), &filename, NULL); 225 webui::ParsePathAndScale(request->url(), &filename, NULL);
204 for (size_t i = 0; i < arraysize(kResources); ++i) { 226 for (size_t i = 0; i < arraysize(kResources); ++i) {
205 if (filename == kResources[i].filename) 227 if (filename == kResources[i].filename)
Mathieu 2015/03/14 19:58:27 is not being in kResources going to cause you prob
fserb 2015/03/16 19:52:27 The endpoints are still there. We only hijack the
206 return true; 228 return true;
207 } 229 }
208 } 230 }
209 return false; 231 return false;
210 } 232 }
211 233
212 std::string LocalNtpSource::GetContentSecurityPolicyFrameSrc() const { 234 std::string LocalNtpSource::GetContentSecurityPolicyFrameSrc() const {
213 // Allow embedding of most visited iframes. 235 // Allow embedding of most visited iframes.
214 return base::StringPrintf("frame-src %s;", 236 return base::StringPrintf("frame-src %s;",
215 chrome::kChromeSearchMostVisitedUrl); 237 chrome::kChromeSearchMostVisitedUrl);
216 } 238 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698