ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / android / banners / app_banner_manager.h
blob78aa3d3e48cc0645030313e9dc591407cd49edf7
1 // Copyright 2014 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_ANDROID_BANNERS_APP_BANNER_MANAGER_H_
6 #define CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_H_
8 #include "base/android/jni_android.h"
9 #include "base/android/jni_weak_ref.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/time/time.h"
14 #include "chrome/browser/android/banners/app_banner_infobar_delegate.h"
15 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h"
16 #include "chrome/browser/ui/android/infobars/app_banner_infobar.h"
17 #include "components/infobars/core/infobar_manager.h"
18 #include "content/public/browser/web_contents_observer.h"
19 #include "content/public/common/manifest.h"
21 namespace content {
22 struct FrameNavigateParams;
23 struct LoadCommittedDetails;
24 } // namespace content
26 namespace infobars {
27 class InfoBar;
28 } // namspace infobars
30 /**
31 * Manages when an app banner is created or dismissed.
33 * Hooks the wiring together for getting the data for a particular app.
34 * Monitors at most one app at a time, tracking the info for the most recently
35 * requested app. Any work in progress for other apps is discarded.
37 * TODO(dfalcantara): Update this when the pipeline requirements resolidify.
40 namespace banners {
42 class AppBannerManager : public content::WebContentsObserver {
43 public:
44 class BannerBitmapFetcher;
46 AppBannerManager(JNIEnv* env, jobject obj, int icon_size);
47 ~AppBannerManager() override;
49 // Destroys the AppBannerManager.
50 void Destroy(JNIEnv* env, jobject obj);
52 // Observes a new WebContents, if necessary.
53 void ReplaceWebContents(JNIEnv* env,
54 jobject obj,
55 jobject jweb_contents);
57 // Called when the Java-side has retrieved information for the app.
58 // Returns |false| if an icon fetch couldn't be kicked off.
59 bool OnAppDetailsRetrieved(JNIEnv* env,
60 jobject obj,
61 jobject japp_data,
62 jstring japp_title,
63 jstring japp_package,
64 jstring jicon_url);
66 // Fetches the icon at the given URL asynchronously.
67 // Returns |false| if this couldn't be kicked off.
68 bool FetchIcon(const GURL& image_url);
70 // Called when everything required to show a banner is ready.
71 void OnFetchComplete(BannerBitmapFetcher* fetcher,
72 const GURL url,
73 const SkBitmap* icon);
75 // Return whether a BitmapFetcher is active.
76 bool IsFetcherActive(JNIEnv* env, jobject jobj);
78 // Returns the current time.
79 static base::Time GetCurrentTime();
81 // WebContentsObserver overrides.
82 void DidNavigateMainFrame(
83 const content::LoadCommittedDetails& details,
84 const content::FrameNavigateParams& params) override;
85 void DidFinishLoad(content::RenderFrameHost* render_frame_host,
86 const GURL& validated_url) override;
87 bool OnMessageReceived(const IPC::Message& message) override;
89 private:
90 friend class AppBannerManagerTest;
92 // Returns whether the given Manifest is following the requirements to show
93 // a web app banner.
94 static bool IsManifestValid(const content::Manifest& manifest);
96 // Called when the manifest has been retrieved, or if there is no manifest to
97 // retrieve.
98 void OnDidGetManifest(const content::Manifest& manifest);
100 // Called when the renderer has returned information about the meta tag.
101 // If there is some metadata for the play store tag, this kicks off the
102 // process of showing a banner for the package designated by |tag_content| on
103 // the page at the |expected_url|.
104 void OnDidRetrieveMetaTagContent(bool success,
105 const std::string& tag_name,
106 const std::string& tag_content,
107 const GURL& expected_url);
109 // Called when the result of the CheckHasServiceWorker query has completed.
110 void OnDidCheckHasServiceWorker(bool has_service_worker);
112 // Record that the banner could be shown at this point, if the triggering
113 // heuristic allowed.
114 void RecordCouldShowBanner(const std::string& package_or_start_url);
116 // Check if the banner should be shown.
117 bool CheckIfShouldShow(const std::string& package_or_start_url);
119 // Cancels an active BitmapFetcher, stopping its banner from appearing.
120 void CancelActiveFetcher();
122 // Whether or not the banners should appear for native apps.
123 static bool IsEnabledForNativeApps();
125 // Icon size that we want to be use for the launcher.
126 const int preferred_icon_size_;
128 // Fetches the icon for an app. Weakly held because they delete themselves.
129 BannerBitmapFetcher* fetcher_;
131 GURL validated_url_;
132 GURL app_icon_url_;
134 base::string16 app_title_;
136 content::Manifest web_app_data_;
138 base::android::ScopedJavaGlobalRef<jobject> native_app_data_;
139 std::string native_app_package_;
141 // AppBannerManager on the Java side.
142 JavaObjectWeakGlobalRef weak_java_banner_view_manager_;
144 // A weak pointer is used as the lifetime of the ServiceWorkerContext is
145 // longer than the lifetime of this banner manager. The banner manager
146 // might be gone when calls sent to the ServiceWorkerContext are completed.
147 base::WeakPtrFactory<AppBannerManager> weak_factory_;
149 DISALLOW_COPY_AND_ASSIGN(AppBannerManager);
150 }; // class AppBannerManager
152 // Register native methods
153 bool RegisterAppBannerManager(JNIEnv* env);
155 } // namespace banners
157 #endif // CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_H_