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/metrics/field_trial.h" | 7 #include "base/metrics/field_trial.h" |
8 #include "chrome/browser/banners/app_banner_data_fetcher.h" | 8 #include "chrome/browser/banners/app_banner_data_fetcher.h" |
9 #include "chrome/browser/banners/app_banner_debug_log.h" | 9 #include "chrome/browser/banners/app_banner_debug_log.h" |
10 #include "chrome/browser/banners/app_banner_settings_helper.h" | 10 #include "chrome/browser/banners/app_banner_settings_helper.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 weak_factory_(this) { | 42 weak_factory_(this) { |
43 } | 43 } |
44 | 44 |
45 AppBannerManager::~AppBannerManager() { | 45 AppBannerManager::~AppBannerManager() { |
46 CancelActiveFetcher(); | 46 CancelActiveFetcher(); |
47 } | 47 } |
48 | 48 |
49 void AppBannerManager::DidFinishLoad( | 49 void AppBannerManager::DidFinishLoad( |
50 content::RenderFrameHost* render_frame_host, | 50 content::RenderFrameHost* render_frame_host, |
51 const GURL& validated_url) { | 51 const GURL& validated_url) { |
52 if (render_frame_host->GetParent()) | 52 if (!ValidateFrameHostAndOrigin(render_frame_host, validated_url)) |
benwells
2015/06/11 01:54:24
What is this change for?
dominickn (DO NOT USE)
2015/06/11 03:32:12
It was due to the former implementation of this fe
| |
53 return; | 53 return; |
54 | 54 |
55 if (data_fetcher_.get() && data_fetcher_->is_active() && | |
56 URLsAreForTheSamePage(data_fetcher_->validated_url(), validated_url)) { | |
57 return; | |
58 } | |
59 | |
60 // A secure origin is required to show banners, so exit early if we see the | |
61 // URL is invalid. | |
62 if (!content::IsOriginSecure(validated_url) && | |
63 !gDisableSecureCheckForTesting) { | |
64 OutputDeveloperNotShownMessage(web_contents(), kNotServedFromSecureOrigin); | |
65 return; | |
66 } | |
67 | |
68 // Kick off the data retrieval pipeline. | 55 // Kick off the data retrieval pipeline. |
69 data_fetcher_ = CreateAppBannerDataFetcher(weak_factory_.GetWeakPtr(), | 56 data_fetcher_ = CreateAppBannerDataFetcher(weak_factory_.GetWeakPtr(), |
70 ideal_icon_size_); | 57 ideal_icon_size_); |
71 data_fetcher_->Start(validated_url); | 58 data_fetcher_->Start(validated_url); |
72 } | 59 } |
73 | 60 |
74 bool AppBannerManager::HandleNonWebApp(const std::string& platform, | 61 bool AppBannerManager::HandleNonWebApp(const std::string& platform, |
75 const GURL& url, | 62 const GURL& url, |
76 const std::string& id) { | 63 const std::string& id) { |
77 return false; | 64 return false; |
78 } | 65 } |
79 | 66 |
67 bool AppBannerManager::ValidateFrameHostAndOrigin( | |
68 content::RenderFrameHost* render_frame_host, | |
69 const GURL& validated_url) { | |
70 if (render_frame_host->GetParent()) | |
71 return false; | |
72 | |
73 if (data_fetcher_.get() && data_fetcher_->is_active() && | |
74 URLsAreForTheSamePage(data_fetcher_->validated_url(), validated_url)) { | |
75 return false; | |
76 } | |
77 | |
78 // A secure origin is required to show banners, so exit early if we see the | |
79 // URL is invalid. | |
80 if (!content::IsOriginSecure(validated_url) && | |
81 !gDisableSecureCheckForTesting) { | |
82 OutputDeveloperNotShownMessage(web_contents(), kNotServedFromSecureOrigin); | |
83 return false; | |
84 } | |
85 return true; | |
86 } | |
87 | |
80 void AppBannerManager::ReplaceWebContents(content::WebContents* web_contents) { | 88 void AppBannerManager::ReplaceWebContents(content::WebContents* web_contents) { |
81 Observe(web_contents); | 89 Observe(web_contents); |
82 if (data_fetcher_.get()) | 90 if (data_fetcher_.get()) |
83 data_fetcher_.get()->ReplaceWebContents(web_contents); | 91 data_fetcher_.get()->ReplaceWebContents(web_contents); |
84 } | 92 } |
85 | 93 |
86 void AppBannerManager::CancelActiveFetcher() { | 94 void AppBannerManager::CancelActiveFetcher() { |
87 if (data_fetcher_ != nullptr) { | 95 if (data_fetcher_ != nullptr) { |
88 data_fetcher_->Cancel(); | 96 data_fetcher_->Cancel(); |
89 data_fetcher_ = nullptr; | 97 data_fetcher_ = nullptr; |
90 } | 98 } |
91 } | 99 } |
92 | 100 |
93 bool AppBannerManager::IsFetcherActive() { | 101 bool AppBannerManager::IsFetcherActive() { |
94 return data_fetcher_ != nullptr && data_fetcher_->is_active(); | 102 return data_fetcher_ != nullptr && data_fetcher_->is_active(); |
95 } | 103 } |
96 | 104 |
97 void AppBannerManager::DisableSecureSchemeCheckForTesting() { | 105 void AppBannerManager::DisableSecureSchemeCheckForTesting() { |
98 gDisableSecureCheckForTesting = true; | 106 gDisableSecureCheckForTesting = true; |
99 } | 107 } |
100 | 108 |
101 bool AppBannerManager::IsEnabled() { | 109 bool AppBannerManager::IsEnabled() { |
102 return base::FieldTrialList::FindFullName("AppBanners") == "Enabled"; | 110 return base::FieldTrialList::FindFullName("AppBanners") == "Enabled"; |
103 } | 111 } |
104 | 112 |
105 } // namespace banners | 113 } // namespace banners |
OLD | NEW |