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

Side by Side Diff: chrome/browser/android/webapps/add_to_homescreen_manager.cc

Issue 2669133003: Update AddToHomescreenDataFetcher to accept badge icon for WebAPK. (Closed)
Patch Set: Addressing comments Created 3 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
« no previous file with comments | « chrome/browser/android/webapps/add_to_homescreen_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/webapps/add_to_homescreen_manager.h" 5 #include "chrome/browser/android/webapps/add_to_homescreen_manager.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/guid.h" 9 #include "base/guid.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 add_shortcut_pending_ = true; 63 add_shortcut_pending_ = true;
64 64
65 base::string16 user_title = 65 base::string16 user_title =
66 base::android::ConvertJavaStringToUTF16(env, j_user_title); 66 base::android::ConvertJavaStringToUTF16(env, j_user_title);
67 if (!user_title.empty()) 67 if (!user_title.empty())
68 data_fetcher_->shortcut_info().user_title = user_title; 68 data_fetcher_->shortcut_info().user_title = user_title;
69 69
70 if (data_fetcher_->is_ready()) { 70 if (data_fetcher_->is_ready()) {
71 // If the fetcher isn't ready yet, the shortcut will be added when it is 71 // If the fetcher isn't ready yet, the shortcut will be added when it is
72 // via OnDataAvailable(); 72 // via OnDataAvailable();
73 AddShortcut(data_fetcher_->shortcut_info(), data_fetcher_->shortcut_icon()); 73 AddShortcut(data_fetcher_->shortcut_info(), data_fetcher_->primary_icon());
74 } 74 }
75 } 75 }
76 76
77 void AddToHomescreenManager::Start(content::WebContents* web_contents) { 77 void AddToHomescreenManager::Start(content::WebContents* web_contents) {
78 bool check_webapk_compatible = false; 78 bool check_webapk_compatible = false;
79 if (ChromeWebApkHost::AreWebApkEnabled() && 79 if (ChromeWebApkHost::AreWebApkEnabled() &&
80 InstallableManager::IsContentSecure(web_contents)) { 80 InstallableManager::IsContentSecure(web_contents)) {
81 check_webapk_compatible = true; 81 check_webapk_compatible = true;
82 } else { 82 } else {
83 ShowDialog(); 83 ShowDialog();
84 } 84 }
85 85
86 data_fetcher_ = new AddToHomescreenDataFetcher( 86 data_fetcher_ = new AddToHomescreenDataFetcher(
87 web_contents, ShortcutHelper::GetIdealHomescreenIconSizeInPx(), 87 web_contents, ShortcutHelper::GetIdealHomescreenIconSizeInPx(),
88 ShortcutHelper::GetMinimumHomescreenIconSizeInPx(), 88 ShortcutHelper::GetMinimumHomescreenIconSizeInPx(),
89 ShortcutHelper::GetIdealSplashImageSizeInPx(), 89 ShortcutHelper::GetIdealSplashImageSizeInPx(),
90 ShortcutHelper::GetMinimumSplashImageSizeInPx(), 90 ShortcutHelper::GetMinimumSplashImageSizeInPx(),
91 ShortcutHelper::GetIdealBadgeIconSizeInPx(),
91 check_webapk_compatible, this); 92 check_webapk_compatible, this);
92 } 93 }
93 94
94 AddToHomescreenManager::~AddToHomescreenManager() { 95 AddToHomescreenManager::~AddToHomescreenManager() {
95 if (data_fetcher_) { 96 if (data_fetcher_) {
96 data_fetcher_->set_weak_observer(nullptr); 97 data_fetcher_->set_weak_observer(nullptr);
97 data_fetcher_ = nullptr; 98 data_fetcher_ = nullptr;
98 } 99 }
99 } 100 }
100 101
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 return; 157 return;
157 JNIEnv* env = base::android::AttachCurrentThread(); 158 JNIEnv* env = base::android::AttachCurrentThread();
158 ScopedJavaLocalRef<jstring> j_user_title = 159 ScopedJavaLocalRef<jstring> j_user_title =
159 base::android::ConvertUTF16ToJavaString(env, user_title); 160 base::android::ConvertUTF16ToJavaString(env, user_title);
160 Java_AddToHomescreenManager_onUserTitleAvailable(env, 161 Java_AddToHomescreenManager_onUserTitleAvailable(env,
161 java_ref_, 162 java_ref_,
162 j_user_title); 163 j_user_title);
163 } 164 }
164 165
165 void AddToHomescreenManager::OnDataAvailable(const ShortcutInfo& info, 166 void AddToHomescreenManager::OnDataAvailable(const ShortcutInfo& info,
166 const SkBitmap& icon) { 167 const SkBitmap& primary_icon,
168 const SkBitmap& badge_icon) {
167 if (is_webapk_compatible_) { 169 if (is_webapk_compatible_) {
170 // TODO(zpeng): Add badge to WebAPK installation flow.
168 WebApkInstallService* install_service = 171 WebApkInstallService* install_service =
169 WebApkInstallService::Get( 172 WebApkInstallService::Get(
170 data_fetcher_->web_contents()->GetBrowserContext()); 173 data_fetcher_->web_contents()->GetBrowserContext());
171 if (install_service->IsInstallInProgress(info.manifest_url)) 174 if (install_service->IsInstallInProgress(info.manifest_url))
172 ShortcutHelper::ShowWebApkInstallInProgressToast(); 175 ShortcutHelper::ShowWebApkInstallInProgressToast();
173 else 176 else
174 CreateInfoBarForWebApk(info, icon); 177 CreateInfoBarForWebApk(info, primary_icon);
175 return; 178 return;
176 } 179 }
177 180
178 JNIEnv* env = base::android::AttachCurrentThread(); 181 JNIEnv* env = base::android::AttachCurrentThread();
179 ScopedJavaLocalRef<jobject> java_bitmap; 182 ScopedJavaLocalRef<jobject> java_bitmap;
180 if (icon.getSize()) 183 if (!primary_icon.drawsNothing())
181 java_bitmap = gfx::ConvertToJavaBitmap(&icon); 184 java_bitmap = gfx::ConvertToJavaBitmap(&primary_icon);
182 185
183 Java_AddToHomescreenManager_onReadyToAdd(env, java_ref_, java_bitmap); 186 Java_AddToHomescreenManager_onReadyToAdd(env, java_ref_, java_bitmap);
184 187
185 if (add_shortcut_pending_) 188 if (add_shortcut_pending_)
186 AddShortcut(info, icon); 189 AddShortcut(info, primary_icon);
187 } 190 }
188 191
189 void AddToHomescreenManager::CreateInfoBarForWebApk(const ShortcutInfo& info, 192 void AddToHomescreenManager::CreateInfoBarForWebApk(const ShortcutInfo& info,
190 const SkBitmap& icon) { 193 const SkBitmap& icon) {
191 banners::AppBannerInfoBarDelegateAndroid::Create( 194 banners::AppBannerInfoBarDelegateAndroid::Create(
192 data_fetcher_->web_contents(), nullptr, info.user_title, 195 data_fetcher_->web_contents(), nullptr, info.user_title,
193 base::MakeUnique<ShortcutInfo>(info), base::MakeUnique<SkBitmap>(icon), 196 base::MakeUnique<ShortcutInfo>(info), base::MakeUnique<SkBitmap>(icon),
194 -1 /* event_request_id */, webapk::INSTALL_SOURCE_MENU); 197 -1 /* event_request_id */, webapk::INSTALL_SOURCE_MENU);
195 } 198 }
196 199
197 SkBitmap AddToHomescreenManager::FinalizeLauncherIconInBackground( 200 SkBitmap AddToHomescreenManager::FinalizeLauncherIconInBackground(
198 const SkBitmap& bitmap, 201 const SkBitmap& bitmap,
199 const GURL& url, 202 const GURL& url,
200 bool* is_generated) { 203 bool* is_generated) {
201 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); 204 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
202 205
203 return ShortcutHelper::FinalizeLauncherIconInBackground(bitmap, url, 206 return ShortcutHelper::FinalizeLauncherIconInBackground(bitmap, url,
204 is_generated); 207 is_generated);
205 } 208 }
OLDNEW
« no previous file with comments | « chrome/browser/android/webapps/add_to_homescreen_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698