| OLD | NEW |
| 1 // Copyright (c) 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/search_tab_helper.h" | 5 #include "chrome/browser/ui/search/search_tab_helper.h" |
| 6 | 6 |
| 7 #include "chrome/browser/google/google_util.h" | 7 #include "chrome/browser/google/google_util.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/search/search.h" | 9 #include "chrome/browser/ui/search/search.h" |
| 10 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
| 11 #include "content/public/browser/navigation_controller.h" | 11 #include "content/public/browser/navigation_controller.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 namespace chrome { | 35 namespace chrome { |
| 36 namespace search { | 36 namespace search { |
| 37 | 37 |
| 38 SearchTabHelper::SearchTabHelper(content::WebContents* web_contents) | 38 SearchTabHelper::SearchTabHelper(content::WebContents* web_contents) |
| 39 : WebContentsObserver(web_contents), | 39 : WebContentsObserver(web_contents), |
| 40 is_search_enabled_(IsSearchEnabled(web_contents)), | 40 is_search_enabled_(IsSearchEnabled(web_contents)), |
| 41 is_initial_navigation_commit_(true), | 41 is_initial_navigation_commit_(true), |
| 42 user_input_in_progress_(false), |
| 42 model_(web_contents) { | 43 model_(web_contents) { |
| 43 if (!is_search_enabled_) | 44 if (!is_search_enabled_) |
| 44 return; | 45 return; |
| 45 | 46 |
| 46 registrar_.Add( | 47 registrar_.Add( |
| 47 this, | 48 this, |
| 48 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 49 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 49 content::Source<content::NavigationController>( | 50 content::Source<content::NavigationController>( |
| 50 &web_contents->GetController())); | 51 &web_contents->GetController())); |
| 51 } | 52 } |
| 52 | 53 |
| 53 SearchTabHelper::~SearchTabHelper() { | 54 SearchTabHelper::~SearchTabHelper() { |
| 54 } | 55 } |
| 55 | 56 |
| 56 void SearchTabHelper::OmniboxEditModelChanged(bool user_input_in_progress, | 57 void SearchTabHelper::OmniboxEditModelChanged(bool user_input_in_progress, |
| 57 bool cancelling) { | 58 bool cancelling) { |
| 58 if (!is_search_enabled_) | 59 if (!is_search_enabled_) |
| 59 return; | 60 return; |
| 60 | 61 |
| 61 if (user_input_in_progress) { | 62 user_input_in_progress_ = user_input_in_progress; |
| 62 const Mode new_mode = Mode(Mode::MODE_SEARCH_SUGGESTIONS, | 63 if (!user_input_in_progress && !cancelling) |
| 63 model_.mode().origin, true); | 64 return; |
| 64 model_.SetMode(new_mode); | 65 |
| 65 } else if (cancelling) { | 66 UpdateModelBasedOnURL(web_contents()->GetURL(), true); |
| 66 UpdateModelBasedOnURL(web_contents()->GetURL(), true); | |
| 67 } | |
| 68 } | 67 } |
| 69 | 68 |
| 70 void SearchTabHelper::NavigationEntryUpdated() { | 69 void SearchTabHelper::NavigationEntryUpdated() { |
| 71 if (!is_search_enabled_) | 70 if (!is_search_enabled_) |
| 72 return; | 71 return; |
| 73 UpdateModelBasedOnURL(web_contents()->GetURL(), true); | 72 UpdateModelBasedOnURL(web_contents()->GetURL(), true); |
| 74 } | 73 } |
| 75 | 74 |
| 76 void SearchTabHelper::NavigateToPendingEntry( | 75 void SearchTabHelper::NavigateToPendingEntry( |
| 77 const GURL& url, | 76 const GURL& url, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 105 void SearchTabHelper::UpdateModelBasedOnURL(const GURL& url, bool animate) { | 104 void SearchTabHelper::UpdateModelBasedOnURL(const GURL& url, bool animate) { |
| 106 Mode::Type type = Mode::MODE_DEFAULT; | 105 Mode::Type type = Mode::MODE_DEFAULT; |
| 107 Mode::Origin origin = Mode::ORIGIN_DEFAULT; | 106 Mode::Origin origin = Mode::ORIGIN_DEFAULT; |
| 108 if (IsNTP(url)) { | 107 if (IsNTP(url)) { |
| 109 type = Mode::MODE_NTP; | 108 type = Mode::MODE_NTP; |
| 110 origin = Mode::ORIGIN_NTP; | 109 origin = Mode::ORIGIN_NTP; |
| 111 } else if (google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec())) { | 110 } else if (google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec())) { |
| 112 type = Mode::MODE_SEARCH_RESULTS; | 111 type = Mode::MODE_SEARCH_RESULTS; |
| 113 origin = Mode::ORIGIN_SEARCH; | 112 origin = Mode::ORIGIN_SEARCH; |
| 114 } | 113 } |
| 114 if (user_input_in_progress_) |
| 115 type = Mode::MODE_SEARCH_SUGGESTIONS; |
| 115 model_.SetMode(Mode(type, origin, animate)); | 116 model_.SetMode(Mode(type, origin, animate)); |
| 116 } | 117 } |
| 117 | 118 |
| 118 const content::WebContents* SearchTabHelper::web_contents() const { | 119 const content::WebContents* SearchTabHelper::web_contents() const { |
| 119 return model_.web_contents(); | 120 return model_.web_contents(); |
| 120 } | 121 } |
| 121 | 122 |
| 122 } // namespace search | 123 } // namespace search |
| 123 } // namespace chrome | 124 } // namespace chrome |
| OLD | NEW |