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 #ifndef CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_
6 #define CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "chrome/browser/banners/app_banner_data_fetcher.h"
12 #include "content/public/browser/web_contents_observer.h"
13 #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerPromptReply.h"
16 struct FrameNavigateParams
;
17 struct LoadCommittedDetails
;
18 } // namespace content
21 class AppBannerDataFetcher
;
24 * Creates an app banner.
26 * Hooks the wiring together for getting the data for a particular app.
27 * Monitors at most one app at a time, tracking the info for the most recently
28 * requested app. Any work in progress for other apps is discarded.
30 class AppBannerManager
: public content::WebContentsObserver
,
31 public AppBannerDataFetcher::Delegate
{
33 static bool IsEnabled();
34 static void DisableSecureSchemeCheckForTesting();
36 // Returns whether or not the URLs match for everything except for the ref.
37 static bool URLsAreForTheSamePage(const GURL
& first
, const GURL
& second
);
39 explicit AppBannerManager(int icon_size
);
40 ~AppBannerManager() override
;
42 // WebContentsObserver overrides.
43 void DidFinishLoad(content::RenderFrameHost
* render_frame_host
,
44 const GURL
& validated_url
) override
;
46 // AppBannerDataFetcher::Delegate overrides.
47 bool OnInvalidManifest(AppBannerDataFetcher
* fetcher
) override
;
50 void ReplaceWebContents(content::WebContents
* web_contents
);
52 // Creates an AppBannerDataFetcher, which constructs an app banner.
53 virtual AppBannerDataFetcher
* CreateAppBannerDataFetcher(
54 base::WeakPtr
<AppBannerDataFetcher::Delegate
> weak_delegate
,
55 const int ideal_icon_size
);
57 // Return whether the AppBannerDataFetcher is active.
58 bool IsFetcherActive();
60 scoped_refptr
<AppBannerDataFetcher
> data_fetcher() { return data_fetcher_
; }
61 int ideal_icon_size() { return ideal_icon_size_
; }
64 // Called after the manager sends a message to the renderer regarding its
65 // intention to show a prompt. The renderer will send a message back with the
66 // opportunity to cancel.
67 void OnBannerPromptReply(content::RenderFrameHost
* render_frame_host
,
69 blink::WebAppBannerPromptReply reply
);
71 // Cancels an active DataFetcher, stopping its banners from appearing.
72 void CancelActiveFetcher();
74 // Ideal icon size to use.
75 const int ideal_icon_size_
;
77 // Fetches the data required to display a banner for the current page.
78 scoped_refptr
<AppBannerDataFetcher
> data_fetcher_
;
80 // A weak pointer is used as the lifetime of the ServiceWorkerContext is
81 // longer than the lifetime of this banner manager. The banner manager
82 // might be gone when calls sent to the ServiceWorkerContext are completed.
83 base::WeakPtrFactory
<AppBannerManager
> weak_factory_
;
85 DISALLOW_COPY_AND_ASSIGN(AppBannerManager
);
86 }; // class AppBannerManager
88 } // namespace banners
90 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_