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/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 DCHECK(IsContentsFrom(instant_tab(), contents)); | 300 DCHECK(IsContentsFrom(instant_tab(), contents)); |
301 | 301 |
302 // The Instant tab navigated. Send it the data it needs to display | 302 // The Instant tab navigated. Send it the data it needs to display |
303 // properly. | 303 // properly. |
304 UpdateInfoForInstantTab(); | 304 UpdateInfoForInstantTab(); |
305 } | 305 } |
306 | 306 |
307 void InstantController::FocusOmnibox(const content::WebContents* contents, | 307 void InstantController::FocusOmnibox(const content::WebContents* contents, |
308 OmniboxFocusState state) { | 308 OmniboxFocusState state) { |
309 DCHECK(IsContentsFrom(instant_tab(), contents)); | 309 DCHECK(IsContentsFrom(instant_tab(), contents)); |
310 | 310 browser_->FocusOmnibox(state); |
311 // Do not add a default case in the switch block for the following reasons: | |
312 // (1) Explicitly handle the new states. If new states are added in the | |
313 // OmniboxFocusState, the compiler will warn the developer to handle the new | |
314 // states. | |
315 // (2) An attacker may control the renderer and sends the browser process a | |
316 // malformed IPC. This function responds to the invalid |state| values by | |
317 // doing nothing instead of crashing the browser process (intentional no-op). | |
318 switch (state) { | |
319 case OMNIBOX_FOCUS_VISIBLE: | |
320 // TODO(samarth): re-enable this once setValue() correctly handles | |
321 // URL-shaped queries. | |
322 // browser_->FocusOmnibox(true); | |
323 break; | |
324 case OMNIBOX_FOCUS_INVISIBLE: | |
325 browser_->FocusOmnibox(false); | |
326 break; | |
327 case OMNIBOX_FOCUS_NONE: | |
328 contents->GetView()->Focus(); | |
329 break; | |
330 } | |
331 } | 311 } |
332 | 312 |
333 void InstantController::NavigateToURL(const content::WebContents* contents, | 313 void InstantController::NavigateToURL(const content::WebContents* contents, |
334 const GURL& url, | 314 const GURL& url, |
335 content::PageTransition transition, | 315 content::PageTransition transition, |
336 WindowOpenDisposition disposition, | 316 WindowOpenDisposition disposition, |
337 bool is_search_type) { | 317 bool is_search_type) { |
338 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( | 318 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( |
339 "NavigateToURL: url='%s'", url.spec().c_str())); | 319 "NavigateToURL: url='%s'", url.spec().c_str())); |
340 | 320 |
341 // TODO(samarth): handle case where contents are no longer "active" (e.g. user | 321 // TODO(samarth): handle case where contents are no longer "active" (e.g. user |
342 // has switched tabs). | 322 // has switched tabs). |
343 if (transition == content::PAGE_TRANSITION_AUTO_BOOKMARK) { | 323 if (transition == content::PAGE_TRANSITION_AUTO_BOOKMARK) { |
344 content::RecordAction( | 324 content::RecordAction( |
345 content::UserMetricsAction("InstantExtended.MostVisitedClicked")); | 325 content::UserMetricsAction("InstantExtended.MostVisitedClicked")); |
346 } else { | 326 } else { |
347 // Exclude navigation by Most Visited click and searches. | 327 // Exclude navigation by Most Visited click and searches. |
348 if (!is_search_type) | 328 if (!is_search_type) |
349 RecordNavigationHistogram(UsingLocalPage(), true, true); | 329 RecordNavigationHistogram(UsingLocalPage(), true, true); |
350 } | 330 } |
351 browser_->OpenURL(url, transition, disposition); | 331 browser_->OpenURL(url, transition, disposition); |
352 } | 332 } |
353 | 333 |
| 334 void InstantController::PasteIntoOmnibox(const content::WebContents* contents, |
| 335 const string16& text) { |
| 336 if (search_mode_.is_origin_default()) |
| 337 return; |
| 338 |
| 339 DCHECK(IsContentsFrom(instant_tab(), contents)); |
| 340 |
| 341 browser_->PasteIntoOmnibox(text); |
| 342 } |
| 343 |
354 void InstantController::ResetInstantTab() { | 344 void InstantController::ResetInstantTab() { |
355 if (!search_mode_.is_origin_default()) { | 345 if (!search_mode_.is_origin_default()) { |
356 content::WebContents* active_tab = browser_->GetActiveWebContents(); | 346 content::WebContents* active_tab = browser_->GetActiveWebContents(); |
357 if (!instant_tab_ || active_tab != instant_tab_->contents()) { | 347 if (!instant_tab_ || active_tab != instant_tab_->contents()) { |
358 instant_tab_.reset(new InstantTab(this, browser_->profile())); | 348 instant_tab_.reset(new InstantTab(this, browser_->profile())); |
359 instant_tab_->Init(active_tab); | 349 instant_tab_->Init(active_tab); |
360 UpdateInfoForInstantTab(); | 350 UpdateInfoForInstantTab(); |
361 } | 351 } |
362 } else { | 352 } else { |
363 instant_tab_.reset(); | 353 instant_tab_.reset(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 content::PAGE_TRANSITION_SERVER_REDIRECT, | 389 content::PAGE_TRANSITION_SERVER_REDIRECT, |
400 std::string()); // No extra headers. | 390 std::string()); // No extra headers. |
401 // TODO(dcblack): Remove extraneous history entry caused by 404s. | 391 // TODO(dcblack): Remove extraneous history entry caused by 404s. |
402 // Note that the base case of a 204 being returned doesn't push a history | 392 // Note that the base case of a 204 being returned doesn't push a history |
403 // entry. | 393 // entry. |
404 } | 394 } |
405 | 395 |
406 InstantService* InstantController::GetInstantService() const { | 396 InstantService* InstantController::GetInstantService() const { |
407 return InstantServiceFactory::GetForProfile(profile()); | 397 return InstantServiceFactory::GetForProfile(profile()); |
408 } | 398 } |
OLD | NEW |