Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: chrome/browser/android/shortcut_helper.cc

Issue 1224273003: webapps: propogate name and shortName from manifest to Java (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test compile on Android Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 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"
(...skipping 25 matching lines...) Expand all
36 : add_shortcut_pending_(false), 36 : add_shortcut_pending_(false),
37 data_fetcher_(new ShortcutDataFetcher(web_contents, this)) { 37 data_fetcher_(new ShortcutDataFetcher(web_contents, this)) {
38 java_ref_.Reset(env, obj); 38 java_ref_.Reset(env, obj);
39 } 39 }
40 40
41 ShortcutHelper::~ShortcutHelper() { 41 ShortcutHelper::~ShortcutHelper() {
42 data_fetcher_->set_weak_observer(nullptr); 42 data_fetcher_->set_weak_observer(nullptr);
43 data_fetcher_ = nullptr; 43 data_fetcher_ = nullptr;
44 } 44 }
45 45
46 void ShortcutHelper::OnTitleAvailable(const base::string16& title) { 46 void ShortcutHelper::OnUserTitleAvailable(const base::string16& user_title) {
47 JNIEnv* env = base::android::AttachCurrentThread(); 47 JNIEnv* env = base::android::AttachCurrentThread();
48 ScopedJavaLocalRef<jstring> j_title = 48 ScopedJavaLocalRef<jstring> j_user_title =
49 base::android::ConvertUTF16ToJavaString(env, title); 49 base::android::ConvertUTF16ToJavaString(env, user_title);
50 Java_ShortcutHelper_onTitleAvailable(env, 50 Java_ShortcutHelper_onUserTitleAvailable(env,
51 java_ref_.obj(), 51 java_ref_.obj(),
52 j_title.obj()); 52 j_user_title.obj());
53 } 53 }
54 54
55 void ShortcutHelper::OnDataAvailable(const ShortcutInfo& info, 55 void ShortcutHelper::OnDataAvailable(const ShortcutInfo& info,
56 const SkBitmap& icon) { 56 const SkBitmap& icon) {
57 JNIEnv* env = base::android::AttachCurrentThread(); 57 JNIEnv* env = base::android::AttachCurrentThread();
58 ScopedJavaLocalRef<jobject> java_bitmap; 58 ScopedJavaLocalRef<jobject> java_bitmap;
59 if (icon.getSize()) 59 if (icon.getSize())
60 java_bitmap = gfx::ConvertToJavaBitmap(&icon); 60 java_bitmap = gfx::ConvertToJavaBitmap(&icon);
61 61
62 Java_ShortcutHelper_onIconAvailable(env, 62 Java_ShortcutHelper_onIconAvailable(env,
(...skipping 30 matching lines...) Expand all
93 base::android::ScopedJavaLocalRef<jobject> ref = 93 base::android::ScopedJavaLocalRef<jobject> ref =
94 Java_ShortcutHelper_finalizeLauncherIcon(env, 94 Java_ShortcutHelper_finalizeLauncherIcon(env,
95 java_url.obj(), 95 java_url.obj(),
96 java_bitmap.obj(), 96 java_bitmap.obj(),
97 dominant_red, 97 dominant_red,
98 dominant_green, 98 dominant_green,
99 dominant_blue); 99 dominant_blue);
100 return gfx::CreateSkBitmapFromJavaBitmap(gfx::JavaBitmap(ref.obj())); 100 return gfx::CreateSkBitmapFromJavaBitmap(gfx::JavaBitmap(ref.obj()));
101 } 101 }
102 102
103 void ShortcutHelper::AddShortcut(JNIEnv* env, jobject obj, jstring jtitle) { 103 void ShortcutHelper::AddShortcut(JNIEnv* env, jobject obj, jstring jusertitle) {
mlamouri (slow - plz ping) 2015/07/09 16:34:17 Hmm, "jtitle" was border line wrt coding style, ju
104 add_shortcut_pending_ = true; 104 add_shortcut_pending_ = true;
105 105
106 base::string16 title = base::android::ConvertJavaStringToUTF16(env, jtitle); 106 base::string16 user_title =
107 if (!title.empty()) 107 base::android::ConvertJavaStringToUTF16(env, jusertitle);
108 data_fetcher_->shortcut_info().title = title; 108 if (!user_title.empty())
109 data_fetcher_->shortcut_info().user_title = user_title;
109 110
110 if (data_fetcher_->is_ready()) { 111 if (data_fetcher_->is_ready()) {
111 // If the fetcher isn't ready yet, the shortcut will be added when it is 112 // If the fetcher isn't ready yet, the shortcut will be added when it is
112 // via OnDataAvailable(); 113 // via OnDataAvailable();
113 AddShortcut(data_fetcher_->shortcut_info(), data_fetcher_->shortcut_icon()); 114 AddShortcut(data_fetcher_->shortcut_info(), data_fetcher_->shortcut_icon());
114 } 115 }
115 } 116 }
116 117
117 void ShortcutHelper::AddShortcut(const ShortcutInfo& info, 118 void ShortcutHelper::AddShortcut(const ShortcutInfo& info,
118 const SkBitmap& icon) { 119 const SkBitmap& icon) {
(...skipping 19 matching lines...) Expand all
138 // static 139 // static
139 void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap( 140 void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap(
140 const ShortcutInfo& info, 141 const ShortcutInfo& info,
141 const SkBitmap& icon_bitmap) { 142 const SkBitmap& icon_bitmap) {
142 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 143 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
143 144
144 // Send the data to the Java side to create the shortcut. 145 // Send the data to the Java side to create the shortcut.
145 JNIEnv* env = base::android::AttachCurrentThread(); 146 JNIEnv* env = base::android::AttachCurrentThread();
146 ScopedJavaLocalRef<jstring> java_url = 147 ScopedJavaLocalRef<jstring> java_url =
147 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); 148 base::android::ConvertUTF8ToJavaString(env, info.url.spec());
148 ScopedJavaLocalRef<jstring> java_title = 149 ScopedJavaLocalRef<jstring> java_user_title =
149 base::android::ConvertUTF16ToJavaString(env, info.title); 150 base::android::ConvertUTF16ToJavaString(env, info.user_title);
151 ScopedJavaLocalRef<jstring> java_name =
152 base::android::ConvertUTF16ToJavaString(env, info.name);
153 ScopedJavaLocalRef<jstring> java_short_name =
154 base::android::ConvertUTF16ToJavaString(env, info.short_name);
150 ScopedJavaLocalRef<jobject> java_bitmap; 155 ScopedJavaLocalRef<jobject> java_bitmap;
151 if (icon_bitmap.getSize()) 156 if (icon_bitmap.getSize())
152 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); 157 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap);
153 158
154 Java_ShortcutHelper_addShortcut( 159 Java_ShortcutHelper_addShortcut(
155 env, 160 env,
156 base::android::GetApplicationContext(), 161 base::android::GetApplicationContext(),
157 java_url.obj(), 162 java_url.obj(),
158 java_title.obj(), 163 java_user_title.obj(),
164 java_name.obj(),
165 java_short_name.obj(),
159 java_bitmap.obj(), 166 java_bitmap.obj(),
160 info.display == content::Manifest::DISPLAY_MODE_STANDALONE, 167 info.display == content::Manifest::DISPLAY_MODE_STANDALONE,
161 info.orientation, 168 info.orientation,
162 info.source); 169 info.source);
163 } 170 }
164 171
165 void ShortcutHelper::RecordAddToHomescreen() { 172 void ShortcutHelper::RecordAddToHomescreen() {
166 // Record that the shortcut has been added, so no banners will be shown 173 // Record that the shortcut has been added, so no banners will be shown
167 // for this app. 174 // for this app.
168 content::WebContents* web_contents = data_fetcher_->web_contents(); 175 content::WebContents* web_contents = data_fetcher_->web_contents();
169 if (!web_contents) 176 if (!web_contents)
170 return; 177 return;
171 178
172 AppBannerSettingsHelper::RecordBannerEvent( 179 AppBannerSettingsHelper::RecordBannerEvent(
173 web_contents, web_contents->GetURL(), 180 web_contents, web_contents->GetURL(),
174 data_fetcher_->shortcut_info().url.spec(), 181 data_fetcher_->shortcut_info().url.spec(),
175 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, 182 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN,
176 base::Time::Now()); 183 base::Time::Now());
177 } 184 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698