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

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

Issue 14715010: Formatting fix. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 7 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 | « chrome/browser/search/search.h ('k') | chrome/browser/search/search_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/search.h" 5 #include "chrome/browser/search/search.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 125
126 void RecordInstantExtendedOptInState(OptInState state) { 126 void RecordInstantExtendedOptInState(OptInState state) {
127 static bool recorded = false; 127 static bool recorded = false;
128 if (!recorded) { 128 if (!recorded) {
129 recorded = true; 129 recorded = true;
130 UMA_HISTOGRAM_ENUMERATION("InstantExtended.OptInState", state, 130 UMA_HISTOGRAM_ENUMERATION("InstantExtended.OptInState", state,
131 OPT_IN_STATE_ENUM_COUNT); 131 OPT_IN_STATE_ENUM_COUNT);
132 } 132 }
133 } 133 }
134 134
135 // Helper for EmbeddedSearchPageVersion. Does not check if in incognito mode.
136 uint64 EmbeddedSearchPageVersionHelper() {
137 // No server-side changes if the local-only Instant Extended is enabled.
138 if (IsLocalOnlyInstantExtendedAPIEnabled())
139 return kEmbeddedPageVersionDisabled;
140
141 // Check the command-line/about:flags setting first, which should have
142 // precedence and allows the trial to not be reported (if it's never queried).
143 const CommandLine* command_line = CommandLine::ForCurrentProcess();
144 if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI)) {
145 RecordInstantExtendedOptInState(OPT_OUT);
146 return kEmbeddedPageVersionDisabled;
147 }
148 if (command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) {
149 // The user has set the about:flags switch to Enabled - give the default
150 // UI version.
151 RecordInstantExtendedOptInState(OPT_IN);
152 return kEmbeddedPageVersionDefault;
153 }
154
155 RecordInstantExtendedOptInState(NOT_SET);
156 FieldTrialFlags flags;
157 if (GetFieldTrialInfo(
158 base::FieldTrialList::FindFullName(kInstantExtendedFieldTrialName),
159 &flags, NULL)) {
160 return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName,
161 kEmbeddedPageVersionDefault,
162 flags);
163 }
164 return kEmbeddedPageVersionDisabled;
165 }
166
135 // Returns true if |contents| is rendered inside the Instant process for 167 // Returns true if |contents| is rendered inside the Instant process for
136 // |profile|. 168 // |profile|.
137 bool IsRenderedInInstantProcess(const content::WebContents* contents, 169 bool IsRenderedInInstantProcess(const content::WebContents* contents,
138 Profile* profile) { 170 Profile* profile) {
139 const content::RenderProcessHost* process_host = 171 const content::RenderProcessHost* process_host =
140 contents->GetRenderProcessHost(); 172 contents->GetRenderProcessHost();
141 if (!process_host) 173 if (!process_host)
142 return false; 174 return false;
143 175
144 const InstantService* instant_service = 176 const InstantService* instant_service =
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 return true; 214 return true;
183 215
184 if (extended_api_enabled && MatchesAnySearchURL(effective_url, template_url)) 216 if (extended_api_enabled && MatchesAnySearchURL(effective_url, template_url))
185 return true; 217 return true;
186 218
187 return false; 219 return false;
188 } 220 }
189 221
190 string16 GetSearchTermsImpl(const content::WebContents* contents, 222 string16 GetSearchTermsImpl(const content::WebContents* contents,
191 const content::NavigationEntry* entry) { 223 const content::NavigationEntry* entry) {
192 if (!IsQueryExtractionEnabled())
193 return string16();
194
195 // For security reasons, don't extract search terms if the page is not being 224 // For security reasons, don't extract search terms if the page is not being
196 // rendered in the privileged Instant renderer process. This is to protect 225 // rendered in the privileged Instant renderer process. This is to protect
197 // against a malicious page somehow scripting the search results page and 226 // against a malicious page somehow scripting the search results page and
198 // faking search terms in the URL. Random pages can't get into the Instant 227 // faking search terms in the URL. Random pages can't get into the Instant
199 // renderer and scripting doesn't work cross-process, so if the page is in 228 // renderer and scripting doesn't work cross-process, so if the page is in
200 // the Instant process, we know it isn't being exploited. 229 // the Instant process, we know it isn't being exploited.
201 // Since iOS and Android doesn't use the instant framework, these checks are 230 // Since iOS and Android doesn't use the instant framework, these checks are
202 // disabled for the two platforms. 231 // disabled for the two platforms.
203 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); 232 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
233
234 if (!IsQueryExtractionEnabled(profile))
235 return string16();
236
204 #if !defined(OS_IOS) && !defined(OS_ANDROID) 237 #if !defined(OS_IOS) && !defined(OS_ANDROID)
205 if (!IsRenderedInInstantProcess(contents, profile) && 238 if (!IsRenderedInInstantProcess(contents, profile) &&
206 (contents->GetController().GetLastCommittedEntry() == entry || 239 (contents->GetController().GetLastCommittedEntry() == entry ||
207 !ShouldAssignURLToInstantRenderer(entry->GetURL(), profile))) 240 !ShouldAssignURLToInstantRenderer(entry->GetURL(), profile)))
208 return string16(); 241 return string16();
209 #endif // !defined(OS_IOS) && !defined(OS_ANDROID) 242 #endif // !defined(OS_IOS) && !defined(OS_ANDROID)
210 // Check to see if search terms have already been extracted. 243 // Check to see if search terms have already been extracted.
211 string16 search_terms = GetSearchTermsFromNavigationEntry(entry); 244 string16 search_terms = GetSearchTermsFromNavigationEntry(entry);
212 if (!search_terms.empty()) 245 if (!search_terms.empty())
213 return search_terms; 246 return search_terms;
(...skipping 17 matching lines...) Expand all
231 264
232 } // namespace 265 } // namespace
233 266
234 // Negative start-margin values prevent the "es_sm" parameter from being used. 267 // Negative start-margin values prevent the "es_sm" parameter from being used.
235 const int kDisableStartMargin = -1; 268 const int kDisableStartMargin = -1;
236 269
237 bool IsInstantExtendedAPIEnabled() { 270 bool IsInstantExtendedAPIEnabled() {
238 #if defined(OS_IOS) || defined(OS_ANDROID) 271 #if defined(OS_IOS) || defined(OS_ANDROID)
239 return false; 272 return false;
240 #else 273 #else
241 // On desktop, query extraction is part of Instant extended, so if one is 274 // TODO(dougw): Switch to EmbeddedSearchPageVersion after the proper
242 // enabled, the other is too. 275 // solution to Issue 232065 has been implemented.
243 return IsQueryExtractionEnabled() || IsLocalOnlyInstantExtendedAPIEnabled(); 276 return EmbeddedSearchPageVersionHelper() ||
277 IsLocalOnlyInstantExtendedAPIEnabled();
244 #endif // defined(OS_IOS) || defined(OS_ANDROID) 278 #endif // defined(OS_IOS) || defined(OS_ANDROID)
245 } 279 }
246 280
247 // Determine what embedded search page version to request from the user's 281 // Determine what embedded search page version to request from the user's
248 // default search provider. If 0, the embedded search UI should not be enabled. 282 // default search provider. If 0, the embedded search UI should not be enabled.
249 uint64 EmbeddedSearchPageVersion() { 283 uint64 EmbeddedSearchPageVersion(Profile* profile) {
250 // No server-side changes if the local-only Instant Extended is enabled. 284 // Disable for incognito. Temporary fix for Issue 232065.
251 if (IsLocalOnlyInstantExtendedAPIEnabled()) 285 #if !defined(OS_IOS) && !defined(OS_ANDROID)
286 if (profile && profile->IsOffTheRecord())
252 return kEmbeddedPageVersionDisabled; 287 return kEmbeddedPageVersionDisabled;
253 288 #endif // !defined(OS_IOS) && !defined(OS_ANDROID)
254 // Check the command-line/about:flags setting first, which should have 289 return EmbeddedSearchPageVersionHelper();
255 // precedence and allows the trial to not be reported (if it's never queried).
256 const CommandLine* command_line = CommandLine::ForCurrentProcess();
257 if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI)) {
258 RecordInstantExtendedOptInState(OPT_OUT);
259 return kEmbeddedPageVersionDisabled;
260 }
261 if (command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) {
262 // The user has set the about:flags switch to Enabled - give the default
263 // UI version.
264 RecordInstantExtendedOptInState(OPT_IN);
265 return kEmbeddedPageVersionDefault;
266 }
267
268 RecordInstantExtendedOptInState(NOT_SET);
269 FieldTrialFlags flags;
270 if (GetFieldTrialInfo(
271 base::FieldTrialList::FindFullName(kInstantExtendedFieldTrialName),
272 &flags, NULL)) {
273 return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName,
274 kEmbeddedPageVersionDefault,
275 flags);
276 }
277 return kEmbeddedPageVersionDisabled;
278 } 290 }
279 291
280 bool IsQueryExtractionEnabled() { 292 bool IsQueryExtractionEnabled(Profile* profile) {
281 return EmbeddedSearchPageVersion() != kEmbeddedPageVersionDisabled; 293 return EmbeddedSearchPageVersion(profile) != kEmbeddedPageVersionDisabled;
282 } 294 }
283 295
284 bool IsLocalOnlyInstantExtendedAPIEnabled() { 296 bool IsLocalOnlyInstantExtendedAPIEnabled() {
285 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 297 const CommandLine* command_line = CommandLine::ForCurrentProcess();
286 if (command_line->HasSwitch(switches::kDisableLocalOnlyInstantExtendedAPI) || 298 if (command_line->HasSwitch(switches::kDisableLocalOnlyInstantExtendedAPI) ||
287 command_line->HasSwitch(switches::kDisableInstantExtendedAPI)) 299 command_line->HasSwitch(switches::kDisableInstantExtendedAPI))
288 return false; 300 return false;
289 if (command_line->HasSwitch(switches::kEnableLocalOnlyInstantExtendedAPI)) 301 if (command_line->HasSwitch(switches::kEnableLocalOnlyInstantExtendedAPI))
290 return true; 302 return true;
291 303
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 636
625 GURL instant_url = TemplateURLRefToGURL(template_url->instant_url_ref(), 637 GURL instant_url = TemplateURLRefToGURL(template_url->instant_url_ref(),
626 kDisableStartMargin); 638 kDisableStartMargin);
627 // Extended mode instant requires a search terms replacement key. 639 // Extended mode instant requires a search terms replacement key.
628 return instant_url.is_valid() && 640 return instant_url.is_valid() &&
629 (!IsInstantExtendedAPIEnabled() || 641 (!IsInstantExtendedAPIEnabled() ||
630 template_url->HasSearchTermsReplacementKey(instant_url)); 642 template_url->HasSearchTermsReplacementKey(instant_url));
631 } 643 }
632 644
633 } // namespace chrome 645 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/search/search.h ('k') | chrome/browser/search/search_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698