| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/local_ntp_source.h" | 5 #include "chrome/browser/search/local_ntp_source.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/feature_list.h" | 9 #include "base/feature_list.h" |
| 10 #include "base/json/json_string_value_serializer.h" | 10 #include "base/json/json_string_value_serializer.h" |
| 11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/memory/ref_counted_memory.h" | 14 #include "base/memory/ref_counted_memory.h" |
| 15 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/search/instant_io_context.h" | 21 #include "chrome/browser/search/instant_io_context.h" |
| 22 #include "chrome/browser/search/local_files_ntp_source.h" | 22 #include "chrome/browser/search/local_files_ntp_source.h" |
| 23 #include "chrome/browser/search/one_google_bar/one_google_bar_data.h" | 23 #include "chrome/browser/search/one_google_bar/one_google_bar_data.h" |
| 24 #include "chrome/browser/search/one_google_bar/one_google_bar_service.h" | 24 #include "chrome/browser/search/one_google_bar/one_google_bar_service.h" |
| 25 #include "chrome/browser/search/one_google_bar/one_google_bar_service_factory.h" | 25 #include "chrome/browser/search/one_google_bar/one_google_bar_service_factory.h" |
| 26 #include "chrome/browser/search_engines/template_url_service_factory.h" | 26 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 27 #include "chrome/browser/themes/theme_properties.h" | 27 #include "chrome/browser/themes/theme_properties.h" |
| 28 #include "chrome/browser/themes/theme_service.h" | 28 #include "chrome/browser/themes/theme_service.h" |
| 29 #include "chrome/browser/themes/theme_service_factory.h" | 29 #include "chrome/browser/themes/theme_service_factory.h" |
| 30 #include "chrome/common/chrome_features.h" |
| 30 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
| 31 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
| 32 #include "chrome/grit/browser_resources.h" | 33 #include "chrome/grit/browser_resources.h" |
| 33 #include "chrome/grit/generated_resources.h" | 34 #include "chrome/grit/generated_resources.h" |
| 34 #include "chrome/grit/theme_resources.h" | 35 #include "chrome/grit/theme_resources.h" |
| 35 #include "components/search_engines/template_url_service.h" | 36 #include "components/search_engines/template_url_service.h" |
| 36 #include "components/search_engines/template_url_service_observer.h" | 37 #include "components/search_engines/template_url_service_observer.h" |
| 37 #include "components/strings/grit/components_strings.h" | 38 #include "components/strings/grit/components_strings.h" |
| 38 #include "content/public/browser/browser_thread.h" | 39 #include "content/public/browser/browser_thread.h" |
| 39 #include "crypto/secure_hash.h" | 40 #include "crypto/secure_hash.h" |
| 40 #include "net/base/hash_value.h" | 41 #include "net/base/hash_value.h" |
| 41 #include "net/url_request/url_request.h" | 42 #include "net/url_request/url_request.h" |
| 42 #include "third_party/skia/include/core/SkColor.h" | 43 #include "third_party/skia/include/core/SkColor.h" |
| 43 #include "ui/base/l10n/l10n_util.h" | 44 #include "ui/base/l10n/l10n_util.h" |
| 44 #include "ui/base/resource/resource_bundle.h" | 45 #include "ui/base/resource/resource_bundle.h" |
| 45 #include "ui/base/webui/web_ui_util.h" | 46 #include "ui/base/webui/web_ui_util.h" |
| 46 #include "ui/resources/grit/ui_resources.h" | 47 #include "ui/resources/grit/ui_resources.h" |
| 47 #include "url/gurl.h" | 48 #include "url/gurl.h" |
| 48 | 49 |
| 49 namespace { | 50 namespace { |
| 50 | 51 |
| 51 base::Feature kOneGoogleBarOnLocalNtpFeature{"OneGoogleBarOnLocalNtp", | |
| 52 base::FEATURE_DISABLED_BY_DEFAULT}; | |
| 53 | |
| 54 // Signifies a locally constructed resource, i.e. not from grit/. | 52 // Signifies a locally constructed resource, i.e. not from grit/. |
| 55 const int kLocalResource = -1; | 53 const int kLocalResource = -1; |
| 56 | 54 |
| 57 const char kConfigDataFilename[] = "config.js"; | 55 const char kConfigDataFilename[] = "config.js"; |
| 58 const char kThemeCSSFilename[] = "theme.css"; | 56 const char kThemeCSSFilename[] = "theme.css"; |
| 59 const char kMainHtmlFilename[] = "local-ntp.html"; | 57 const char kMainHtmlFilename[] = "local-ntp.html"; |
| 60 const char kOneGoogleBarScriptFilename[] = "one-google.js"; | 58 const char kOneGoogleBarScriptFilename[] = "one-google.js"; |
| 61 const char kOneGoogleBarInHeadStyleFilename[] = "one-google/in-head.css"; | 59 const char kOneGoogleBarInHeadStyleFilename[] = "one-google/in-head.css"; |
| 62 const char kOneGoogleBarInHeadScriptFilename[] = "one-google/in-head.js"; | 60 const char kOneGoogleBarInHeadScriptFilename[] = "one-google/in-head.js"; |
| 63 const char kOneGoogleBarAfterBarScriptFilename[] = "one-google/after-bar.js"; | 61 const char kOneGoogleBarAfterBarScriptFilename[] = "one-google/after-bar.js"; |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 | 231 |
| 234 LocalNtpSource::LocalNtpSource(Profile* profile) | 232 LocalNtpSource::LocalNtpSource(Profile* profile) |
| 235 : profile_(profile), | 233 : profile_(profile), |
| 236 one_google_bar_service_(nullptr), | 234 one_google_bar_service_(nullptr), |
| 237 one_google_bar_service_observer_(this), | 235 one_google_bar_service_observer_(this), |
| 238 default_search_provider_is_google_(false), | 236 default_search_provider_is_google_(false), |
| 239 default_search_provider_is_google_io_thread_(false), | 237 default_search_provider_is_google_io_thread_(false), |
| 240 weak_ptr_factory_(this) { | 238 weak_ptr_factory_(this) { |
| 241 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 239 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 242 | 240 |
| 243 if (base::FeatureList::IsEnabled(kOneGoogleBarOnLocalNtpFeature)) { | 241 if (base::FeatureList::IsEnabled(features::kOneGoogleBarOnLocalNtp)) { |
| 244 one_google_bar_service_ = | 242 one_google_bar_service_ = |
| 245 OneGoogleBarServiceFactory::GetForProfile(profile_); | 243 OneGoogleBarServiceFactory::GetForProfile(profile_); |
| 246 } | 244 } |
| 247 | 245 |
| 248 // |one_google_bar_service_| is null in incognito, or when the feature is | 246 // |one_google_bar_service_| is null in incognito, or when the feature is |
| 249 // disabled. | 247 // disabled. |
| 250 if (one_google_bar_service_) | 248 if (one_google_bar_service_) |
| 251 one_google_bar_service_observer_.Add(one_google_bar_service_); | 249 one_google_bar_service_observer_.Add(one_google_bar_service_); |
| 252 | 250 |
| 253 TemplateURLService* template_url_service = | 251 TemplateURLService* template_url_service = |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 | 507 |
| 510 LocalNtpSource::OneGoogleBarRequest::OneGoogleBarRequest( | 508 LocalNtpSource::OneGoogleBarRequest::OneGoogleBarRequest( |
| 511 base::TimeTicks start_time, | 509 base::TimeTicks start_time, |
| 512 const content::URLDataSource::GotDataCallback& callback) | 510 const content::URLDataSource::GotDataCallback& callback) |
| 513 : start_time(start_time), callback(callback) {} | 511 : start_time(start_time), callback(callback) {} |
| 514 | 512 |
| 515 LocalNtpSource::OneGoogleBarRequest::OneGoogleBarRequest( | 513 LocalNtpSource::OneGoogleBarRequest::OneGoogleBarRequest( |
| 516 const OneGoogleBarRequest&) = default; | 514 const OneGoogleBarRequest&) = default; |
| 517 | 515 |
| 518 LocalNtpSource::OneGoogleBarRequest::~OneGoogleBarRequest() = default; | 516 LocalNtpSource::OneGoogleBarRequest::~OneGoogleBarRequest() = default; |
| OLD | NEW |