OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/shortcut_helper.h" | 5 #include "chrome/browser/android/shortcut_helper.h" |
6 | 6 |
7 #include <jni.h> | 7 #include <jni.h> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
11 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "base/task/cancelable_task_tracker.h" | 16 #include "base/task/cancelable_task_tracker.h" |
17 #include "base/threading/worker_pool.h" | 17 #include "base/threading/worker_pool.h" |
18 #include "chrome/browser/android/manifest_icon_selector.h" | 18 #include "chrome/browser/android/manifest_icon_selector.h" |
19 #include "chrome/browser/android/tab_android.h" | 19 #include "chrome/browser/android/tab_android.h" |
20 #include "chrome/browser/banners/app_banner_settings_helper.h" | |
20 #include "chrome/browser/favicon/favicon_service.h" | 21 #include "chrome/browser/favicon/favicon_service.h" |
21 #include "chrome/browser/favicon/favicon_service_factory.h" | 22 #include "chrome/browser/favicon/favicon_service_factory.h" |
22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/common/chrome_constants.h" | 24 #include "chrome/common/chrome_constants.h" |
24 #include "chrome/common/render_messages.h" | 25 #include "chrome/common/render_messages.h" |
25 #include "chrome/common/web_application_info.h" | 26 #include "chrome/common/web_application_info.h" |
26 #include "components/dom_distiller/core/url_utils.h" | 27 #include "components/dom_distiller/core/url_utils.h" |
27 #include "content/public/browser/user_metrics.h" | 28 #include "content/public/browser/user_metrics.h" |
28 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
29 #include "content/public/browser/web_contents_observer.h" | 30 #include "content/public/browser/web_contents_observer.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 case MANIFEST_ICON_STATUS_DONE: | 212 case MANIFEST_ICON_STATUS_DONE: |
212 AddShortcutUsingManifestIcon(); | 213 AddShortcutUsingManifestIcon(); |
213 break; | 214 break; |
214 } | 215 } |
215 } | 216 } |
216 | 217 |
217 void ShortcutHelper::AddShortcutUsingManifestIcon() { | 218 void ShortcutHelper::AddShortcutUsingManifestIcon() { |
218 // Stop observing so we don't get destroyed while doing the last steps. | 219 // Stop observing so we don't get destroyed while doing the last steps. |
219 Observe(NULL); | 220 Observe(NULL); |
220 | 221 |
222 RecordAddToHomescreen(); | |
223 | |
221 base::WorkerPool::PostTask( | 224 base::WorkerPool::PostTask( |
222 FROM_HERE, | 225 FROM_HERE, |
223 base::Bind(&ShortcutHelper::AddShortcutInBackgroundWithSkBitmap, | 226 base::Bind(&ShortcutHelper::AddShortcutInBackgroundWithSkBitmap, |
224 shortcut_info_, | 227 shortcut_info_, |
225 manifest_icon_), | 228 manifest_icon_), |
226 true); | 229 true); |
227 | 230 |
228 Destroy(); | 231 Destroy(); |
229 } | 232 } |
230 | 233 |
231 void ShortcutHelper::AddShortcutUsingFavicon() { | 234 void ShortcutHelper::AddShortcutUsingFavicon() { |
235 RecordAddToHomescreen(); | |
gone
2015/02/17 17:58:43
The common point in the pathway for these is to go
benwells
2015/02/17 19:49:53
That's true but it is on the wrong thread. See htt
gone
2015/02/17 19:52:08
Hrm, fair point.
| |
236 | |
232 Profile* profile = | 237 Profile* profile = |
233 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 238 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
234 | 239 |
235 // Grab the best, largest icon we can find to represent this bookmark. | 240 // Grab the best, largest icon we can find to represent this bookmark. |
236 // TODO(dfalcantara): Try combining with the new BookmarksHandler once its | 241 // TODO(dfalcantara): Try combining with the new BookmarksHandler once its |
237 // rewrite is further along. | 242 // rewrite is further along. |
238 std::vector<int> icon_types; | 243 std::vector<int> icon_types; |
239 icon_types.push_back(favicon_base::FAVICON); | 244 icon_types.push_back(favicon_base::FAVICON); |
240 icon_types.push_back(favicon_base::TOUCH_PRECOMPOSED_ICON | | 245 icon_types.push_back(favicon_base::TOUCH_PRECOMPOSED_ICON | |
241 favicon_base::TOUCH_ICON); | 246 favicon_base::TOUCH_ICON); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
329 base::android::GetApplicationContext(), | 334 base::android::GetApplicationContext(), |
330 java_url.obj(), | 335 java_url.obj(), |
331 java_title.obj(), | 336 java_title.obj(), |
332 java_bitmap.obj(), | 337 java_bitmap.obj(), |
333 r_value, | 338 r_value, |
334 g_value, | 339 g_value, |
335 b_value, | 340 b_value, |
336 info.display == content::Manifest::DISPLAY_MODE_STANDALONE, | 341 info.display == content::Manifest::DISPLAY_MODE_STANDALONE, |
337 info.orientation); | 342 info.orientation); |
338 } | 343 } |
344 | |
345 void ShortcutHelper::RecordAddToHomescreen() { | |
346 // Record that the shortcut has been added, so no banners will be shown | |
347 // for this app. | |
348 AppBannerSettingsHelper::RecordBannerEvent( | |
349 web_contents(), shortcut_info_.url, shortcut_info_.url.spec(), | |
350 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, | |
351 base::Time::Now()); | |
352 } | |
OLD | NEW |