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

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

Issue 2363183002: Skip installation process if WebAPK is already installed. (Closed)
Patch Set: 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 #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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 if (!user_title.empty()) 61 if (!user_title.empty())
62 data_fetcher_->shortcut_info().user_title = user_title; 62 data_fetcher_->shortcut_info().user_title = user_title;
63 63
64 if (data_fetcher_->is_ready()) { 64 if (data_fetcher_->is_ready()) {
65 // If the fetcher isn't ready yet, the shortcut will be added when it is 65 // If the fetcher isn't ready yet, the shortcut will be added when it is
66 // via OnDataAvailable(); 66 // via OnDataAvailable();
67 AddShortcut(data_fetcher_->shortcut_info(), data_fetcher_->shortcut_icon()); 67 AddShortcut(data_fetcher_->shortcut_info(), data_fetcher_->shortcut_icon());
68 } 68 }
69 } 69 }
70 70
71 void AddToHomescreenManager::Start(content::WebContents* web_contents) { 71 void AddToHomescreenManager::Start(content::WebContents* web_contents) {
pkotwicz 2016/09/29 14:18:54 Thank you for making the changes in this file. The
F 2016/09/30 18:02:02 Done. Will do :)
72 bool check_installable = false; 72 // Check whether to check WebApk compatibility.
73 bool check_webapk_compatible = false;
73 if (ChromeWebApkHost::AreWebApkEnabled() && 74 if (ChromeWebApkHost::AreWebApkEnabled() &&
74 content::IsOriginSecure(web_contents->GetLastCommittedURL())) { 75 content::IsOriginSecure(web_contents->GetLastCommittedURL())) {
75 check_installable = true; 76 check_webapk_compatible = true;
76 } else { 77 } else {
77 ShowDialog(); 78 ShowDialog();
78 } 79 }
79 80
80 data_fetcher_ = new AddToHomescreenDataFetcher( 81 data_fetcher_ = new AddToHomescreenDataFetcher(
81 web_contents, ShortcutHelper::GetIdealHomescreenIconSizeInDp(), 82 web_contents, ShortcutHelper::GetIdealHomescreenIconSizeInDp(),
82 ShortcutHelper::GetMinimumHomescreenIconSizeInDp(), 83 ShortcutHelper::GetMinimumHomescreenIconSizeInDp(),
83 ShortcutHelper::GetIdealSplashImageSizeInDp(), 84 ShortcutHelper::GetIdealSplashImageSizeInDp(),
84 ShortcutHelper::GetMinimumSplashImageSizeInDp(), 85 ShortcutHelper::GetMinimumSplashImageSizeInDp(),
85 check_installable, this); 86 check_webapk_compatible, this);
86 } 87 }
87 88
88 AddToHomescreenManager::~AddToHomescreenManager() { 89 AddToHomescreenManager::~AddToHomescreenManager() {
89 if (data_fetcher_) { 90 if (data_fetcher_) {
90 data_fetcher_->set_weak_observer(nullptr); 91 data_fetcher_->set_weak_observer(nullptr);
91 data_fetcher_ = nullptr; 92 data_fetcher_ = nullptr;
92 } 93 }
93 } 94 }
94 95
95 void AddToHomescreenManager::ShowDialog() { 96 void AddToHomescreenManager::ShowDialog() {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 ScopedJavaLocalRef<jstring> j_user_title = 146 ScopedJavaLocalRef<jstring> j_user_title =
146 base::android::ConvertUTF16ToJavaString(env, user_title); 147 base::android::ConvertUTF16ToJavaString(env, user_title);
147 Java_AddToHomescreenManager_onUserTitleAvailable(env, 148 Java_AddToHomescreenManager_onUserTitleAvailable(env,
148 java_ref_, 149 java_ref_,
149 j_user_title); 150 j_user_title);
150 } 151 }
151 152
152 void AddToHomescreenManager::OnDataAvailable(const ShortcutInfo& info, 153 void AddToHomescreenManager::OnDataAvailable(const ShortcutInfo& info,
153 const SkBitmap& icon) { 154 const SkBitmap& icon) {
154 if (is_webapk_compatible_) { 155 if (is_webapk_compatible_) {
155 CreateInfoBarForWebAPK(info, icon); 156 CreateInfoBarForWebApk(info, icon);
156 return; 157 return;
157 } 158 }
158 159
159 JNIEnv* env = base::android::AttachCurrentThread(); 160 JNIEnv* env = base::android::AttachCurrentThread();
160 ScopedJavaLocalRef<jobject> java_bitmap; 161 ScopedJavaLocalRef<jobject> java_bitmap;
161 if (icon.getSize()) 162 if (icon.getSize())
162 java_bitmap = gfx::ConvertToJavaBitmap(&icon); 163 java_bitmap = gfx::ConvertToJavaBitmap(&icon);
163 164
164 Java_AddToHomescreenManager_onReadyToAdd(env, java_ref_, java_bitmap); 165 Java_AddToHomescreenManager_onReadyToAdd(env, java_ref_, java_bitmap);
165 166
166 if (add_shortcut_pending_) 167 if (add_shortcut_pending_)
167 AddShortcut(info, icon); 168 AddShortcut(info, icon);
168 } 169 }
169 170
170 void AddToHomescreenManager::CreateInfoBarForWebAPK(const ShortcutInfo& info, 171 void AddToHomescreenManager::CreateInfoBarForWebApk(const ShortcutInfo& info,
171 const SkBitmap& icon) { 172 const SkBitmap& icon) {
172 banners::AppBannerInfoBarDelegateAndroid::Create( 173 banners::AppBannerInfoBarDelegateAndroid::Create(
173 data_fetcher_->web_contents(), nullptr, info.user_title, 174 data_fetcher_->web_contents(), nullptr, info.user_title,
174 base::MakeUnique<ShortcutInfo>(info), base::MakeUnique<SkBitmap>(icon), 175 base::MakeUnique<ShortcutInfo>(info), base::MakeUnique<SkBitmap>(icon),
175 -1 /* event_request_id */, true /* is_webapk */, 176 -1 /* event_request_id */, true /* is_webapk */,
176 true /* start_install_webapk */); 177 true /* start_install_webapk */);
177 } 178 }
178 179
179 SkBitmap AddToHomescreenManager::FinalizeLauncherIconInBackground( 180 SkBitmap AddToHomescreenManager::FinalizeLauncherIconInBackground(
180 const SkBitmap& bitmap, 181 const SkBitmap& bitmap,
181 const GURL& url, 182 const GURL& url,
182 bool* is_generated) { 183 bool* is_generated) {
183 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); 184 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
184 185
185 return ShortcutHelper::FinalizeLauncherIconInBackground(bitmap, url, 186 return ShortcutHelper::FinalizeLauncherIconInBackground(bitmap, url,
186 is_generated); 187 is_generated);
187 } 188 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698