OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_H_ |
6 #define CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_H_ | 6 #define CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_H_ |
7 | 7 |
8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
9 #include "base/android/jni_weak_ref.h" | 9 #include "base/android/jni_weak_ref.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "chrome/browser/android/banners/app_banner_infobar_delegate.h" | 13 #include "chrome/browser/android/banners/app_banner_infobar_delegate.h" |
14 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" | 14 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" |
15 #include "chrome/browser/ui/android/infobars/app_banner_infobar.h" | 15 #include "chrome/browser/ui/android/infobars/app_banner_infobar.h" |
16 #include "components/infobars/core/infobar_manager.h" | 16 #include "components/infobars/core/infobar_manager.h" |
17 #include "content/public/browser/web_contents_observer.h" | 17 #include "content/public/browser/web_contents_observer.h" |
18 #include "content/public/common/manifest.h" | 18 #include "content/public/common/manifest.h" |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 struct FrameNavigateParams; | 21 struct FrameNavigateParams; |
22 struct LoadCommittedDetails; | 22 struct LoadCommittedDetails; |
23 struct Manifest; | |
24 } // namespace content | 23 } // namespace content |
25 | 24 |
26 namespace infobars { | 25 namespace infobars { |
27 class InfoBar; | 26 class InfoBar; |
28 } // namspace infobars | 27 } // namspace infobars |
29 | 28 |
30 /** | 29 /** |
31 * Manages when an app banner is created or dismissed. | 30 * Manages when an app banner is created or dismissed. |
32 * | 31 * |
33 * Hooks the wiring together for getting the data for a particular app. | 32 * Hooks the wiring together for getting the data for a particular app. |
(...skipping 27 matching lines...) Expand all Loading... |
61 * | 60 * |
62 * Because of the asynchronous nature of this pipeline, it's entirely possible | 61 * Because of the asynchronous nature of this pipeline, it's entirely possible |
63 * that a request to show a banner is interrupted by another request. The | 62 * that a request to show a banner is interrupted by another request. The |
64 * Java side manages what happens in these situations, which will usually result | 63 * Java side manages what happens in these situations, which will usually result |
65 * in dropping the old banner request on the floor. | 64 * in dropping the old banner request on the floor. |
66 */ | 65 */ |
67 | 66 |
68 namespace banners { | 67 namespace banners { |
69 | 68 |
70 class AppBannerManager : public chrome::BitmapFetcherDelegate, | 69 class AppBannerManager : public chrome::BitmapFetcherDelegate, |
71 public content::WebContentsObserver, | 70 public content::WebContentsObserver { |
72 public AppBannerInfoBarDelegate::AppDelegate { | |
73 public: | 71 public: |
74 AppBannerManager(JNIEnv* env, jobject obj); | 72 AppBannerManager(JNIEnv* env, jobject obj); |
75 ~AppBannerManager() override; | 73 ~AppBannerManager() override; |
76 | 74 |
77 // Destroys the AppBannerManager. | 75 // Destroys the AppBannerManager. |
78 void Destroy(JNIEnv* env, jobject obj); | 76 void Destroy(JNIEnv* env, jobject obj); |
79 | 77 |
80 // Blocks a banner for |package_name| from appearing on the domain for |url|. | |
81 void BlockBanner(JNIEnv* env, jobject obj, jstring jurl, jstring jpackage); | |
82 | |
83 // Observes a new WebContents, if necessary. | 78 // Observes a new WebContents, if necessary. |
84 void ReplaceWebContents(JNIEnv* env, | 79 void ReplaceWebContents(JNIEnv* env, |
85 jobject obj, | 80 jobject obj, |
86 jobject jweb_contents); | 81 jobject jweb_contents); |
87 | 82 |
88 // Called when the Java-side has retrieved information for the app. | 83 // Called when the Java-side has retrieved information for the app. |
89 // Returns |false| if an icon fetch couldn't be kicked off. | 84 // Returns |false| if an icon fetch couldn't be kicked off. |
90 bool OnAppDetailsRetrieved(JNIEnv* env, | 85 bool OnAppDetailsRetrieved(JNIEnv* env, |
91 jobject obj, | 86 jobject obj, |
92 jobject japp_data, | 87 jobject japp_data, |
93 jstring japp_title, | 88 jstring japp_title, |
94 jstring japp_package, | 89 jstring japp_package, |
95 jstring jicon_url); | 90 jstring jicon_url); |
96 | 91 |
97 // Called when the installation Intent has been handled and focus has been | |
98 // returned to Chrome. | |
99 void OnInstallIntentReturned(JNIEnv* env, | |
100 jobject obj, | |
101 jboolean jis_installing); | |
102 | |
103 // Called when the InstallerDelegate task has finished. | |
104 void OnInstallFinished(JNIEnv* env, | |
105 jobject obj, | |
106 jboolean success); | |
107 | |
108 // Fetches the icon at the given URL asynchronously. | 92 // Fetches the icon at the given URL asynchronously. |
109 // Returns |false| if this couldn't be kicked off. | 93 // Returns |false| if this couldn't be kicked off. |
110 bool FetchIcon(const GURL& image_url); | 94 bool FetchIcon(const GURL& image_url); |
111 | 95 |
112 // Installs the app defined by the manifest. | |
113 // TODO(dfalcantara): Fold into Install() when more CLs land. | |
114 static void InstallManifestApp(const content::Manifest& manifest, | |
115 const SkBitmap& icon); | |
116 | |
117 // Called when the AppBannerInfoBar's button needs to be updated. | |
118 void UpdateInstallState(JNIEnv* env, jobject obj); | |
119 | |
120 // WebContentsObserver overrides. | 96 // WebContentsObserver overrides. |
121 void DidNavigateMainFrame( | 97 void DidNavigateMainFrame( |
122 const content::LoadCommittedDetails& details, | 98 const content::LoadCommittedDetails& details, |
123 const content::FrameNavigateParams& params) override; | 99 const content::FrameNavigateParams& params) override; |
124 void DidFinishLoad(content::RenderFrameHost* render_frame_host, | 100 void DidFinishLoad(content::RenderFrameHost* render_frame_host, |
125 const GURL& validated_url) override; | 101 const GURL& validated_url) override; |
126 bool OnMessageReceived(const IPC::Message& message) override; | 102 bool OnMessageReceived(const IPC::Message& message) override; |
127 | 103 |
128 // BitmapFetcherDelegate overrides. | 104 // BitmapFetcherDelegate overrides. |
129 void OnFetchComplete(const GURL url, const SkBitmap* bitmap) override; | 105 void OnFetchComplete(const GURL url, const SkBitmap* bitmap) override; |
130 | 106 |
131 // AppBannerInfoBarDelegate::AppDelegate overrides. | |
132 void Block() const override; | |
133 bool OnButtonClicked() const override; | |
134 bool OnLinkClicked() const override; | |
135 void OnInfoBarDestroyed() override; | |
136 base::string16 GetTitle() const override; | |
137 gfx::Image GetIcon() const override; | |
138 | |
139 private: | 107 private: |
140 // Gets the preferred icon size for the banner icons. | 108 // Gets the preferred icon size for the banner icons. |
141 int GetPreferredIconSize(); | 109 int GetPreferredIconSize(); |
142 | 110 |
143 // Called when the manifest has been retrieved, or if there is no manifest to | 111 // Called when the manifest has been retrieved, or if there is no manifest to |
144 // retrieve. | 112 // retrieve. |
145 void OnDidGetManifest(const content::Manifest& manifest); | 113 void OnDidGetManifest(const content::Manifest& manifest); |
146 | 114 |
147 // Called when the renderer has returned information about the meta tag. | 115 // Called when the renderer has returned information about the meta tag. |
148 // If there is some metadata for the play store tag, this kicks off the | 116 // If there is some metadata for the play store tag, this kicks off the |
(...skipping 13 matching lines...) Expand all Loading... |
162 | 130 |
163 // Check if the banner should be shown. | 131 // Check if the banner should be shown. |
164 bool CheckIfShouldShow(const std::string& package_or_start_url); | 132 bool CheckIfShouldShow(const std::string& package_or_start_url); |
165 | 133 |
166 // Fetches the icon for an app. | 134 // Fetches the icon for an app. |
167 scoped_ptr<chrome::BitmapFetcher> fetcher_; | 135 scoped_ptr<chrome::BitmapFetcher> fetcher_; |
168 GURL validated_url_; | 136 GURL validated_url_; |
169 GURL app_icon_url_; | 137 GURL app_icon_url_; |
170 | 138 |
171 base::string16 app_title_; | 139 base::string16 app_title_; |
172 scoped_ptr<SkBitmap> app_icon_; | |
173 | 140 |
174 content::Manifest web_app_data_; | 141 content::Manifest web_app_data_; |
175 | 142 |
176 base::android::ScopedJavaGlobalRef<jobject> native_app_data_; | 143 base::android::ScopedJavaGlobalRef<jobject> native_app_data_; |
177 std::string native_app_package_; | 144 std::string native_app_package_; |
178 | 145 |
179 // Weak pointer to the InfoBar that is being managed. | |
180 AppBannerInfoBar* weak_infobar_ptr_; | |
181 | |
182 // AppBannerManager on the Java side. | 146 // AppBannerManager on the Java side. |
183 JavaObjectWeakGlobalRef weak_java_banner_view_manager_; | 147 JavaObjectWeakGlobalRef weak_java_banner_view_manager_; |
184 | 148 |
185 // A weak pointer is used as the lifetime of the ServiceWorkerContext is | 149 // A weak pointer is used as the lifetime of the ServiceWorkerContext is |
186 // longer than the lifetime of this banner manager. The banner manager | 150 // longer than the lifetime of this banner manager. The banner manager |
187 // might be gone when calls sent to the ServiceWorkerContext are completed. | 151 // might be gone when calls sent to the ServiceWorkerContext are completed. |
188 base::WeakPtrFactory<AppBannerManager> weak_factory_; | 152 base::WeakPtrFactory<AppBannerManager> weak_factory_; |
189 | 153 |
190 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); | 154 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); |
191 }; // class AppBannerManager | 155 }; // class AppBannerManager |
192 | 156 |
193 // Register native methods | 157 // Register native methods |
194 bool RegisterAppBannerManager(JNIEnv* env); | 158 bool RegisterAppBannerManager(JNIEnv* env); |
195 | 159 |
196 } // namespace banners | 160 } // namespace banners |
197 | 161 |
198 #endif // CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_H_ | 162 #endif // CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_H_ |
OLD | NEW |