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

Side by Side Diff: chrome/browser/ui/search/search_tab_helper.cc

Issue 10832216: Clicks broken in NTP section of Search overlay (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months 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 | Annotate | Revision Log
OLDNEW
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
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 content::WebContents* SearchTabHelper::GetNTPWebContents() {
52 if (!ntp_web_contents_.get()) {
53 ntp_web_contents_.reset(content::WebContents::Create(
54 model_.tab_contents()->profile(),
55 model_.tab_contents()->web_contents()->GetSiteInstance(),
56 MSG_ROUTING_NONE,
57 NULL,
58 NULL));
59 ntp_web_contents_->GetController().LoadURL(
60 GURL(chrome::kChromeUINewTabURL),
61 content::Referrer(),
62 content::PAGE_TRANSITION_START_PAGE,
63 std::string());
64 }
65 return ntp_web_contents_.get();
66 }
67
68 void SearchTabHelper::OmniboxEditModelChanged(OmniboxEditModel* edit_model) { 51 void SearchTabHelper::OmniboxEditModelChanged(OmniboxEditModel* edit_model) {
69 if (!is_search_enabled_) 52 if (!is_search_enabled_)
70 return; 53 return;
71 54
72 if (model_.mode().is_ntp()) { 55 if (model_.mode().is_ntp()) {
73 if (edit_model->user_input_in_progress()) 56 if (edit_model->user_input_in_progress())
74 model_.SetMode(Mode(Mode::MODE_SEARCH, true)); 57 model_.SetMode(Mode(Mode::MODE_SEARCH, true));
75 return; 58 return;
76 } 59 }
77 60
78 Mode::Type mode = Mode::MODE_DEFAULT; 61 Mode::Type mode = Mode::MODE_DEFAULT;
79 GURL url(web_contents()->GetURL()); 62 GURL url(web_contents()->GetURL());
80 // TODO(kuan): revisit this condition when zero suggest becomes available. 63 // TODO(kuan): revisit this condition when zero suggest becomes available.
81 if (google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec()) || 64 if (google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec()) ||
82 (edit_model->has_focus() && edit_model->user_input_in_progress())) { 65 (edit_model->has_focus() && edit_model->user_input_in_progress())) {
83 mode = Mode::MODE_SEARCH; 66 mode = Mode::MODE_SEARCH;
84 } 67 }
85 model_.SetMode(Mode(mode, true)); 68 model_.SetMode(Mode(mode, true));
86 } 69 }
87 70
88 void SearchTabHelper::NavigateToPendingEntry( 71 void SearchTabHelper::NavigateToPendingEntry(
89 const GURL& url, 72 const GURL& url,
90 content::NavigationController::ReloadType reload_type) { 73 content::NavigationController::ReloadType reload_type) {
91 if (!is_search_enabled_) 74 if (!is_search_enabled_)
92 return; 75 return;
93 76
94 UpdateModel(url); 77 UpdateModel(url);
95 FlushNTP(url);
96 } 78 }
97 79
98 void SearchTabHelper::Observe( 80 void SearchTabHelper::Observe(
99 int type, 81 int type,
100 const content::NotificationSource& source, 82 const content::NotificationSource& source,
101 const content::NotificationDetails& details) { 83 const content::NotificationDetails& details) {
102 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type); 84 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type);
103 content::LoadCommittedDetails* committed_details = 85 content::LoadCommittedDetails* committed_details =
104 content::Details<content::LoadCommittedDetails>(details).ptr(); 86 content::Details<content::LoadCommittedDetails>(details).ptr();
105 UpdateModel(committed_details->entry->GetURL()); 87 UpdateModel(committed_details->entry->GetURL());
106 FlushNTP(committed_details->entry->GetURL());
107 } 88 }
108 89
109 void SearchTabHelper::UpdateModel(const GURL& url) { 90 void SearchTabHelper::UpdateModel(const GURL& url) {
110 Mode::Type type = Mode::MODE_DEFAULT; 91 Mode::Type type = Mode::MODE_DEFAULT;
111 if (IsNTP(url)) 92 if (IsNTP(url))
112 type = Mode::MODE_NTP; 93 type = Mode::MODE_NTP;
113 else if (google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec())) 94 else if (google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec()))
114 type = Mode::MODE_SEARCH; 95 type = Mode::MODE_SEARCH;
115 model_.SetMode(Mode(type, true)); 96 model_.SetMode(Mode(type, true));
116 } 97 }
117 98
118 void SearchTabHelper::FlushNTP(const GURL& url) {
119 if (!IsNTP(url) &&
120 !google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec())) {
121 ntp_web_contents_.reset();
122 }
123 }
124
125 } // namespace search 99 } // namespace search
126 } // namespace chrome 100 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698