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

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

Issue 367413003: No chrome dependencies in TemplateURLFetcher and TemplateURLParser (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/template_url_fetcher_ui_callbacks.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/web_contents.h" 19 #include "content/public/browser/web_contents.h"
20 #include "content/public/common/frame_navigate_params.h" 20 #include "content/public/common/frame_navigate_params.h"
21 21
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 bool handled = true; 76 bool handled = true;
77 IPC_BEGIN_MESSAGE_MAP(SearchEngineTabHelper, message) 77 IPC_BEGIN_MESSAGE_MAP(SearchEngineTabHelper, message)
78 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PageHasOSDD, OnPageHasOSDD) 78 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PageHasOSDD, OnPageHasOSDD)
79 IPC_MESSAGE_UNHANDLED(handled = false) 79 IPC_MESSAGE_UNHANDLED(handled = false)
80 IPC_END_MESSAGE_MAP() 80 IPC_END_MESSAGE_MAP()
81 81
82 return handled; 82 return handled;
83 } 83 }
84 84
85 SearchEngineTabHelper::SearchEngineTabHelper(WebContents* web_contents) 85 SearchEngineTabHelper::SearchEngineTabHelper(WebContents* web_contents)
86 : content::WebContentsObserver(web_contents) { 86 : content::WebContentsObserver(web_contents),
87 weak_ptr_factory_(this) {
87 DCHECK(web_contents); 88 DCHECK(web_contents);
88 } 89 }
89 90
90 void SearchEngineTabHelper::OnPageHasOSDD( 91 void SearchEngineTabHelper::OnPageHasOSDD(
91 const GURL& page_url, 92 const GURL& page_url,
92 const GURL& osdd_url, 93 const GURL& osdd_url,
93 const search_provider::OSDDType& msg_provider_type) { 94 const search_provider::OSDDType& msg_provider_type) {
94 // Checks to see if we should generate a keyword based on the OSDD, and if 95 // Checks to see if we should generate a keyword based on the OSDD, and if
95 // necessary uses TemplateURLFetcher to download the OSDD and create a 96 // necessary uses TemplateURLFetcher to download the OSDD and create a
96 // keyword. 97 // keyword.
(...skipping 30 matching lines...) Expand all
127 if (provider_type == TemplateURLFetcher::AUTODETECTED_PROVIDER) { 128 if (provider_type == TemplateURLFetcher::AUTODETECTED_PROVIDER) {
128 keyword = GenerateKeywordFromNavigationEntry(entry); 129 keyword = GenerateKeywordFromNavigationEntry(entry);
129 if (keyword.empty()) 130 if (keyword.empty())
130 return; 131 return;
131 } 132 }
132 133
133 // Download the OpenSearch description document. If this is successful, a 134 // Download the OpenSearch description document. If this is successful, a
134 // new keyword will be created when done. 135 // new keyword will be created when done.
135 TemplateURLFetcherFactory::GetForProfile(profile)->ScheduleDownload( 136 TemplateURLFetcherFactory::GetForProfile(profile)->ScheduleDownload(
136 keyword, osdd_url, entry->GetFavicon().url, web_contents(), 137 keyword, osdd_url, entry->GetFavicon().url, web_contents(),
137 new TemplateURLFetcherUICallbacks(this, web_contents()), provider_type); 138 base::Bind(&SearchEngineTabHelper::OnDownloadedOSDD,
139 weak_ptr_factory_.GetWeakPtr()),
140 provider_type);
141 }
142
143 void SearchEngineTabHelper::OnDownloadedOSDD(
144 scoped_ptr<TemplateURL> template_url) {
145 Profile* profile =
146 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
147 delegate_->ConfirmAddSearchProvider(template_url.release(), profile);
Peter Kasting 2014/07/07 22:48:44 Bonus points if in some future change you make Con
hashimoto 2014/07/08 00:19:36 That should be nice. I'll do it later.
138 } 148 }
139 149
140 void SearchEngineTabHelper::GenerateKeywordIfNecessary( 150 void SearchEngineTabHelper::GenerateKeywordIfNecessary(
141 const content::FrameNavigateParams& params) { 151 const content::FrameNavigateParams& params) {
142 if (!params.searchable_form_url.is_valid()) 152 if (!params.searchable_form_url.is_valid())
143 return; 153 return;
144 154
145 Profile* profile = 155 Profile* profile =
146 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 156 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
147 if (profile->IsOffTheRecord()) 157 if (profile->IsOffTheRecord())
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 // the favicon url wasn't obtained before the load started. This assumes the 206 // the favicon url wasn't obtained before the load started. This assumes the
197 // latter. 207 // latter.
198 // TODO(sky): Need a way to set the favicon that doesn't involve generating 208 // TODO(sky): Need a way to set the favicon that doesn't involve generating
199 // its url. 209 // its url.
200 data.favicon_url = current_favicon.is_valid() ? 210 data.favicon_url = current_favicon.is_valid() ?
201 current_favicon : TemplateURL::GenerateFaviconURL(params.referrer.url); 211 current_favicon : TemplateURL::GenerateFaviconURL(params.referrer.url);
202 data.safe_for_autoreplace = true; 212 data.safe_for_autoreplace = true;
203 data.input_encodings.push_back(params.searchable_form_encoding); 213 data.input_encodings.push_back(params.searchable_form_encoding);
204 url_service->Add(new TemplateURL(data)); 214 url_service->Add(new TemplateURL(data));
205 } 215 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698