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_weak_ref.h"
9 #include "base/basictypes.h"
10 #include "base/strings/string16.h"
11 #include "base/task/cancelable_task_tracker.h"
12 #include "chrome/browser/android/tab_android.h"
13 #include "content/public/browser/web_contents_observer.h"
15 namespace favicon_base
{
16 struct FaviconBitmapResult
;
17 } // namespace favicon_base
21 } // namespace content
29 // Adds a shortcut to the current URL to the Android home screen.
30 // This proceeds over three phases:
31 // 1) The renderer is asked to parse out webapp related meta tags with an async
33 // 2) The highest-resolution favicon available is retrieved for use as the
34 // icon on the home screen.
35 // 3) A JNI call is made to fire an Intent at the Android launcher, which adds
37 class ShortcutBuilder
: public content::WebContentsObserver
{
45 explicit ShortcutBuilder(content::WebContents
* web_contents
,
46 const base::string16
& title
,
47 int launcher_large_icon_size
);
48 virtual ~ShortcutBuilder() {}
50 void OnDidRetrieveWebappInformation(bool success
,
51 bool is_mobile_webapp_capable
,
52 bool is_apple_mobile_webapp_capable
,
53 const GURL
& expected_url
);
55 void FinishAddingShortcut(
56 const favicon_base::FaviconBitmapResult
& bitmap_result
);
58 // WebContentsObserver
59 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
60 virtual void WebContentsDestroyed(content::WebContents
* web_contents
)
67 base::string16 title_
;
68 int launcher_large_icon_size_
;
69 ShortcutType shortcut_type_
;
70 base::CancelableTaskTracker cancelable_task_tracker_
;
72 DISALLOW_COPY_AND_ASSIGN(ShortcutBuilder
);
75 class ShortcutHelper
{
77 // Adds a shortcut to the current URL to the Android home screen, firing
78 // background tasks to pull all the data required.
79 static void AddShortcut(content::WebContents
* web_contents
,
80 const base::string16
& title
,
81 int launcher_larger_icon_size
);
83 // Adds a shortcut to the launcher. Must be called from a WorkerPool task.
84 static void AddShortcutInBackground(
86 const base::string16
& title
,
87 ShortcutBuilder::ShortcutType shortcut_type
,
88 const favicon_base::FaviconBitmapResult
& bitmap_result
);
90 // Registers JNI hooks.
91 static bool RegisterShortcutHelper(JNIEnv
* env
);
94 DISALLOW_COPY_AND_ASSIGN(ShortcutHelper
);
97 #endif // CHROME_BROWSER_ANDROID_SHORTCUT_HELPER_H_