| 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" | |
| 20 #include "chrome/browser/banners/app_banner_settings_helper.h" | 19 #include "chrome/browser/banners/app_banner_settings_helper.h" |
| 21 #include "chrome/browser/favicon/favicon_service.h" | 20 #include "chrome/browser/favicon/favicon_service.h" |
| 22 #include "chrome/browser/favicon/favicon_service_factory.h" | 21 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/common/chrome_constants.h" | 23 #include "chrome/common/chrome_constants.h" |
| 25 #include "chrome/common/render_messages.h" | 24 #include "chrome/common/render_messages.h" |
| 26 #include "chrome/common/web_application_info.h" | 25 #include "chrome/common/web_application_info.h" |
| 27 #include "components/dom_distiller/core/url_utils.h" | 26 #include "components/dom_distiller/core/url_utils.h" |
| 28 #include "content/public/browser/user_metrics.h" | 27 #include "content/public/browser/user_metrics.h" |
| 29 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 30 #include "content/public/browser/web_contents_observer.h" | 29 #include "content/public/browser/web_contents_observer.h" |
| 31 #include "content/public/common/frame_navigate_params.h" | 30 #include "content/public/common/frame_navigate_params.h" |
| 32 #include "content/public/common/manifest.h" | 31 #include "content/public/common/manifest.h" |
| 33 #include "jni/ShortcutHelper_jni.h" | 32 #include "jni/ShortcutHelper_jni.h" |
| 34 #include "net/base/mime_util.h" | 33 #include "net/base/mime_util.h" |
| 35 #include "third_party/WebKit/public/platform/WebScreenOrientationLockType.h" | 34 #include "third_party/WebKit/public/platform/WebScreenOrientationLockType.h" |
| 36 #include "ui/gfx/android/java_bitmap.h" | 35 #include "ui/gfx/android/java_bitmap.h" |
| 37 #include "ui/gfx/codec/png_codec.h" | 36 #include "ui/gfx/codec/png_codec.h" |
| 38 #include "ui/gfx/color_analysis.h" | 37 #include "ui/gfx/color_analysis.h" |
| 39 #include "ui/gfx/favicon_size.h" | 38 #include "ui/gfx/favicon_size.h" |
| 40 #include "ui/gfx/screen.h" | 39 #include "ui/gfx/screen.h" |
| 41 #include "url/gurl.h" | 40 #include "url/gurl.h" |
| 42 | 41 |
| 43 using content::Manifest; | 42 using content::Manifest; |
| 44 | 43 |
| 45 // Android's preferred icon size in DP is 48, as defined in | 44 // Android's preferred icon size in DP is 48, as defined in |
| 46 // http://developer.android.com/design/style/iconography.html | 45 // http://developer.android.com/design/style/iconography.html |
| 47 const int ShortcutHelper::kPreferredIconSizeInDp = 48; | 46 const int ShortcutHelper::kPreferredIconSizeInDp = 48; |
| 48 | 47 |
| 49 jlong Initialize(JNIEnv* env, jobject obj, jlong tab_android_ptr) { | 48 jlong Initialize(JNIEnv* env, jobject obj, jobject java_web_contents) { |
| 50 TabAndroid* tab = reinterpret_cast<TabAndroid*>(tab_android_ptr); | 49 content::WebContents* web_contents = |
| 51 | 50 content::WebContents::FromJavaWebContents(java_web_contents); |
| 52 ShortcutHelper* shortcut_helper = | 51 ShortcutHelper* shortcut_helper = new ShortcutHelper(env, obj, web_contents); |
| 53 new ShortcutHelper(env, obj, tab->web_contents()); | |
| 54 shortcut_helper->Initialize(); | 52 shortcut_helper->Initialize(); |
| 55 | 53 |
| 56 return reinterpret_cast<intptr_t>(shortcut_helper); | 54 return reinterpret_cast<intptr_t>(shortcut_helper); |
| 57 } | 55 } |
| 58 | 56 |
| 59 ShortcutHelper::ShortcutHelper(JNIEnv* env, | 57 ShortcutHelper::ShortcutHelper(JNIEnv* env, |
| 60 jobject obj, | 58 jobject obj, |
| 61 content::WebContents* web_contents) | 59 content::WebContents* web_contents) |
| 62 : WebContentsObserver(web_contents), | 60 : WebContentsObserver(web_contents), |
| 63 java_ref_(env, obj), | 61 java_ref_(env, obj), |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 } | 344 } |
| 347 | 345 |
| 348 void ShortcutHelper::RecordAddToHomescreen() { | 346 void ShortcutHelper::RecordAddToHomescreen() { |
| 349 // Record that the shortcut has been added, so no banners will be shown | 347 // Record that the shortcut has been added, so no banners will be shown |
| 350 // for this app. | 348 // for this app. |
| 351 AppBannerSettingsHelper::RecordBannerEvent( | 349 AppBannerSettingsHelper::RecordBannerEvent( |
| 352 web_contents(), shortcut_info_.url, shortcut_info_.url.spec(), | 350 web_contents(), shortcut_info_.url, shortcut_info_.url.spec(), |
| 353 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, | 351 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, |
| 354 base::Time::Now()); | 352 base::Time::Now()); |
| 355 } | 353 } |
| OLD | NEW |