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/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1162 ShowOverlay(100, INSTANT_SIZE_PERCENT); | 1162 ShowOverlay(100, INSTANT_SIZE_PERCENT); |
1163 } | 1163 } |
1164 | 1164 |
1165 void InstantController::ShowInstantOverlay(const content::WebContents* contents, | 1165 void InstantController::ShowInstantOverlay(const content::WebContents* contents, |
1166 int height, | 1166 int height, |
1167 InstantSizeUnits units) { | 1167 InstantSizeUnits units) { |
1168 if (extended_enabled_ && IsContentsFrom(overlay(), contents)) | 1168 if (extended_enabled_ && IsContentsFrom(overlay(), contents)) |
1169 ShowOverlay(height, units); | 1169 ShowOverlay(height, units); |
1170 } | 1170 } |
1171 | 1171 |
1172 void InstantController::FocusOmnibox(const content::WebContents* contents) { | 1172 void InstantController::FocusOmnibox(const content::WebContents* contents, |
| 1173 OmniboxFocusState state) { |
1173 if (!extended_enabled_) | 1174 if (!extended_enabled_) |
1174 return; | 1175 return; |
1175 | 1176 |
1176 DCHECK(IsContentsFrom(instant_tab(), contents)); | 1177 DCHECK(IsContentsFrom(instant_tab(), contents)); |
1177 browser_->FocusOmnibox(true); | |
1178 } | |
1179 | 1178 |
1180 void InstantController::StartCapturingKeyStrokes( | 1179 // Do not add a default case in the switch block for the following reasons: |
1181 const content::WebContents* contents) { | 1180 // (1) Explicitly handle the new states. If new states are added in the |
1182 if (!extended_enabled_) | 1181 // OmniboxFocusState, the compiler will warn the developer to handle the new |
1183 return; | 1182 // states. |
1184 | 1183 // (2) An attacker may control the renderer and sends the browser process a |
1185 DCHECK(IsContentsFrom(instant_tab(), contents)); | 1184 // malformed IPC. This function responds to the invalid |state| values by |
1186 browser_->FocusOmnibox(false); | 1185 // doing nothing instead of crashing the browser process (intentional no-op). |
1187 } | 1186 switch (state) { |
1188 | 1187 case OMNIBOX_FOCUS_VISIBLE: |
1189 void InstantController::StopCapturingKeyStrokes( | 1188 browser_->FocusOmnibox(true); |
1190 content::WebContents* contents) { | 1189 break; |
1191 // Nothing to do if omnibox doesn't have invisible focus. | 1190 case OMNIBOX_FOCUS_INVISIBLE: |
1192 if (!extended_enabled_ || omnibox_focus_state_ != OMNIBOX_FOCUS_INVISIBLE) | 1191 browser_->FocusOmnibox(false); |
1193 return; | 1192 break; |
1194 | 1193 case OMNIBOX_FOCUS_NONE: |
1195 DCHECK(IsContentsFrom(instant_tab(), contents)); | 1194 if (omnibox_focus_state_ != OMNIBOX_FOCUS_INVISIBLE) |
1196 contents->GetView()->Focus(); | 1195 contents->GetView()->Focus(); |
| 1196 break; |
| 1197 } |
1197 } | 1198 } |
1198 | 1199 |
1199 void InstantController::NavigateToURL(const content::WebContents* contents, | 1200 void InstantController::NavigateToURL(const content::WebContents* contents, |
1200 const GURL& url, | 1201 const GURL& url, |
1201 content::PageTransition transition, | 1202 content::PageTransition transition, |
1202 WindowOpenDisposition disposition) { | 1203 WindowOpenDisposition disposition) { |
1203 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( | 1204 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( |
1204 "NavigateToURL: url='%s'", url.spec().c_str())); | 1205 "NavigateToURL: url='%s'", url.spec().c_str())); |
1205 | 1206 |
1206 // TODO(samarth): handle case where contents are no longer "active" (e.g. user | 1207 // TODO(samarth): handle case where contents are no longer "active" (e.g. user |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1610 | 1611 |
1611 // If this is not window startup, switch. | 1612 // If this is not window startup, switch. |
1612 // TODO(shishir): This is not completely reliable. Find a better way to detect | 1613 // TODO(shishir): This is not completely reliable. Find a better way to detect |
1613 // startup time. | 1614 // startup time. |
1614 if (browser_->GetActiveWebContents()) | 1615 if (browser_->GetActiveWebContents()) |
1615 return true; | 1616 return true; |
1616 | 1617 |
1617 return chrome::IsAggressiveLocalNTPFallbackEnabled(); | 1618 return chrome::IsAggressiveLocalNTPFallbackEnabled(); |
1618 } | 1619 } |
1619 | 1620 |
OLD | NEW |