| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 if (template_url_ == | 46 if (template_url_ == |
| 47 TemplateURLServiceFactory::GetForProfile(profile_)-> | 47 TemplateURLServiceFactory::GetForProfile(profile_)-> |
| 48 GetDefaultSearchProvider()) | 48 GetDefaultSearchProvider()) |
| 49 return false; | 49 return false; |
| 50 return GURL(url).is_valid(); | 50 return GURL(url).is_valid(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 // If the url has a search term, replace it with a random string and make | 53 // If the url has a search term, replace it with a random string and make |
| 54 // sure the resulting URL is valid. We don't check the validity of the url | 54 // sure the resulting URL is valid. We don't check the validity of the url |
| 55 // with the search term as that is not necessarily valid. | 55 // with the search term as that is not necessarily valid. |
| 56 return GURL(template_ref.ReplaceSearchTerms(TemplateURL(), ASCIIToUTF16("a"), | 56 return GURL(template_ref.ReplaceSearchTerms(profile_, |
| 57 TemplateURL(), ASCIIToUTF16("a"), |
| 57 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())).is_valid(); | 58 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())).is_valid(); |
| 58 } | 59 } |
| 59 | 60 |
| 60 bool EditSearchEngineController::IsKeywordValid( | 61 bool EditSearchEngineController::IsKeywordValid( |
| 61 const string16& keyword_input) const { | 62 const string16& keyword_input) const { |
| 62 string16 keyword_input_trimmed(CollapseWhitespace(keyword_input, true)); | 63 string16 keyword_input_trimmed(CollapseWhitespace(keyword_input, true)); |
| 63 if (keyword_input_trimmed.empty()) | 64 if (keyword_input_trimmed.empty()) |
| 64 return false; // Do not allow empty keyword. | 65 return false; // Do not allow empty keyword. |
| 65 const TemplateURL* turl_with_keyword = | 66 const TemplateURL* turl_with_keyword = |
| 66 TemplateURLServiceFactory::GetForProfile(profile_)-> | 67 TemplateURLServiceFactory::GetForProfile(profile_)-> |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 TRIM_ALL, &url); | 131 TRIM_ALL, &url); |
| 131 if (url.empty()) | 132 if (url.empty()) |
| 132 return url; | 133 return url; |
| 133 | 134 |
| 134 // Parse the string as a URL to determine the scheme. If we need to, add the | 135 // 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}) | 136 // 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. | 137 // we need to replace the search terms before testing for the scheme. |
| 137 TemplateURL t_url; | 138 TemplateURL t_url; |
| 138 t_url.SetURL(url, 0, 0); | 139 t_url.SetURL(url, 0, 0); |
| 139 std::string expanded_url = | 140 std::string expanded_url = |
| 140 t_url.url()->ReplaceSearchTerms(t_url, ASCIIToUTF16("x"), 0, string16()); | 141 t_url.url()->ReplaceSearchTerms(profile_, t_url, ASCIIToUTF16("x"), 0, |
| 142 string16()); |
| 141 url_parse::Parsed parts; | 143 url_parse::Parsed parts; |
| 142 std::string scheme( | 144 std::string scheme( |
| 143 URLFixerUpper::SegmentURL(expanded_url, &parts)); | 145 URLFixerUpper::SegmentURL(expanded_url, &parts)); |
| 144 if (!parts.scheme.is_valid()) { | 146 if (!parts.scheme.is_valid()) { |
| 145 scheme.append("://"); | 147 scheme.append("://"); |
| 146 url.insert(0, scheme); | 148 url.insert(0, scheme); |
| 147 } | 149 } |
| 148 | 150 |
| 149 return url; | 151 return url; |
| 150 } | 152 } |
| 151 | |
| OLD | NEW |