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

Unified Diff: chrome/browser/ui/search/instant_controller.cc

Issue 12851023: Refactor omnibox focus API into a single method. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 8 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
« no previous file with comments | « chrome/browser/ui/search/instant_controller.h ('k') | chrome/browser/ui/search/instant_page.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/search/instant_controller.cc
diff --git a/chrome/browser/ui/search/instant_controller.cc b/chrome/browser/ui/search/instant_controller.cc
index e02831bd7e542f615c88f55b7af387b4503f9a73..31dc8081233980dc2ef6022f91ad83ed90bfb106 100644
--- a/chrome/browser/ui/search/instant_controller.cc
+++ b/chrome/browser/ui/search/instant_controller.cc
@@ -1169,31 +1169,32 @@ void InstantController::ShowInstantOverlay(const content::WebContents* contents,
ShowOverlay(height, units);
}
-void InstantController::FocusOmnibox(const content::WebContents* contents) {
+void InstantController::FocusOmnibox(const content::WebContents* contents,
+ OmniboxFocusState state) {
if (!extended_enabled_)
return;
DCHECK(IsContentsFrom(instant_tab(), contents));
- browser_->FocusOmnibox(true);
-}
-
-void InstantController::StartCapturingKeyStrokes(
- const content::WebContents* contents) {
- if (!extended_enabled_)
- return;
-
- DCHECK(IsContentsFrom(instant_tab(), contents));
- browser_->FocusOmnibox(false);
-}
-
-void InstantController::StopCapturingKeyStrokes(
- content::WebContents* contents) {
- // Nothing to do if omnibox doesn't have invisible focus.
- if (!extended_enabled_ || omnibox_focus_state_ != OMNIBOX_FOCUS_INVISIBLE)
- return;
- DCHECK(IsContentsFrom(instant_tab(), contents));
- contents->GetView()->Focus();
+ // 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:
+ browser_->FocusOmnibox(true);
+ break;
+ case OMNIBOX_FOCUS_INVISIBLE:
+ browser_->FocusOmnibox(false);
+ break;
+ case OMNIBOX_FOCUS_NONE:
+ if (omnibox_focus_state_ != OMNIBOX_FOCUS_INVISIBLE)
+ contents->GetView()->Focus();
+ break;
+ }
}
void InstantController::NavigateToURL(const content::WebContents* contents,
« no previous file with comments | « chrome/browser/ui/search/instant_controller.h ('k') | chrome/browser/ui/search/instant_page.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698