| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/banners/app_banner_data_fetcher.h" | 5 #include "chrome/browser/banners/app_banner_data_fetcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/lazy_instance.h" |
| 9 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/banners/app_banner_debug_log.h" | 13 #include "chrome/browser/banners/app_banner_debug_log.h" |
| 13 #include "chrome/browser/banners/app_banner_metrics.h" | 14 #include "chrome/browser/banners/app_banner_metrics.h" |
| 14 #include "chrome/browser/banners/app_banner_settings_helper.h" | 15 #include "chrome/browser/banners/app_banner_settings_helper.h" |
| 15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/manifest/manifest_icon_downloader.h" | 17 #include "chrome/browser/manifest/manifest_icon_downloader.h" |
| 17 #include "chrome/browser/manifest/manifest_icon_selector.h" | 18 #include "chrome/browser/manifest/manifest_icon_selector.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/common/render_messages.h" | 21 #include "chrome/common/render_messages.h" |
| 21 #include "components/rappor/rappor_utils.h" | 22 #include "components/rappor/rappor_utils.h" |
| 22 #include "content/public/browser/browser_context.h" | 23 #include "content/public/browser/browser_context.h" |
| 23 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/browser/navigation_details.h" | 25 #include "content/public/browser/navigation_details.h" |
| 25 #include "content/public/browser/render_frame_host.h" | 26 #include "content/public/browser/render_frame_host.h" |
| 26 #include "content/public/browser/service_worker_context.h" | 27 #include "content/public/browser/service_worker_context.h" |
| 27 #include "content/public/browser/storage_partition.h" | 28 #include "content/public/browser/storage_partition.h" |
| 28 #include "net/base/load_flags.h" | 29 #include "net/base/load_flags.h" |
| 29 #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerProm
ptReply.h" | 30 #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerProm
ptReply.h" |
| 30 #include "ui/gfx/screen.h" | 31 #include "ui/gfx/screen.h" |
| 31 | 32 |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| 34 base::TimeDelta gTimeDeltaForTesting; | 35 base::LazyInstance<base::TimeDelta> gTimeDeltaForTesting = |
| 36 LAZY_INSTANCE_INITIALIZER; |
| 35 int gCurrentRequestID = -1; | 37 int gCurrentRequestID = -1; |
| 36 const char kPngExtension[] = ".png"; | 38 const char kPngExtension[] = ".png"; |
| 37 | 39 |
| 38 // The requirement for now is an image/png that is at least 144x144. | 40 // The requirement for now is an image/png that is at least 144x144. |
| 39 const int kIconMinimumSize = 144; | 41 const int kIconMinimumSize = 144; |
| 40 bool DoesManifestContainRequiredIcon(const content::Manifest& manifest) { | 42 bool DoesManifestContainRequiredIcon(const content::Manifest& manifest) { |
| 41 for (const auto& icon : manifest.icons) { | 43 for (const auto& icon : manifest.icons) { |
| 42 // The type field is optional. If it isn't present, fall back on checking | 44 // The type field is optional. If it isn't present, fall back on checking |
| 43 // the src extension, and allow the icon if the extension ends with png. | 45 // the src extension, and allow the icon if the extension ends with png. |
| 44 if (!base::EqualsASCII(icon.type.string(), "image/png") && | 46 if (!base::EqualsASCII(icon.type.string(), "image/png") && |
| (...skipping 12 matching lines...) Expand all Loading... |
| 57 | 59 |
| 58 return false; | 60 return false; |
| 59 } | 61 } |
| 60 | 62 |
| 61 } // anonymous namespace | 63 } // anonymous namespace |
| 62 | 64 |
| 63 namespace banners { | 65 namespace banners { |
| 64 | 66 |
| 65 // static | 67 // static |
| 66 base::Time AppBannerDataFetcher::GetCurrentTime() { | 68 base::Time AppBannerDataFetcher::GetCurrentTime() { |
| 67 return base::Time::Now() + gTimeDeltaForTesting; | 69 return base::Time::Now() + gTimeDeltaForTesting.Get(); |
| 68 } | 70 } |
| 69 | 71 |
| 70 // static | 72 // static |
| 71 void AppBannerDataFetcher::SetTimeDeltaForTesting(int days) { | 73 void AppBannerDataFetcher::SetTimeDeltaForTesting(int days) { |
| 72 gTimeDeltaForTesting = base::TimeDelta::FromDays(days); | 74 gTimeDeltaForTesting.Get() = base::TimeDelta::FromDays(days); |
| 73 } | 75 } |
| 74 | 76 |
| 75 AppBannerDataFetcher::AppBannerDataFetcher(content::WebContents* web_contents, | 77 AppBannerDataFetcher::AppBannerDataFetcher(content::WebContents* web_contents, |
| 76 base::WeakPtr<Delegate> delegate, | 78 base::WeakPtr<Delegate> delegate, |
| 77 int ideal_icon_size_in_dp, | 79 int ideal_icon_size_in_dp, |
| 78 int minimum_icon_size_in_dp, | 80 int minimum_icon_size_in_dp, |
| 79 bool is_debug_mode) | 81 bool is_debug_mode) |
| 80 : WebContentsObserver(web_contents), | 82 : WebContentsObserver(web_contents), |
| 81 weak_delegate_(delegate), | 83 weak_delegate_(delegate), |
| 82 ideal_icon_size_in_dp_(ideal_icon_size_in_dp), | 84 ideal_icon_size_in_dp_(ideal_icon_size_in_dp), |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 } | 467 } |
| 466 if (!DoesManifestContainRequiredIcon(manifest)) { | 468 if (!DoesManifestContainRequiredIcon(manifest)) { |
| 467 OutputDeveloperNotShownMessage(web_contents, kManifestMissingSuitableIcon, | 469 OutputDeveloperNotShownMessage(web_contents, kManifestMissingSuitableIcon, |
| 468 is_debug_mode); | 470 is_debug_mode); |
| 469 return false; | 471 return false; |
| 470 } | 472 } |
| 471 return true; | 473 return true; |
| 472 } | 474 } |
| 473 | 475 |
| 474 } // namespace banners | 476 } // namespace banners |
| OLD | NEW |