summaryrefslogtreecommitdiffstats
path: root/chrome/browser/android/banners/app_banner_manager_android.h
blob: 1d609072140e8b27e55eaf1212b7e69e270f6496 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2015 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_BANNERS_APP_BANNER_MANAGER_ANDROID_H_
#define CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_ANDROID_H_

#include "base/android/jni_android.h"
#include "base/android/jni_weak_ref.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/android/banners/app_banner_data_fetcher_android.h"
#include "chrome/browser/banners/app_banner_debug_log.h"
#include "chrome/browser/banners/app_banner_manager.h"

namespace banners {
class AppBannerDataFetcherAndroid;

// Extends the AppBannerManager to support native Android apps.
// TODO(dfalcantara): Flip it so the C++ AppBannerManagerAndroid owns the
// Java AppBannerManager, move ownership of the AppBannerManagerAndroid to
// the TabAndroid class, then move functions for retriving info from Java to
// the AppBannerDataFetcherAndroid.
class AppBannerManagerAndroid : public AppBannerManager {
 public:
  // Registers native methods.
  static bool Register(JNIEnv* env);

  AppBannerManagerAndroid(JNIEnv* env, jobject obj);
  ~AppBannerManagerAndroid() override;

  // Destroys the AppBannerManagerAndroid.
  void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj);

  // Observes a new WebContents, if necessary.
  void ReplaceWebContents(
      JNIEnv* env,
      const base::android::JavaParamRef<jobject>& obj,
      const base::android::JavaParamRef<jobject>& jweb_contents);

  // Return whether a BitmapFetcher is active.
  bool IsFetcherActive(JNIEnv* env,
                       const base::android::JavaParamRef<jobject>& jobj);

  // Called when the Java-side has retrieved information for the app.
  // Returns |false| if an icon fetch couldn't be kicked off.
  bool OnAppDetailsRetrieved(
      JNIEnv* env,
      const base::android::JavaParamRef<jobject>& obj,
      const base::android::JavaParamRef<jobject>& japp_data,
      const base::android::JavaParamRef<jstring>& japp_title,
      const base::android::JavaParamRef<jstring>& japp_package,
      const base::android::JavaParamRef<jstring>& jicon_url);

 protected:
  AppBannerDataFetcher* CreateAppBannerDataFetcher(
      base::WeakPtr<AppBannerDataFetcher::Delegate> weak_delegate) override;

 private:
  // AppBannerDataFetcher::Delegate overrides.
  bool HandleNonWebApp(const std::string& platform,
                       const GURL& url,
                       const std::string& id) override;

  bool CheckPlatformAndId(const std::string& platform, const std::string& id);

  bool CheckFetcherMatchesContents();

  std::string ExtractQueryValueForName(const GURL& url,
                                       const std::string& name);

  // AppBannerManager on the Java side.
  JavaObjectWeakGlobalRef weak_java_banner_view_manager_;

  DISALLOW_COPY_AND_ASSIGN(AppBannerManagerAndroid);
};  // class AppBannerManagerAndroid

}  // namespace banners

#endif  // CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_ANDROID_H_