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/ui/search/instant_controller.h" | 5 #include "chrome/browser/ui/search/instant_controller.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 // properly. | 311 // properly. |
312 UpdateInfoForInstantTab(); | 312 UpdateInfoForInstantTab(); |
313 } | 313 } |
314 | 314 |
315 void InstantController::FocusOmnibox(const content::WebContents* contents, | 315 void InstantController::FocusOmnibox(const content::WebContents* contents, |
316 OmniboxFocusState state) { | 316 OmniboxFocusState state) { |
317 if (!extended_enabled()) | 317 if (!extended_enabled()) |
318 return; | 318 return; |
319 | 319 |
320 DCHECK(IsContentsFrom(instant_tab(), contents)); | 320 DCHECK(IsContentsFrom(instant_tab(), contents)); |
321 | 321 browser_->FocusOmnibox(contents, state); |
322 // Do not add a default case in the switch block for the following reasons: | |
323 // (1) Explicitly handle the new states. If new states are added in the | |
324 // OmniboxFocusState, the compiler will warn the developer to handle the new | |
325 // states. | |
326 // (2) An attacker may control the renderer and sends the browser process a | |
327 // malformed IPC. This function responds to the invalid |state| values by | |
328 // doing nothing instead of crashing the browser process (intentional no-op). | |
329 switch (state) { | |
330 case OMNIBOX_FOCUS_VISIBLE: | |
331 // TODO(samarth): re-enable this once setValue() correctly handles | |
332 // URL-shaped queries. | |
333 // browser_->FocusOmnibox(true); | |
334 break; | |
335 case OMNIBOX_FOCUS_INVISIBLE: | |
336 browser_->FocusOmnibox(false); | |
337 break; | |
338 case OMNIBOX_FOCUS_NONE: | |
339 contents->GetView()->Focus(); | |
340 break; | |
341 } | |
342 } | 322 } |
343 | 323 |
344 void InstantController::NavigateToURL(const content::WebContents* contents, | 324 void InstantController::NavigateToURL(const content::WebContents* contents, |
345 const GURL& url, | 325 const GURL& url, |
346 content::PageTransition transition, | 326 content::PageTransition transition, |
347 WindowOpenDisposition disposition, | 327 WindowOpenDisposition disposition, |
348 bool is_search_type) { | 328 bool is_search_type) { |
349 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( | 329 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( |
350 "NavigateToURL: url='%s'", url.spec().c_str())); | 330 "NavigateToURL: url='%s'", url.spec().c_str())); |
351 | 331 |
352 // TODO(samarth): handle case where contents are no longer "active" (e.g. user | 332 // TODO(samarth): handle case where contents are no longer "active" (e.g. user |
353 // has switched tabs). | 333 // has switched tabs). |
354 if (!extended_enabled()) | 334 if (!extended_enabled()) |
355 return; | 335 return; |
356 | 336 |
357 if (transition == content::PAGE_TRANSITION_AUTO_BOOKMARK) { | 337 if (transition == content::PAGE_TRANSITION_AUTO_BOOKMARK) { |
358 content::RecordAction( | 338 content::RecordAction( |
359 content::UserMetricsAction("InstantExtended.MostVisitedClicked")); | 339 content::UserMetricsAction("InstantExtended.MostVisitedClicked")); |
360 } else { | 340 } else { |
361 // Exclude navigation by Most Visited click and searches. | 341 // Exclude navigation by Most Visited click and searches. |
362 if (!is_search_type) | 342 if (!is_search_type) |
363 RecordNavigationHistogram(UsingLocalPage(), true, true); | 343 RecordNavigationHistogram(UsingLocalPage(), true, true); |
364 } | 344 } |
365 browser_->OpenURL(url, transition, disposition); | 345 browser_->OpenURL(url, transition, disposition); |
366 } | 346 } |
367 | 347 |
| 348 void InstantController::PasteIntoOmnibox(const content::WebContents* contents) { |
| 349 if (!extended_enabled() || search_mode_.is_origin_default()) |
| 350 return; |
| 351 |
| 352 DCHECK(IsContentsFrom(instant_tab(), contents)); |
| 353 |
| 354 browser_->PasteIntoOmnibox(); |
| 355 } |
| 356 |
368 bool InstantController::extended_enabled() const { | 357 bool InstantController::extended_enabled() const { |
369 return extended_enabled_; | 358 return extended_enabled_; |
370 } | 359 } |
371 | 360 |
372 void InstantController::ResetInstantTab() { | 361 void InstantController::ResetInstantTab() { |
373 if (!search_mode_.is_origin_default()) { | 362 if (!search_mode_.is_origin_default()) { |
374 content::WebContents* active_tab = browser_->GetActiveWebContents(); | 363 content::WebContents* active_tab = browser_->GetActiveWebContents(); |
375 if (!instant_tab_ || active_tab != instant_tab_->contents()) { | 364 if (!instant_tab_ || active_tab != instant_tab_->contents()) { |
376 instant_tab_.reset(new InstantTab(this, browser_->profile())); | 365 instant_tab_.reset(new InstantTab(this, browser_->profile())); |
377 instant_tab_->Init(active_tab); | 366 instant_tab_->Init(active_tab); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 content::PAGE_TRANSITION_SERVER_REDIRECT, | 406 content::PAGE_TRANSITION_SERVER_REDIRECT, |
418 std::string()); // No extra headers. | 407 std::string()); // No extra headers. |
419 // TODO(dcblack): Remove extraneous history entry caused by 404s. | 408 // TODO(dcblack): Remove extraneous history entry caused by 404s. |
420 // Note that the base case of a 204 being returned doesn't push a history | 409 // Note that the base case of a 204 being returned doesn't push a history |
421 // entry. | 410 // entry. |
422 } | 411 } |
423 | 412 |
424 InstantService* InstantController::GetInstantService() const { | 413 InstantService* InstantController::GetInstantService() const { |
425 return InstantServiceFactory::GetForProfile(profile()); | 414 return InstantServiceFactory::GetForProfile(profile()); |
426 } | 415 } |
OLD | NEW |