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

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

Issue 2138973002: Initial CL for talking to the WebAPK server to generate WebAPK (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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_array.h" 10 #include "base/android/jni_array.h"
11 #include "base/android/jni_string.h" 11 #include "base/android/jni_string.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/strings/string16.h" 15 #include "base/strings/string16.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "chrome/browser/android/webapk/webapk_builder.h"
17 #include "chrome/browser/manifest/manifest_icon_downloader.h" 18 #include "chrome/browser/manifest/manifest_icon_downloader.h"
18 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
19 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
21 #include "jni/ShortcutHelper_jni.h" 22 #include "jni/ShortcutHelper_jni.h"
22 #include "ui/gfx/android/java_bitmap.h" 23 #include "ui/gfx/android/java_bitmap.h"
23 #include "ui/gfx/color_analysis.h" 24 #include "ui/gfx/color_analysis.h"
24 #include "url/gurl.h" 25 #include "url/gurl.h"
25 26
26 using content::Manifest; 27 using content::Manifest;
(...skipping 28 matching lines...) Expand all
55 56
56 // Try to ensure that the data returned is sane. 57 // Try to ensure that the data returned is sane.
57 DCHECK(kMinimumHomescreenIconSize <= kIdealHomescreenIconSize); 58 DCHECK(kMinimumHomescreenIconSize <= kIdealHomescreenIconSize);
58 DCHECK(kMinimumSplashImageSize <= kIdealSplashImageSize); 59 DCHECK(kMinimumSplashImageSize <= kIdealSplashImageSize);
59 } 60 }
60 61
61 } // anonymous namespace 62 } // anonymous namespace
62 63
63 // static 64 // static
64 void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap( 65 void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap(
66 content::BrowserContext* browser_context,
65 const ShortcutInfo& info, 67 const ShortcutInfo& info,
66 const std::string& webapp_id, 68 const std::string& webapp_id,
67 const SkBitmap& icon_bitmap, 69 const SkBitmap& icon_bitmap,
68 const base::Closure& splash_image_callback) { 70 const base::Closure& splash_image_callback) {
69 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 71 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
70 72
71 if (info.display == blink::WebDisplayModeStandalone || 73 if (info.display == blink::WebDisplayModeStandalone ||
72 info.display == blink::WebDisplayModeFullscreen) { 74 info.display == blink::WebDisplayModeFullscreen) {
73 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 75 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
74 switches::kEnableWebApk)) { 76 switches::kEnableWebApk)) {
75 AddWebApkInBackgroundWithSkBitmap(info, webapp_id, icon_bitmap); 77 AddWebApkInBackgroundWithSkBitmap(browser_context, info, icon_bitmap);
76 return; 78 return;
77 } 79 }
78 AddWebappInBackgroundWithSkBitmap(info, webapp_id, icon_bitmap, 80 AddWebappInBackgroundWithSkBitmap(info, webapp_id, icon_bitmap,
79 splash_image_callback); 81 splash_image_callback);
80 return; 82 return;
81 } 83 }
82 AddBookmarkShortcutInBackgroundWithSkBitmap(info, icon_bitmap); 84 AddBookmarkShortcutInBackgroundWithSkBitmap(info, icon_bitmap);
83 } 85 }
84 86
85 // static 87 // static
86 void ShortcutHelper::AddWebApkInBackgroundWithSkBitmap( 88 void ShortcutHelper::AddWebApkInBackgroundWithSkBitmap(
89 content::BrowserContext* browser_context,
87 const ShortcutInfo& info, 90 const ShortcutInfo& info,
88 const std::string& webapp_id,
89 const SkBitmap& icon_bitmap) { 91 const SkBitmap& icon_bitmap) {
90 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 92 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
91 93 WebApkBuilder* builder =
92 // TODO(pkotwicz): Send request to WebAPK server to generate WebAPK. 94 new WebApkBuilder(browser_context, info, icon_bitmap);
Yaron 2016/07/13 00:24:00 brief comment on ownership please
pkotwicz 2016/07/13 02:15:30 Done.
93 95 builder->BuildAsync(base::Bind(&ShortcutHelper::OnBuiltWebApk));
94 JNIEnv* env = base::android::AttachCurrentThread();
95 ScopedJavaLocalRef<jstring> java_url =
96 base::android::ConvertUTF8ToJavaString(env, info.url.spec());
97 ScopedJavaLocalRef<jstring> java_scope_url =
98 base::android::ConvertUTF8ToJavaString(env, info.scope.spec());
99 ScopedJavaLocalRef<jstring> java_name =
100 base::android::ConvertUTF16ToJavaString(env, info.name);
101 ScopedJavaLocalRef<jstring> java_short_name =
102 base::android::ConvertUTF16ToJavaString(env, info.short_name);
103 ScopedJavaLocalRef<jstring> java_icon_url =
104 base::android::ConvertUTF8ToJavaString(env, info.icon_url.spec());
105 ScopedJavaLocalRef<jobject> java_bitmap;
106 if (icon_bitmap.getSize())
107 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap);
108 ScopedJavaLocalRef<jstring> java_manifest_url =
109 base::android::ConvertUTF8ToJavaString(env, info.manifest_url.spec());
110
111 Java_ShortcutHelper_installWebApk(
112 env,
113 java_url.obj(),
114 java_scope_url.obj(),
115 java_name.obj(),
116 java_short_name.obj(),
117 java_icon_url.obj(),
118 java_bitmap.obj(),
119 info.display,
120 info.orientation,
121 info.theme_color,
122 info.background_color,
123 java_manifest_url.obj());
124 } 96 }
125 97
126 // static 98 // static
127 void ShortcutHelper::AddWebappInBackgroundWithSkBitmap( 99 void ShortcutHelper::AddWebappInBackgroundWithSkBitmap(
128 const ShortcutInfo& info, 100 const ShortcutInfo& info,
129 const std::string& webapp_id, 101 const std::string& webapp_id,
130 const SkBitmap& icon_bitmap, 102 const SkBitmap& icon_bitmap,
131 const base::Closure& splash_image_callback) { 103 const base::Closure& splash_image_callback) {
132 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 104 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
133 105
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 base::android::ConvertUTF16ToJavaString(env, info.user_title); 158 base::android::ConvertUTF16ToJavaString(env, info.user_title);
187 ScopedJavaLocalRef<jobject> java_bitmap; 159 ScopedJavaLocalRef<jobject> java_bitmap;
188 if (icon_bitmap.getSize()) 160 if (icon_bitmap.getSize())
189 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); 161 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap);
190 162
191 Java_ShortcutHelper_addBookmarkShortcut(env, java_url.obj(), 163 Java_ShortcutHelper_addBookmarkShortcut(env, java_url.obj(),
192 java_user_title.obj(), 164 java_user_title.obj(),
193 java_bitmap.obj(), info.source); 165 java_bitmap.obj(), info.source);
194 } 166 }
195 167
168 void ShortcutHelper::OnBuiltWebApk(bool success) {
Yaron 2016/07/13 00:24:01 without any state on what was successful (Shortcut
pkotwicz 2016/07/13 02:15:30 Yes ShortcutHelper::OnBuiltWebApk() should take mo
169 if (success) {
170 LOG(ERROR)
171 << "Sent request to create WebAPK to server. Seems to have worked.";
172 } else {
173 LOG(ERROR) << "Server request to create WebAPK failed.";
174 }
175 // TODO(pkotwicz): Figure out what to do when building WebAPK fails.
176 // (crbug.com/626950)
177 }
178
196 int ShortcutHelper::GetIdealHomescreenIconSizeInDp() { 179 int ShortcutHelper::GetIdealHomescreenIconSizeInDp() {
197 if (kIdealHomescreenIconSize == -1) 180 if (kIdealHomescreenIconSize == -1)
198 GetHomescreenIconAndSplashImageSizes(); 181 GetHomescreenIconAndSplashImageSizes();
199 return kIdealHomescreenIconSize; 182 return kIdealHomescreenIconSize;
200 } 183 }
201 184
202 int ShortcutHelper::GetMinimumHomescreenIconSizeInDp() { 185 int ShortcutHelper::GetMinimumHomescreenIconSizeInDp() {
203 if (kMinimumHomescreenIconSize == -1) 186 if (kMinimumHomescreenIconSize == -1)
204 GetHomescreenIconAndSplashImageSizes(); 187 GetHomescreenIconAndSplashImageSizes();
205 return kMinimumHomescreenIconSize; 188 return kMinimumHomescreenIconSize;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 DCHECK(jsplash_image_callback); 293 DCHECK(jsplash_image_callback);
311 base::Closure* splash_image_callback = 294 base::Closure* splash_image_callback =
312 reinterpret_cast<base::Closure*>(jsplash_image_callback); 295 reinterpret_cast<base::Closure*>(jsplash_image_callback);
313 splash_image_callback->Run(); 296 splash_image_callback->Run();
314 delete splash_image_callback; 297 delete splash_image_callback;
315 } 298 }
316 299
317 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { 300 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) {
318 return RegisterNativesImpl(env); 301 return RegisterNativesImpl(env);
319 } 302 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698