Chromium Code Reviews| 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" |
| 11 #include "content/public/browser/navigation_details.h" | 11 #include "content/public/browser/navigation_details.h" |
| 12 #include "content/public/browser/render_frame_host.h" | 12 #include "content/public/browser/render_frame_host.h" |
| 13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 14 #include "content/public/common/frame_navigate_params.h" | 14 #include "content/public/common/frame_navigate_params.h" |
| 15 #include "content/public/common/origin_util.h" | 15 #include "content/public/common/origin_util.h" |
| 16 #include "net/base/load_flags.h" | 16 #include "net/base/load_flags.h" |
| 17 #include "ui/gfx/screen.h" | 17 #include "ui/gfx/screen.h" |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 bool gDisableSecureCheckForTesting = false; | 20 bool gDisableSecureCheckForTesting = false; |
| 21 | |
| 22 // Used for non-mobile platforms. | |
| 23 int kMinimumIconSize = 144; | |
|
benwells
2015/06/02 05:53:35
Can we use the extension icon constant? At some po
dominickn (DO NOT USE)
2015/06/02 06:51:32
The extensions code isn't compiled on Android, so
| |
| 24 | |
| 21 } // anonymous namespace | 25 } // anonymous namespace |
| 22 | 26 |
| 27 DEFINE_WEB_CONTENTS_USER_DATA_KEY(banners::AppBannerManager); | |
| 28 | |
| 23 namespace banners { | 29 namespace banners { |
| 24 | 30 |
| 25 bool AppBannerManager::URLsAreForTheSamePage(const GURL& first, | 31 bool AppBannerManager::URLsAreForTheSamePage(const GURL& first, |
| 26 const GURL& second) { | 32 const GURL& second) { |
| 27 return first.GetWithEmptyPath() == second.GetWithEmptyPath() && | 33 return first.GetWithEmptyPath() == second.GetWithEmptyPath() && |
| 28 first.path() == second.path() && first.query() == second.query(); | 34 first.path() == second.path() && first.query() == second.query(); |
| 29 } | 35 } |
| 30 | 36 |
| 31 AppBannerManager::AppBannerManager(int icon_size) | 37 AppBannerManager::AppBannerManager(int icon_size) |
| 32 : ideal_icon_size_(icon_size), | 38 : ideal_icon_size_(icon_size), |
| 33 data_fetcher_(nullptr), | 39 data_fetcher_(nullptr), |
| 34 weak_factory_(this) { | 40 weak_factory_(this) { |
| 35 } | 41 } |
| 36 | 42 |
| 43 AppBannerManager::AppBannerManager(content::WebContents* web_contents) | |
| 44 : content::WebContentsObserver(web_contents), | |
| 45 ideal_icon_size_(kMinimumIconSize), | |
| 46 data_fetcher_(nullptr), | |
| 47 weak_factory_(this) { | |
| 48 } | |
| 49 | |
| 37 AppBannerManager::~AppBannerManager() { | 50 AppBannerManager::~AppBannerManager() { |
| 38 CancelActiveFetcher(); | 51 CancelActiveFetcher(); |
| 39 } | 52 } |
| 40 | 53 |
| 41 void AppBannerManager::DidFinishLoad( | 54 void AppBannerManager::DidFinishLoad( |
| 42 content::RenderFrameHost* render_frame_host, | 55 content::RenderFrameHost* render_frame_host, |
| 43 const GURL& validated_url) { | 56 const GURL& validated_url) { |
| 44 if (render_frame_host->GetParent()) | 57 if (render_frame_host->GetParent()) |
| 45 return; | 58 return; |
| 46 | 59 |
| 47 if (data_fetcher_.get() && data_fetcher_->is_active() && | 60 if (data_fetcher_.get() && data_fetcher_->is_active() && |
| 48 URLsAreForTheSamePage(data_fetcher_->validated_url(), validated_url)) { | 61 URLsAreForTheSamePage(data_fetcher_->validated_url(), validated_url)) { |
| 49 return; | 62 return; |
| 50 } | 63 } |
| 51 | 64 |
| 52 // A secure origin is required to show banners, so exit early if we see the | 65 // A secure origin is required to show banners, so exit early if we see the |
| 53 // URL is invalid. | 66 // URL is invalid. |
| 54 if (!content::IsOriginSecure(validated_url) && | 67 if (!content::IsOriginSecure(validated_url) && |
| 55 !gDisableSecureCheckForTesting) { | 68 !gDisableSecureCheckForTesting) { |
| 56 OutputDeveloperNotShownMessage(web_contents(), kNotServedFromSecureOrigin); | 69 OutputDeveloperNotShownMessage(web_contents(), kNotServedFromSecureOrigin); |
| 57 return; | 70 return; |
| 58 } | 71 } |
| 59 | 72 |
| 60 // Kick off the data retrieval pipeline. | 73 // Kick off the data retrieval pipeline. |
| 61 data_fetcher_ = CreateAppBannerDataFetcher(weak_factory_.GetWeakPtr(), | 74 data_fetcher_ = CreateAppBannerDataFetcher(weak_factory_.GetWeakPtr(), |
| 62 ideal_icon_size_); | 75 ideal_icon_size_); |
| 63 data_fetcher_->Start(validated_url); | 76 data_fetcher_->Start(validated_url); |
| 64 } | 77 } |
| 65 | 78 |
| 66 | |
| 67 bool AppBannerManager::HandleNonWebApp(const std::string& platform, | 79 bool AppBannerManager::HandleNonWebApp(const std::string& platform, |
| 68 const GURL& url, | 80 const GURL& url, |
| 69 const std::string& id) { | 81 const std::string& id) { |
| 70 return false; | 82 return false; |
| 71 } | 83 } |
| 72 | 84 |
| 73 void AppBannerManager::ReplaceWebContents(content::WebContents* web_contents) { | 85 void AppBannerManager::ReplaceWebContents(content::WebContents* web_contents) { |
| 74 Observe(web_contents); | 86 Observe(web_contents); |
| 75 if (data_fetcher_.get()) | 87 if (data_fetcher_.get()) |
| 76 data_fetcher_.get()->ReplaceWebContents(web_contents); | 88 data_fetcher_.get()->ReplaceWebContents(web_contents); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 96 | 108 |
| 97 void AppBannerManager::DisableSecureSchemeCheckForTesting() { | 109 void AppBannerManager::DisableSecureSchemeCheckForTesting() { |
| 98 gDisableSecureCheckForTesting = true; | 110 gDisableSecureCheckForTesting = true; |
| 99 } | 111 } |
| 100 | 112 |
| 101 bool AppBannerManager::IsEnabled() { | 113 bool AppBannerManager::IsEnabled() { |
| 102 return base::FieldTrialList::FindFullName("AppBanners") == "Enabled"; | 114 return base::FieldTrialList::FindFullName("AppBanners") == "Enabled"; |
| 103 } | 115 } |
| 104 | 116 |
| 105 } // namespace banners | 117 } // namespace banners |
| OLD | NEW |