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