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 23 matching lines...) Expand all Loading... |
34 weak_factory_(this) { | 34 weak_factory_(this) { |
35 } | 35 } |
36 | 36 |
37 AppBannerManager::~AppBannerManager() { | 37 AppBannerManager::~AppBannerManager() { |
38 CancelActiveFetcher(); | 38 CancelActiveFetcher(); |
39 } | 39 } |
40 | 40 |
41 void AppBannerManager::DidFinishLoad( | 41 void AppBannerManager::DidFinishLoad( |
42 content::RenderFrameHost* render_frame_host, | 42 content::RenderFrameHost* render_frame_host, |
43 const GURL& validated_url) { | 43 const GURL& validated_url) { |
44 if (render_frame_host->GetParent()) | 44 if (!ValidateFrameHostAndOrigin(render_frame_host, validated_url)) |
45 return; | 45 return; |
46 | 46 |
47 if (data_fetcher_.get() && data_fetcher_->is_active() && | |
48 URLsAreForTheSamePage(data_fetcher_->validated_url(), validated_url)) { | |
49 return; | |
50 } | |
51 | |
52 // A secure origin is required to show banners, so exit early if we see the | |
53 // URL is invalid. | |
54 if (!content::IsOriginSecure(validated_url) && | |
55 !gDisableSecureCheckForTesting) { | |
56 OutputDeveloperNotShownMessage(web_contents(), kNotServedFromSecureOrigin); | |
57 return; | |
58 } | |
59 | |
60 // Kick off the data retrieval pipeline. | 47 // Kick off the data retrieval pipeline. |
61 data_fetcher_ = CreateAppBannerDataFetcher(weak_factory_.GetWeakPtr(), | 48 data_fetcher_ = CreateAppBannerDataFetcher(weak_factory_.GetWeakPtr(), |
62 ideal_icon_size_); | 49 ideal_icon_size_); |
63 data_fetcher_->Start(validated_url); | 50 data_fetcher_->Start(validated_url); |
64 } | 51 } |
65 | 52 |
66 | 53 |
67 bool AppBannerManager::HandleNonWebApp(const std::string& platform, | 54 bool AppBannerManager::HandleNonWebApp(const std::string& platform, |
68 const GURL& url, | 55 const GURL& url, |
69 const std::string& id) { | 56 const std::string& id) { |
70 return false; | 57 return false; |
71 } | 58 } |
72 | 59 |
| 60 bool AppBannerManager::ValidateFrameHostAndOrigin( |
| 61 content::RenderFrameHost* render_frame_host, |
| 62 const GURL& validated_url) { |
| 63 if (render_frame_host->GetParent()) |
| 64 return false; |
| 65 |
| 66 if (data_fetcher_.get() && data_fetcher_->is_active() && |
| 67 URLsAreForTheSamePage(data_fetcher_->validated_url(), validated_url)) { |
| 68 return false; |
| 69 } |
| 70 |
| 71 // A secure origin is required to show banners, so exit early if we see the |
| 72 // URL is invalid. |
| 73 if (!content::IsOriginSecure(validated_url) && |
| 74 !gDisableSecureCheckForTesting) { |
| 75 OutputDeveloperNotShownMessage(web_contents(), kNotServedFromSecureOrigin); |
| 76 return false; |
| 77 } |
| 78 return true; |
| 79 } |
| 80 |
73 void AppBannerManager::ReplaceWebContents(content::WebContents* web_contents) { | 81 void AppBannerManager::ReplaceWebContents(content::WebContents* web_contents) { |
74 Observe(web_contents); | 82 Observe(web_contents); |
75 if (data_fetcher_.get()) | 83 if (data_fetcher_.get()) |
76 data_fetcher_.get()->ReplaceWebContents(web_contents); | 84 data_fetcher_.get()->ReplaceWebContents(web_contents); |
77 } | 85 } |
78 | 86 |
79 AppBannerDataFetcher* AppBannerManager::CreateAppBannerDataFetcher( | 87 AppBannerDataFetcher* AppBannerManager::CreateAppBannerDataFetcher( |
80 base::WeakPtr<AppBannerDataFetcher::Delegate> weak_delegate, | 88 base::WeakPtr<AppBannerDataFetcher::Delegate> weak_delegate, |
81 const int ideal_icon_size) { | 89 const int ideal_icon_size) { |
82 return new AppBannerDataFetcher(web_contents(), weak_delegate, | 90 return new AppBannerDataFetcher(web_contents(), weak_delegate, |
(...skipping 13 matching lines...) Expand all Loading... |
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 |