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

Side by Side Diff: chrome/browser/ui/search_engines/search_engine_tab_helper.cc

Issue 8983010: Convert WebContents to return a content::NavigationController instead of the implementation. Upda... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix mac Created 8 years, 11 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_engines/search_engine_tab_helper.h" 5 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h"
6 6
7 #include "chrome/browser/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/search_engines/template_url.h" 8 #include "chrome/browser/search_engines/template_url.h"
9 #include "chrome/browser/search_engines/template_url_fetcher.h" 9 #include "chrome/browser/search_engines/template_url_fetcher.h"
10 #include "chrome/browser/search_engines/template_url_service.h" 10 #include "chrome/browser/search_engines/template_url_service.h"
11 #include "chrome/browser/search_engines/template_url_service_factory.h" 11 #include "chrome/browser/search_engines/template_url_service_factory.h"
12 #include "chrome/browser/ui/search_engines/template_url_fetcher_ui_callbacks.h" 12 #include "chrome/browser/ui/search_engines/template_url_fetcher_ui_callbacks.h"
13 #include "chrome/common/render_messages.h" 13 #include "chrome/common/render_messages.h"
14 #include "content/browser/tab_contents/navigation_controller.h"
15 #include "content/public/browser/favicon_status.h" 14 #include "content/public/browser/favicon_status.h"
15 #include "content/public/browser/navigation_controller.h"
16 #include "content/public/browser/navigation_entry.h" 16 #include "content/public/browser/navigation_entry.h"
17 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
18 #include "content/public/common/frame_navigate_params.h" 18 #include "content/public/common/frame_navigate_params.h"
19 19
20 using content::NavigationEntry; 20 using content::NavigationEntry;
21 using content::WebContents; 21 using content::WebContents;
22 22
23 namespace { 23 namespace {
24 24
25 // Returns true if the entry's transition type is FORM_SUBMIT. 25 // Returns true if the entry's transition type is FORM_SUBMIT.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 85
86 case search_provider::EXPLICIT_PROVIDER: 86 case search_provider::EXPLICIT_PROVIDER:
87 provider_type = TemplateURLFetcher::EXPLICIT_PROVIDER; 87 provider_type = TemplateURLFetcher::EXPLICIT_PROVIDER;
88 break; 88 break;
89 89
90 default: 90 default:
91 NOTREACHED(); 91 NOTREACHED();
92 return; 92 return;
93 } 93 }
94 94
95 const NavigationController& controller = web_contents()->GetController(); 95 const content::NavigationController& controller =
96 web_contents()->GetController();
96 const NavigationEntry* entry = controller.GetLastCommittedEntry(); 97 const NavigationEntry* entry = controller.GetLastCommittedEntry();
97 DCHECK(entry); 98 DCHECK(entry);
98 99
99 const NavigationEntry* base_entry = entry; 100 const NavigationEntry* base_entry = entry;
100 if (IsFormSubmit(base_entry)) { 101 if (IsFormSubmit(base_entry)) {
101 // If the current page is a form submit, find the last page that was not 102 // If the current page is a form submit, find the last page that was not
102 // a form submit and use its url to generate the keyword from. 103 // a form submit and use its url to generate the keyword from.
103 int index = controller.GetLastCommittedEntryIndex() - 1; 104 int index = controller.GetLastCommittedEntryIndex() - 1;
104 while (index >= 0 && IsFormSubmit(controller.GetEntryAtIndex(index))) 105 while (index >= 0 && IsFormSubmit(controller.GetEntryAtIndex(index)))
105 index--; 106 index--;
(...skipping 29 matching lines...) Expand all
135 void SearchEngineTabHelper::GenerateKeywordIfNecessary( 136 void SearchEngineTabHelper::GenerateKeywordIfNecessary(
136 const content::FrameNavigateParams& params) { 137 const content::FrameNavigateParams& params) {
137 if (!params.searchable_form_url.is_valid()) 138 if (!params.searchable_form_url.is_valid())
138 return; 139 return;
139 140
140 Profile* profile = 141 Profile* profile =
141 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 142 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
142 if (profile->IsOffTheRecord()) 143 if (profile->IsOffTheRecord())
143 return; 144 return;
144 145
145 const NavigationController& controller = web_contents()->GetController(); 146 const content::NavigationController& controller =
147 web_contents()->GetController();
146 int last_index = controller.GetLastCommittedEntryIndex(); 148 int last_index = controller.GetLastCommittedEntryIndex();
147 // When there was no previous page, the last index will be 0. This is 149 // When there was no previous page, the last index will be 0. This is
148 // normally due to a form submit that opened in a new tab. 150 // normally due to a form submit that opened in a new tab.
149 // TODO(brettw) bug 916126: we should support keywords when form submits 151 // TODO(brettw) bug 916126: we should support keywords when form submits
150 // happen in new tabs. 152 // happen in new tabs.
151 if (last_index <= 0) 153 if (last_index <= 0)
152 return; 154 return;
153 const NavigationEntry* previous_entry = 155 const NavigationEntry* previous_entry =
154 controller.GetEntryAtIndex(last_index - 1); 156 controller.GetEntryAtIndex(last_index - 1);
155 if (IsFormSubmit(previous_entry)) { 157 if (IsFormSubmit(previous_entry)) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 // or the favicon url wasn't obtained before the load started. This assumes 205 // or the favicon url wasn't obtained before the load started. This assumes
204 // the later. 206 // the later.
205 // TODO(sky): Need a way to set the favicon that doesn't involve generating 207 // TODO(sky): Need a way to set the favicon that doesn't involve generating
206 // its url. 208 // its url.
207 new_url->SetFaviconURL( 209 new_url->SetFaviconURL(
208 TemplateURL::GenerateFaviconURL(params.referrer.url)); 210 TemplateURL::GenerateFaviconURL(params.referrer.url));
209 } 211 }
210 new_url->set_safe_for_autoreplace(true); 212 new_url->set_safe_for_autoreplace(true);
211 url_service->Add(new_url); 213 url_service->Add(new_url);
212 } 214 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698