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

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

Issue 371333003: No content dependencies in TemplateURLFetcher (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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_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_fetcher.h" 8 #include "chrome/browser/search_engines/template_url_fetcher.h"
9 #include "chrome/browser/search_engines/template_url_fetcher_factory.h" 9 #include "chrome/browser/search_engines/template_url_fetcher_factory.h"
10 #include "chrome/browser/search_engines/template_url_service_factory.h" 10 #include "chrome/browser/search_engines/template_url_service_factory.h"
11 #include "chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h" 11 #include "chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h"
12 #include "chrome/common/render_messages.h" 12 #include "chrome/common/render_messages.h"
13 #include "chrome/common/url_constants.h" 13 #include "chrome/common/url_constants.h"
14 #include "components/search_engines/template_url.h" 14 #include "components/search_engines/template_url.h"
15 #include "components/search_engines/template_url_service.h" 15 #include "components/search_engines/template_url_service.h"
16 #include "content/public/browser/favicon_status.h" 16 #include "content/public/browser/favicon_status.h"
17 #include "content/public/browser/navigation_controller.h" 17 #include "content/public/browser/navigation_controller.h"
18 #include "content/public/browser/navigation_entry.h" 18 #include "content/public/browser/navigation_entry.h"
19 #include "content/public/browser/render_frame_host.h"
20 #include "content/public/browser/render_process_host.h"
19 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
20 #include "content/public/common/frame_navigate_params.h" 22 #include "content/public/common/frame_navigate_params.h"
23 #include "content/public/common/url_fetcher.h"
21 24
22 using content::NavigationController; 25 using content::NavigationController;
23 using content::NavigationEntry; 26 using content::NavigationEntry;
24 using content::WebContents; 27 using content::WebContents;
25 28
26 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SearchEngineTabHelper); 29 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SearchEngineTabHelper);
27 30
28 namespace { 31 namespace {
29 32
30 // Returns true if the entry's transition type is FORM_SUBMIT. 33 // Returns true if the entry's transition type is FORM_SUBMIT.
(...skipping 23 matching lines...) Expand all
54 // 57 //
55 // If we relax the path constraint, we need to be sure to sanitize the path 58 // If we relax the path constraint, we need to be sure to sanitize the path
56 // elements and update AutocompletePopup to look for keywords using the path. 59 // elements and update AutocompletePopup to look for keywords using the path.
57 // See http://b/issue?id=863583. 60 // See http://b/issue?id=863583.
58 if (!url.SchemeIs(url::kHttpScheme) || (url.path().length() > 1)) 61 if (!url.SchemeIs(url::kHttpScheme) || (url.path().length() > 1))
59 return base::string16(); 62 return base::string16();
60 63
61 return TemplateURL::GenerateKeyword(url); 64 return TemplateURL::GenerateKeyword(url);
62 } 65 }
63 66
67 void AssociateURLFetcherWithWebContents(content::WebContents* web_contents,
68 net::URLFetcher* url_fetcher) {
69 content::AssociateURLFetcherWithRenderFrame(
70 url_fetcher,
71 web_contents->GetURL(),
72 web_contents->GetRenderProcessHost()->GetID(),
73 web_contents->GetMainFrame()->GetRoutingID());
74 }
75
64 } // namespace 76 } // namespace
65 77
66 SearchEngineTabHelper::~SearchEngineTabHelper() { 78 SearchEngineTabHelper::~SearchEngineTabHelper() {
67 } 79 }
68 80
69 void SearchEngineTabHelper::DidNavigateMainFrame( 81 void SearchEngineTabHelper::DidNavigateMainFrame(
70 const content::LoadCommittedDetails& /*details*/, 82 const content::LoadCommittedDetails& /*details*/,
71 const content::FrameNavigateParams& params) { 83 const content::FrameNavigateParams& params) {
72 GenerateKeywordIfNecessary(params); 84 GenerateKeywordIfNecessary(params);
73 } 85 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 base::string16 keyword; 139 base::string16 keyword;
128 if (provider_type == TemplateURLFetcher::AUTODETECTED_PROVIDER) { 140 if (provider_type == TemplateURLFetcher::AUTODETECTED_PROVIDER) {
129 keyword = GenerateKeywordFromNavigationEntry(entry); 141 keyword = GenerateKeywordFromNavigationEntry(entry);
130 if (keyword.empty()) 142 if (keyword.empty())
131 return; 143 return;
132 } 144 }
133 145
134 // Download the OpenSearch description document. If this is successful, a 146 // Download the OpenSearch description document. If this is successful, a
135 // new keyword will be created when done. 147 // new keyword will be created when done.
136 TemplateURLFetcherFactory::GetForProfile(profile)->ScheduleDownload( 148 TemplateURLFetcherFactory::GetForProfile(profile)->ScheduleDownload(
137 keyword, osdd_url, entry->GetFavicon().url, web_contents(), 149 keyword, osdd_url, entry->GetFavicon().url,
150 base::Bind(&AssociateURLFetcherWithWebContents, web_contents()),
138 base::Bind(&SearchEngineTabHelper::OnDownloadedOSDD, 151 base::Bind(&SearchEngineTabHelper::OnDownloadedOSDD,
139 weak_ptr_factory_.GetWeakPtr()), 152 weak_ptr_factory_.GetWeakPtr()),
140 provider_type); 153 provider_type);
141 } 154 }
142 155
143 void SearchEngineTabHelper::OnDownloadedOSDD( 156 void SearchEngineTabHelper::OnDownloadedOSDD(
144 scoped_ptr<TemplateURL> template_url) { 157 scoped_ptr<TemplateURL> template_url) {
145 Profile* profile = 158 Profile* profile =
146 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 159 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
147 delegate_->ConfirmAddSearchProvider(template_url.release(), profile); 160 delegate_->ConfirmAddSearchProvider(template_url.release(), profile);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 // the favicon url wasn't obtained before the load started. This assumes the 219 // the favicon url wasn't obtained before the load started. This assumes the
207 // latter. 220 // latter.
208 // TODO(sky): Need a way to set the favicon that doesn't involve generating 221 // TODO(sky): Need a way to set the favicon that doesn't involve generating
209 // its url. 222 // its url.
210 data.favicon_url = current_favicon.is_valid() ? 223 data.favicon_url = current_favicon.is_valid() ?
211 current_favicon : TemplateURL::GenerateFaviconURL(params.referrer.url); 224 current_favicon : TemplateURL::GenerateFaviconURL(params.referrer.url);
212 data.safe_for_autoreplace = true; 225 data.safe_for_autoreplace = true;
213 data.input_encodings.push_back(params.searchable_form_encoding); 226 data.input_encodings.push_back(params.searchable_form_encoding);
214 url_service->Add(new TemplateURL(data)); 227 url_service->Add(new TemplateURL(data));
215 } 228 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698