Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(432)

Unified Diff: chrome/browser/ui/browser_instant_controller.cc

Issue 20501002: Adds paste function to searchbox api and handles paste event on fakebox (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adds optional text param to paste. Also adds drop behavior to fakebox. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 650da0db6435c40773e5a6802b4245f4f36f8499..58ff2213b062c7c3f06bee781c5428fb75f942a1 100644
--- a/chrome/browser/ui/browser_instant_controller.cc
+++ b/chrome/browser/ui/browser_instant_controller.cc
@@ -18,6 +18,7 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/omnibox/location_bar.h"
+#include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
#include "chrome/browser/ui/omnibox/omnibox_view.h"
#include "chrome/browser/ui/search/instant_ntp.h"
#include "chrome/browser/ui/search/search_model.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,43 @@ void BrowserInstantController::ReplaceWebContentsAt(
index);
}
-void BrowserInstantController::FocusOmnibox(bool caret_visibility) {
+void BrowserInstantController::FocusOmnibox(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()) {
+ content::WebContents* content = GetActiveWebContents();
samarth 2013/08/06 18:39:44 nit: s/content/contents
jfweitz 2013/08/09 02:37:41 Done.
+ if (content) {
samarth 2013/08/06 18:39:44 nit: no braces for single-line condition
jfweitz 2013/08/09 02:37:41 Done.
+ content->GetView()->Focus();
+ }
+ }
+ break;
}
}
@@ -189,6 +216,26 @@ void BrowserInstantController::OpenURL(
false));
}
+void BrowserInstantController::PasteIntoOmnibox(const string16& text) {
+ OmniboxView* omnibox_view = browser_->window()->GetLocationBar()->
+ GetLocationEntry();
+ string16 text_to_paste;
samarth 2013/08/06 18:39:44 nit: simply: string16 text_to_paste = text.empty()
jfweitz 2013/08/09 02:37:41 Done.
+ if (text.empty()) {
+ text_to_paste = omnibox_view->GetClipboardText();
+ } else {
+ text_to_paste = omnibox_view->SanitizeTextForPaste(text);
+ }
+
+ if (!text_to_paste.empty()) {
+ if (!omnibox_view->model()->has_focus())
+ omnibox_view->SetFocus();
+ omnibox_view->OnBeforePossibleChange();
+ omnibox_view->model()->on_paste();
+ omnibox_view->SetUserText(text_to_paste);
+ omnibox_view->OnAfterPossibleChange();
+ }
+}
+
void BrowserInstantController::SetOmniboxBounds(const gfx::Rect& bounds) {
instant_.SetOmniboxBounds(bounds);
}

Powered by Google App Engine
This is Rietveld 408576698