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