OLD | NEW |
---|---|
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/android/webapk/webapk_metrics.h" | |
12 #include "chrome/browser/banners/app_banner_manager.h" | 13 #include "chrome/browser/banners/app_banner_manager.h" |
13 #include "components/infobars/core/confirm_infobar_delegate.h" | 14 #include "components/infobars/core/confirm_infobar_delegate.h" |
14 #include "ui/gfx/image/image.h" | 15 #include "ui/gfx/image/image.h" |
15 #include "url/gurl.h" | 16 #include "url/gurl.h" |
16 | 17 |
17 namespace content { | 18 namespace content { |
18 class WebContents; | 19 class WebContents; |
19 } | 20 } |
20 | 21 |
21 namespace infobars { | 22 namespace infobars { |
(...skipping 11 matching lines...) Expand all Loading... | |
33 // Creates an infobar and delegate for promoting the installation of a web | 34 // Creates an infobar and delegate for promoting the installation of a web |
34 // app, and adds the infobar to the InfoBarManager for |web_contents|. | 35 // app, and adds the infobar to the InfoBarManager for |web_contents|. |
35 static bool Create( | 36 static bool Create( |
36 content::WebContents* web_contents, | 37 content::WebContents* web_contents, |
37 base::WeakPtr<AppBannerManager> weak_manager, | 38 base::WeakPtr<AppBannerManager> weak_manager, |
38 const base::string16& app_title, | 39 const base::string16& app_title, |
39 std::unique_ptr<ShortcutInfo> info, | 40 std::unique_ptr<ShortcutInfo> info, |
40 std::unique_ptr<SkBitmap> icon, | 41 std::unique_ptr<SkBitmap> icon, |
41 int event_request_id, | 42 int event_request_id, |
42 bool is_webapk, | 43 bool is_webapk, |
43 bool start_install_webapk); | 44 webapk::InstallSource install_source); |
44 | 45 |
45 // Creates and shows the infobar for an Android app. | 46 // Creates and shows the infobar for an Android app. |
46 // Creates an infobar and delegate for promoting the installation of an | 47 // Creates an infobar and delegate for promoting the installation of an |
47 // Android app, and adds the infobar to the InfoBarManager for |web_contents|. | 48 // Android app, and adds the infobar to the InfoBarManager for |web_contents|. |
48 static bool Create( | 49 static bool Create( |
49 content::WebContents* web_contents, | 50 content::WebContents* web_contents, |
50 const base::string16& app_title, | 51 const base::string16& app_title, |
51 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, | 52 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, |
52 std::unique_ptr<SkBitmap> icon, | 53 std::unique_ptr<SkBitmap> icon, |
53 const std::string& native_app_package, | 54 const std::string& native_app_package, |
(...skipping 10 matching lines...) Expand all Loading... | |
64 // returned to Chrome. | 65 // returned to Chrome. |
65 void OnInstallIntentReturned(JNIEnv* env, | 66 void OnInstallIntentReturned(JNIEnv* env, |
66 const base::android::JavaParamRef<jobject>& obj, | 67 const base::android::JavaParamRef<jobject>& obj, |
67 jboolean jis_installing); | 68 jboolean jis_installing); |
68 | 69 |
69 // Called when the InstallerDelegate task has finished. | 70 // Called when the InstallerDelegate task has finished. |
70 void OnInstallFinished(JNIEnv* env, | 71 void OnInstallFinished(JNIEnv* env, |
71 const base::android::JavaParamRef<jobject>& obj, | 72 const base::android::JavaParamRef<jobject>& obj, |
72 jboolean success); | 73 jboolean success); |
73 | 74 |
74 // When user accepts to install a WebAPK, this function sends a request | 75 // ConfirmInfoBarDelegate: |
75 // to the WebAPK Server to create a WebAPK and install it. It returns | 76 bool Accept() override; |
76 // false to prevent infobar from disappearing when installation starts. | |
77 // When user clicks the Open button after the intallation is compelete, this | |
78 // function launches the installed WebAPK and returns true. | |
79 bool AcceptWebApk(content::WebContents* web_contents); | |
80 | 77 |
81 private: | 78 private: |
82 // The states of a WebAPK installation, where the infobar is displayed during | 79 // The states of a WebAPK installation, where the infobar is displayed during |
83 // the entire installation process. This state is used to correctly record | 80 // the entire installation process. This state is used to correctly record |
84 // UMA metrics. | 81 // UMA metrics. |
85 enum InstallState { | 82 enum InstallState { |
86 INSTALL_NOT_STARTED, | 83 INSTALL_NOT_STARTED, |
87 INSTALLING, | 84 INSTALLING, |
88 INSTALLED, | 85 INSTALLED, |
89 }; | 86 }; |
90 | 87 |
91 // Delegate for promoting a web app. | 88 // Delegate for promoting a web app. |
92 AppBannerInfoBarDelegateAndroid( | 89 AppBannerInfoBarDelegateAndroid( |
93 base::WeakPtr<AppBannerManager> weak_manager, | 90 base::WeakPtr<AppBannerManager> weak_manager, |
94 const base::string16& app_title, | 91 const base::string16& app_title, |
95 std::unique_ptr<ShortcutInfo> info, | 92 std::unique_ptr<ShortcutInfo> info, |
96 std::unique_ptr<SkBitmap> icon, | 93 std::unique_ptr<SkBitmap> icon, |
97 int event_request_id, | 94 int event_request_id, |
98 bool is_webapk); | 95 bool is_webapk, |
96 webapk::InstallSource install_source); | |
99 | 97 |
100 // Delegate for promoting an Android app. | 98 // Delegate for promoting an Android app. |
101 AppBannerInfoBarDelegateAndroid( | 99 AppBannerInfoBarDelegateAndroid( |
102 const base::string16& app_title, | 100 const base::string16& app_title, |
103 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, | 101 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, |
104 std::unique_ptr<SkBitmap> icon, | 102 std::unique_ptr<SkBitmap> icon, |
105 const std::string& native_app_package, | 103 const std::string& native_app_package, |
106 const std::string& referrer, | 104 const std::string& referrer, |
107 int event_request_id); | 105 int event_request_id); |
108 | 106 |
109 void CreateJavaDelegate(); | 107 void CreateJavaDelegate(); |
110 bool AcceptNativeApp(content::WebContents* web_contents); | 108 bool AcceptNativeApp(content::WebContents* web_contents); |
111 bool AcceptWebApp(content::WebContents* web_contents); | 109 bool AcceptWebApp(content::WebContents* web_contents); |
110 | |
111 // When user accepts to install a WebAPK, this function sends a request | |
112 // to the WebAPK Server to create a WebAPK and install it. It returns | |
113 // false to prevent infobar from disappearing when installation starts. | |
114 // When user clicks the Open button after the intallation is compelete, this | |
115 // function launches the installed WebAPK and returns true. | |
116 bool AcceptWebApk(content::WebContents* web_contents); | |
pkotwicz
2016/09/26 20:23:10
Nit: New line
Whenever I add a function which has
Xi Han
2016/09/26 20:33:31
Done.
| |
112 void SendBannerAccepted(content::WebContents* web_contents, | 117 void SendBannerAccepted(content::WebContents* web_contents, |
113 const std::string& platform); | 118 const std::string& platform); |
114 void OnWebApkInstallFinished(bool success, const std::string& webapk_package); | 119 void OnWebApkInstallFinished(bool success, const std::string& webapk_package); |
115 void TrackWebApkInstallationDismissEvents(InstallState install_state); | 120 void TrackWebApkInstallationDismissEvents(InstallState install_state); |
116 | 121 |
117 // ConfirmInfoBarDelegate: | 122 // ConfirmInfoBarDelegate: |
118 infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override; | 123 infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override; |
119 gfx::Image GetIcon() const override; | 124 gfx::Image GetIcon() const override; |
120 void InfoBarDismissed() override; | 125 void InfoBarDismissed() override; |
121 base::string16 GetMessageText() const override; | 126 base::string16 GetMessageText() const override; |
122 int GetButtons() const override; | 127 int GetButtons() const override; |
123 bool Accept() override; | |
124 bool LinkClicked(WindowOpenDisposition disposition) override; | 128 bool LinkClicked(WindowOpenDisposition disposition) override; |
125 | 129 |
126 base::android::ScopedJavaGlobalRef<jobject> java_delegate_; | 130 base::android::ScopedJavaGlobalRef<jobject> java_delegate_; |
127 | 131 |
128 // Used to fetch the splash screen icon for webapps. | 132 // Used to fetch the splash screen icon for webapps. |
129 base::WeakPtr<AppBannerManager> weak_manager_; | 133 base::WeakPtr<AppBannerManager> weak_manager_; |
130 | 134 |
131 base::string16 app_title_; | 135 base::string16 app_title_; |
132 std::unique_ptr<ShortcutInfo> shortcut_info_; | 136 std::unique_ptr<ShortcutInfo> shortcut_info_; |
133 | 137 |
134 base::android::ScopedJavaGlobalRef<jobject> native_app_data_; | 138 base::android::ScopedJavaGlobalRef<jobject> native_app_data_; |
135 | 139 |
136 std::unique_ptr<SkBitmap> icon_; | 140 std::unique_ptr<SkBitmap> icon_; |
137 | 141 |
138 std::string native_app_package_; | 142 std::string native_app_package_; |
139 std::string referrer_; | 143 std::string referrer_; |
140 int event_request_id_; | 144 int event_request_id_; |
141 bool has_user_interaction_; | 145 bool has_user_interaction_; |
142 | 146 |
143 std::string webapk_package_name_; | 147 std::string webapk_package_name_; |
144 bool is_webapk_; | 148 bool is_webapk_; |
145 | 149 |
146 // Indicates the current state of a WebAPK installation. | 150 // Indicates the current state of a WebAPK installation. |
147 InstallState install_state_; | 151 InstallState install_state_; |
148 | 152 |
153 // Indicates the way in which a WebAPK (if applicable) is installed: from the | |
154 // menu or from an app banner. | |
155 webapk::InstallSource install_source_; | |
pkotwicz
2016/09/26 20:23:10
Nit: |install_source_| -> |webapk_install_source_|
Xi Han
2016/09/26 20:33:31
Done.
| |
156 | |
149 base::WeakPtrFactory<AppBannerInfoBarDelegateAndroid> weak_ptr_factory_; | 157 base::WeakPtrFactory<AppBannerInfoBarDelegateAndroid> weak_ptr_factory_; |
150 | 158 |
151 DISALLOW_COPY_AND_ASSIGN(AppBannerInfoBarDelegateAndroid); | 159 DISALLOW_COPY_AND_ASSIGN(AppBannerInfoBarDelegateAndroid); |
152 }; | 160 }; |
153 | 161 |
154 // Register native methods. | 162 // Register native methods. |
155 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env); | 163 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env); |
156 | 164 |
157 } // namespace banners | 165 } // namespace banners |
158 | 166 |
159 #endif // CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_INFOBAR_DELEGATE_ANDROID_H_ | 167 #endif // CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_INFOBAR_DELEGATE_ANDROID_H_ |
OLD | NEW |