Move Webstore URL concepts to //extensions and out
[chromium-blink-merge.git] / chrome / browser / android / shortcut_helper.h
blob48009608c1f622ad46add5cdb937d5f210d006d6
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/strings/string16.h"
12 #include "base/task/cancelable_task_tracker.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"
17 #include "third_party/WebKit/public/platform/WebScreenOrientationLockType.h"
19 namespace content {
20 class WebContents;
21 } // namespace content
23 namespace IPC {
24 class Message;
27 class GURL;
29 // ShortcutHelper is the C++ counterpart of org.chromium.chrome.browser's
30 // ShortcutHelper in Java. The object is owned by the Java object. It is created
31 // from there via a JNI (Initialize) call and can be destroyed from Java too
32 // using TearDown. When the Java implementations calls AddShortcut, it gives up
33 // the ownership of the object. The instance will then destroy itself when done.
34 class ShortcutHelper : public content::WebContentsObserver {
35 public:
36 ShortcutHelper(JNIEnv* env,
37 jobject obj,
38 content::WebContents* web_contents);
40 // Initialize the helper by requesting the information about the page to the
41 // renderer process. The initialization is asynchronous and
42 // OnDidRetrieveWebappInformation is expected to be called when finished.
43 void Initialize();
45 // Called by the Java counter part to let the object knows that it can destroy
46 // itself.
47 void TearDown(JNIEnv* env, jobject obj);
49 // IPC message received when the initialization is finished.
50 void OnDidGetWebApplicationInfo(const WebApplicationInfo& web_app_info);
52 // Callback run when the Manifest is ready to be used.
53 void OnDidGetManifest(const content::Manifest& manifest);
55 // Adds a shortcut to the current URL to the Android home screen.
56 void AddShortcut(JNIEnv* env,
57 jobject obj,
58 jstring title,
59 jint launcher_large_icon_size);
61 void FinishAddingShortcut(
62 const favicon_base::FaviconRawBitmapResult& bitmap_result);
64 // WebContentsObserver
65 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
66 virtual void WebContentsDestroyed() OVERRIDE;
68 // Adds a shortcut to the launcher. Must be called from a WorkerPool task.
69 static void AddShortcutInBackground(
70 const GURL& url,
71 const base::string16& title,
72 content::Manifest::DisplayMode display,
73 const favicon_base::FaviconRawBitmapResult& bitmap_result,
74 blink::WebScreenOrientationLockType orientation);
76 // Registers JNI hooks.
77 static bool RegisterShortcutHelper(JNIEnv* env);
79 private:
80 virtual ~ShortcutHelper();
82 void Destroy();
84 JavaObjectWeakGlobalRef java_ref_;
86 GURL url_;
87 base::string16 title_;
88 int launcher_large_icon_size_;
89 content::Manifest::DisplayMode display_;
90 favicon_base::FaviconRawBitmapResult icon_;
91 base::CancelableTaskTracker cancelable_task_tracker_;
92 blink::WebScreenOrientationLockType orientation_;
94 base::WeakPtrFactory<ShortcutHelper> weak_ptr_factory_;
96 DISALLOW_COPY_AND_ASSIGN(ShortcutHelper);
99 #endif // CHROME_BROWSER_ANDROID_SHORTCUT_HELPER_H_