| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 // static | 73 // static |
| 74 bool AppBannerManager::URLsAreForTheSamePage(const GURL& first, | 74 bool AppBannerManager::URLsAreForTheSamePage(const GURL& first, |
| 75 const GURL& second) { | 75 const GURL& second) { |
| 76 return first.GetWithEmptyPath() == second.GetWithEmptyPath() && | 76 return first.GetWithEmptyPath() == second.GetWithEmptyPath() && |
| 77 first.path_piece() == second.path_piece() && | 77 first.path_piece() == second.path_piece() && |
| 78 first.query_piece() == second.query_piece(); | 78 first.query_piece() == second.query_piece(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void AppBannerManager::RequestAppBanner(const GURL& validated_url, | 81 void AppBannerManager::RequestAppBanner(const GURL& validated_url, |
| 82 bool is_debug_mode) { | 82 bool is_debug_mode) { |
| 83 content::WebContents* contents = web_contents(); |
| 84 |
| 83 // Don't start a redundant banner request. Otherwise, if one is running, | 85 // Don't start a redundant banner request. Otherwise, if one is running, |
| 84 // invalidate our weak pointers so it terminates. | 86 // invalidate our weak pointers so it terminates. |
| 85 content::WebContents* contents = web_contents(); | |
| 86 if (is_active_) { | 87 if (is_active_) { |
| 87 if (URLsAreForTheSamePage(validated_url, contents->GetLastCommittedURL())) | 88 if (URLsAreForTheSamePage(validated_url, contents->GetLastCommittedURL())) |
| 88 return; | 89 return; |
| 89 else | 90 else |
| 90 weak_factory_.InvalidateWeakPtrs(); | 91 weak_factory_.InvalidateWeakPtrs(); |
| 91 } | 92 } |
| 92 | 93 |
| 93 is_active_ = true; | 94 is_active_ = true; |
| 94 is_debug_mode_ = is_debug_mode; | 95 is_debug_mode_ = is_debug_mode; |
| 95 | 96 |
| 96 // We only need to call ReportStatus if we aren't in debug mode (this avoids | 97 // We only need to call ReportStatus if we aren't in debug mode (this avoids |
| 97 // skew from testing). | 98 // skew from testing). |
| 98 DCHECK(!need_to_log_status_); | 99 DCHECK(!need_to_log_status_); |
| 99 need_to_log_status_ = !IsDebugMode(); | 100 need_to_log_status_ = !IsDebugMode(); |
| 100 | 101 |
| 101 if (contents->GetMainFrame()->GetParent()) { | 102 // Exit if this is an incognito window, non-main frame, or insecure context. |
| 102 ReportStatus(contents, NOT_IN_MAIN_FRAME); | 103 InstallableStatusCode code = NO_ERROR_DETECTED; |
| 103 Stop(); | 104 if (Profile::FromBrowserContext(contents->GetBrowserContext()) |
| 104 return; | 105 ->IsOffTheRecord()) { |
| 106 code = IN_INCOGNITO; |
| 107 } else if (contents->GetMainFrame()->GetParent()) { |
| 108 code = NOT_IN_MAIN_FRAME; |
| 109 } else if (!content::IsOriginSecure(validated_url)) { |
| 110 code = NOT_FROM_SECURE_ORIGIN; |
| 105 } | 111 } |
| 106 | 112 |
| 107 // A secure origin is required to show banners, so exit early if we see the | 113 if (code != NO_ERROR_DETECTED) { |
| 108 // URL is invalid. | |
| 109 if (!content::IsOriginSecure(validated_url)) { | |
| 110 ReportStatus(contents, NOT_FROM_SECURE_ORIGIN); | 114 ReportStatus(contents, NOT_FROM_SECURE_ORIGIN); |
| 111 Stop(); | 115 Stop(); |
| 112 return; | 116 return; |
| 113 } | 117 } |
| 114 | 118 |
| 115 if (validated_url_.is_empty()) | 119 if (validated_url_.is_empty()) |
| 116 validated_url_ = validated_url; | 120 validated_url_ = validated_url; |
| 117 | 121 |
| 118 // Any existing binding is invalid when we request a new banner. | 122 // Any existing binding is invalid when we request a new banner. |
| 119 if (binding_.is_bound()) | 123 if (binding_.is_bound()) |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 // Simulate a non-canceled OnBannerPromptReply to show the delayed banner. | 540 // Simulate a non-canceled OnBannerPromptReply to show the delayed banner. |
| 537 // Don't reset |was_canceled_by_page_| yet for metrics purposes. | 541 // Don't reset |was_canceled_by_page_| yet for metrics purposes. |
| 538 OnBannerPromptReply(blink::mojom::AppBannerPromptReply::NONE, referrer_); | 542 OnBannerPromptReply(blink::mojom::AppBannerPromptReply::NONE, referrer_); |
| 539 } else { | 543 } else { |
| 540 // Log that the prompt request was made for when we get the prompt reply. | 544 // Log that the prompt request was made for when we get the prompt reply. |
| 541 page_requested_prompt_ = true; | 545 page_requested_prompt_ = true; |
| 542 } | 546 } |
| 543 } | 547 } |
| 544 | 548 |
| 545 } // namespace banners | 549 } // namespace banners |
| OLD | NEW |