| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/search_engines/template_url_model.h" | 5 #include "chrome/browser/search_engines/template_url_model.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/command_line.h" |
| 9 #include "base/environment.h" |
| 8 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
| 9 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 10 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/extensions/extensions_service.h" | 13 #include "chrome/browser/extensions/extensions_service.h" |
| 12 #include "chrome/browser/google_url_tracker.h" | 14 #include "chrome/browser/google_url_tracker.h" |
| 13 #include "chrome/browser/history/history.h" | 15 #include "chrome/browser/history/history.h" |
| 14 #include "chrome/browser/history/history_notifications.h" | 16 #include "chrome/browser/history/history_notifications.h" |
| 15 #include "chrome/browser/net/url_fixer_upper.h" | 17 #include "chrome/browser/net/url_fixer_upper.h" |
| 16 #include "chrome/browser/pref_service.h" | 18 #include "chrome/browser/pref_service.h" |
| 17 #include "chrome/browser/profile.h" | 19 #include "chrome/browser/profile.h" |
| 18 #include "chrome/browser/rlz/rlz.h" | 20 #include "chrome/browser/rlz/rlz.h" |
| 19 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 21 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
| 22 #include "chrome/common/chrome_switches.h" |
| 23 #include "chrome/common/env_vars.h" |
| 20 #include "chrome/common/extensions/extension.h" | 24 #include "chrome/common/extensions/extension.h" |
| 21 #include "chrome/common/notification_service.h" | 25 #include "chrome/common/notification_service.h" |
| 22 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 23 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
| 24 #include "net/base/net_util.h" | 28 #include "net/base/net_util.h" |
| 25 | 29 |
| 26 using base::Time; | 30 using base::Time; |
| 27 | 31 |
| 28 // String in the URL that is replaced by the search term. | 32 // String in the URL that is replaced by the search term. |
| 29 static const char kSearchTermParameter[] = "{searchTerms}"; | 33 static const char kSearchTermParameter[] = "{searchTerms}"; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 123 |
| 120 // TemplateURLModel ends up owning the TemplateURL, don't try and free it. | 124 // TemplateURLModel ends up owning the TemplateURL, don't try and free it. |
| 121 TemplateURL* template_url = new TemplateURL(); | 125 TemplateURL* template_url = new TemplateURL(); |
| 122 template_url->set_keyword(initializers[i].keyword); | 126 template_url->set_keyword(initializers[i].keyword); |
| 123 template_url->set_short_name(initializers[i].content); | 127 template_url->set_short_name(initializers[i].content); |
| 124 template_url->SetURL(osd_url, 0, 0); | 128 template_url->SetURL(osd_url, 0, 0); |
| 125 Add(template_url); | 129 Add(template_url); |
| 126 } | 130 } |
| 127 | 131 |
| 128 // Request a server check for the correct Google URL if Google is the default | 132 // Request a server check for the correct Google URL if Google is the default |
| 129 // search engine. | 133 // search engine, not in headless mode and not in Chrome Frame. |
| 130 const TemplateURL* default_provider = GetDefaultSearchProvider(); | 134 const TemplateURL* default_provider = GetDefaultSearchProvider(); |
| 131 if (default_provider) { | 135 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 136 if (default_provider && !env->HasVar(env_vars::kHeadless) && |
| 137 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kCrhomeFrame)) { |
| 132 const TemplateURLRef* default_provider_ref = default_provider->url(); | 138 const TemplateURLRef* default_provider_ref = default_provider->url(); |
| 133 if (default_provider_ref && default_provider_ref->HasGoogleBaseURLs()) | 139 if (default_provider_ref && default_provider_ref->HasGoogleBaseURLs()) |
| 134 GoogleURLTracker::RequestServerCheck(); | 140 GoogleURLTracker::RequestServerCheck(); |
| 135 } | 141 } |
| 136 } | 142 } |
| 137 | 143 |
| 138 // static | 144 // static |
| 139 std::wstring TemplateURLModel::GenerateKeyword(const GURL& url, | 145 std::wstring TemplateURLModel::GenerateKeyword(const GURL& url, |
| 140 bool autodetected) { | 146 bool autodetected) { |
| 141 // Don't autogenerate keywords for referrers that are the result of a form | 147 // Don't autogenerate keywords for referrers that are the result of a form |
| (...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1106 const TemplateURL* TemplateURLModel::GetTemplateURLForExtension( | 1112 const TemplateURL* TemplateURLModel::GetTemplateURLForExtension( |
| 1107 Extension* extension) const { | 1113 Extension* extension) const { |
| 1108 for (TemplateURLVector::const_iterator i = template_urls_.begin(); | 1114 for (TemplateURLVector::const_iterator i = template_urls_.begin(); |
| 1109 i != template_urls_.end(); ++i) { | 1115 i != template_urls_.end(); ++i) { |
| 1110 if ((*i)->IsExtensionKeyword() && (*i)->url()->GetHost() == extension->id()) | 1116 if ((*i)->IsExtensionKeyword() && (*i)->url()->GetHost() == extension->id()) |
| 1111 return *i; | 1117 return *i; |
| 1112 } | 1118 } |
| 1113 | 1119 |
| 1114 return NULL; | 1120 return NULL; |
| 1115 } | 1121 } |
| OLD | NEW |