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/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/search_engines/template_url.h" | 10 #include "chrome/browser/search_engines/template_url.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 TemplateURLData data; | 44 TemplateURLData data; |
45 data.SetURL(url); | 45 data.SetURL(url); |
46 TemplateURL t_url(profile_, 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_ && |
55 GetDefaultSearchProvider())) | 55 template_url_ == TemplateURLServiceFactory::GetForProfile(profile_)-> |
| 56 GetDefaultSearchProvider()) |
56 return false; | 57 return false; |
57 | 58 |
58 // Replace any search term with a placeholder string and make sure the | 59 // Replace any search term with a placeholder string and make sure the |
59 // resulting URL is valid. | 60 // resulting URL is valid. |
60 return GURL(template_ref.ReplaceSearchTerms( | 61 return GURL(template_ref.ReplaceSearchTerms( |
61 TemplateURLRef::SearchTermsArgs(base::ASCIIToUTF16("x")))).is_valid(); | 62 TemplateURLRef::SearchTermsArgs(base::ASCIIToUTF16("x")))).is_valid(); |
62 } | 63 } |
63 | 64 |
64 bool EditSearchEngineController::IsKeywordValid( | 65 bool EditSearchEngineController::IsKeywordValid( |
65 const base::string16& keyword_input) const { | 66 const base::string16& keyword_input) const { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 TemplateURL t_url(profile_, data); | 138 TemplateURL t_url(profile_, data); |
138 std::string expanded_url(t_url.url_ref().ReplaceSearchTerms( | 139 std::string expanded_url(t_url.url_ref().ReplaceSearchTerms( |
139 TemplateURLRef::SearchTermsArgs(base::ASCIIToUTF16("x")))); | 140 TemplateURLRef::SearchTermsArgs(base::ASCIIToUTF16("x")))); |
140 url::Parsed parts; | 141 url::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 } |
OLD | NEW |