Chromium Code Reviews| 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; | 33 bool gDisableSecureCheckForTesting = false; |
|
dominickn
2016/10/25 03:13:39
If you're removing the method, you should remove t
| |
| 34 int gCurrentRequestID = -1; | 34 int gCurrentRequestID = -1; |
| 35 base::LazyInstance<base::TimeDelta> gTimeDeltaForTesting = | 35 base::LazyInstance<base::TimeDelta> gTimeDeltaForTesting = |
| 36 LAZY_INSTANCE_INITIALIZER; | 36 LAZY_INSTANCE_INITIALIZER; |
| 37 | 37 |
| 38 // Returns |size_in_px| in dp, i.e. divided by the current device scale factor. | 38 // Returns |size_in_px| in dp, i.e. divided by the current device scale factor. |
| 39 int ConvertIconSizeFromPxToDp(int size_in_px) { | 39 int ConvertIconSizeFromPxToDp(int size_in_px) { |
| 40 return size_in_px / | 40 return size_in_px / |
| 41 display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor(); | 41 display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor(); |
| 42 } | 42 } |
| 43 | 43 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 56 params.fetch_valid_icon = true; | 56 params.fetch_valid_icon = true; |
| 57 | 57 |
| 58 return params; | 58 return params; |
| 59 } | 59 } |
| 60 | 60 |
| 61 } // anonymous namespace | 61 } // anonymous namespace |
| 62 | 62 |
| 63 namespace banners { | 63 namespace banners { |
| 64 | 64 |
| 65 // static | 65 // static |
| 66 void AppBannerManager::DisableSecureSchemeCheckForTesting() { | |
| 67 gDisableSecureCheckForTesting = true; | |
| 68 } | |
| 69 | |
| 70 // static | |
| 71 base::Time AppBannerManager::GetCurrentTime() { | 66 base::Time AppBannerManager::GetCurrentTime() { |
| 72 return base::Time::Now() + gTimeDeltaForTesting.Get(); | 67 return base::Time::Now() + gTimeDeltaForTesting.Get(); |
| 73 } | 68 } |
| 74 | 69 |
| 75 // static | 70 // static |
| 76 void AppBannerManager::SetTimeDeltaForTesting(int days) { | 71 void AppBannerManager::SetTimeDeltaForTesting(int days) { |
| 77 gTimeDeltaForTesting.Get() = base::TimeDelta::FromDays(days); | 72 gTimeDeltaForTesting.Get() = base::TimeDelta::FromDays(days); |
| 78 } | 73 } |
| 79 | 74 |
| 80 // static | 75 // static |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 need_to_log_status_ = !IsDebugMode(); | 107 need_to_log_status_ = !IsDebugMode(); |
| 113 | 108 |
| 114 if (contents->GetMainFrame()->GetParent()) { | 109 if (contents->GetMainFrame()->GetParent()) { |
| 115 ReportStatus(contents, NOT_IN_MAIN_FRAME); | 110 ReportStatus(contents, NOT_IN_MAIN_FRAME); |
| 116 Stop(); | 111 Stop(); |
| 117 return; | 112 return; |
| 118 } | 113 } |
| 119 | 114 |
| 120 // A secure origin is required to show banners, so exit early if we see the | 115 // A secure origin is required to show banners, so exit early if we see the |
| 121 // URL is invalid. | 116 // URL is invalid. |
| 117 LOG(ERROR) << validated_url; | |
|
dominickn
2016/10/25 03:13:39
Remove this log spam.
| |
| 122 if (!content::IsOriginSecure(validated_url) && | 118 if (!content::IsOriginSecure(validated_url) && |
| 123 !gDisableSecureCheckForTesting) { | 119 !gDisableSecureCheckForTesting) { |
|
dominickn
2016/10/25 03:13:39
Remove the check for the global here. It's useless
| |
| 124 ReportStatus(contents, NOT_FROM_SECURE_ORIGIN); | 120 ReportStatus(contents, NOT_FROM_SECURE_ORIGIN); |
| 125 Stop(); | 121 Stop(); |
| 126 return; | 122 return; |
| 127 } | 123 } |
| 128 | 124 |
| 129 if (validated_url_.is_empty()) | 125 if (validated_url_.is_empty()) |
| 130 validated_url_ = validated_url; | 126 validated_url_ = validated_url; |
| 131 | 127 |
| 132 manager_->GetData( | 128 manager_->GetData( |
| 133 ParamsToGetManifest(), | 129 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. | 529 // Don't reset |was_canceled_by_page_| yet for metrics purposes. |
| 534 OnBannerPromptReply(render_frame_host, request_id, | 530 OnBannerPromptReply(render_frame_host, request_id, |
| 535 blink::WebAppBannerPromptReply::None, referrer_); | 531 blink::WebAppBannerPromptReply::None, referrer_); |
| 536 } else { | 532 } else { |
| 537 // Log that the prompt request was made for when we get the prompt reply. | 533 // Log that the prompt request was made for when we get the prompt reply. |
| 538 page_requested_prompt_ = true; | 534 page_requested_prompt_ = true; |
| 539 } | 535 } |
| 540 } | 536 } |
| 541 | 537 |
| 542 } // namespace banners | 538 } // namespace banners |
| OLD | NEW |