Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / banners / app_banner_manager.h
blob97623e4fa2ac59aae3686df86de723cfb7c93fc5
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"
15 namespace content {
16 struct FrameNavigateParams;
17 struct LoadCommittedDetails;
18 } // namespace content
20 namespace banners {
21 class AppBannerDataFetcher;
23 /**
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 {
32 public:
33 static void DisableSecureSchemeCheckForTesting();
35 static void SetEngagementWeights(double direct_engagement,
36 double indirect_engagement);
38 // Returns whether or not the URLs match for everything except for the ref.
39 static bool URLsAreForTheSamePage(const GURL& first, const GURL& second);
41 explicit AppBannerManager(int ideal_icon_size_in_dp);
42 ~AppBannerManager() override;
44 // WebContentsObserver overrides.
45 void DidCommitProvisionalLoadForFrame(
46 content::RenderFrameHost* render_frame_host,
47 const GURL& url,
48 ui::PageTransition transition_type) override;
50 void DidFinishLoad(content::RenderFrameHost* render_frame_host,
51 const GURL& validated_url) override;
53 protected:
54 AppBannerManager(content::WebContents* web_contents,
55 int ideal_icon_size_in_dp);
57 void ReplaceWebContents(content::WebContents* web_contents);
59 // Creates an AppBannerDataFetcher, which constructs an app banner.
60 virtual AppBannerDataFetcher* CreateAppBannerDataFetcher(
61 base::WeakPtr<AppBannerDataFetcher::Delegate> weak_delegate,
62 const int ideal_icon_size_in_dp) = 0;
64 // Return whether the AppBannerDataFetcher is active.
65 bool IsFetcherActive();
67 scoped_refptr<AppBannerDataFetcher> data_fetcher() { return data_fetcher_; }
68 int ideal_icon_size_in_dp() const { return ideal_icon_size_in_dp_; }
70 private:
71 // AppBannerDataFetcher::Delegate overrides.
72 bool HandleNonWebApp(const std::string& platform,
73 const GURL& url,
74 const std::string& id) override;
76 // Called after the manager sends a message to the renderer regarding its
77 // intention to show a prompt. The renderer will send a message back with the
78 // opportunity to cancel.
79 void OnBannerPromptReply(content::RenderFrameHost* render_frame_host,
80 int request_id,
81 blink::WebAppBannerPromptReply reply);
83 // Cancels an active DataFetcher, stopping its banners from appearing.
84 void CancelActiveFetcher();
86 // Ideal icon size to use.
87 const int ideal_icon_size_in_dp_;
89 // The type of navigation made to the page
90 ui::PageTransition last_transition_type_;
92 // Fetches the data required to display a banner for the current page.
93 scoped_refptr<AppBannerDataFetcher> data_fetcher_;
95 // A weak pointer is used as the lifetime of the ServiceWorkerContext is
96 // longer than the lifetime of this banner manager. The banner manager
97 // might be gone when calls sent to the ServiceWorkerContext are completed.
98 base::WeakPtrFactory<AppBannerManager> weak_factory_;
100 DISALLOW_COPY_AND_ASSIGN(AppBannerManager);
101 }; // class AppBannerManager
103 } // namespace banners
105 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_