EMMA Coverage Report (generated Fri Aug 23 16:39:17 PDT 2013)
[all classes][org.chromium.chrome.browser]

COVERAGE SUMMARY FOR SOURCE FILE [ShortcutHelper.java]

nameclass, %method, %block, %line, %
ShortcutHelper.java100% (1/1)75%  (3/4)89%  (66/74)85%  (17/20)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ShortcutHelper100% (1/1)75%  (3/4)89%  (66/74)85%  (17/20)
ShortcutHelper (): void 0%   (0/1)0%   (0/3)0%   (0/1)
addShortcut (TabBase): void 100% (1/1)62%  (8/13)60%  (3/5)
addShortcut (Context, String, String, Bitmap, int, int, int, boolean): void 100% (1/1)100% (53/53)100% (11/11)
setWebappActivityInfo (String, String): void 100% (1/1)100% (5/5)100% (3/3)

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.
4 
5package org.chromium.chrome.browser;
6 
7import android.content.Context;
8import android.content.Intent;
9import android.graphics.Bitmap;
10import android.util.Log;
11 
12import org.chromium.base.CalledByNative;
13import org.chromium.chrome.browser.BookmarkUtils;
14 
15import java.util.UUID;
16 
17/**
18 * This is a helper class to create shortcuts on the Android home screen.
19 */
20public class ShortcutHelper {
21    public static final String EXTRA_ID = "webapp_id";
22    public static final String EXTRA_URL = "webapp_url";
23 
24    private static String sWebappActivityPackageName;
25    private static String sWebappActivityClassName;
26 
27    /**
28     * Sets the Activity that gets launched when a webapp shortcut is clicked.
29     * @param packageName Package of the Activity to launch.
30     * @param className Class name of the Activity to launch.
31     */
32    public static void setWebappActivityInfo(String packageName, String className) {
33        sWebappActivityPackageName = packageName;
34        sWebappActivityClassName = className;
35    }
36 
37    /**
38     * Adds a shortcut for the current Tab.
39     * @param tab Tab to create a shortcut for.
40     */
41    public static void addShortcut(TabBase tab) {
42        if (sWebappActivityPackageName == null || sWebappActivityClassName == null) {
43            Log.e("ShortcutHelper", "ShortcutHelper is uninitialized.  Aborting.");
44            return;
45        }
46        nativeAddShortcut(tab.getNativePtr());
47    }
48 
49    /**
50     * Called when we have to fire an Intent to add a shortcut to the homescreen.
51     * If the webpage indicated that it was capable of functioning as a webapp, it is added as a
52     * shortcut to a webapp Activity rather than as a general bookmark.
53     */
54    @SuppressWarnings("unused")
55    @CalledByNative
56    private static void addShortcut(Context context, String url, String title, Bitmap favicon,
57            int red, int green, int blue, boolean isWebappCapable) {
58        Intent addIntent;
59        if (isWebappCapable && !sWebappActivityPackageName.isEmpty()
60                && !sWebappActivityClassName.isEmpty()) {
61            // Add the shortcut as a launcher icon for a Webapp.
62            String id = UUID.randomUUID().toString();
63 
64            Intent shortcutIntent = new Intent();
65            shortcutIntent.setClassName(sWebappActivityPackageName, sWebappActivityClassName);
66            shortcutIntent.putExtra(EXTRA_URL, url);
67            shortcutIntent.putExtra(EXTRA_ID, id);
68 
69            addIntent = BookmarkUtils.createAddToHomeIntent(context, shortcutIntent, title, favicon,
70                            red, green, blue);
71        } else {
72            // Add the shortcut as a regular bookmark.
73            addIntent = BookmarkUtils.createAddToHomeIntent(context, url, title, favicon, red,
74                            green, blue);
75        }
76        context.sendBroadcast(addIntent);
77    }
78 
79    private static native void nativeAddShortcut(int tabAndroidPtr);
80}

[all classes][org.chromium.chrome.browser]
EMMA 2.0.5312 (C) Vladimir Roubtsov