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/search_tab_helper.h" | 5 #include "chrome/browser/ui/search/search_tab_helper.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 return; | 391 return; |
392 | 392 |
393 if (!history::MostVisitedTilesExperiment::IsDontShowOpenURLsEnabled()) | 393 if (!history::MostVisitedTilesExperiment::IsDontShowOpenURLsEnabled()) |
394 return; | 394 return; |
395 | 395 |
396 history::MostVisitedTilesExperiment::RemoveItemsMatchingOpenTabs( | 396 history::MostVisitedTilesExperiment::RemoveItemsMatchingOpenTabs( |
397 delegate_->GetOpenUrls(), items); | 397 delegate_->GetOpenUrls(), items); |
398 } | 398 } |
399 | 399 |
400 void SearchTabHelper::FocusOmnibox(OmniboxFocusState state) { | 400 void SearchTabHelper::FocusOmnibox(OmniboxFocusState state) { |
| 401 // TODO(kmadhusu): Move platform specific code from here and get rid of #ifdef. |
| 402 #if !defined(OS_ANDROID) |
401 OmniboxView* omnibox = GetOmniboxView(); | 403 OmniboxView* omnibox = GetOmniboxView(); |
402 if (!omnibox) | 404 if (!omnibox) |
403 return; | 405 return; |
404 | 406 |
405 // Do not add a default case in the switch block for the following reasons: | 407 // Do not add a default case in the switch block for the following reasons: |
406 // (1) Explicitly handle the new states. If new states are added in the | 408 // (1) Explicitly handle the new states. If new states are added in the |
407 // OmniboxFocusState, the compiler will warn the developer to handle the new | 409 // OmniboxFocusState, the compiler will warn the developer to handle the new |
408 // states. | 410 // states. |
409 // (2) An attacker may control the renderer and sends the browser process a | 411 // (2) An attacker may control the renderer and sends the browser process a |
410 // malformed IPC. This function responds to the invalid |state| values by | 412 // malformed IPC. This function responds to the invalid |state| values by |
(...skipping 15 matching lines...) Expand all Loading... |
426 omnibox->ShowImeIfNeeded(); | 428 omnibox->ShowImeIfNeeded(); |
427 break; | 429 break; |
428 case OMNIBOX_FOCUS_NONE: | 430 case OMNIBOX_FOCUS_NONE: |
429 // Remove focus only if the popup is closed. This will prevent someone | 431 // Remove focus only if the popup is closed. This will prevent someone |
430 // from changing the omnibox value and closing the popup without user | 432 // from changing the omnibox value and closing the popup without user |
431 // interaction. | 433 // interaction. |
432 if (!omnibox->model()->popup_model()->IsOpen()) | 434 if (!omnibox->model()->popup_model()->IsOpen()) |
433 web_contents()->GetView()->Focus(); | 435 web_contents()->GetView()->Focus(); |
434 break; | 436 break; |
435 } | 437 } |
| 438 #endif |
436 } | 439 } |
437 | 440 |
438 void SearchTabHelper::NavigateToURL(const GURL& url, | 441 void SearchTabHelper::NavigateToURL(const GURL& url, |
439 WindowOpenDisposition disposition, | 442 WindowOpenDisposition disposition, |
440 bool is_most_visited_item_url) { | 443 bool is_most_visited_item_url) { |
441 if (is_most_visited_item_url) { | 444 if (is_most_visited_item_url) { |
442 content::RecordAction( | 445 content::RecordAction( |
443 base::UserMetricsAction("InstantExtended.MostVisitedClicked")); | 446 base::UserMetricsAction("InstantExtended.MostVisitedClicked")); |
444 } | 447 } |
445 | 448 |
(...skipping 29 matching lines...) Expand all Loading... |
475 web_contents())->LogMostVisitedImpression(position, provider); | 478 web_contents())->LogMostVisitedImpression(position, provider); |
476 } | 479 } |
477 | 480 |
478 void SearchTabHelper::OnLogMostVisitedNavigation( | 481 void SearchTabHelper::OnLogMostVisitedNavigation( |
479 int position, const base::string16& provider) { | 482 int position, const base::string16& provider) { |
480 NTPUserDataLogger::GetOrCreateFromWebContents( | 483 NTPUserDataLogger::GetOrCreateFromWebContents( |
481 web_contents())->LogMostVisitedNavigation(position, provider); | 484 web_contents())->LogMostVisitedNavigation(position, provider); |
482 } | 485 } |
483 | 486 |
484 void SearchTabHelper::PasteIntoOmnibox(const base::string16& text) { | 487 void SearchTabHelper::PasteIntoOmnibox(const base::string16& text) { |
| 488 // TODO(kmadhusu): Move platform specific code from here and get rid of #ifdef. |
| 489 #if !defined(OS_ANDROID) |
485 OmniboxView* omnibox = GetOmniboxView(); | 490 OmniboxView* omnibox = GetOmniboxView(); |
486 if (!omnibox) | 491 if (!omnibox) |
487 return; | 492 return; |
488 | |
489 // The first case is for right click to paste, where the text is retrieved | 493 // The first case is for right click to paste, where the text is retrieved |
490 // from the clipboard already sanitized. The second case is needed to handle | 494 // from the clipboard already sanitized. The second case is needed to handle |
491 // drag-and-drop value and it has to be sanitazed before setting it into the | 495 // drag-and-drop value and it has to be sanitazed before setting it into the |
492 // omnibox. | 496 // omnibox. |
493 base::string16 text_to_paste = text.empty() ? omnibox->GetClipboardText() : | 497 base::string16 text_to_paste = text.empty() ? omnibox->GetClipboardText() : |
494 omnibox->SanitizeTextForPaste(text); | 498 omnibox->SanitizeTextForPaste(text); |
495 | 499 |
496 if (text_to_paste.empty()) | 500 if (text_to_paste.empty()) |
497 return; | 501 return; |
498 | 502 |
499 if (!omnibox->model()->has_focus()) | 503 if (!omnibox->model()->has_focus()) |
500 omnibox->SetFocus(); | 504 omnibox->SetFocus(); |
501 | 505 |
502 omnibox->OnBeforePossibleChange(); | 506 omnibox->OnBeforePossibleChange(); |
503 omnibox->model()->OnPaste(); | 507 omnibox->model()->OnPaste(); |
504 omnibox->SetUserText(text_to_paste); | 508 omnibox->SetUserText(text_to_paste); |
505 omnibox->OnAfterPossibleChange(); | 509 omnibox->OnAfterPossibleChange(); |
| 510 #endif |
506 } | 511 } |
507 | 512 |
508 void SearchTabHelper::OnChromeIdentityCheck(const base::string16& identity) { | 513 void SearchTabHelper::OnChromeIdentityCheck(const base::string16& identity) { |
509 SigninManagerBase* manager = SigninManagerFactory::GetForProfile(profile()); | 514 SigninManagerBase* manager = SigninManagerFactory::GetForProfile(profile()); |
510 if (manager) { | 515 if (manager) { |
511 const base::string16 username = | 516 const base::string16 username = |
512 base::UTF8ToUTF16(manager->GetAuthenticatedUsername()); | 517 base::UTF8ToUTF16(manager->GetAuthenticatedUsername()); |
513 ipc_router_.SendChromeIdentityCheckResult(identity, | 518 ipc_router_.SendChromeIdentityCheckResult(identity, |
514 identity == username); | 519 identity == username); |
515 } | 520 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 | 576 |
572 bool SearchTabHelper::IsInputInProgress() const { | 577 bool SearchTabHelper::IsInputInProgress() const { |
573 OmniboxView* omnibox = GetOmniboxView(); | 578 OmniboxView* omnibox = GetOmniboxView(); |
574 return !model_.mode().is_ntp() && omnibox && | 579 return !model_.mode().is_ntp() && omnibox && |
575 omnibox->model()->focus_state() == OMNIBOX_FOCUS_VISIBLE; | 580 omnibox->model()->focus_state() == OMNIBOX_FOCUS_VISIBLE; |
576 } | 581 } |
577 | 582 |
578 OmniboxView* SearchTabHelper::GetOmniboxView() const { | 583 OmniboxView* SearchTabHelper::GetOmniboxView() const { |
579 return delegate_ ? delegate_->GetOmniboxView() : NULL; | 584 return delegate_ ? delegate_->GetOmniboxView() : NULL; |
580 } | 585 } |
OLD | NEW |