OLD | NEW |
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 24 matching lines...) Expand all Loading... |
35 const std::string& url_input) const { | 35 const std::string& url_input) const { |
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 TemplateURL t_url; | 44 TemplateURL t_url; |
45 t_url.SetURL(url); | 45 TemplateURLRef template_ref(&t_url, url); |
46 const TemplateURLRef& template_ref = t_url.url_ref(); | |
47 if (!template_ref.IsValid()) | 46 if (!template_ref.IsValid()) |
48 return false; | 47 return false; |
49 | 48 |
50 // If this is going to be the default search engine, it must support | 49 // If this is going to be the default search engine, it must support |
51 // replacement. | 50 // replacement. |
52 if (!template_ref.SupportsReplacement() && | 51 if (!template_ref.SupportsReplacement() && |
53 (template_url_ == TemplateURLServiceFactory::GetForProfile(profile_)-> | 52 (template_url_ == TemplateURLServiceFactory::GetForProfile(profile_)-> |
54 GetDefaultSearchProvider())) | 53 GetDefaultSearchProvider())) |
55 return false; | 54 return false; |
56 | 55 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 TrimWhitespace(TemplateURLRef::DisplayURLToURLRef(UTF8ToUTF16(url_input)), | 128 TrimWhitespace(TemplateURLRef::DisplayURLToURLRef(UTF8ToUTF16(url_input)), |
130 TRIM_ALL, &url); | 129 TRIM_ALL, &url); |
131 if (url.empty()) | 130 if (url.empty()) |
132 return url; | 131 return url; |
133 | 132 |
134 // Parse the string as a URL to determine the scheme. If we need to, add the | 133 // Parse the string as a URL to determine the scheme. If we need to, add the |
135 // scheme. As the scheme may be expanded (as happens with {google:baseURL}) | 134 // scheme. As the scheme may be expanded (as happens with {google:baseURL}) |
136 // we need to replace the search terms before testing for the scheme. | 135 // we need to replace the search terms before testing for the scheme. |
137 TemplateURL t_url; | 136 TemplateURL t_url; |
138 t_url.SetURL(url); | 137 t_url.SetURL(url); |
139 std::string expanded_url(t_url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("x"), | 138 std::string expanded_url(t_url.url()->ReplaceSearchTerms(ASCIIToUTF16("x"), |
140 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); | 139 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); |
141 url_parse::Parsed parts; | 140 url_parse::Parsed parts; |
142 std::string scheme(URLFixerUpper::SegmentURL(expanded_url, &parts)); | 141 std::string scheme(URLFixerUpper::SegmentURL(expanded_url, &parts)); |
143 if (!parts.scheme.is_valid()) | 142 if (!parts.scheme.is_valid()) |
144 url.insert(0, scheme + "://"); | 143 url.insert(0, scheme + "://"); |
145 | 144 |
146 return url; | 145 return url; |
147 } | 146 } |
148 | 147 |
OLD | NEW |