| 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/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 // When we have no Delegate, we know that the template_url_ hasn't yet been | 120 // When we have no Delegate, we know that the template_url_ hasn't yet been |
| 121 // added to the model, so we need to clean it up. | 121 // added to the model, so we need to clean it up. |
| 122 delete template_url_; | 122 delete template_url_; |
| 123 template_url_ = NULL; | 123 template_url_ = NULL; |
| 124 } | 124 } |
| 125 } | 125 } |
| 126 | 126 |
| 127 std::string EditSearchEngineController::GetFixedUpURL( | 127 std::string EditSearchEngineController::GetFixedUpURL( |
| 128 const std::string& url_input) const { | 128 const std::string& url_input) const { |
| 129 std::string url; | 129 std::string url; |
| 130 base::TrimWhitespace(TemplateURLRef::DisplayURLToURLRef( | 130 base::TrimWhitespaceASCII( |
| 131 base::UTF8ToUTF16(url_input)), | 131 TemplateURLRef::DisplayURLToURLRef(base::UTF8ToUTF16(url_input)), |
| 132 base::TRIM_ALL, &url); | 132 base::TRIM_ALL, &url); |
| 133 if (url.empty()) | 133 if (url.empty()) |
| 134 return url; | 134 return url; |
| 135 | 135 |
| 136 // Parse the string as a URL to determine the scheme. If we need to, add the | 136 // Parse the string as a URL to determine the scheme. If we need to, add the |
| 137 // scheme. As the scheme may be expanded (as happens with {google:baseURL}) | 137 // scheme. As the scheme may be expanded (as happens with {google:baseURL}) |
| 138 // we need to replace the search terms before testing for the scheme. | 138 // we need to replace the search terms before testing for the scheme. |
| 139 TemplateURLData data; | 139 TemplateURLData data; |
| 140 data.SetURL(url); | 140 data.SetURL(url); |
| 141 TemplateURL t_url(data); | 141 TemplateURL t_url(data); |
| 142 std::string expanded_url(t_url.url_ref().ReplaceSearchTerms( | 142 std::string expanded_url(t_url.url_ref().ReplaceSearchTerms( |
| 143 TemplateURLRef::SearchTermsArgs(base::ASCIIToUTF16("x")), | 143 TemplateURLRef::SearchTermsArgs(base::ASCIIToUTF16("x")), |
| 144 TemplateURLServiceFactory::GetForProfile(profile_)->search_terms_data())); | 144 TemplateURLServiceFactory::GetForProfile(profile_)->search_terms_data())); |
| 145 url::Parsed parts; | 145 url::Parsed parts; |
| 146 std::string scheme(url_formatter::SegmentURL(expanded_url, &parts)); | 146 std::string scheme(url_formatter::SegmentURL(expanded_url, &parts)); |
| 147 if (!parts.scheme.is_valid()) | 147 if (!parts.scheme.is_valid()) |
| 148 url.insert(0, scheme + "://"); | 148 url.insert(0, scheme + "://"); |
| 149 | 149 |
| 150 return url; | 150 return url; |
| 151 } | 151 } |
| OLD | NEW |