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

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: Merge branch 'master' into webapk_builder_impl2 Created 4 years, 4 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_installer.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::AddToLauncherInBackgroundWithSkBitmap( 65 void ShortcutHelper::AddToLauncherInBackgroundWithSkBitmap(
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 InstallWebApkInBackgroundWithSkBitmap(info, webapp_id, icon_bitmap); 77 InstallWebApkInBackgroundWithSkBitmap(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 AddShortcutInBackgroundWithSkBitmap(info, icon_bitmap); 84 AddShortcutInBackgroundWithSkBitmap(info, icon_bitmap);
83 } 85 }
84 86
85 // static 87 // static
86 void ShortcutHelper::InstallWebApkInBackgroundWithSkBitmap( 88 void ShortcutHelper::InstallWebApkInBackgroundWithSkBitmap(
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 // WebApkInstaller destroys itself when it is done.
92 // TODO(pkotwicz): Send request to WebAPK server to generate WebAPK. 94 WebApkInstaller* builder =
93 95 new WebApkInstaller(browser_context, info, icon_bitmap);
94 JNIEnv* env = base::android::AttachCurrentThread(); 96 builder->InstallAsync(base::Bind(&ShortcutHelper::OnBuiltWebApk));
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 } 97 }
125 98
126 // static 99 // static
127 void ShortcutHelper::AddWebappInBackgroundWithSkBitmap( 100 void ShortcutHelper::AddWebappInBackgroundWithSkBitmap(
128 const ShortcutInfo& info, 101 const ShortcutInfo& info,
129 const std::string& webapp_id, 102 const std::string& webapp_id,
130 const SkBitmap& icon_bitmap, 103 const SkBitmap& icon_bitmap,
131 const base::Closure& splash_image_callback) { 104 const base::Closure& splash_image_callback) {
132 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 105 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
133 106
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 ScopedJavaLocalRef<jstring> java_user_title = 158 ScopedJavaLocalRef<jstring> java_user_title =
186 base::android::ConvertUTF16ToJavaString(env, info.user_title); 159 base::android::ConvertUTF16ToJavaString(env, info.user_title);
187 ScopedJavaLocalRef<jobject> java_bitmap; 160 ScopedJavaLocalRef<jobject> java_bitmap;
188 if (icon_bitmap.getSize()) 161 if (icon_bitmap.getSize())
189 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); 162 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap);
190 163
191 Java_ShortcutHelper_addShortcut(env, java_url.obj(), java_user_title.obj(), 164 Java_ShortcutHelper_addShortcut(env, java_url.obj(), java_user_title.obj(),
192 java_bitmap.obj(), info.source); 165 java_bitmap.obj(), info.source);
193 } 166 }
194 167
168 void ShortcutHelper::OnBuiltWebApk(bool success) {
169 if (success) {
170 LOG(ERROR) << "Sent request to install WebAPK. Seems to have worked.";
171 } else {
172 LOG(ERROR) << "WebAPK install failed.";
173 }
174 // TODO(pkotwicz): Figure out what to do when installing WebAPK fails.
175 // (crbug.com/626950)
176 }
177
195 int ShortcutHelper::GetIdealHomescreenIconSizeInDp() { 178 int ShortcutHelper::GetIdealHomescreenIconSizeInDp() {
196 if (kIdealHomescreenIconSize == -1) 179 if (kIdealHomescreenIconSize == -1)
197 GetHomescreenIconAndSplashImageSizes(); 180 GetHomescreenIconAndSplashImageSizes();
198 return kIdealHomescreenIconSize; 181 return kIdealHomescreenIconSize;
199 } 182 }
200 183
201 int ShortcutHelper::GetMinimumHomescreenIconSizeInDp() { 184 int ShortcutHelper::GetMinimumHomescreenIconSizeInDp() {
202 if (kMinimumHomescreenIconSize == -1) 185 if (kMinimumHomescreenIconSize == -1)
203 GetHomescreenIconAndSplashImageSizes(); 186 GetHomescreenIconAndSplashImageSizes();
204 return kMinimumHomescreenIconSize; 187 return kMinimumHomescreenIconSize;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 DCHECK(jsplash_image_callback); 292 DCHECK(jsplash_image_callback);
310 base::Closure* splash_image_callback = 293 base::Closure* splash_image_callback =
311 reinterpret_cast<base::Closure*>(jsplash_image_callback); 294 reinterpret_cast<base::Closure*>(jsplash_image_callback);
312 splash_image_callback->Run(); 295 splash_image_callback->Run();
313 delete splash_image_callback; 296 delete splash_image_callback;
314 } 297 }
315 298
316 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { 299 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) {
317 return RegisterNativesImpl(env); 300 return RegisterNativesImpl(env);
318 } 301 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698