Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Unified Diff: chrome/browser/android/webapps/add_to_homescreen_process.h

Issue 2244223002: Determine whether to show "Add to Homescreen" dialog or WebAPK infobar (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge branch 'master' into webapk_dialog_detector Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/webapps/add_to_homescreen_process.h
diff --git a/chrome/browser/android/webapps/add_to_homescreen_dialog_helper.h b/chrome/browser/android/webapps/add_to_homescreen_process.h
similarity index 53%
rename from chrome/browser/android/webapps/add_to_homescreen_dialog_helper.h
rename to chrome/browser/android/webapps/add_to_homescreen_process.h
index 296011b65785f4a9bf31a87b6829b72e01154a70..f390b87a83f00270ea9771410cf81c47db8f95b1 100644
--- a/chrome/browser/android/webapps/add_to_homescreen_dialog_helper.h
+++ b/chrome/browser/android/webapps/add_to_homescreen_process.h
@@ -1,15 +1,15 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
+// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DIALOG_HELPER_H_
-#define CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DIALOG_HELPER_H_
+#ifndef CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_PROCESS_H_
+#define CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_PROCESS_H_
#include "base/android/jni_android.h"
#include "base/android/scoped_java_ref.h"
#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
#include "chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h"
-#include "third_party/skia/include/core/SkBitmap.h"
namespace content {
class WebContents;
@@ -20,39 +20,50 @@ class Message;
}
class GURL;
+class SkBitmap;
+struct InstallableData;
struct ShortcutInfo;
-// AddToHomescreenDialogHelper is the C++ counterpart of
-// org.chromium.chrome.browser's AddToHomescreenDialogHelper in Java. The object
-// is owned by the Java object. It is created from there via a JNI (Initialize)
-// call and MUST BE DESTROYED via Destroy().
-class AddToHomescreenDialogHelper :
- public AddToHomescreenDataFetcher::Observer {
+// AddToHomescreenProcess is the C++ counterpart of
+// org.chromium.chrome.browser's AddToHomescreenProcess in Java. The object
+// is owned by the Java object. It is created from there via a JNI
+// (InitializeAndStart) call and MUST BE DESTROYED via Destroy().
+class AddToHomescreenProcess : public AddToHomescreenDataFetcher::Observer {
public:
- AddToHomescreenDialogHelper(JNIEnv* env,
- jobject obj,
- content::WebContents* web_contents);
+ AddToHomescreenProcess(JNIEnv* env, jobject obj);
+
+ // Registers JNI hooks.
+ static bool Register(JNIEnv* env);
// Called by the Java counterpart to destroy its native half.
void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj);
- // Registers JNI hooks.
- static bool RegisterAddToHomescreenDialogHelper(JNIEnv* env);
-
// Adds a shortcut to the current URL to the Android home screen.
void AddShortcut(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
const base::android::JavaParamRef<jstring>& title);
- // AddToHomescreenDataFetcher::Observer
- void OnUserTitleAvailable(const base::string16& user_title) override;
- void OnDataAvailable(const ShortcutInfo& info, const SkBitmap& icon) override;
- SkBitmap FinalizeLauncherIconInBackground(const SkBitmap& icon,
- const GURL& url,
- bool* is_generated) override;
+ // Starts add-to-homescreen process.
+ void Start(content::WebContents* web_contents);
private:
- virtual ~AddToHomescreenDialogHelper();
+ ~AddToHomescreenProcess() override;
+
+ // Checks whether the current page in |web_contents| can be made into a
+ // WebAPK.
+ void CheckWebApkCompatible(content::WebContents* web_contents);
+
+ // Called once the request for "installability data" started by
+ // CheckWebApkCompatible() has completed.
+ void OnGotWebApkCompatibilityData(content::WebContents* web_contents,
+ const InstallableData& installable_data);
+
+ // Shows alert to prompt user for name of home screen shortcut.
+ void ShowDialog();
+
+ // Starts fetching home screen shortcut data (like Web Manifest and home
+ // screen icon).
+ void StartFetchingInfoForShortcut(content::WebContents* web_contents);
// Called only when the AddToHomescreenDataFetcher has retrieved all of the
// data needed to add the shortcut.
@@ -60,6 +71,13 @@ class AddToHomescreenDialogHelper :
void RecordAddToHomescreen();
+ // AddToHomescreenDataFetcher::Observer
+ void OnUserTitleAvailable(const base::string16& user_title) override;
+ void OnDataAvailable(const ShortcutInfo& info, const SkBitmap& icon) override;
+ SkBitmap FinalizeLauncherIconInBackground(const SkBitmap& icon,
+ const GURL& url,
+ bool* is_generated) override;
+
// Points to the Java object.
base::android::ScopedJavaGlobalRef<jobject> java_ref_;
@@ -70,7 +88,9 @@ class AddToHomescreenDialogHelper :
// Fetches data required to add a shortcut.
scoped_refptr<AddToHomescreenDataFetcher> data_fetcher_;
- DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDialogHelper);
+ base::WeakPtrFactory<AddToHomescreenProcess> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(AddToHomescreenProcess);
};
-#endif // CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DIALOG_HELPER_H_
+#endif // CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_PROCESS_H_

Powered by Google App Engine
This is Rietveld 408576698