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

Side by Side Diff: chrome/browser/instant/instant_controller.cc

Issue 11416187: Commit instant loader when the instant page navigates away from instant URL. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixing issue caused due to removal of TabContents. Created 8 years 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/instant/instant_controller.h ('k') | chrome/browser/instant/instant_loader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 // to the page, but otherwise, nothing else to do. 437 // to the page, but otherwise, nothing else to do.
438 if (instant_tab_) { 438 if (instant_tab_) {
439 if (last_match_was_search_ && type == INSTANT_COMMIT_PRESSED_ENTER) { 439 if (last_match_was_search_ && type == INSTANT_COMMIT_PRESSED_ENTER) {
440 instant_tab_->Submit(last_omnibox_text_); 440 instant_tab_->Submit(last_omnibox_text_);
441 instant_tab_->contents()->Focus(); 441 instant_tab_->contents()->Focus();
442 return true; 442 return true;
443 } 443 }
444 return false; 444 return false;
445 } 445 }
446 446
447 if (!IsPreviewingSearchResults()) 447 if (!IsPreviewingSearchResults() && type != INSTANT_COMMIT_NAVIGATED)
448 return false; 448 return false;
449 449
450 if (type == INSTANT_COMMIT_FOCUS_LOST) 450 if (type == INSTANT_COMMIT_FOCUS_LOST)
451 loader_->Cancel(last_omnibox_text_); 451 loader_->Cancel(last_omnibox_text_);
452 else 452 else if (type != INSTANT_COMMIT_NAVIGATED)
453 loader_->Submit(last_omnibox_text_); 453 loader_->Submit(last_omnibox_text_);
454 454
455 content::WebContents* preview = loader_->ReleaseContents(); 455 content::WebContents* preview = loader_->ReleaseContents();
456 456
457 if (extended_enabled_) { 457 if (extended_enabled_) {
458 // Consider what's happening: 458 // Consider what's happening:
459 // 1. The user has typed a query in the omnibox and committed it (either 459 // 1. The user has typed a query in the omnibox and committed it (either
460 // by pressing Enter or clicking on the preview). 460 // by pressing Enter or clicking on the preview).
461 // 2. We commit the preview to the tab strip, and tell the page. 461 // 2. We commit the preview to the tab strip, and tell the page.
462 // 3. The page will update the URL hash fragment with the query terms. 462 // 3. The page will update the URL hash fragment with the query terms.
(...skipping 17 matching lines...) Expand all
480 } 480 }
481 } 481 }
482 482
483 // If the preview page has navigated since the last Update(), we need to add 483 // If the preview page has navigated since the last Update(), we need to add
484 // the navigation to history ourselves. Else, the page will navigate after 484 // the navigation to history ourselves. Else, the page will navigate after
485 // commit, and it will be added to history in the usual manner. 485 // commit, and it will be added to history in the usual manner.
486 const history::HistoryAddPageArgs& last_navigation = 486 const history::HistoryAddPageArgs& last_navigation =
487 loader_->last_navigation(); 487 loader_->last_navigation();
488 if (!last_navigation.url.is_empty()) { 488 if (!last_navigation.url.is_empty()) {
489 content::NavigationEntry* entry = preview->GetController().GetActiveEntry(); 489 content::NavigationEntry* entry = preview->GetController().GetActiveEntry();
490 DCHECK_EQ(last_navigation.url, entry->GetURL()); 490
491 // The last navigation should be the same as the active entry if the loader
492 // is in search mode. During navigation, the active entry could have
493 // changed since DidCommitProvisionalLoadForFrame is called after the entry
494 // is changed.
495 // TODO(shishir): Should we commit the last navigation for
496 // INSTANT_COMMIT_NAVIGATED.
497 DCHECK(type == INSTANT_COMMIT_NAVIGATED ||
498 last_navigation.url == entry->GetURL());
491 499
492 // Add the page to history. 500 // Add the page to history.
493 HistoryTabHelper* history_tab_helper = 501 HistoryTabHelper* history_tab_helper =
494 HistoryTabHelper::FromWebContents(preview); 502 HistoryTabHelper::FromWebContents(preview);
495 history_tab_helper->UpdateHistoryForNavigation(last_navigation); 503 history_tab_helper->UpdateHistoryForNavigation(last_navigation);
496 504
497 // Update the page title. 505 // Update the page title.
498 history_tab_helper->UpdateHistoryPageTitle(*entry); 506 history_tab_helper->UpdateHistoryPageTitle(*entry);
499 } 507 }
500 508
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 793
786 void InstantController::InstantLoaderRenderViewGone() { 794 void InstantController::InstantLoaderRenderViewGone() {
787 ++blacklisted_urls_[loader_->instant_url()]; 795 ++blacklisted_urls_[loader_->instant_url()];
788 HideInternal(); 796 HideInternal();
789 delete loader_->ReleaseContents(); 797 delete loader_->ReleaseContents();
790 // Delay deletion as we have gotten here from an InstantLoader method. 798 // Delay deletion as we have gotten here from an InstantLoader method.
791 MessageLoop::current()->DeleteSoon(FROM_HERE, loader_.release()); 799 MessageLoop::current()->DeleteSoon(FROM_HERE, loader_.release());
792 CreateDefaultLoader(); 800 CreateDefaultLoader();
793 } 801 }
794 802
803 void InstantController::InstantLoaderAboutToNavigateMainFrame(const GURL& url) {
804 GURL instant_url(loader_->instant_url());
805
806 // Don't commit if the URL being navigated to has the same host and path as
807 // the instant URL. This enables the instant page to change the query
808 // parameters and fragments of the URL without it navigating.
809 if (url.host() != instant_url.host() || url.path() != instant_url.path())
810 CommitIfPossible(INSTANT_COMMIT_NAVIGATED);
811 }
812
795 bool InstantController::ResetLoader(const TemplateURL* template_url, 813 bool InstantController::ResetLoader(const TemplateURL* template_url,
796 const content::WebContents* active_tab) { 814 const content::WebContents* active_tab) {
797 std::string instant_url; 815 std::string instant_url;
798 if (!GetInstantURL(template_url, &instant_url)) 816 if (!GetInstantURL(template_url, &instant_url))
799 return false; 817 return false;
800 818
801 if (loader_ && loader_->instant_url() == instant_url) 819 if (loader_ && loader_->instant_url() == instant_url)
802 return true; 820 return true;
803 821
804 HideInternal(); 822 HideInternal();
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW
« no previous file with comments | « chrome/browser/instant/instant_controller.h ('k') | chrome/browser/instant/instant_loader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698