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 16 matching lines...) Expand all Loading... |
27 return first.GetWithEmptyPath() == second.GetWithEmptyPath() && | 27 return first.GetWithEmptyPath() == second.GetWithEmptyPath() && |
28 first.path() == second.path() && first.query() == second.query(); | 28 first.path() == second.path() && first.query() == second.query(); |
29 } | 29 } |
30 | 30 |
31 AppBannerManager::AppBannerManager(int icon_size) | 31 AppBannerManager::AppBannerManager(int icon_size) |
32 : ideal_icon_size_(icon_size), | 32 : ideal_icon_size_(icon_size), |
33 data_fetcher_(nullptr), | 33 data_fetcher_(nullptr), |
34 weak_factory_(this) { | 34 weak_factory_(this) { |
35 } | 35 } |
36 | 36 |
| 37 AppBannerManager::AppBannerManager(content::WebContents* web_contents, |
| 38 int icon_size) |
| 39 : content::WebContentsObserver(web_contents), |
| 40 ideal_icon_size_(icon_size), |
| 41 data_fetcher_(nullptr), |
| 42 weak_factory_(this) { |
| 43 } |
| 44 |
37 AppBannerManager::~AppBannerManager() { | 45 AppBannerManager::~AppBannerManager() { |
38 CancelActiveFetcher(); | 46 CancelActiveFetcher(); |
39 } | 47 } |
40 | 48 |
41 void AppBannerManager::DidFinishLoad( | 49 void AppBannerManager::DidFinishLoad( |
42 content::RenderFrameHost* render_frame_host, | 50 content::RenderFrameHost* render_frame_host, |
43 const GURL& validated_url) { | 51 const GURL& validated_url) { |
44 if (render_frame_host->GetParent()) | 52 if (render_frame_host->GetParent()) |
45 return; | 53 return; |
46 | 54 |
47 if (data_fetcher_.get() && data_fetcher_->is_active() && | 55 if (data_fetcher_.get() && data_fetcher_->is_active() && |
48 URLsAreForTheSamePage(data_fetcher_->validated_url(), validated_url)) { | 56 URLsAreForTheSamePage(data_fetcher_->validated_url(), validated_url)) { |
49 return; | 57 return; |
50 } | 58 } |
51 | 59 |
52 // A secure origin is required to show banners, so exit early if we see the | 60 // A secure origin is required to show banners, so exit early if we see the |
53 // URL is invalid. | 61 // URL is invalid. |
54 if (!content::IsOriginSecure(validated_url) && | 62 if (!content::IsOriginSecure(validated_url) && |
55 !gDisableSecureCheckForTesting) { | 63 !gDisableSecureCheckForTesting) { |
56 OutputDeveloperNotShownMessage(web_contents(), kNotServedFromSecureOrigin); | 64 OutputDeveloperNotShownMessage(web_contents(), kNotServedFromSecureOrigin); |
57 return; | 65 return; |
58 } | 66 } |
59 | 67 |
60 // Kick off the data retrieval pipeline. | 68 // Kick off the data retrieval pipeline. |
61 data_fetcher_ = CreateAppBannerDataFetcher(weak_factory_.GetWeakPtr(), | 69 data_fetcher_ = CreateAppBannerDataFetcher(weak_factory_.GetWeakPtr(), |
62 ideal_icon_size_); | 70 ideal_icon_size_); |
63 data_fetcher_->Start(validated_url); | 71 data_fetcher_->Start(validated_url); |
64 } | 72 } |
65 | 73 |
66 | |
67 bool AppBannerManager::HandleNonWebApp(const std::string& platform, | 74 bool AppBannerManager::HandleNonWebApp(const std::string& platform, |
68 const GURL& url, | 75 const GURL& url, |
69 const std::string& id) { | 76 const std::string& id) { |
70 return false; | 77 return false; |
71 } | 78 } |
72 | 79 |
73 void AppBannerManager::ReplaceWebContents(content::WebContents* web_contents) { | 80 void AppBannerManager::ReplaceWebContents(content::WebContents* web_contents) { |
74 Observe(web_contents); | 81 Observe(web_contents); |
75 if (data_fetcher_.get()) | 82 if (data_fetcher_.get()) |
76 data_fetcher_.get()->ReplaceWebContents(web_contents); | 83 data_fetcher_.get()->ReplaceWebContents(web_contents); |
77 } | 84 } |
78 | 85 |
79 AppBannerDataFetcher* AppBannerManager::CreateAppBannerDataFetcher( | |
80 base::WeakPtr<AppBannerDataFetcher::Delegate> weak_delegate, | |
81 const int ideal_icon_size) { | |
82 return new AppBannerDataFetcher(web_contents(), weak_delegate, | |
83 ideal_icon_size); | |
84 } | |
85 | |
86 void AppBannerManager::CancelActiveFetcher() { | 86 void AppBannerManager::CancelActiveFetcher() { |
87 if (data_fetcher_ != nullptr) { | 87 if (data_fetcher_ != nullptr) { |
88 data_fetcher_->Cancel(); | 88 data_fetcher_->Cancel(); |
89 data_fetcher_ = nullptr; | 89 data_fetcher_ = nullptr; |
90 } | 90 } |
91 } | 91 } |
92 | 92 |
93 bool AppBannerManager::IsFetcherActive() { | 93 bool AppBannerManager::IsFetcherActive() { |
94 return data_fetcher_ != nullptr && data_fetcher_->is_active(); | 94 return data_fetcher_ != nullptr && data_fetcher_->is_active(); |
95 } | 95 } |
96 | 96 |
97 void AppBannerManager::DisableSecureSchemeCheckForTesting() { | 97 void AppBannerManager::DisableSecureSchemeCheckForTesting() { |
98 gDisableSecureCheckForTesting = true; | 98 gDisableSecureCheckForTesting = true; |
99 } | 99 } |
100 | 100 |
101 bool AppBannerManager::IsEnabled() { | 101 bool AppBannerManager::IsEnabled() { |
102 return base::FieldTrialList::FindFullName("AppBanners") == "Enabled"; | 102 return base::FieldTrialList::FindFullName("AppBanners") == "Enabled"; |
103 } | 103 } |
104 | 104 |
105 } // namespace banners | 105 } // namespace banners |
OLD | NEW |