Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / android / webapps / add_to_homescreen_dialog_helper.h
blob448c5c12d680f6ec6225778a26bede369284e47c
1 // Copyright 2015 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_WEBAPPS_ADD_TO_HOMESCREEN_DIALOG_HELPER_H_
6 #define CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DIALOG_HELPER_H_
8 #include "base/android/jni_android.h"
9 #include "base/android/jni_weak_ref.h"
10 #include "base/basictypes.h"
11 #include "chrome/browser/android/shortcut_info.h"
12 #include "chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h"
13 #include "content/public/common/manifest.h"
15 namespace content {
16 class WebContents;
17 } // namespace content
19 namespace IPC {
20 class Message;
23 class GURL;
25 // AddToHomescreenDialogHelper is the C++ counterpart of
26 // org.chromium.chrome.browser's AddToHomescreenDialogHelper in Java. The object
27 // is owned by the Java object. It is created from there via a JNI (Initialize)
28 // call and MUST BE DESTROYED via Destroy().
29 class AddToHomescreenDialogHelper :
30 public AddToHomescreenDataFetcher::Observer {
31 public:
32 AddToHomescreenDialogHelper(JNIEnv* env,
33 jobject obj,
34 content::WebContents* web_contents);
36 // Called by the Java counterpart to destroy its native half.
37 void Destroy(JNIEnv* env, jobject obj);
39 // Registers JNI hooks.
40 static bool RegisterAddToHomescreenDialogHelper(JNIEnv* env);
42 // Adds a shortcut to the current URL to the Android home screen.
43 void AddShortcut(JNIEnv* env, jobject obj, jstring title);
45 // AddToHomescreenDataFetcher::Observer
46 void OnUserTitleAvailable(const base::string16& user_title) override;
47 void OnDataAvailable(const ShortcutInfo& info, const SkBitmap& icon) override;
48 SkBitmap FinalizeLauncherIcon(const SkBitmap& icon, const GURL& url) override;
50 private:
51 virtual ~AddToHomescreenDialogHelper();
53 // Called only when the AddToHomescreenDataFetcher has retrieved all of the
54 // data needed to add the shortcut.
55 void AddShortcut(const ShortcutInfo& info, const SkBitmap& icon);
57 void RecordAddToHomescreen();
59 // Points to the Java object.
60 base::android::ScopedJavaGlobalRef<jobject> java_ref_;
62 // Whether the user has requested that a shortcut be added while a fetch was
63 // in progress.
64 bool add_shortcut_pending_;
66 // Fetches data required to add a shortcut.
67 scoped_refptr<AddToHomescreenDataFetcher> data_fetcher_;
69 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDialogHelper);
72 #endif // CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DIALOG_HELPER_H_