| 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/instant/instant_controller.h" | 5 #include "chrome/browser/instant/instant_controller.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 else | 409 else |
| 410 loader_->UpOrDownKeyPressed(count); | 410 loader_->UpOrDownKeyPressed(count); |
| 411 | 411 |
| 412 return true; | 412 return true; |
| 413 } | 413 } |
| 414 | 414 |
| 415 content::WebContents* InstantController::GetPreviewContents() const { | 415 content::WebContents* InstantController::GetPreviewContents() const { |
| 416 return loader_ ? loader_->contents() : NULL; | 416 return loader_ ? loader_->contents() : NULL; |
| 417 } | 417 } |
| 418 | 418 |
| 419 bool InstantController::IsCurrent() const { | 419 bool InstantController::IsCurrentSearch() const { |
| 420 return model_.mode().is_search_suggestions() && last_match_was_search_; | 420 return model_.mode().is_search_suggestions() && last_match_was_search_; |
| 421 } | 421 } |
| 422 | 422 |
| 423 bool InstantController::CommitIfCurrent(InstantCommitType type) { | 423 bool InstantController::CommitIfCurrent(InstantCommitType type) { |
| 424 if (!extended_enabled_ && !instant_enabled_) | 424 if (!extended_enabled_ && !instant_enabled_) |
| 425 return false; | 425 return false; |
| 426 | 426 |
| 427 DVLOG(1) << "CommitIfCurrent: type=" << type << " last_omnibox_text_='" | 427 DVLOG(1) << "CommitIfCurrent: type=" << type << " last_omnibox_text_='" |
| 428 << last_omnibox_text_ << "' last_match_was_search_=" | 428 << last_omnibox_text_ << "' last_match_was_search_=" |
| 429 << last_match_was_search_ << " instant_tab_=" << instant_tab_; | 429 << last_match_was_search_ << " instant_tab_=" << instant_tab_; |
| 430 | 430 |
| 431 // If we are on an already committed search results page, send a submit event | 431 // If we are on an already committed search results page, send a submit event |
| 432 // to the page, but otherwise, nothing else to do. | 432 // to the page, but otherwise, nothing else to do. |
| 433 if (instant_tab_) { | 433 if (instant_tab_) { |
| 434 if (last_match_was_search_ && type == INSTANT_COMMIT_PRESSED_ENTER) { | 434 if (last_match_was_search_ && type == INSTANT_COMMIT_PRESSED_ENTER) { |
| 435 instant_tab_->Submit(last_omnibox_text_); | 435 instant_tab_->Submit(last_omnibox_text_); |
| 436 return true; | 436 return true; |
| 437 } | 437 } |
| 438 return false; | 438 return false; |
| 439 } | 439 } |
| 440 | 440 |
| 441 if (!IsCurrent()) | 441 if (!IsCurrentSearch() && type != INSTANT_COMMIT_NAVIGATED) |
| 442 return false; | 442 return false; |
| 443 | 443 |
| 444 if (type == INSTANT_COMMIT_FOCUS_LOST) | 444 if (type == INSTANT_COMMIT_FOCUS_LOST) |
| 445 loader_->Cancel(last_omnibox_text_); | 445 loader_->Cancel(last_omnibox_text_); |
| 446 else | 446 else if (type != INSTANT_COMMIT_NAVIGATED) |
| 447 loader_->Submit(last_omnibox_text_); | 447 loader_->Submit(last_omnibox_text_); |
| 448 | 448 |
| 449 content::WebContents* preview = loader_->ReleaseContents(); | 449 content::WebContents* preview = loader_->ReleaseContents(); |
| 450 | 450 |
| 451 if (extended_enabled_) { | 451 if (extended_enabled_) { |
| 452 // Consider what's happening: | 452 // Consider what's happening: |
| 453 // 1. The user has typed a query in the omnibox and committed it (either | 453 // 1. The user has typed a query in the omnibox and committed it (either |
| 454 // by pressing Enter or clicking on the preview). | 454 // by pressing Enter or clicking on the preview). |
| 455 // 2. We commit the preview to the tab strip, and tell the page. | 455 // 2. We commit the preview to the tab strip, and tell the page. |
| 456 // 3. The page will update the URL hash fragment with the query terms. | 456 // 3. The page will update the URL hash fragment with the query terms. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 474 } | 474 } |
| 475 } | 475 } |
| 476 | 476 |
| 477 // If the preview page has navigated since the last Update(), we need to add | 477 // If the preview page has navigated since the last Update(), we need to add |
| 478 // the navigation to history ourselves. Else, the page will navigate after | 478 // the navigation to history ourselves. Else, the page will navigate after |
| 479 // commit, and it will be added to history in the usual manner. | 479 // commit, and it will be added to history in the usual manner. |
| 480 const history::HistoryAddPageArgs& last_navigation = | 480 const history::HistoryAddPageArgs& last_navigation = |
| 481 loader_->last_navigation(); | 481 loader_->last_navigation(); |
| 482 if (!last_navigation.url.is_empty()) { | 482 if (!last_navigation.url.is_empty()) { |
| 483 content::NavigationEntry* entry = preview->GetController().GetActiveEntry(); | 483 content::NavigationEntry* entry = preview->GetController().GetActiveEntry(); |
| 484 DCHECK_EQ(last_navigation.url, entry->GetURL()); | 484 |
| 485 // The last navigation should be the same as the active entry if the loader |
| 486 // is in search mode. During navigation, the active entry could have |
| 487 // changed since DidCommitProvisionalLoadForFrame is called after the entry |
| 488 // is changed. |
| 489 // TODO(shishir): Should we commit the last navigation for |
| 490 // INSTANT_COMMIT_NAVIGATED. |
| 491 DCHECK(type == INSTANT_COMMIT_NAVIGATED || |
| 492 last_navigation.url == entry->GetURL()); |
| 485 | 493 |
| 486 // Add the page to history. | 494 // Add the page to history. |
| 487 HistoryTabHelper* history_tab_helper = | 495 HistoryTabHelper* history_tab_helper = |
| 488 HistoryTabHelper::FromWebContents(preview); | 496 HistoryTabHelper::FromWebContents(preview); |
| 489 history_tab_helper->UpdateHistoryForNavigation(last_navigation); | 497 history_tab_helper->UpdateHistoryForNavigation(last_navigation); |
| 490 | 498 |
| 491 // Update the page title. | 499 // Update the page title. |
| 492 history_tab_helper->UpdateHistoryPageTitle(*entry); | 500 history_tab_helper->UpdateHistoryPageTitle(*entry); |
| 493 } | 501 } |
| 494 | 502 |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 | 791 |
| 784 void InstantController::InstantLoaderRenderViewGone() { | 792 void InstantController::InstantLoaderRenderViewGone() { |
| 785 ++blacklisted_urls_[loader_->instant_url()]; | 793 ++blacklisted_urls_[loader_->instant_url()]; |
| 786 HideInternal(); | 794 HideInternal(); |
| 787 delete loader_->ReleaseContents(); | 795 delete loader_->ReleaseContents(); |
| 788 // Delay deletion as we have gotten here from an InstantLoader method. | 796 // Delay deletion as we have gotten here from an InstantLoader method. |
| 789 MessageLoop::current()->DeleteSoon(FROM_HERE, loader_.release()); | 797 MessageLoop::current()->DeleteSoon(FROM_HERE, loader_.release()); |
| 790 CreateDefaultLoader(); | 798 CreateDefaultLoader(); |
| 791 } | 799 } |
| 792 | 800 |
| 801 void InstantController::InstantLoaderAboutToNavigateMainFrame(const GURL& url) { |
| 802 GURL instant_url(loader_->instant_url()); |
| 803 |
| 804 // Don't commit if the URL being navigated to has the same host and path as |
| 805 // the instant URL. This enables the instant page to change the query |
| 806 // parameters and fragments of the URL without it navigating. |
| 807 if (url.host() != instant_url.host() || url.path() != instant_url.path()) |
| 808 CommitIfCurrent(INSTANT_COMMIT_NAVIGATED); |
| 809 } |
| 810 |
| 793 bool InstantController::ResetLoader(const TemplateURL* template_url, | 811 bool InstantController::ResetLoader(const TemplateURL* template_url, |
| 794 const content::WebContents* active_tab) { | 812 const content::WebContents* active_tab) { |
| 795 std::string instant_url; | 813 std::string instant_url; |
| 796 if (!GetInstantURL(template_url, &instant_url)) | 814 if (!GetInstantURL(template_url, &instant_url)) |
| 797 return false; | 815 return false; |
| 798 | 816 |
| 799 if (loader_ && loader_->instant_url() == instant_url) | 817 if (loader_ && loader_->instant_url() == instant_url) |
| 800 return true; | 818 return true; |
| 801 | 819 |
| 802 HideInternal(); | 820 HideInternal(); |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1030 } | 1048 } |
| 1031 | 1049 |
| 1032 std::map<std::string, int>::const_iterator iter = | 1050 std::map<std::string, int>::const_iterator iter = |
| 1033 blacklisted_urls_.find(*instant_url); | 1051 blacklisted_urls_.find(*instant_url); |
| 1034 if (iter != blacklisted_urls_.end() && | 1052 if (iter != blacklisted_urls_.end() && |
| 1035 iter->second > kMaxInstantSupportFailures) | 1053 iter->second > kMaxInstantSupportFailures) |
| 1036 return false; | 1054 return false; |
| 1037 | 1055 |
| 1038 return true; | 1056 return true; |
| 1039 } | 1057 } |
| OLD | NEW |