Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(389)

Side by Side Diff: chrome/browser/android/banners/app_banner_infobar_delegate_android.h

Issue 2290603005: Trigger app banner when add to homescreen is pressed and WebAPKs are enabled. (Closed)
Patch Set: Nits. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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_INFOBAR_DELEGATE_ANDROID_H_ 5 #ifndef CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_INFOBAR_DELEGATE_ANDROID_H_
6 #define CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_INFOBAR_DELEGATE_ANDROID_H_ 6 #define CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_INFOBAR_DELEGATE_ANDROID_H_
7 7
8 #include "base/android/scoped_java_ref.h" 8 #include "base/android/scoped_java_ref.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 #include "chrome/browser/banners/app_banner_manager.h" 12 #include "chrome/browser/banners/app_banner_manager.h"
13 #include "components/infobars/core/confirm_infobar_delegate.h" 13 #include "components/infobars/core/confirm_infobar_delegate.h"
14 #include "content/public/common/manifest.h"
15 #include "ui/gfx/image/image.h" 14 #include "ui/gfx/image/image.h"
16 #include "url/gurl.h" 15 #include "url/gurl.h"
17 16
18 namespace content { 17 namespace content {
19 class WebContents; 18 class WebContents;
20 } 19 }
21 20
22 namespace infobars { 21 namespace infobars {
23 class InfoBarManager; 22 class InfoBarManager;
24 } 23 }
25 24
26 class AppBannerInfoBar; 25 class AppBannerInfoBar;
26 struct ShortcutInfo;
27 27
28 namespace banners { 28 namespace banners {
29 29
30 // Manages installation of an app being promoted by a page. 30 // Manages installation of an app being promoted by a page.
31 class AppBannerInfoBarDelegateAndroid : public ConfirmInfoBarDelegate { 31 class AppBannerInfoBarDelegateAndroid : public ConfirmInfoBarDelegate {
32 public: 32 public:
33 // Delegate for promoting a web app. 33 // Delegate for promoting a web app.
34 AppBannerInfoBarDelegateAndroid( 34 AppBannerInfoBarDelegateAndroid(
Peter Kasting 2016/09/06 19:31:23 Infobar delegate classes shouldn't have public con
Xi Han 2016/09/07 15:53:17 Done.
35 base::WeakPtr<AppBannerManager> weak_manager, 35 base::WeakPtr<AppBannerManager> weak_manager,
36 const base::string16& app_title, 36 const base::string16& app_title,
37 const GURL& manifest_url, 37 std::unique_ptr<ShortcutInfo> info,
Peter Kasting 2016/09/06 19:31:23 Why are you passing and storing this by unique_ptr
Xi Han 2016/09/07 15:53:17 Mostly because it is empty when the delegate is in
Peter Kasting 2016/09/08 04:56:56 That makes sense for now. It seems like this can
38 const content::Manifest& manifest,
39 const GURL& icon_url,
40 std::unique_ptr<SkBitmap> icon, 38 std::unique_ptr<SkBitmap> icon,
41 int event_request_id, 39 int event_request_id,
42 bool is_webapk); 40 bool is_webapk);
43 41
44 // Delegate for promoting an Android app. 42 // Delegate for promoting an Android app.
45 AppBannerInfoBarDelegateAndroid( 43 AppBannerInfoBarDelegateAndroid(
Peter Kasting 2016/09/06 19:31:23 Strongly consider splitting this infobar delegate
Xi Han 2016/09/07 15:53:17 I agree, but I assume it is a big refactoring. It
Peter Kasting 2016/09/08 04:56:56 I'm fine with that.
46 const base::string16& app_title, 44 const base::string16& app_title,
47 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, 45 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data,
48 std::unique_ptr<SkBitmap> icon, 46 std::unique_ptr<SkBitmap> icon,
49 const std::string& native_app_package, 47 const std::string& native_app_package,
50 const std::string& referrer, 48 const std::string& referrer,
51 int event_request_id); 49 int event_request_id);
52 50
53 ~AppBannerInfoBarDelegateAndroid() override; 51 ~AppBannerInfoBarDelegateAndroid() override;
54 52
55 // Called when the AppBannerInfoBar's button needs to be updated. 53 // Called when the AppBannerInfoBar's button needs to be updated.
56 void UpdateInstallState(JNIEnv* env, 54 void UpdateInstallState(JNIEnv* env,
57 const base::android::JavaParamRef<jobject>& obj); 55 const base::android::JavaParamRef<jobject>& obj);
58 56
59 // Called when the installation Intent has been handled and focus has been 57 // Called when the installation Intent has been handled and focus has been
60 // returned to Chrome. 58 // returned to Chrome.
61 void OnInstallIntentReturned(JNIEnv* env, 59 void OnInstallIntentReturned(JNIEnv* env,
62 const base::android::JavaParamRef<jobject>& obj, 60 const base::android::JavaParamRef<jobject>& obj,
63 jboolean jis_installing); 61 jboolean jis_installing);
64 62
65 // Called when the InstallerDelegate task has finished. 63 // Called when the InstallerDelegate task has finished.
66 void OnInstallFinished(JNIEnv* env, 64 void OnInstallFinished(JNIEnv* env,
67 const base::android::JavaParamRef<jobject>& obj, 65 const base::android::JavaParamRef<jobject>& obj,
68 jboolean success); 66 jboolean success);
69 67
68 // Called when user clicks the "Add To Homescreen" from the app menu to
69 // install a WebAPK. This function sets the text on infobar to "Adding" and
70 // disables the button to avoid user interaction. It also starts the WebAPK's
71 // installation process automatically.
72 void InstallWebApk(content::WebContents* web_contents);
73
70 private: 74 private:
71 void CreateJavaDelegate(); 75 void CreateJavaDelegate();
72 bool AcceptNativeApp(content::WebContents* web_contents); 76 bool AcceptNativeApp(content::WebContents* web_contents);
73 bool AcceptWebApp(content::WebContents* web_contents); 77 bool AcceptWebApp(content::WebContents* web_contents);
74 bool AcceptWebApk(content::WebContents* web_contents); 78 bool AcceptWebApk(content::WebContents* web_contents);
75 void SendBannerAccepted(content::WebContents* web_contents, 79 void SendBannerAccepted(content::WebContents* web_contents,
76 const std::string& platform); 80 const std::string& platform);
77 void OnWebApkInstallFinished(bool success, const std::string& webapk_package); 81 void OnWebApkInstallFinished(bool success, const std::string& webapk_package);
78 82
79 // ConfirmInfoBarDelegate: 83 // ConfirmInfoBarDelegate:
80 infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override; 84 infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override;
81 gfx::Image GetIcon() const override; 85 gfx::Image GetIcon() const override;
82 void InfoBarDismissed() override; 86 void InfoBarDismissed() override;
83 base::string16 GetMessageText() const override; 87 base::string16 GetMessageText() const override;
84 int GetButtons() const override; 88 int GetButtons() const override;
85 bool Accept() override; 89 bool Accept() override;
86 bool LinkClicked(WindowOpenDisposition disposition) override; 90 bool LinkClicked(WindowOpenDisposition disposition) override;
91 AppBannerInfoBarDelegateAndroid* AsAppBannerInfoBarDelegateAndroid() override;
87 92
88 base::android::ScopedJavaGlobalRef<jobject> java_delegate_; 93 base::android::ScopedJavaGlobalRef<jobject> java_delegate_;
89 94
90 // Used to fetch the splash screen icon for webapps. 95 // Used to fetch the splash screen icon for webapps.
91 base::WeakPtr<AppBannerManager> weak_manager_; 96 base::WeakPtr<AppBannerManager> weak_manager_;
92 97
93 base::string16 app_title_; 98 base::string16 app_title_;
94 GURL manifest_url_; 99 std::unique_ptr<ShortcutInfo> shortcut_info_;
95 content::Manifest manifest_;
96 100
97 base::android::ScopedJavaGlobalRef<jobject> native_app_data_; 101 base::android::ScopedJavaGlobalRef<jobject> native_app_data_;
98 102
99 GURL icon_url_;
100 std::unique_ptr<SkBitmap> icon_; 103 std::unique_ptr<SkBitmap> icon_;
101 104
102 std::string native_app_package_; 105 std::string native_app_package_;
103 std::string referrer_; 106 std::string referrer_;
104 int event_request_id_; 107 int event_request_id_;
105 bool has_user_interaction_; 108 bool has_user_interaction_;
106 109
107 std::string webapk_package_name_; 110 std::string webapk_package_name_;
108 bool is_webapk_; 111 bool is_webapk_;
109 112
110 base::WeakPtrFactory<AppBannerInfoBarDelegateAndroid> weak_ptr_factory_; 113 base::WeakPtrFactory<AppBannerInfoBarDelegateAndroid> weak_ptr_factory_;
111 114
112 DISALLOW_COPY_AND_ASSIGN(AppBannerInfoBarDelegateAndroid); 115 DISALLOW_COPY_AND_ASSIGN(AppBannerInfoBarDelegateAndroid);
113 }; // AppBannerInfoBarDelegateAndroid 116 }; // AppBannerInfoBarDelegateAndroid
Peter Kasting 2016/09/06 19:31:23 Nit: We don't use trailing comments like this when
Xi Han 2016/09/07 15:53:17 Done.
114 117
115 // Register native methods. 118 // Register native methods.
116 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env); 119 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env);
117 120
118 } // namespace banners 121 } // namespace banners
119 122
120 #endif // CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_INFOBAR_DELEGATE_ANDROID_H_ 123 #endif // CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_INFOBAR_DELEGATE_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698