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_dialog_helper.h" | 5 #include "chrome/browser/android/webapps/add_to_homescreen_dialog_helper.h" |
6 | 6 |
7 #include <jni.h> | 7 #include <jni.h> |
8 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/guid.h" | |
12 #include "base/location.h" | 13 #include "base/location.h" |
13 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
15 #include "chrome/browser/android/shortcut_helper.h" | 16 #include "chrome/browser/android/shortcut_helper.h" |
16 #include "chrome/browser/banners/app_banner_settings_helper.h" | 17 #include "chrome/browser/banners/app_banner_settings_helper.h" |
17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
19 #include "content/public/common/manifest.h" | 20 #include "content/public/common/manifest.h" |
20 #include "jni/AddToHomescreenDialogHelper_jni.h" | 21 #include "jni/AddToHomescreenDialogHelper_jni.h" |
21 #include "ui/gfx/android/java_bitmap.h" | 22 #include "ui/gfx/android/java_bitmap.h" |
22 #include "ui/gfx/color_analysis.h" | 23 #include "ui/gfx/color_analysis.h" |
23 #include "url/gurl.h" | 24 #include "url/gurl.h" |
24 | 25 |
25 using content::Manifest; | 26 using content::Manifest; |
26 | 27 |
27 jlong Initialize(JNIEnv* env, jobject obj, jobject java_web_contents) { | 28 jlong Initialize(JNIEnv* env, |
29 jobject obj, | |
30 jobject java_web_contents, | |
31 jint ideal_splash_icon_size_in_dp, | |
Lalit Maganti
2015/08/26 21:18:21
And here.
Lalit Maganti
2015/08/26 22:55:00
Done.
| |
32 jint ideal_icon_size_in_dp) { | |
28 content::WebContents* web_contents = | 33 content::WebContents* web_contents = |
29 content::WebContents::FromJavaWebContents(java_web_contents); | 34 content::WebContents::FromJavaWebContents(java_web_contents); |
30 AddToHomescreenDialogHelper* add_to_homescreen_helper = | 35 AddToHomescreenDialogHelper* add_to_homescreen_helper = |
31 new AddToHomescreenDialogHelper(env, obj, web_contents); | 36 new AddToHomescreenDialogHelper(env, obj, web_contents, |
37 ideal_splash_icon_size_in_dp, ideal_icon_size_in_dp); | |
32 return reinterpret_cast<intptr_t>(add_to_homescreen_helper); | 38 return reinterpret_cast<intptr_t>(add_to_homescreen_helper); |
33 } | 39 } |
34 | 40 |
35 AddToHomescreenDialogHelper::AddToHomescreenDialogHelper(JNIEnv* env, | 41 AddToHomescreenDialogHelper::AddToHomescreenDialogHelper( |
36 jobject obj, | 42 JNIEnv* env, |
37 content::WebContents* web_contents) | 43 jobject obj, |
44 content::WebContents* web_contents, | |
45 int ideal_splash_icon_size_in_dp, | |
Lalit Maganti
2015/08/26 21:18:21
And here.
Lalit Maganti
2015/08/26 22:55:00
Done.
| |
46 int ideal_icon_size_in_dp) | |
38 : add_shortcut_pending_(false), | 47 : add_shortcut_pending_(false), |
39 data_fetcher_(new AddToHomescreenDataFetcher(web_contents, this)) { | 48 data_fetcher_(new AddToHomescreenDataFetcher(web_contents, |
49 ideal_splash_icon_size_in_dp, | |
50 ideal_icon_size_in_dp, | |
51 this)) { | |
40 java_ref_.Reset(env, obj); | 52 java_ref_.Reset(env, obj); |
41 } | 53 } |
42 | 54 |
43 AddToHomescreenDialogHelper::~AddToHomescreenDialogHelper() { | 55 AddToHomescreenDialogHelper::~AddToHomescreenDialogHelper() { |
44 data_fetcher_->set_weak_observer(nullptr); | 56 data_fetcher_->set_weak_observer(nullptr); |
45 data_fetcher_ = nullptr; | 57 data_fetcher_ = nullptr; |
46 } | 58 } |
47 | 59 |
48 void AddToHomescreenDialogHelper::OnUserTitleAvailable( | 60 void AddToHomescreenDialogHelper::OnUserTitleAvailable( |
49 const base::string16& user_title) { | 61 const base::string16& user_title) { |
50 JNIEnv* env = base::android::AttachCurrentThread(); | 62 JNIEnv* env = base::android::AttachCurrentThread(); |
51 ScopedJavaLocalRef<jstring> j_user_title = | 63 ScopedJavaLocalRef<jstring> j_user_title = |
52 base::android::ConvertUTF16ToJavaString(env, user_title); | 64 base::android::ConvertUTF16ToJavaString(env, user_title); |
53 Java_AddToHomescreenDialogHelper_onUserTitleAvailable(env, | 65 Java_AddToHomescreenDialogHelper_onUserTitleAvailable(env, |
54 java_ref_.obj(), | 66 java_ref_.obj(), |
55 j_user_title.obj()); | 67 j_user_title.obj()); |
56 } | 68 } |
57 | 69 |
58 void AddToHomescreenDialogHelper::OnDataAvailable(const ShortcutInfo& info, | 70 void AddToHomescreenDialogHelper::OnDataAvailable(const ShortcutInfo& info, |
59 const SkBitmap& icon) { | 71 const SkBitmap& icon) { |
60 JNIEnv* env = base::android::AttachCurrentThread(); | 72 JNIEnv* env = base::android::AttachCurrentThread(); |
61 ScopedJavaLocalRef<jobject> java_bitmap; | 73 ScopedJavaLocalRef<jobject> java_bitmap; |
62 if (icon.getSize()) | 74 if (icon.getSize()) |
63 java_bitmap = gfx::ConvertToJavaBitmap(&icon); | 75 java_bitmap = gfx::ConvertToJavaBitmap(&icon); |
64 | 76 |
65 Java_AddToHomescreenDialogHelper_onIconAvailable(env, | 77 Java_AddToHomescreenDialogHelper_onIconAvailable(env, |
66 java_ref_.obj(), | 78 java_ref_.obj(), |
67 java_bitmap.obj()); | 79 java_bitmap.obj()); |
68 | 80 |
69 if (add_shortcut_pending_) | 81 if (add_shortcut_pending_) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 data_fetcher_->shortcut_info().user_title = user_title; | 127 data_fetcher_->shortcut_info().user_title = user_title; |
116 | 128 |
117 if (data_fetcher_->is_ready()) { | 129 if (data_fetcher_->is_ready()) { |
118 // If the fetcher isn't ready yet, the shortcut will be added when it is | 130 // If the fetcher isn't ready yet, the shortcut will be added when it is |
119 // via OnDataAvailable(); | 131 // via OnDataAvailable(); |
120 AddShortcut(data_fetcher_->shortcut_info(), data_fetcher_->shortcut_icon()); | 132 AddShortcut(data_fetcher_->shortcut_info(), data_fetcher_->shortcut_icon()); |
121 } | 133 } |
122 } | 134 } |
123 | 135 |
124 void AddToHomescreenDialogHelper::AddShortcut(const ShortcutInfo& info, | 136 void AddToHomescreenDialogHelper::AddShortcut(const ShortcutInfo& info, |
125 const SkBitmap& icon) { | 137 const SkBitmap& icon) { |
126 DCHECK(add_shortcut_pending_); | 138 DCHECK(add_shortcut_pending_); |
127 if (!add_shortcut_pending_) | 139 if (!add_shortcut_pending_) |
128 return; | 140 return; |
129 add_shortcut_pending_ = false; | 141 add_shortcut_pending_ = false; |
130 | 142 |
131 RecordAddToHomescreen(); | 143 RecordAddToHomescreen(); |
132 | 144 |
145 const std::string& uid = base::GenerateGUID(); | |
133 content::BrowserThread::PostTask( | 146 content::BrowserThread::PostTask( |
134 content::BrowserThread::IO, | 147 content::BrowserThread::IO, |
135 FROM_HERE, | 148 FROM_HERE, |
136 base::Bind(&ShortcutHelper::AddShortcutInBackgroundWithSkBitmap, | 149 base::Bind(&ShortcutHelper::AddShortcutInBackgroundWithSkBitmap, |
137 info, | 150 info, |
151 uid, | |
138 icon)); | 152 icon)); |
153 | |
154 data_fetcher_->FetchSplashscreenImage(uid); | |
139 } | 155 } |
140 | 156 |
141 bool AddToHomescreenDialogHelper::RegisterAddToHomescreenDialogHelper( | 157 bool AddToHomescreenDialogHelper::RegisterAddToHomescreenDialogHelper( |
142 JNIEnv* env) { | 158 JNIEnv* env) { |
143 return RegisterNativesImpl(env); | 159 return RegisterNativesImpl(env); |
144 } | 160 } |
145 | 161 |
146 void AddToHomescreenDialogHelper::RecordAddToHomescreen() { | 162 void AddToHomescreenDialogHelper::RecordAddToHomescreen() { |
147 // Record that the shortcut has been added, so no banners will be shown | 163 // Record that the shortcut has been added, so no banners will be shown |
148 // for this app. | 164 // for this app. |
149 content::WebContents* web_contents = data_fetcher_->web_contents(); | 165 content::WebContents* web_contents = data_fetcher_->web_contents(); |
150 if (!web_contents) | 166 if (!web_contents) |
151 return; | 167 return; |
152 | 168 |
153 AppBannerSettingsHelper::RecordBannerEvent( | 169 AppBannerSettingsHelper::RecordBannerEvent( |
154 web_contents, web_contents->GetURL(), | 170 web_contents, web_contents->GetURL(), |
155 data_fetcher_->shortcut_info().url.spec(), | 171 data_fetcher_->shortcut_info().url.spec(), |
156 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, | 172 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, |
157 base::Time::Now()); | 173 base::Time::Now()); |
158 } | 174 } |
OLD | NEW |