Chromium Code Reviews| Index: chrome/browser/ui/browser_instant_controller.cc |
| diff --git a/chrome/browser/ui/browser_instant_controller.cc b/chrome/browser/ui/browser_instant_controller.cc |
| index c36cad8f18c4a95cdad1b152c92d0a5434947b9f..30799edaddec30d3b487bdffd2ecfd1528b92c36 100644 |
| --- a/chrome/browser/ui/browser_instant_controller.cc |
| +++ b/chrome/browser/ui/browser_instant_controller.cc |
| @@ -19,6 +19,7 @@ |
| #include "chrome/browser/ui/browser_window.h" |
| #include "chrome/browser/ui/omnibox/location_bar.h" |
| #include "chrome/browser/ui/omnibox/omnibox_view.h" |
| +#include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
| #include "chrome/browser/ui/search/instant_ntp.h" |
| #include "chrome/browser/ui/search/search_model.h" |
| #include "chrome/browser/ui/search/search_tab_helper.h" |
| @@ -30,6 +31,7 @@ |
| #include "content/public/browser/render_process_host.h" |
| #include "content/public/browser/user_metrics.h" |
| #include "content/public/browser/web_contents.h" |
| +#include "content/public/browser/web_contents_view.h" |
| using content::UserMetricsAction; |
| @@ -151,18 +153,41 @@ void BrowserInstantController::ReplaceWebContentsAt( |
| index); |
| } |
| -void BrowserInstantController::FocusOmnibox(bool caret_visibility) { |
| +void BrowserInstantController::FocusOmnibox( |
| + const content::WebContents* contents, |
| + OmniboxFocusState state) { |
| OmniboxView* omnibox_view = browser_->window()->GetLocationBar()-> |
| GetLocationEntry(); |
| - omnibox_view->SetFocus(); |
| - omnibox_view->model()->SetCaretVisibility(caret_visibility); |
| - if (!caret_visibility) { |
| - // If the user clicked on the fakebox, any text already in the omnibox |
| - // should get cleared when they start typing. Selecting all the existing |
| - // text is a convenient way to accomplish this. It also gives a slight |
| - // visual cue to users who really understand selection state about what will |
| - // happen if they start typing. |
| - omnibox_view->SelectAll(false); |
| + |
| + // Do not add a default case in the switch block for the following reasons: |
| + // (1) Explicitly handle the new states. If new states are added in the |
| + // OmniboxFocusState, the compiler will warn the developer to handle the new |
| + // states. |
| + // (2) An attacker may control the renderer and sends the browser process a |
| + // malformed IPC. This function responds to the invalid |state| values by |
| + // doing nothing instead of crashing the browser process (intentional no-op). |
| + switch (state) { |
| + case OMNIBOX_FOCUS_VISIBLE: |
| + omnibox_view->SetFocus(); |
| + omnibox_view->model()->SetCaretVisibility(true); |
| + break; |
| + case OMNIBOX_FOCUS_INVISIBLE: |
| + omnibox_view->SetFocus(); |
| + omnibox_view->model()->SetCaretVisibility(false); |
| + // If the user clicked on the fakebox, any text already in the omnibox |
| + // should get cleared when they start typing. Selecting all the existing |
| + // text is a convenient way to accomplish this. It also gives a slight |
| + // visual cue to users who really understand selection state about what |
| + // will happen if they start typing. |
| + omnibox_view->SelectAll(false); |
| + break; |
| + case OMNIBOX_FOCUS_NONE: |
| + // Remove focus only if the popup is closed. This will prevent someone |
| + // from changing the omnibox value and closing the popup without user |
| + // interaction. |
| + if (!omnibox_view->model()->popup_model()->IsOpen()) |
| + contents->GetView()->Focus(); |
|
samarth
2013/07/31 01:44:37
Instead of passing in |contents| here you can get
jfweitz
2013/08/03 00:02:00
Done.
|
| + break; |
| } |
| } |
| @@ -189,6 +214,21 @@ void BrowserInstantController::OpenURL( |
| false)); |
| } |
| +void BrowserInstantController::PasteIntoOmnibox() { |
| + OmniboxView* omnibox_view = browser_->window()->GetLocationBar()-> |
| + GetLocationEntry(); |
| + string16 clipboardText = omnibox_view->GetClipboardText(); |
| + |
| + if (!clipboardText.empty()) { |
| + if (!omnibox_view->model()->has_focus()) |
| + omnibox_view->SetFocus(); |
| + omnibox_view->OnBeforePossibleChange(); |
| + omnibox_view->SetUserText(clipboardText); |
| + omnibox_view->model()->on_paste(); |
|
samarth
2013/07/31 01:44:37
This needs to be called before you SetUserText.
jfweitz
2013/08/03 00:02:00
Done.
|
| + omnibox_view->OnAfterPossibleChange(); |
| + } |
| +} |
| + |
| void BrowserInstantController::SetOmniboxBounds(const gfx::Rect& bounds) { |
| instant_.SetOmniboxBounds(bounds); |
| } |