Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / android / shortcut_helper.h
blob6200c3c89875702ee877fb594bcef2f8e8463919
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 #ifndef CHROME_BROWSER_ANDROID_SHORTCUT_HELPER_H_
6 #define CHROME_BROWSER_ANDROID_SHORTCUT_HELPER_H_
8 #include "base/android/jni_android.h"
9 #include "base/android/jni_weak_ref.h"
10 #include "base/basictypes.h"
11 #include "base/task/cancelable_task_tracker.h"
12 #include "chrome/browser/android/shortcut_info.h"
13 #include "chrome/common/web_application_info.h"
14 #include "components/favicon_base/favicon_types.h"
15 #include "content/public/browser/web_contents_observer.h"
16 #include "content/public/common/manifest.h"
18 namespace content {
19 class WebContents;
20 } // namespace content
22 namespace IPC {
23 class Message;
26 class GURL;
28 // ShortcutHelper is the C++ counterpart of org.chromium.chrome.browser's
29 // ShortcutHelper in Java. The object is owned by the Java object. It is created
30 // from there via a JNI (Initialize) call and can be destroyed from Java too
31 // using TearDown. When the Java implementations calls AddShortcut, it gives up
32 // the ownership of the object. The instance will then destroy itself when done.
33 class ShortcutHelper : public content::WebContentsObserver {
34 public:
35 ShortcutHelper(JNIEnv* env,
36 jobject obj,
37 content::WebContents* web_contents);
39 // Initialize the helper by requesting the information about the page to the
40 // renderer process. The initialization is asynchronous and
41 // OnDidRetrieveWebappInformation is expected to be called when finished.
42 void Initialize();
44 // Called by the Java counter part to let the object knows that it can destroy
45 // itself.
46 void TearDown(JNIEnv* env, jobject obj);
48 // IPC message received when the initialization is finished.
49 void OnDidGetWebApplicationInfo(const WebApplicationInfo& web_app_info);
51 // Callback run when the Manifest is ready to be used.
52 void OnDidGetManifest(const content::Manifest& manifest);
54 // Adds a shortcut to the current URL to the Android home screen.
55 void AddShortcut(JNIEnv* env,
56 jobject obj,
57 jstring title,
58 jint launcher_large_icon_size);
60 // Callback run when the requested Manifest icon is ready to be used.
61 void OnDidDownloadIcon(int id,
62 int http_status_code,
63 const GURL& url,
64 const std::vector<SkBitmap>& bitmaps,
65 const std::vector<gfx::Size>& sizes);
67 // Called after AddShortcut() and OnDidDownloadIcon() are run if
68 // OnDidDownloadIcon has a valid icon.
69 void AddShortcutUsingManifestIcon();
71 // Use FaviconService to get the best available favicon and create the
72 // shortcut using it. This is used when no Manifest icons are available or
73 // appropriate.
74 void AddShortcutUsingFavicon();
76 // Callback run when a favicon is received from GetFavicon() call.
77 void OnDidGetFavicon(
78 const favicon_base::FaviconRawBitmapResult& bitmap_result);
80 // WebContentsObserver
81 bool OnMessageReceived(const IPC::Message& message) override;
82 void WebContentsDestroyed() override;
84 // Adds a shortcut to the launcher using a FaviconRawBitmapResult.
85 // Must be called from a WorkerPool task.
86 static void AddShortcutInBackgroundWithRawBitmap(
87 const ShortcutInfo& info,
88 const favicon_base::FaviconRawBitmapResult& bitmap_result);
90 // Adds a shortcut to the launcher using a SkBitmap.
91 // Must be called from a WorkerPool task.
92 static void AddShortcutInBackgroundWithSkBitmap(
93 const ShortcutInfo& info,
94 const SkBitmap& icon_bitmap,
95 const bool return_to_homescreen);
97 // Registers JNI hooks.
98 static bool RegisterShortcutHelper(JNIEnv* env);
100 private:
101 enum ManifestIconStatus {
102 MANIFEST_ICON_STATUS_NONE,
103 MANIFEST_ICON_STATUS_FETCHING,
104 MANIFEST_ICON_STATUS_DONE
107 ~ShortcutHelper() override;
109 void Destroy();
111 void RecordAddToHomescreen();
113 JavaObjectWeakGlobalRef java_ref_;
115 ShortcutInfo shortcut_info_;
116 SkBitmap manifest_icon_;
117 base::CancelableTaskTracker cancelable_task_tracker_;
119 bool add_shortcut_requested_;
121 ManifestIconStatus manifest_icon_status_;
122 const int preferred_icon_size_in_px_;
123 static const int kPreferredIconSizeInDp;
125 base::WeakPtrFactory<ShortcutHelper> weak_ptr_factory_;
127 DISALLOW_COPY_AND_ASSIGN(ShortcutHelper);
130 #endif // CHROME_BROWSER_ANDROID_SHORTCUT_HELPER_H_