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

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

Issue 10173001: Add a Profile* member to TemplateURL. This makes some invocations of ReplaceSearchTerms() a bit le… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 8 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/edit_search_engine_controller.h" 5 #include "chrome/browser/ui/search_engines/edit_search_engine_controller.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/net/url_fixer_upper.h" 9 #include "chrome/browser/net/url_fixer_upper.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 25 matching lines...) Expand all
36 std::string url = GetFixedUpURL(url_input); 36 std::string url = GetFixedUpURL(url_input);
37 if (url.empty()) 37 if (url.empty())
38 return false; 38 return false;
39 39
40 // Convert |url| to a TemplateURLRef so we can check its validity even if it 40 // Convert |url| to a TemplateURLRef so we can check its validity even if it
41 // contains replacement strings. We do this by constructing a dummy 41 // contains replacement strings. We do this by constructing a dummy
42 // TemplateURL owner because |template_url_| might be NULL and we can't call 42 // TemplateURL owner because |template_url_| might be NULL and we can't call
43 // TemplateURLRef::IsValid() when its owner is NULL. 43 // TemplateURLRef::IsValid() when its owner is NULL.
44 TemplateURLData data; 44 TemplateURLData data;
45 data.SetURL(url); 45 data.SetURL(url);
46 TemplateURL t_url(data); 46 TemplateURL t_url(profile_, data);
47 const TemplateURLRef& template_ref = t_url.url_ref(); 47 const TemplateURLRef& template_ref = t_url.url_ref();
48 if (!template_ref.IsValid()) 48 if (!template_ref.IsValid())
49 return false; 49 return false;
50 50
51 // If this is going to be the default search engine, it must support 51 // If this is going to be the default search engine, it must support
52 // replacement. 52 // replacement.
53 if (!template_ref.SupportsReplacement() && 53 if (!template_ref.SupportsReplacement() &&
54 (template_url_ == TemplateURLServiceFactory::GetForProfile(profile_)-> 54 (template_url_ == TemplateURLServiceFactory::GetForProfile(profile_)->
55 GetDefaultSearchProvider())) 55 GetDefaultSearchProvider()))
56 return false; 56 return false;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 TrimWhitespace(TemplateURLRef::DisplayURLToURLRef(UTF8ToUTF16(url_input)), 125 TrimWhitespace(TemplateURLRef::DisplayURLToURLRef(UTF8ToUTF16(url_input)),
126 TRIM_ALL, &url); 126 TRIM_ALL, &url);
127 if (url.empty()) 127 if (url.empty())
128 return url; 128 return url;
129 129
130 // Parse the string as a URL to determine the scheme. If we need to, add the 130 // Parse the string as a URL to determine the scheme. If we need to, add the
131 // scheme. As the scheme may be expanded (as happens with {google:baseURL}) 131 // scheme. As the scheme may be expanded (as happens with {google:baseURL})
132 // we need to replace the search terms before testing for the scheme. 132 // we need to replace the search terms before testing for the scheme.
133 TemplateURLData data; 133 TemplateURLData data;
134 data.SetURL(url); 134 data.SetURL(url);
135 TemplateURL t_url(data); 135 TemplateURL t_url(profile_, data);
136 std::string expanded_url(t_url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("x"), 136 std::string expanded_url(t_url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("x"),
137 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); 137 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
138 url_parse::Parsed parts; 138 url_parse::Parsed parts;
139 std::string scheme(URLFixerUpper::SegmentURL(expanded_url, &parts)); 139 std::string scheme(URLFixerUpper::SegmentURL(expanded_url, &parts));
140 if (!parts.scheme.is_valid()) 140 if (!parts.scheme.is_valid())
141 url.insert(0, scheme + "://"); 141 url.insert(0, scheme + "://");
142 142
143 return url; 143 return url;
144 } 144 }
145 145
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698