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/location.h" | 9 #include "base/location.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 void AddToHomescreenManager::AddShortcut( | 67 void AddToHomescreenManager::AddShortcut( |
68 JNIEnv* env, | 68 JNIEnv* env, |
69 const JavaParamRef<jobject>& obj, | 69 const JavaParamRef<jobject>& obj, |
70 const JavaParamRef<jstring>& j_user_title) { | 70 const JavaParamRef<jstring>& j_user_title) { |
71 content::WebContents* web_contents = data_fetcher_->web_contents(); | 71 content::WebContents* web_contents = data_fetcher_->web_contents(); |
72 if (!web_contents) | 72 if (!web_contents) |
73 return; | 73 return; |
74 | 74 |
75 base::string16 user_title = | 75 base::string16 user_title = |
76 base::android::ConvertJavaStringToUTF16(env, j_user_title); | 76 base::android::ConvertJavaStringToUTF16(env, j_user_title); |
77 if (!user_title.empty()) | 77 data_fetcher_->shortcut_info().user_title = user_title; |
78 data_fetcher_->shortcut_info().user_title = user_title; | |
79 | 78 |
80 RecordAddToHomescreen(); | 79 RecordAddToHomescreen(); |
81 ShortcutHelper::AddToLauncherWithSkBitmap(web_contents, | 80 ShortcutHelper::AddToLauncherWithSkBitmap(web_contents, |
82 data_fetcher_->shortcut_info(), | 81 data_fetcher_->shortcut_info(), |
83 data_fetcher_->primary_icon()); | 82 data_fetcher_->primary_icon()); |
84 | 83 |
85 // Fire the appinstalled event. | 84 // Fire the appinstalled event. |
86 banners::AppBannerManagerAndroid* app_banner_manager = | 85 banners::AppBannerManagerAndroid* app_banner_manager = |
87 banners::AppBannerManagerAndroid::FromWebContents(web_contents); | 86 banners::AppBannerManagerAndroid::FromWebContents(web_contents); |
88 app_banner_manager->OnInstall(); | 87 app_banner_manager->OnInstall(); |
89 } | 88 } |
90 | 89 |
91 void AddToHomescreenManager::Start(content::WebContents* web_contents) { | 90 void AddToHomescreenManager::Start(content::WebContents* web_contents) { |
92 bool check_webapk_compatible = false; | 91 bool check_webapk_compatible = false; |
93 if (ChromeWebApkHost::CanInstallWebApk() && | 92 if (ChromeWebApkHost::CanInstallWebApk() && |
94 InstallableManager::IsContentSecure(web_contents)) { | 93 InstallableManager::IsContentSecure(web_contents)) { |
95 check_webapk_compatible = true; | 94 check_webapk_compatible = true; |
96 } else { | 95 } else { |
97 ShowDialog(); | 96 ShowDialog(); |
98 } | 97 } |
99 | 98 |
100 data_fetcher_ = new AddToHomescreenDataFetcher( | 99 data_fetcher_ = base::MakeUnique<AddToHomescreenDataFetcher>( |
101 web_contents, ShortcutHelper::GetIdealHomescreenIconSizeInPx(), | 100 web_contents, ShortcutHelper::GetIdealHomescreenIconSizeInPx(), |
102 ShortcutHelper::GetMinimumHomescreenIconSizeInPx(), | 101 ShortcutHelper::GetMinimumHomescreenIconSizeInPx(), |
103 ShortcutHelper::GetIdealSplashImageSizeInPx(), | 102 ShortcutHelper::GetIdealSplashImageSizeInPx(), |
104 ShortcutHelper::GetMinimumSplashImageSizeInPx(), | 103 ShortcutHelper::GetMinimumSplashImageSizeInPx(), |
105 ShortcutHelper::GetIdealBadgeIconSizeInPx(), kDataTimeoutInMilliseconds, | 104 ShortcutHelper::GetIdealBadgeIconSizeInPx(), kDataTimeoutInMilliseconds, |
106 check_webapk_compatible, this); | 105 check_webapk_compatible, this); |
107 } | 106 } |
108 | 107 |
109 AddToHomescreenManager::~AddToHomescreenManager() { | 108 AddToHomescreenManager::~AddToHomescreenManager() {} |
110 if (data_fetcher_) { | |
111 data_fetcher_->set_weak_observer(nullptr); | |
112 data_fetcher_ = nullptr; | |
113 } | |
114 } | |
115 | 109 |
116 void AddToHomescreenManager::ShowDialog() { | 110 void AddToHomescreenManager::ShowDialog() { |
117 JNIEnv* env = base::android::AttachCurrentThread(); | 111 JNIEnv* env = base::android::AttachCurrentThread(); |
118 Java_AddToHomescreenManager_showDialog(env, java_ref_); | 112 Java_AddToHomescreenManager_showDialog(env, java_ref_); |
119 } | 113 } |
120 | 114 |
121 void AddToHomescreenManager::RecordAddToHomescreen() { | 115 void AddToHomescreenManager::RecordAddToHomescreen() { |
122 // Record that the shortcut has been added, so no banners will be shown | 116 // Record that the shortcut has been added, so no banners will be shown |
123 // for this app. | 117 // for this app. |
124 content::WebContents* web_contents = data_fetcher_->web_contents(); | 118 content::WebContents* web_contents = data_fetcher_->web_contents(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 const SkBitmap& badge_icon) { | 176 const SkBitmap& badge_icon) { |
183 content::WebContents* web_contents = data_fetcher_->web_contents(); | 177 content::WebContents* web_contents = data_fetcher_->web_contents(); |
184 banners::AppBannerManagerAndroid* app_banner_manager = | 178 banners::AppBannerManagerAndroid* app_banner_manager = |
185 banners::AppBannerManagerAndroid::FromWebContents(web_contents); | 179 banners::AppBannerManagerAndroid::FromWebContents(web_contents); |
186 banners::AppBannerInfoBarDelegateAndroid::Create( | 180 banners::AppBannerInfoBarDelegateAndroid::Create( |
187 web_contents, app_banner_manager->GetWeakPtr(), | 181 web_contents, app_banner_manager->GetWeakPtr(), |
188 base::MakeUnique<ShortcutInfo>(info), primary_icon, badge_icon, | 182 base::MakeUnique<ShortcutInfo>(info), primary_icon, badge_icon, |
189 -1 /* event_request_id */, true /* is_webapk */, | 183 -1 /* event_request_id */, true /* is_webapk */, |
190 webapk::INSTALL_SOURCE_MENU); | 184 webapk::INSTALL_SOURCE_MENU); |
191 } | 185 } |
192 | |
193 SkBitmap AddToHomescreenManager::FinalizeLauncherIconInBackground( | |
194 const SkBitmap& bitmap, | |
195 const GURL& url, | |
196 bool* is_generated) { | |
197 base::ThreadRestrictions::AssertIOAllowed(); | |
198 | |
199 return ShortcutHelper::FinalizeLauncherIconInBackground(bitmap, url, | |
200 is_generated); | |
201 } | |
OLD | NEW |