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 #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 Loading... |
63 data_fetcher_->shortcut_info().user_title = user_title; | 63 data_fetcher_->shortcut_info().user_title = user_title; |
64 | 64 |
65 if (data_fetcher_->is_ready()) { | 65 if (data_fetcher_->is_ready()) { |
66 // If the fetcher isn't ready yet, the shortcut will be added when it is | 66 // If the fetcher isn't ready yet, the shortcut will be added when it is |
67 // via OnDataAvailable(); | 67 // via OnDataAvailable(); |
68 AddShortcut(data_fetcher_->shortcut_info(), data_fetcher_->shortcut_icon()); | 68 AddShortcut(data_fetcher_->shortcut_info(), data_fetcher_->shortcut_icon()); |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 void AddToHomescreenManager::Start(content::WebContents* web_contents) { | 72 void AddToHomescreenManager::Start(content::WebContents* web_contents) { |
73 bool check_installable = false; | 73 bool check_webapk_compatible = false; |
74 if (ChromeWebApkHost::AreWebApkEnabled() && | 74 if (ChromeWebApkHost::AreWebApkEnabled() && |
75 content::IsOriginSecure(web_contents->GetLastCommittedURL())) { | 75 content::IsOriginSecure(web_contents->GetLastCommittedURL())) { |
76 check_installable = true; | 76 check_webapk_compatible = true; |
77 } else { | 77 } else { |
78 ShowDialog(); | 78 ShowDialog(); |
79 } | 79 } |
80 | 80 |
81 data_fetcher_ = new AddToHomescreenDataFetcher( | 81 data_fetcher_ = new AddToHomescreenDataFetcher( |
82 web_contents, ShortcutHelper::GetIdealHomescreenIconSizeInDp(), | 82 web_contents, ShortcutHelper::GetIdealHomescreenIconSizeInDp(), |
83 ShortcutHelper::GetMinimumHomescreenIconSizeInDp(), | 83 ShortcutHelper::GetMinimumHomescreenIconSizeInDp(), |
84 ShortcutHelper::GetIdealSplashImageSizeInDp(), | 84 ShortcutHelper::GetIdealSplashImageSizeInDp(), |
85 ShortcutHelper::GetMinimumSplashImageSizeInDp(), | 85 ShortcutHelper::GetMinimumSplashImageSizeInDp(), |
86 check_installable, this); | 86 check_webapk_compatible, this); |
87 } | 87 } |
88 | 88 |
89 AddToHomescreenManager::~AddToHomescreenManager() { | 89 AddToHomescreenManager::~AddToHomescreenManager() { |
90 if (data_fetcher_) { | 90 if (data_fetcher_) { |
91 data_fetcher_->set_weak_observer(nullptr); | 91 data_fetcher_->set_weak_observer(nullptr); |
92 data_fetcher_ = nullptr; | 92 data_fetcher_ = nullptr; |
93 } | 93 } |
94 } | 94 } |
95 | 95 |
96 void AddToHomescreenManager::ShowDialog() { | 96 void AddToHomescreenManager::ShowDialog() { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 ScopedJavaLocalRef<jstring> j_user_title = | 146 ScopedJavaLocalRef<jstring> j_user_title = |
147 base::android::ConvertUTF16ToJavaString(env, user_title); | 147 base::android::ConvertUTF16ToJavaString(env, user_title); |
148 Java_AddToHomescreenManager_onUserTitleAvailable(env, | 148 Java_AddToHomescreenManager_onUserTitleAvailable(env, |
149 java_ref_, | 149 java_ref_, |
150 j_user_title); | 150 j_user_title); |
151 } | 151 } |
152 | 152 |
153 void AddToHomescreenManager::OnDataAvailable(const ShortcutInfo& info, | 153 void AddToHomescreenManager::OnDataAvailable(const ShortcutInfo& info, |
154 const SkBitmap& icon) { | 154 const SkBitmap& icon) { |
155 if (is_webapk_compatible_) { | 155 if (is_webapk_compatible_) { |
156 CreateInfoBarForWebAPK(info, icon); | 156 CreateInfoBarForWebApk(info, icon); |
157 return; | 157 return; |
158 } | 158 } |
159 | 159 |
160 JNIEnv* env = base::android::AttachCurrentThread(); | 160 JNIEnv* env = base::android::AttachCurrentThread(); |
161 ScopedJavaLocalRef<jobject> java_bitmap; | 161 ScopedJavaLocalRef<jobject> java_bitmap; |
162 if (icon.getSize()) | 162 if (icon.getSize()) |
163 java_bitmap = gfx::ConvertToJavaBitmap(&icon); | 163 java_bitmap = gfx::ConvertToJavaBitmap(&icon); |
164 | 164 |
165 Java_AddToHomescreenManager_onReadyToAdd(env, java_ref_, java_bitmap); | 165 Java_AddToHomescreenManager_onReadyToAdd(env, java_ref_, java_bitmap); |
166 | 166 |
167 if (add_shortcut_pending_) | 167 if (add_shortcut_pending_) |
168 AddShortcut(info, icon); | 168 AddShortcut(info, icon); |
169 } | 169 } |
170 | 170 |
171 void AddToHomescreenManager::CreateInfoBarForWebAPK(const ShortcutInfo& info, | 171 void AddToHomescreenManager::CreateInfoBarForWebApk(const ShortcutInfo& info, |
172 const SkBitmap& icon) { | 172 const SkBitmap& icon) { |
173 banners::AppBannerInfoBarDelegateAndroid::Create( | 173 banners::AppBannerInfoBarDelegateAndroid::Create( |
174 data_fetcher_->web_contents(), nullptr, info.user_title, | 174 data_fetcher_->web_contents(), nullptr, info.user_title, |
175 base::MakeUnique<ShortcutInfo>(info), base::MakeUnique<SkBitmap>(icon), | 175 base::MakeUnique<ShortcutInfo>(info), base::MakeUnique<SkBitmap>(icon), |
176 -1 /* event_request_id */, true /* is_webapk */, | 176 -1 /* event_request_id */, true /* is_webapk */, |
177 webapk::INSTALL_SOURCE_MENU); | 177 webapk::INSTALL_SOURCE_MENU); |
178 } | 178 } |
179 | 179 |
180 SkBitmap AddToHomescreenManager::FinalizeLauncherIconInBackground( | 180 SkBitmap AddToHomescreenManager::FinalizeLauncherIconInBackground( |
181 const SkBitmap& bitmap, | 181 const SkBitmap& bitmap, |
182 const GURL& url, | 182 const GURL& url, |
183 bool* is_generated) { | 183 bool* is_generated) { |
184 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 184 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
185 | 185 |
186 return ShortcutHelper::FinalizeLauncherIconInBackground(bitmap, url, | 186 return ShortcutHelper::FinalizeLauncherIconInBackground(bitmap, url, |
187 is_generated); | 187 is_generated); |
188 } | 188 } |
OLD | NEW |