OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/omnibox/omnibox_edit_model.h" | 9 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
10 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 10 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 registrar_.Add( | 41 registrar_.Add( |
42 this, | 42 this, |
43 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 43 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
44 content::Source<content::NavigationController>( | 44 content::Source<content::NavigationController>( |
45 &contents->web_contents()->GetController())); | 45 &contents->web_contents()->GetController())); |
46 } | 46 } |
47 | 47 |
48 SearchTabHelper::~SearchTabHelper() { | 48 SearchTabHelper::~SearchTabHelper() { |
49 } | 49 } |
50 | 50 |
51 void SearchTabHelper::OmniboxEditModelChanged(OmniboxEditModel* edit_model) { | 51 void SearchTabHelper::OmniboxEditModelChanged(bool user_input_in_progress, |
| 52 bool cancelling) { |
52 if (!is_search_enabled_) | 53 if (!is_search_enabled_) |
53 return; | 54 return; |
54 | 55 |
55 if (model_.mode().is_ntp()) { | 56 if (user_input_in_progress) |
56 if (edit_model->user_input_in_progress()) | 57 model_.SetMode(Mode(Mode::MODE_SEARCH_SUGGESTIONS, true)); |
57 model_.SetMode(Mode(Mode::MODE_SEARCH, true)); | 58 else if (cancelling) |
58 return; | 59 UpdateModelBasedOnURL(web_contents()->GetURL(), true); |
59 } | |
60 | |
61 Mode::Type mode = Mode::MODE_DEFAULT; | |
62 GURL url(web_contents()->GetURL()); | |
63 // TODO(kuan): revisit this condition when zero suggest becomes available. | |
64 if (google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec()) || | |
65 (edit_model->has_focus() && edit_model->user_input_in_progress())) { | |
66 mode = Mode::MODE_SEARCH; | |
67 } | |
68 model_.SetMode(Mode(mode, true)); | |
69 } | 60 } |
70 | 61 |
71 void SearchTabHelper::NavigateToPendingEntry( | 62 void SearchTabHelper::NavigateToPendingEntry( |
72 const GURL& url, | 63 const GURL& url, |
73 content::NavigationController::ReloadType reload_type) { | 64 content::NavigationController::ReloadType reload_type) { |
74 if (!is_search_enabled_) | 65 if (!is_search_enabled_) |
75 return; | 66 return; |
76 | 67 |
77 // Do not animate if this url is the very first navigation for the tab. | 68 // Do not animate if this url is the very first navigation for the tab. |
78 UpdateModel(url, !web_contents()->GetController().IsInitialNavigation()); | 69 // NTP mode changes are initiated at "pending", all others are initiated |
| 70 // when "committed". This is because NTP is rendered natively so is faster |
| 71 // to render than the web contents and we need to coordinate the animations. |
| 72 if (IsNTP(url)) { |
| 73 UpdateModelBasedOnURL( |
| 74 url, |
| 75 !web_contents()->GetController().IsInitialNavigation()); |
| 76 } |
79 } | 77 } |
80 | 78 |
81 void SearchTabHelper::Observe( | 79 void SearchTabHelper::Observe( |
82 int type, | 80 int type, |
83 const content::NotificationSource& source, | 81 const content::NotificationSource& source, |
84 const content::NotificationDetails& details) { | 82 const content::NotificationDetails& details) { |
85 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type); | 83 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type); |
86 content::LoadCommittedDetails* committed_details = | 84 content::LoadCommittedDetails* committed_details = |
87 content::Details<content::LoadCommittedDetails>(details).ptr(); | 85 content::Details<content::LoadCommittedDetails>(details).ptr(); |
88 // TODO(dhollowa): NavigationController::IsInitialNavigation() is always false | 86 |
89 // by the time NOTIFICATION_NAV_ENTRY_COMMITTED is received, so please handle | 87 // TODO(dhollowa): Fix |NavigationController::IsInitialNavigation()| so that |
90 // it appropriately when restructuring NavigateToPendingEntry() and this | 88 // it spans the |NOTIFICATION_NAV_ENTRY_COMMITTED| notification. |
91 // methods. | 89 // See comment in |NavigateToPendingEntry()| about why |!IsNTP()| is used. |
92 UpdateModel(committed_details->entry->GetURL(), | 90 if (!IsNTP(committed_details->entry->GetURL())) { |
93 !web_contents()->GetController().IsInitialNavigation()); | 91 UpdateModelBasedOnURL( |
| 92 committed_details->entry->GetURL(), |
| 93 !web_contents()->GetController().IsInitialNavigation()); |
| 94 } |
94 } | 95 } |
95 | 96 |
96 void SearchTabHelper::UpdateModel(const GURL& url, bool animate) { | 97 void SearchTabHelper::UpdateModelBasedOnURL(const GURL& url, bool animate) { |
97 Mode::Type type = Mode::MODE_DEFAULT; | 98 Mode::Type type = Mode::MODE_DEFAULT; |
98 if (IsNTP(url)) | 99 if (IsNTP(url)) |
99 type = Mode::MODE_NTP; | 100 type = Mode::MODE_NTP; |
100 else if (google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec())) | 101 else if (google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec())) |
101 type = Mode::MODE_SEARCH; | 102 type = Mode::MODE_SEARCH_RESULTS; |
102 model_.SetMode(Mode(type, animate)); | 103 model_.SetMode(Mode(type, animate)); |
103 } | 104 } |
104 | 105 |
| 106 content::WebContents* SearchTabHelper::web_contents() { |
| 107 return model_.tab_contents()->web_contents(); |
| 108 } |
| 109 |
105 } // namespace search | 110 } // namespace search |
106 } // namespace chrome | 111 } // namespace chrome |
OLD | NEW |