Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / android / shortcut_helper.cc
blobcead81b0d9f22a05e0c5ef072dfd7b067508c017
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
3 // found in the LICENSE file.
5 #include "chrome/browser/android/shortcut_helper.h"
7 #include <jni.h>
9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h"
11 #include "base/basictypes.h"
12 #include "base/strings/string16.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/manifest/manifest_icon_downloader.h"
15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/web_contents.h"
17 #include "jni/ShortcutHelper_jni.h"
18 #include "ui/gfx/android/java_bitmap.h"
19 #include "url/gurl.h"
21 using content::Manifest;
23 // static
24 void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap(
25 const ShortcutInfo& info,
26 const std::string& webapp_id,
27 const SkBitmap& icon_bitmap) {
28 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
30 // Send the data to the Java side to create the shortcut.
31 JNIEnv* env = base::android::AttachCurrentThread();
32 ScopedJavaLocalRef<jstring> java_webapp_id =
33 base::android::ConvertUTF8ToJavaString(env, webapp_id);
34 ScopedJavaLocalRef<jstring> java_url =
35 base::android::ConvertUTF8ToJavaString(env, info.url.spec());
36 ScopedJavaLocalRef<jstring> java_user_title =
37 base::android::ConvertUTF16ToJavaString(env, info.user_title);
38 ScopedJavaLocalRef<jstring> java_name =
39 base::android::ConvertUTF16ToJavaString(env, info.name);
40 ScopedJavaLocalRef<jstring> java_short_name =
41 base::android::ConvertUTF16ToJavaString(env, info.short_name);
42 ScopedJavaLocalRef<jobject> java_bitmap;
43 if (icon_bitmap.getSize())
44 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap);
46 Java_ShortcutHelper_addShortcut(
47 env,
48 base::android::GetApplicationContext(),
49 java_webapp_id.obj(),
50 java_url.obj(),
51 java_user_title.obj(),
52 java_name.obj(),
53 java_short_name.obj(),
54 java_bitmap.obj(),
55 info.display == blink::WebDisplayModeStandalone,
56 info.orientation,
57 info.source,
58 info.theme_color,
59 info.background_color);
62 // static
63 void ShortcutHelper::FetchSplashScreenImage(
64 content::WebContents* web_contents,
65 const GURL& image_url,
66 const int ideal_splash_image_size_in_dp,
67 const std::string& webapp_id) {
68 // This is a fire and forget task. It is not vital for the splash screen image
69 // to be downloaded so if the downloader returns false there is no fallback.
70 ManifestIconDownloader::Download(
71 web_contents,
72 image_url,
73 ideal_splash_image_size_in_dp,
74 base::Bind(&ShortcutHelper::StoreWebappData, webapp_id));
77 // static
78 void ShortcutHelper::StoreWebappData(
79 const std::string& webapp_id,
80 const SkBitmap& splash_image) {
81 if (splash_image.drawsNothing())
82 return;
84 JNIEnv* env = base::android::AttachCurrentThread();
85 ScopedJavaLocalRef<jstring> java_webapp_id =
86 base::android::ConvertUTF8ToJavaString(env, webapp_id);
87 ScopedJavaLocalRef<jobject> java_splash_image =
88 gfx::ConvertToJavaBitmap(&splash_image);
90 Java_ShortcutHelper_storeWebappData(
91 env,
92 base::android::GetApplicationContext(),
93 java_webapp_id.obj(),
94 java_splash_image.obj());
97 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) {
98 return RegisterNativesImpl(env);