Chromium Code Reviews| 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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 switch (state) { | 329 switch (state) { |
| 330 case OMNIBOX_FOCUS_VISIBLE: | 330 case OMNIBOX_FOCUS_VISIBLE: |
| 331 // TODO(samarth): re-enable this once setValue() correctly handles | 331 // TODO(samarth): re-enable this once setValue() correctly handles |
| 332 // URL-shaped queries. | 332 // URL-shaped queries. |
| 333 // browser_->FocusOmnibox(true); | 333 // browser_->FocusOmnibox(true); |
| 334 break; | 334 break; |
| 335 case OMNIBOX_FOCUS_INVISIBLE: | 335 case OMNIBOX_FOCUS_INVISIBLE: |
| 336 browser_->FocusOmnibox(false); | 336 browser_->FocusOmnibox(false); |
| 337 break; | 337 break; |
| 338 case OMNIBOX_FOCUS_NONE: | 338 case OMNIBOX_FOCUS_NONE: |
| 339 contents->GetView()->Focus(); | 339 contents->GetView()->Focus(); |
|
samarth
2013/07/26 22:51:41
As we discussed before, this is troublesome becaus
jfweitz
2013/07/29 18:48:25
Done.
| |
| 340 break; | 340 break; |
| 341 } | 341 } |
| 342 } | 342 } |
| 343 | 343 |
| 344 void InstantController::NavigateToURL(const content::WebContents* contents, | 344 void InstantController::NavigateToURL(const content::WebContents* contents, |
| 345 const GURL& url, | 345 const GURL& url, |
| 346 content::PageTransition transition, | 346 content::PageTransition transition, |
| 347 WindowOpenDisposition disposition, | 347 WindowOpenDisposition disposition, |
| 348 bool is_search_type) { | 348 bool is_search_type) { |
| 349 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( | 349 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( |
| 350 "NavigateToURL: url='%s'", url.spec().c_str())); | 350 "NavigateToURL: url='%s'", url.spec().c_str())); |
| 351 | 351 |
| 352 // TODO(samarth): handle case where contents are no longer "active" (e.g. user | 352 // TODO(samarth): handle case where contents are no longer "active" (e.g. user |
| 353 // has switched tabs). | 353 // has switched tabs). |
| 354 if (!extended_enabled()) | 354 if (!extended_enabled()) |
| 355 return; | 355 return; |
| 356 | 356 |
| 357 if (transition == content::PAGE_TRANSITION_AUTO_BOOKMARK) { | 357 if (transition == content::PAGE_TRANSITION_AUTO_BOOKMARK) { |
| 358 content::RecordAction( | 358 content::RecordAction( |
| 359 content::UserMetricsAction("InstantExtended.MostVisitedClicked")); | 359 content::UserMetricsAction("InstantExtended.MostVisitedClicked")); |
| 360 } else { | 360 } else { |
| 361 // Exclude navigation by Most Visited click and searches. | 361 // Exclude navigation by Most Visited click and searches. |
| 362 if (!is_search_type) | 362 if (!is_search_type) |
| 363 RecordNavigationHistogram(UsingLocalPage(), true, true); | 363 RecordNavigationHistogram(UsingLocalPage(), true, true); |
| 364 } | 364 } |
| 365 browser_->OpenURL(url, transition, disposition); | 365 browser_->OpenURL(url, transition, disposition); |
| 366 } | 366 } |
| 367 | 367 |
| 368 void InstantController::PasteIntoOmnibox(const content::WebContents* contents) { | |
| 369 if (!extended_enabled() || search_mode_.is_origin_default()) | |
| 370 return; | |
| 371 | |
| 372 DCHECK(IsContentsFrom(instant_tab(), contents)); | |
| 373 | |
| 374 browser_->PasteIntoOmnibox(); | |
| 375 } | |
| 376 | |
| 368 bool InstantController::extended_enabled() const { | 377 bool InstantController::extended_enabled() const { |
| 369 return extended_enabled_; | 378 return extended_enabled_; |
| 370 } | 379 } |
| 371 | 380 |
| 372 void InstantController::ResetInstantTab() { | 381 void InstantController::ResetInstantTab() { |
| 373 if (!search_mode_.is_origin_default()) { | 382 if (!search_mode_.is_origin_default()) { |
| 374 content::WebContents* active_tab = browser_->GetActiveWebContents(); | 383 content::WebContents* active_tab = browser_->GetActiveWebContents(); |
| 375 if (!instant_tab_ || active_tab != instant_tab_->contents()) { | 384 if (!instant_tab_ || active_tab != instant_tab_->contents()) { |
| 376 instant_tab_.reset(new InstantTab(this, browser_->profile())); | 385 instant_tab_.reset(new InstantTab(this, browser_->profile())); |
| 377 instant_tab_->Init(active_tab); | 386 instant_tab_->Init(active_tab); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 417 content::PAGE_TRANSITION_SERVER_REDIRECT, | 426 content::PAGE_TRANSITION_SERVER_REDIRECT, |
| 418 std::string()); // No extra headers. | 427 std::string()); // No extra headers. |
| 419 // TODO(dcblack): Remove extraneous history entry caused by 404s. | 428 // 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 | 429 // Note that the base case of a 204 being returned doesn't push a history |
| 421 // entry. | 430 // entry. |
| 422 } | 431 } |
| 423 | 432 |
| 424 InstantService* InstantController::GetInstantService() const { | 433 InstantService* InstantController::GetInstantService() const { |
| 425 return InstantServiceFactory::GetForProfile(profile()); | 434 return InstantServiceFactory::GetForProfile(profile()); |
| 426 } | 435 } |
| OLD | NEW |