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"
17 } // namespace content
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
{
32 AddToHomescreenDialogHelper(JNIEnv
* env
,
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
;
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
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_