blob: c11b4cb121197f0d7ab9d69e51142e5c318522aa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_
#define CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/banners/app_banner_data_fetcher.h"
#include "content/public/browser/web_contents_observer.h"
#include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerPromptReply.h"
namespace content {
struct FrameNavigateParams;
struct LoadCommittedDetails;
} // namespace content
namespace banners {
class AppBannerDataFetcher;
/**
* Creates an app banner.
*
* Hooks the wiring together for getting the data for a particular app.
* Monitors at most one app at a time, tracking the info for the most recently
* requested app. Any work in progress for other apps is discarded.
*/
class AppBannerManager : public content::WebContentsObserver,
public AppBannerDataFetcher::Delegate {
public:
static void DisableSecureSchemeCheckForTesting();
static void SetEngagementWeights(double direct_engagement,
double indirect_engagement);
// Returns whether or not the URLs match for everything except for the ref.
static bool URLsAreForTheSamePage(const GURL& first, const GURL& second);
AppBannerManager();
~AppBannerManager() override;
protected:
explicit AppBannerManager(content::WebContents* web_contents);
void ReplaceWebContents(content::WebContents* web_contents);
// Creates an AppBannerDataFetcher, which constructs an app banner.
virtual AppBannerDataFetcher* CreateAppBannerDataFetcher(
base::WeakPtr<AppBannerDataFetcher::Delegate> weak_delegate) = 0;
// Return whether the AppBannerDataFetcher is active.
bool IsFetcherActive();
scoped_refptr<AppBannerDataFetcher> data_fetcher() { return data_fetcher_; }
private:
// WebContentsObserver overrides.
void DidNavigateMainFrame(
const content::LoadCommittedDetails& details,
const content::FrameNavigateParams& params) override;
void DidFinishLoad(content::RenderFrameHost* render_frame_host,
const GURL& validated_url) override;
// AppBannerDataFetcher::Delegate overrides.
bool HandleNonWebApp(const std::string& platform,
const GURL& url,
const std::string& id) override;
// Cancels an active DataFetcher, stopping its banners from appearing.
void CancelActiveFetcher();
// The type of navigation made to the page
ui::PageTransition last_transition_type_;
// Fetches the data required to display a banner for the current page.
scoped_refptr<AppBannerDataFetcher> data_fetcher_;
// A weak pointer is used as the lifetime of the ServiceWorkerContext is
// longer than the lifetime of this banner manager. The banner manager
// might be gone when calls sent to the ServiceWorkerContext are completed.
base::WeakPtrFactory<AppBannerManager> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(AppBannerManager);
}; // class AppBannerManager
} // namespace banners
#endif // CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_
|