| 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/extensions/apps_promo.h" | 5 #include "chrome/browser/extensions/apps_promo.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/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/prefs/pref_service.h" | 11 #include "chrome/browser/prefs/pref_service.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/webui/ntp/shown_sections_handler.h" | 13 #include "chrome/browser/ui/webui/ntp/shown_sections_handler.h" |
| 14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
| 16 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
| 17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 18 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 19 #include "content/public/common/url_constants.h" | 19 #include "content/public/common/url_constants.h" |
| 20 #include "content/common/net/url_fetcher.h" |
| 20 #include "net/base/load_flags.h" | 21 #include "net/base/load_flags.h" |
| 21 #include "net/url_request/url_request_status.h" | 22 #include "net/url_request/url_request_status.h" |
| 22 | 23 |
| 23 const int AppsPromo::kDefaultAppsCounterMax = 10; | 24 const int AppsPromo::kDefaultAppsCounterMax = 10; |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 // The default logo for the promo. | 28 // The default logo for the promo. |
| 28 const char kDefaultLogo[] = "chrome://theme/IDR_WEBSTORE_ICON"; | 29 const char kDefaultLogo[] = "chrome://theme/IDR_WEBSTORE_ICON"; |
| 29 | 30 |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 } | 346 } |
| 346 } | 347 } |
| 347 | 348 |
| 348 AppsPromoLogoFetcher::~AppsPromoLogoFetcher() {} | 349 AppsPromoLogoFetcher::~AppsPromoLogoFetcher() {} |
| 349 | 350 |
| 350 void AppsPromoLogoFetcher::OnURLFetchComplete(const URLFetcher* source) { | 351 void AppsPromoLogoFetcher::OnURLFetchComplete(const URLFetcher* source) { |
| 351 std::string data; | 352 std::string data; |
| 352 std::string base64_data; | 353 std::string base64_data; |
| 353 | 354 |
| 354 CHECK(source == url_fetcher_.get()); | 355 CHECK(source == url_fetcher_.get()); |
| 355 CHECK(source->GetResponseAsString(&data)); | 356 source->GetResponseAsString(&data); |
| 356 | 357 |
| 357 if (source->status().is_success() && | 358 if (source->status().is_success() && |
| 358 source->response_code() == kHttpSuccess && | 359 source->response_code() == kHttpSuccess && |
| 359 base::Base64Encode(data, &base64_data)) { | 360 base::Base64Encode(data, &base64_data)) { |
| 360 AppsPromo::SetSourcePromoLogoURL(promo_data_.logo); | 361 AppsPromo::SetSourcePromoLogoURL(promo_data_.logo); |
| 361 promo_data_.logo = GURL(kPNGDataURLPrefix + base64_data); | 362 promo_data_.logo = GURL(kPNGDataURLPrefix + base64_data); |
| 362 } else { | 363 } else { |
| 363 // The logo wasn't downloaded correctly or we failed to encode it in | 364 // The logo wasn't downloaded correctly or we failed to encode it in |
| 364 // base64. Reset the source URL so we fetch it again next time. AppsPromo | 365 // base64. Reset the source URL so we fetch it again next time. AppsPromo |
| 365 // will revert to the default logo. | 366 // will revert to the default logo. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 391 content::NotificationService::current()->Notify( | 392 content::NotificationService::current()->Notify( |
| 392 chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED, | 393 chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED, |
| 393 content::Source<Profile>(profile_), | 394 content::Source<Profile>(profile_), |
| 394 content::NotificationService::NoDetails()); | 395 content::NotificationService::NoDetails()); |
| 395 } | 396 } |
| 396 | 397 |
| 397 bool AppsPromoLogoFetcher::SupportsLogoURL() { | 398 bool AppsPromoLogoFetcher::SupportsLogoURL() { |
| 398 URLPattern allowed_urls(URLPattern::SCHEME_HTTPS, kValidLogoPattern); | 399 URLPattern allowed_urls(URLPattern::SCHEME_HTTPS, kValidLogoPattern); |
| 399 return allowed_urls.MatchesURL(promo_data_.logo); | 400 return allowed_urls.MatchesURL(promo_data_.logo); |
| 400 } | 401 } |
| OLD | NEW |