[Media Router] Add integration tests and e2e tests for media router and presentation...
[chromium-blink-merge.git] / chrome / browser / banners / app_banner_manager.cc
blobdd3615d7c47fe25355a4d3a6ddfa439acaf7fdce
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
3 // found in the LICENSE file.
5 #include "chrome/browser/banners/app_banner_manager.h"
7 #include "base/metrics/field_trial.h"
8 #include "chrome/browser/banners/app_banner_data_fetcher.h"
9 #include "chrome/browser/banners/app_banner_debug_log.h"
10 #include "chrome/browser/banners/app_banner_settings_helper.h"
11 #include "content/public/browser/navigation_details.h"
12 #include "content/public/browser/render_frame_host.h"
13 #include "content/public/browser/web_contents.h"
14 #include "content/public/common/frame_navigate_params.h"
15 #include "content/public/common/origin_util.h"
16 #include "net/base/load_flags.h"
17 #include "ui/gfx/screen.h"
19 namespace {
20 bool gDisableSecureCheckForTesting = false;
21 } // anonymous namespace
23 namespace banners {
25 bool AppBannerManager::URLsAreForTheSamePage(const GURL& first,
26 const GURL& second) {
27 return first.GetWithEmptyPath() == second.GetWithEmptyPath() &&
28 first.path() == second.path() && first.query() == second.query();
31 AppBannerManager::AppBannerManager(int icon_size)
32 : ideal_icon_size_(icon_size),
33 data_fetcher_(nullptr),
34 weak_factory_(this) {
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) {
45 AppBannerManager::~AppBannerManager() {
46 CancelActiveFetcher();
49 void AppBannerManager::DidFinishLoad(
50 content::RenderFrameHost* render_frame_host,
51 const GURL& validated_url) {
52 if (render_frame_host->GetParent())
53 return;
55 if (data_fetcher_.get() && data_fetcher_->is_active() &&
56 URLsAreForTheSamePage(data_fetcher_->validated_url(), validated_url)) {
57 return;
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;
68 // Kick off the data retrieval pipeline.
69 data_fetcher_ = CreateAppBannerDataFetcher(weak_factory_.GetWeakPtr(),
70 ideal_icon_size_);
71 data_fetcher_->Start(validated_url);
74 bool AppBannerManager::HandleNonWebApp(const std::string& platform,
75 const GURL& url,
76 const std::string& id) {
77 return false;
80 void AppBannerManager::ReplaceWebContents(content::WebContents* web_contents) {
81 Observe(web_contents);
82 if (data_fetcher_.get())
83 data_fetcher_.get()->ReplaceWebContents(web_contents);
86 void AppBannerManager::CancelActiveFetcher() {
87 if (data_fetcher_ != nullptr) {
88 data_fetcher_->Cancel();
89 data_fetcher_ = nullptr;
93 bool AppBannerManager::IsFetcherActive() {
94 return data_fetcher_ != nullptr && data_fetcher_->is_active();
97 void AppBannerManager::DisableSecureSchemeCheckForTesting() {
98 gDisableSecureCheckForTesting = true;
101 bool AppBannerManager::IsEnabled() {
102 return base::FieldTrialList::FindFullName("AppBanners") == "Enabled";
105 } // namespace banners