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

Side by Side Diff: chrome/browser/android/banners/app_banner_infobar_delegate.cc

Issue 922953002: Minor infobar cleanup. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Resync Created 5 years, 10 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 #include "chrome/browser/android/banners/app_banner_infobar_delegate.h" 5 #include "chrome/browser/android/banners/app_banner_infobar_delegate.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 app_icon, 63 app_icon,
64 web_app_data, 64 web_app_data,
65 base::android::ScopedJavaGlobalRef<jobject>(), 65 base::android::ScopedJavaGlobalRef<jobject>(),
66 std::string())); 66 std::string()));
67 AppBannerInfoBar* infobar = new AppBannerInfoBar(delegate.Pass(), 67 AppBannerInfoBar* infobar = new AppBannerInfoBar(delegate.Pass(),
68 web_app_data.start_url); 68 web_app_data.start_url);
69 return infobar_manager->AddInfoBar(make_scoped_ptr(infobar)) 69 return infobar_manager->AddInfoBar(make_scoped_ptr(infobar))
70 ? infobar : nullptr; 70 ? infobar : nullptr;
71 } 71 }
72 72
73 AppBannerInfoBarDelegate::~AppBannerInfoBarDelegate() {
74 TrackDismissEvent(DISMISS_EVENT_DISMISSED);
75 JNIEnv* env = base::android::AttachCurrentThread();
76 Java_AppBannerInfoBarDelegate_destroy(env,
77 java_delegate_.obj());
78 java_delegate_.Reset();
79 }
80
81 void AppBannerInfoBarDelegate::UpdateInstallState(JNIEnv* env, jobject obj) {
82 if (native_app_data_.is_null())
83 return;
84
85 int newState = Java_AppBannerInfoBarDelegate_determineInstallState(
86 env,
87 java_delegate_.obj(),
88 native_app_data_.obj());
89 static_cast<AppBannerInfoBar*>(infobar())->OnInstallStateChanged(newState);
90 }
91
92 void AppBannerInfoBarDelegate::OnInstallIntentReturned(
93 JNIEnv* env,
94 jobject obj,
95 jboolean jis_installing) {
96 if (!infobar())
97 return;
98
99 content::WebContents* web_contents =
100 InfoBarService::WebContentsFromInfoBar(infobar());
101 if (!web_contents)
102 return;
103
104 if (jis_installing) {
105 AppBannerSettingsHelper::RecordBannerEvent(
106 web_contents,
107 web_contents->GetURL(),
108 native_app_package_,
109 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN,
110 AppBannerManager::GetCurrentTime());
111
112 TrackInstallEvent(INSTALL_EVENT_NATIVE_APP_INSTALL_STARTED);
113 rappor::SampleDomainAndRegistryFromGURL("AppBanner.NativeApp.Installed",
114 web_contents->GetURL());
115 }
116
117 UpdateInstallState(env, obj);
118 }
119
120 void AppBannerInfoBarDelegate::OnInstallFinished(JNIEnv* env,
121 jobject obj,
122 jboolean success) {
123 if (!infobar())
124 return;
125
126 if (success) {
127 TrackInstallEvent(INSTALL_EVENT_NATIVE_APP_INSTALL_COMPLETED);
128 UpdateInstallState(env, obj);
129 } else if (infobar()->owner()) {
130 TrackDismissEvent(DISMISS_EVENT_INSTALL_TIMEOUT);
131 infobar()->owner()->RemoveInfoBar(infobar());
132 }
133 }
134
73 AppBannerInfoBarDelegate::AppBannerInfoBarDelegate( 135 AppBannerInfoBarDelegate::AppBannerInfoBarDelegate(
74 const base::string16& app_title, 136 const base::string16& app_title,
75 SkBitmap* app_icon, 137 SkBitmap* app_icon,
76 const content::Manifest& web_app_data, 138 const content::Manifest& web_app_data,
77 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, 139 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data,
78 const std::string& native_app_package) 140 const std::string& native_app_package)
79 : app_title_(app_title), 141 : app_title_(app_title),
80 app_icon_(app_icon), 142 app_icon_(app_icon),
81 web_app_data_(web_app_data), 143 web_app_data_(web_app_data),
82 native_app_data_(native_app_data), 144 native_app_data_(native_app_data),
83 native_app_package_(native_app_package) { 145 native_app_package_(native_app_package) {
84 DCHECK(native_app_data_.is_null() ^ web_app_data_.IsEmpty()); 146 DCHECK(native_app_data_.is_null() ^ web_app_data_.IsEmpty());
85 JNIEnv* env = base::android::AttachCurrentThread(); 147 JNIEnv* env = base::android::AttachCurrentThread();
86 java_delegate_.Reset(Java_AppBannerInfoBarDelegate_create( 148 java_delegate_.Reset(Java_AppBannerInfoBarDelegate_create(
87 env, 149 env,
88 reinterpret_cast<intptr_t>(this))); 150 reinterpret_cast<intptr_t>(this)));
89 } 151 }
90 152
91 AppBannerInfoBarDelegate::~AppBannerInfoBarDelegate() {
92 TrackDismissEvent(DISMISS_EVENT_DISMISSED);
93 JNIEnv* env = base::android::AttachCurrentThread();
94 Java_AppBannerInfoBarDelegate_destroy(env,
95 java_delegate_.obj());
96 java_delegate_.Reset();
97 }
98
99 base::string16 AppBannerInfoBarDelegate::GetMessageText() const {
100 return app_title_;
101 }
102
103 int AppBannerInfoBarDelegate::GetButtons() const {
104 return BUTTON_OK;
105 }
106
107 gfx::Image AppBannerInfoBarDelegate::GetIcon() const { 153 gfx::Image AppBannerInfoBarDelegate::GetIcon() const {
108 return gfx::Image::CreateFrom1xBitmap(*app_icon_.get()); 154 return gfx::Image::CreateFrom1xBitmap(*app_icon_.get());
109 } 155 }
110 156
111 void AppBannerInfoBarDelegate::InfoBarDismissed() { 157 void AppBannerInfoBarDelegate::InfoBarDismissed() {
112 content::WebContents* web_contents = 158 content::WebContents* web_contents =
113 InfoBarService::WebContentsFromInfoBar(infobar()); 159 InfoBarService::WebContentsFromInfoBar(infobar());
114 if (!web_contents) 160 if (!web_contents)
115 return; 161 return;
116 162
(...skipping 13 matching lines...) Expand all
130 web_contents, web_contents->GetURL(), 176 web_contents, web_contents->GetURL(),
131 web_app_data_.start_url.spec(), 177 web_app_data_.start_url.spec(),
132 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_BLOCK, 178 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_BLOCK,
133 AppBannerManager::GetCurrentTime()); 179 AppBannerManager::GetCurrentTime());
134 180
135 rappor::SampleDomainAndRegistryFromGURL("AppBanner.WebApp.Dismissed", 181 rappor::SampleDomainAndRegistryFromGURL("AppBanner.WebApp.Dismissed",
136 web_contents->GetURL()); 182 web_contents->GetURL());
137 } 183 }
138 } 184 }
139 185
186 base::string16 AppBannerInfoBarDelegate::GetMessageText() const {
187 return app_title_;
188 }
189
190 int AppBannerInfoBarDelegate::GetButtons() const {
191 return BUTTON_OK;
192 }
193
140 bool AppBannerInfoBarDelegate::Accept() { 194 bool AppBannerInfoBarDelegate::Accept() {
141 content::WebContents* web_contents = 195 content::WebContents* web_contents =
142 InfoBarService::WebContentsFromInfoBar(infobar()); 196 InfoBarService::WebContentsFromInfoBar(infobar());
143 if (!web_contents) { 197 if (!web_contents) {
144 TrackDismissEvent(DISMISS_EVENT_ERROR); 198 TrackDismissEvent(DISMISS_EVENT_ERROR);
145 return true; 199 return true;
146 } 200 }
147 201
148 if (!native_app_data_.is_null()) { 202 if (!native_app_data_.is_null()) {
149 JNIEnv* env = base::android::AttachCurrentThread(); 203 JNIEnv* env = base::android::AttachCurrentThread();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 264
211 Java_AppBannerInfoBarDelegate_showAppDetails(env, 265 Java_AppBannerInfoBarDelegate_showAppDetails(env,
212 java_delegate_.obj(), 266 java_delegate_.obj(),
213 tab->GetJavaObject().obj(), 267 tab->GetJavaObject().obj(),
214 native_app_data_.obj()); 268 native_app_data_.obj());
215 269
216 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); 270 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK);
217 return true; 271 return true;
218 } 272 }
219 273
220 void AppBannerInfoBarDelegate::OnInstallIntentReturned(
221 JNIEnv* env,
222 jobject obj,
223 jboolean jis_installing) {
224 if (!infobar())
225 return;
226
227 content::WebContents* web_contents =
228 InfoBarService::WebContentsFromInfoBar(infobar());
229 if (!web_contents)
230 return;
231
232 if (jis_installing) {
233 AppBannerSettingsHelper::RecordBannerEvent(
234 web_contents,
235 web_contents->GetURL(),
236 native_app_package_,
237 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN,
238 AppBannerManager::GetCurrentTime());
239
240 TrackInstallEvent(INSTALL_EVENT_NATIVE_APP_INSTALL_STARTED);
241 rappor::SampleDomainAndRegistryFromGURL("AppBanner.NativeApp.Installed",
242 web_contents->GetURL());
243 }
244
245 UpdateInstallState(env, obj);
246 }
247
248 void AppBannerInfoBarDelegate::OnInstallFinished(JNIEnv* env,
249 jobject obj,
250 jboolean success) {
251 if (!infobar())
252 return;
253
254 if (success) {
255 TrackInstallEvent(INSTALL_EVENT_NATIVE_APP_INSTALL_COMPLETED);
256 UpdateInstallState(env, obj);
257 } else if (infobar()->owner()) {
258 TrackDismissEvent(DISMISS_EVENT_INSTALL_TIMEOUT);
259 infobar()->owner()->RemoveInfoBar(infobar());
260 }
261 }
262
263 void AppBannerInfoBarDelegate::UpdateInstallState(JNIEnv* env, jobject obj) {
264 if (native_app_data_.is_null())
265 return;
266
267 int newState = Java_AppBannerInfoBarDelegate_determineInstallState(
268 env,
269 java_delegate_.obj(),
270 native_app_data_.obj());
271 static_cast<AppBannerInfoBar*>(infobar())->OnInstallStateChanged(newState);
272 }
273
274
275 bool RegisterAppBannerInfoBarDelegate(JNIEnv* env) { 274 bool RegisterAppBannerInfoBarDelegate(JNIEnv* env) {
276 return RegisterNativesImpl(env); 275 return RegisterNativesImpl(env);
277 } 276 }
278 277
279 } // namespace banners 278 } // namespace banners
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698