| OLD | NEW |
| 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 package org.chromium.chrome.browser; | 5 package org.chromium.chrome.browser; |
| 6 | 6 |
| 7 import android.app.ActivityManager; | 7 import android.app.ActivityManager; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.content.Intent; | 9 import android.content.Intent; |
| 10 import android.graphics.Bitmap; | 10 import android.graphics.Bitmap; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 shortcutIntent = new Intent(); | 148 shortcutIntent = new Intent(); |
| 149 shortcutIntent.setAction(sFullScreenAction); | 149 shortcutIntent.setAction(sFullScreenAction); |
| 150 shortcutIntent.putExtra(EXTRA_ICON, encodedIcon); | 150 shortcutIntent.putExtra(EXTRA_ICON, encodedIcon); |
| 151 shortcutIntent.putExtra(EXTRA_ID, UUID.randomUUID().toString()); | 151 shortcutIntent.putExtra(EXTRA_ID, UUID.randomUUID().toString()); |
| 152 shortcutIntent.putExtra(EXTRA_TITLE, title); | 152 shortcutIntent.putExtra(EXTRA_TITLE, title); |
| 153 shortcutIntent.putExtra(EXTRA_URL, url); | 153 shortcutIntent.putExtra(EXTRA_URL, url); |
| 154 shortcutIntent.putExtra(EXTRA_ORIENTATION, orientation); | 154 shortcutIntent.putExtra(EXTRA_ORIENTATION, orientation); |
| 155 shortcutIntent.putExtra(EXTRA_MAC, getEncodedMac(context, url)); | 155 shortcutIntent.putExtra(EXTRA_MAC, getEncodedMac(context, url)); |
| 156 } else { | 156 } else { |
| 157 // Add the shortcut as a launcher icon to open in the browser Activi
ty. | 157 // Add the shortcut as a launcher icon to open in the browser Activi
ty. |
| 158 shortcutIntent = BookmarkUtils.createShortcutIntent(context, url); | 158 shortcutIntent = BookmarkUtils.createShortcutIntent(url); |
| 159 } | 159 } |
| 160 | 160 |
| 161 shortcutIntent.setPackage(context.getPackageName()); | 161 shortcutIntent.setPackage(context.getPackageName()); |
| 162 context.sendBroadcast(BookmarkUtils.createAddToHomeIntent(context, short
cutIntent, title, | 162 Bitmap launchIcon = BookmarkUtils.createLauncherIcon(context, icon, url,
red, green, blue); |
| 163 icon, url, red, green, blue)); | 163 context.sendBroadcast(BookmarkUtils.createAddToHomeIntent(shortcutIntent
, title, |
| 164 launchIcon, url)); |
| 164 | 165 |
| 165 // Alert the user about adding the shortcut. | 166 // Alert the user about adding the shortcut. |
| 166 if (returnToHomescreen) { | 167 if (returnToHomescreen) { |
| 167 Intent homeIntent = new Intent(Intent.ACTION_MAIN); | 168 Intent homeIntent = new Intent(Intent.ACTION_MAIN); |
| 168 homeIntent.addCategory(Intent.CATEGORY_HOME); | 169 homeIntent.addCategory(Intent.CATEGORY_HOME); |
| 169 homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 170 homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 170 context.startActivity(homeIntent); | 171 context.startActivity(homeIntent); |
| 171 } else { | 172 } else { |
| 172 final String shortUrl = UrlUtilities.getDomainAndRegistry(url, true)
; | 173 final String shortUrl = UrlUtilities.getDomainAndRegistry(url, true)
; |
| 173 Handler handler = new Handler(Looper.getMainLooper()); | 174 Handler handler = new Handler(Looper.getMainLooper()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 193 // lacks the key for the extra. | 194 // lacks the key for the extra. |
| 194 byte[] mac = WebappAuthenticator.getMacForUrl(context, url); | 195 byte[] mac = WebappAuthenticator.getMacForUrl(context, url); |
| 195 return Base64.encodeToString(mac, Base64.DEFAULT); | 196 return Base64.encodeToString(mac, Base64.DEFAULT); |
| 196 } | 197 } |
| 197 | 198 |
| 198 private native long nativeInitialize(WebContents webContents); | 199 private native long nativeInitialize(WebContents webContents); |
| 199 private native void nativeAddShortcut(long nativeShortcutHelper, String user
RequestedTitle, | 200 private native void nativeAddShortcut(long nativeShortcutHelper, String user
RequestedTitle, |
| 200 int launcherLargeIconSize); | 201 int launcherLargeIconSize); |
| 201 private native void nativeTearDown(long nativeShortcutHelper); | 202 private native void nativeTearDown(long nativeShortcutHelper); |
| 202 } | 203 } |
| OLD | NEW |