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

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: Minor spelling fix. 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
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 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 (!IsCurrent() && type != INSTANT_COMMIT_NAVIGATED)
samarth 2012/12/07 01:14:34 This goes against the name of this function :) Ho
Shishir 2012/12/07 21:01:25 It seemed better to rename IsCurrent to IsCurrentS
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
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
samarth 2012/12/07 01:14:34 I'm a little confused by this. Is the situation y
Shishir 2012/12/07 21:01:25 Yes its the case you describe.
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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 767
760 void InstantController::InstantLoaderContentsFocused() { 768 void InstantController::InstantLoaderContentsFocused() {
761 #if defined(USE_AURA) 769 #if defined(USE_AURA)
762 // On aura the omnibox only receives a focus lost if we initiate the focus 770 // On aura the omnibox only receives a focus lost if we initiate the focus
763 // change. This does that. 771 // change. This does that.
764 if (!model_.mode().is_default()) 772 if (!model_.mode().is_default())
765 browser_->InstantPreviewFocused(); 773 browser_->InstantPreviewFocused();
766 #endif 774 #endif
767 } 775 }
768 776
777 void InstantController::InstantLoaderAboutToNavigateMainFrame(const GURL& url) {
778 GURL instant_url(loader_->instant_url());
779
780 // Might be navigating to the instant URL.
781 if (url == instant_url)
samarth 2012/12/07 01:14:34 Why is this check necessary given the check below?
Shishir 2012/12/07 21:01:25 Not really necessary, just makes it clear that nav
782 return;
783
784 // Don't commit if the URL being navigated to has the same host and path as
785 // the instant URL. This enables the instant page to change the query
786 // parameters and fragments of the URL without it navigating.
787 if (url.host() != instant_url.host() || url.path() != instant_url.path())
788 CommitIfCurrent(INSTANT_COMMIT_NAVIGATED);
789 }
790
769 bool InstantController::ResetLoader(const TemplateURL* template_url, 791 bool InstantController::ResetLoader(const TemplateURL* template_url,
770 const content::WebContents* active_tab) { 792 const content::WebContents* active_tab) {
771 std::string instant_url; 793 std::string instant_url;
772 if (!GetInstantURL(template_url, &instant_url)) 794 if (!GetInstantURL(template_url, &instant_url))
773 return false; 795 return false;
774 796
775 if (loader_ && loader_->instant_url() == instant_url) 797 if (loader_ && loader_->instant_url() == instant_url)
776 return true; 798 return true;
777 799
778 HideInternal(); 800 HideInternal();
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 } 1027 }
1006 1028
1007 std::map<std::string, int>::const_iterator iter = 1029 std::map<std::string, int>::const_iterator iter =
1008 blacklisted_urls_.find(*instant_url); 1030 blacklisted_urls_.find(*instant_url);
1009 if (iter != blacklisted_urls_.end() && 1031 if (iter != blacklisted_urls_.end() &&
1010 iter->second > kMaxInstantSupportFailures) 1032 iter->second > kMaxInstantSupportFailures)
1011 return false; 1033 return false;
1012 1034
1013 return true; 1035 return true;
1014 } 1036 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698