OLD | NEW |
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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 state = INSTANT_EXTENDED_OPT_IN_LOCAL; | 142 state = INSTANT_EXTENDED_OPT_IN_LOCAL; |
143 } else if (command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) { | 143 } else if (command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) { |
144 state = INSTANT_EXTENDED_OPT_IN; | 144 state = INSTANT_EXTENDED_OPT_IN; |
145 } | 145 } |
146 | 146 |
147 UMA_HISTOGRAM_ENUMERATION("InstantExtended.OptInState", state, | 147 UMA_HISTOGRAM_ENUMERATION("InstantExtended.OptInState", state, |
148 INSTANT_EXTENDED_OPT_IN_STATE_ENUM_COUNT); | 148 INSTANT_EXTENDED_OPT_IN_STATE_ENUM_COUNT); |
149 } | 149 } |
150 } | 150 } |
151 | 151 |
152 // Helper for EmbeddedSearchPageVersion. Does not check if in incognito mode. | |
153 uint64 EmbeddedSearchPageVersionHelper() { | |
154 // No server-side changes if the local-only Instant Extended is enabled. | |
155 if (IsLocalOnlyInstantExtendedAPIEnabled()) | |
156 return kEmbeddedPageVersionDisabled; | |
157 | |
158 // Check the command-line/about:flags setting first, which should have | |
159 // precedence and allows the trial to not be reported (if it's never queried). | |
160 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
161 if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI)) | |
162 return kEmbeddedPageVersionDisabled; | |
163 if (command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) { | |
164 // The user has set the about:flags switch to Enabled - give the default | |
165 // UI version. | |
166 return kEmbeddedPageVersionDefault; | |
167 } | |
168 | |
169 FieldTrialFlags flags; | |
170 if (GetFieldTrialInfo( | |
171 base::FieldTrialList::FindFullName(kInstantExtendedFieldTrialName), | |
172 &flags, NULL)) { | |
173 return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName, | |
174 kEmbeddedPageVersionDefault, | |
175 flags); | |
176 } | |
177 return kEmbeddedPageVersionDisabled; | |
178 } | |
179 | |
180 // Returns true if |contents| is rendered inside the Instant process for | 152 // Returns true if |contents| is rendered inside the Instant process for |
181 // |profile|. | 153 // |profile|. |
182 bool IsRenderedInInstantProcess(const content::WebContents* contents, | 154 bool IsRenderedInInstantProcess(const content::WebContents* contents, |
183 Profile* profile) { | 155 Profile* profile) { |
184 const content::RenderProcessHost* process_host = | 156 const content::RenderProcessHost* process_host = |
185 contents->GetRenderProcessHost(); | 157 contents->GetRenderProcessHost(); |
186 if (!process_host) | 158 if (!process_host) |
187 return false; | 159 return false; |
188 | 160 |
189 const InstantService* instant_service = | 161 const InstantService* instant_service = |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 return true; | 199 return true; |
228 | 200 |
229 if (extended_api_enabled && MatchesAnySearchURL(effective_url, template_url)) | 201 if (extended_api_enabled && MatchesAnySearchURL(effective_url, template_url)) |
230 return true; | 202 return true; |
231 | 203 |
232 return false; | 204 return false; |
233 } | 205 } |
234 | 206 |
235 string16 GetSearchTermsImpl(const content::WebContents* contents, | 207 string16 GetSearchTermsImpl(const content::WebContents* contents, |
236 const content::NavigationEntry* entry) { | 208 const content::NavigationEntry* entry) { |
| 209 if (!IsQueryExtractionEnabled()) |
| 210 return string16(); |
| 211 |
237 // For security reasons, don't extract search terms if the page is not being | 212 // For security reasons, don't extract search terms if the page is not being |
238 // rendered in the privileged Instant renderer process. This is to protect | 213 // rendered in the privileged Instant renderer process. This is to protect |
239 // against a malicious page somehow scripting the search results page and | 214 // against a malicious page somehow scripting the search results page and |
240 // faking search terms in the URL. Random pages can't get into the Instant | 215 // faking search terms in the URL. Random pages can't get into the Instant |
241 // renderer and scripting doesn't work cross-process, so if the page is in | 216 // renderer and scripting doesn't work cross-process, so if the page is in |
242 // the Instant process, we know it isn't being exploited. | 217 // the Instant process, we know it isn't being exploited. |
243 // Since iOS and Android doesn't use the instant framework, these checks are | 218 // Since iOS and Android doesn't use the instant framework, these checks are |
244 // disabled for the two platforms. | 219 // disabled for the two platforms. |
245 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 220 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
246 | |
247 if (!IsQueryExtractionEnabled(profile)) | |
248 return string16(); | |
249 | |
250 #if !defined(OS_IOS) && !defined(OS_ANDROID) | 221 #if !defined(OS_IOS) && !defined(OS_ANDROID) |
251 if (!IsRenderedInInstantProcess(contents, profile) && | 222 if (!IsRenderedInInstantProcess(contents, profile) && |
252 (contents->GetController().GetLastCommittedEntry() == entry || | 223 (contents->GetController().GetLastCommittedEntry() == entry || |
253 !ShouldAssignURLToInstantRenderer(entry->GetURL(), profile))) | 224 !ShouldAssignURLToInstantRenderer(entry->GetURL(), profile))) |
254 return string16(); | 225 return string16(); |
255 #endif // !defined(OS_IOS) && !defined(OS_ANDROID) | 226 #endif // !defined(OS_IOS) && !defined(OS_ANDROID) |
256 // Check to see if search terms have already been extracted. | 227 // Check to see if search terms have already been extracted. |
257 string16 search_terms = GetSearchTermsFromNavigationEntry(entry); | 228 string16 search_terms = GetSearchTermsFromNavigationEntry(entry); |
258 if (!search_terms.empty()) | 229 if (!search_terms.empty()) |
259 return search_terms; | 230 return search_terms; |
260 | 231 |
261 // Otherwise, extract from the URL. | 232 // Otherwise, extract from the URL. |
262 return GetSearchTermsFromURL(profile, entry->GetVirtualURL()); | 233 return GetSearchTermsFromURL(profile, entry->GetVirtualURL()); |
263 } | 234 } |
264 | 235 |
265 } // namespace | 236 } // namespace |
266 | 237 |
267 // Negative start-margin values prevent the "es_sm" parameter from being used. | 238 // Negative start-margin values prevent the "es_sm" parameter from being used. |
268 const int kDisableStartMargin = -1; | 239 const int kDisableStartMargin = -1; |
269 | 240 |
270 bool IsInstantExtendedAPIEnabled() { | 241 bool IsInstantExtendedAPIEnabled() { |
271 #if defined(OS_IOS) || defined(OS_ANDROID) | 242 #if defined(OS_IOS) || defined(OS_ANDROID) |
272 return false; | 243 return false; |
273 #else | 244 #else |
274 // TODO(dougw): Switch to EmbeddedSearchPageVersion after the proper | 245 // On desktop, query extraction is part of Instant extended, so if one is |
275 // solution to Issue 232065 has been implemented. | 246 // enabled, the other is too. |
276 return EmbeddedSearchPageVersionHelper() || | 247 return IsQueryExtractionEnabled() || IsLocalOnlyInstantExtendedAPIEnabled(); |
277 IsLocalOnlyInstantExtendedAPIEnabled(); | |
278 #endif // defined(OS_IOS) || defined(OS_ANDROID) | 248 #endif // defined(OS_IOS) || defined(OS_ANDROID) |
279 } | 249 } |
280 | 250 |
281 // Determine what embedded search page version to request from the user's | 251 // Determine what embedded search page version to request from the user's |
282 // default search provider. If 0, the embedded search UI should not be enabled. | 252 // default search provider. If 0, the embedded search UI should not be enabled. |
283 uint64 EmbeddedSearchPageVersion(Profile* profile) { | 253 uint64 EmbeddedSearchPageVersion() { |
284 // Disable for incognito. Temporary fix for Issue 232065. | 254 // No server-side changes if the local-only Instant Extended is enabled. |
285 #if !defined(OS_IOS) && !defined(OS_ANDROID) | 255 if (IsLocalOnlyInstantExtendedAPIEnabled()) |
286 if (!profile || profile->IsOffTheRecord()) | |
287 return kEmbeddedPageVersionDisabled; | 256 return kEmbeddedPageVersionDisabled; |
288 #endif // !defined(OS_IOS) && !defined(OS_ANDROID) | 257 |
289 return EmbeddedSearchPageVersionHelper(); | 258 // Check the command-line/about:flags setting first, which should have |
| 259 // precedence and allows the trial to not be reported (if it's never queried). |
| 260 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 261 if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI)) |
| 262 return kEmbeddedPageVersionDisabled; |
| 263 if (command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) { |
| 264 // The user has set the about:flags switch to Enabled - give the default |
| 265 // UI version. |
| 266 return kEmbeddedPageVersionDefault; |
| 267 } |
| 268 |
| 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; |
290 } | 278 } |
291 | 279 |
292 bool IsQueryExtractionEnabled(Profile* profile) { | 280 bool IsQueryExtractionEnabled() { |
293 return EmbeddedSearchPageVersion(profile) != kEmbeddedPageVersionDisabled; | 281 return EmbeddedSearchPageVersion() != kEmbeddedPageVersionDisabled; |
294 } | 282 } |
295 | 283 |
296 bool IsLocalOnlyInstantExtendedAPIEnabled() { | 284 bool IsLocalOnlyInstantExtendedAPIEnabled() { |
297 RecordInstantExtendedOptInState(); | 285 RecordInstantExtendedOptInState(); |
298 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 286 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
299 if (command_line->HasSwitch(switches::kDisableLocalOnlyInstantExtendedAPI) || | 287 if (command_line->HasSwitch(switches::kDisableLocalOnlyInstantExtendedAPI) || |
300 command_line->HasSwitch(switches::kDisableInstantExtendedAPI)) { | 288 command_line->HasSwitch(switches::kDisableInstantExtendedAPI)) { |
301 return false; | 289 return false; |
302 } | 290 } |
303 if (command_line->HasSwitch(switches::kEnableLocalOnlyInstantExtendedAPI)) | 291 if (command_line->HasSwitch(switches::kEnableLocalOnlyInstantExtendedAPI)) |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 for (size_t i = 0; i < items_b.size(); ++i) { | 742 for (size_t i = 0; i < items_b.size(); ++i) { |
755 if (items_b[i].url != items_a[i].url || | 743 if (items_b[i].url != items_a[i].url || |
756 items_b[i].title != items_a[i].title) { | 744 items_b[i].title != items_a[i].title) { |
757 return false; | 745 return false; |
758 } | 746 } |
759 } | 747 } |
760 return true; | 748 return true; |
761 } | 749 } |
762 | 750 |
763 } // namespace chrome | 751 } // namespace chrome |
OLD | NEW |