| 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_manager.h" | 5 #include "chrome/browser/banners/app_banner_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "content/public/browser/render_frame_host.h" | 23 #include "content/public/browser/render_frame_host.h" |
| 24 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 25 #include "content/public/common/origin_util.h" | 25 #include "content/public/common/origin_util.h" |
| 26 #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerProm
ptReply.h" | 26 #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerProm
ptReply.h" |
| 27 #include "third_party/skia/include/core/SkBitmap.h" | 27 #include "third_party/skia/include/core/SkBitmap.h" |
| 28 #include "ui/display/display.h" | 28 #include "ui/display/display.h" |
| 29 #include "ui/display/screen.h" | 29 #include "ui/display/screen.h" |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 bool gDisableSecureCheckForTesting = false; | |
| 34 int gCurrentRequestID = -1; | 33 int gCurrentRequestID = -1; |
| 35 base::LazyInstance<base::TimeDelta> gTimeDeltaForTesting = | 34 base::LazyInstance<base::TimeDelta> gTimeDeltaForTesting = |
| 36 LAZY_INSTANCE_INITIALIZER; | 35 LAZY_INSTANCE_INITIALIZER; |
| 37 | 36 |
| 38 // Returns |size_in_px| in dp, i.e. divided by the current device scale factor. | 37 // Returns |size_in_px| in dp, i.e. divided by the current device scale factor. |
| 39 int ConvertIconSizeFromPxToDp(int size_in_px) { | 38 int ConvertIconSizeFromPxToDp(int size_in_px) { |
| 40 return size_in_px / | 39 return size_in_px / |
| 41 display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor(); | 40 display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor(); |
| 42 } | 41 } |
| 43 | 42 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 56 params.fetch_valid_icon = true; | 55 params.fetch_valid_icon = true; |
| 57 | 56 |
| 58 return params; | 57 return params; |
| 59 } | 58 } |
| 60 | 59 |
| 61 } // anonymous namespace | 60 } // anonymous namespace |
| 62 | 61 |
| 63 namespace banners { | 62 namespace banners { |
| 64 | 63 |
| 65 // static | 64 // static |
| 66 void AppBannerManager::DisableSecureSchemeCheckForTesting() { | |
| 67 gDisableSecureCheckForTesting = true; | |
| 68 } | |
| 69 | |
| 70 // static | |
| 71 base::Time AppBannerManager::GetCurrentTime() { | 65 base::Time AppBannerManager::GetCurrentTime() { |
| 72 return base::Time::Now() + gTimeDeltaForTesting.Get(); | 66 return base::Time::Now() + gTimeDeltaForTesting.Get(); |
| 73 } | 67 } |
| 74 | 68 |
| 75 // static | 69 // static |
| 76 void AppBannerManager::SetTimeDeltaForTesting(int days) { | 70 void AppBannerManager::SetTimeDeltaForTesting(int days) { |
| 77 gTimeDeltaForTesting.Get() = base::TimeDelta::FromDays(days); | 71 gTimeDeltaForTesting.Get() = base::TimeDelta::FromDays(days); |
| 78 } | 72 } |
| 79 | 73 |
| 80 // static | 74 // static |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 need_to_log_status_ = !IsDebugMode(); | 106 need_to_log_status_ = !IsDebugMode(); |
| 113 | 107 |
| 114 if (contents->GetMainFrame()->GetParent()) { | 108 if (contents->GetMainFrame()->GetParent()) { |
| 115 ReportStatus(contents, NOT_IN_MAIN_FRAME); | 109 ReportStatus(contents, NOT_IN_MAIN_FRAME); |
| 116 Stop(); | 110 Stop(); |
| 117 return; | 111 return; |
| 118 } | 112 } |
| 119 | 113 |
| 120 // A secure origin is required to show banners, so exit early if we see the | 114 // A secure origin is required to show banners, so exit early if we see the |
| 121 // URL is invalid. | 115 // URL is invalid. |
| 122 if (!content::IsOriginSecure(validated_url) && | 116 if (!content::IsOriginSecure(validated_url)) { |
| 123 !gDisableSecureCheckForTesting) { | |
| 124 ReportStatus(contents, NOT_FROM_SECURE_ORIGIN); | 117 ReportStatus(contents, NOT_FROM_SECURE_ORIGIN); |
| 125 Stop(); | 118 Stop(); |
| 126 return; | 119 return; |
| 127 } | 120 } |
| 128 | 121 |
| 129 if (validated_url_.is_empty()) | 122 if (validated_url_.is_empty()) |
| 130 validated_url_ = validated_url; | 123 validated_url_ = validated_url; |
| 131 | 124 |
| 132 manager_->GetData( | 125 manager_->GetData( |
| 133 ParamsToGetManifest(), | 126 ParamsToGetManifest(), |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 // Don't reset |was_canceled_by_page_| yet for metrics purposes. | 526 // Don't reset |was_canceled_by_page_| yet for metrics purposes. |
| 534 OnBannerPromptReply(render_frame_host, request_id, | 527 OnBannerPromptReply(render_frame_host, request_id, |
| 535 blink::WebAppBannerPromptReply::None, referrer_); | 528 blink::WebAppBannerPromptReply::None, referrer_); |
| 536 } else { | 529 } else { |
| 537 // Log that the prompt request was made for when we get the prompt reply. | 530 // Log that the prompt request was made for when we get the prompt reply. |
| 538 page_requested_prompt_ = true; | 531 page_requested_prompt_ = true; |
| 539 } | 532 } |
| 540 } | 533 } |
| 541 | 534 |
| 542 } // namespace banners | 535 } // namespace banners |
| OLD | NEW |