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

Side by Side Diff: chrome/browser/android/banners/app_banner_manager.h

Issue 156343002: Let AppBannerManager really create and manage banners (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Upload error Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_H_ 5 #ifndef CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_H_
6 #define CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_H_ 6 #define CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_H_
7 7
8 #include "base/android/jni_android.h" 8 #include "base/android/jni_android.h"
9 #include "base/android/jni_helper.h" 9 #include "base/android/jni_helper.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "chrome/browser/android/meta_tag_observer.h" 11 #include "chrome/browser/android/meta_tag_observer.h"
12 #include "chrome/browser/bitmap_fetcher.h"
12 13
13 namespace content { 14 namespace content {
14 struct FrameNavigateParams; 15 struct FrameNavigateParams;
15 struct LoadCommittedDetails; 16 struct LoadCommittedDetails;
16 } // namespace content 17 } // namespace content
17 18
18 /** 19 /**
19 * Manages when an app banner is created or dismissed. 20 * Manages when an app banner is created or dismissed.
20 * 21 *
21 * Hooks the wiring together for getting the data for a particular app. 22 * Hooks the wiring together for getting the data for a particular app.
22 * Monitors at most one package at a time, and tracks the info for the 23 * Monitors at most one package at a time, and tracks the info for the
23 * most recent app that was requested. Any work in progress for other apps is 24 * most recent app that was requested. Any work in progress for other apps is
24 * discarded. 25 * discarded.
26 *
27 * The procedure for creating a banner spans multiple asynchronous calls across
28 * the JNI boundary, as well as querying a Service to get info about the app.
29 *
30 * 0) A navigation of the main frame is triggered. Upon completion of the load,
31 * the page is parsed for the correct meta tag. If it doesn't exist, abort.
32 *
33 * 1) The AppBannerManager is alerted about the tag's contents, which should
34 * be the Play Store package name. This is sent to the Java side
35 * AppBannerManager.
36 *
37 * 2) The AppBannerManager's ServiceDelegate is asynchronously queried about the
38 * package name.
39 *
40 * 3) At some point, the Java-side AppBannerManager is alerted of the completed
41 * query and is given back data about the requested package, which includes a
42 * URL for the app's icon. This URL is sent to native code for retrieval.
43 *
44 * 4) The process of fetching the icon begins by invoking the BitmapFetcher,
45 * which works asynchonously.
46 *
47 * 5) Once the icon has been downloaded, the icon is sent to the Java-side
48 * AppBannerManager to (finally) create a AppBannerView, assuming that the
49 * app we retrieved the details for is still for the page that requested it.
50 *
51 * Because of the asynchronous nature of this pipeline, it's entirely possible
52 * that a request to show a banner is interrupted by another request. The
53 * Java side manages what happens in these situations, which will usually result
54 * in dropping the old banner request on the floor.
25 */ 55 */
26 class AppBannerManager : public MetaTagObserver { 56 class AppBannerManager : public chrome::BitmapFetcherDelegate,
57 public MetaTagObserver {
27 public: 58 public:
28 AppBannerManager(JNIEnv* env, jobject obj); 59 AppBannerManager(JNIEnv* env, jobject obj);
29 virtual ~AppBannerManager(); 60 virtual ~AppBannerManager();
30 61
31 // Destroys the AppBannerManager. 62 // Destroys the AppBannerManager.
32 void Destroy(JNIEnv* env, jobject obj); 63 void Destroy(JNIEnv* env, jobject obj);
33 64
65 // Blocks a banner for |package_name| from appearing on the domain for |url|.
66 void BlockBanner(JNIEnv* env, jobject obj, jstring jurl, jstring jpackage);
67
34 // Observes a new WebContents, if necessary. 68 // Observes a new WebContents, if necessary.
35 void ReplaceWebContents(JNIEnv* env, 69 void ReplaceWebContents(JNIEnv* env,
36 jobject obj, 70 jobject obj,
37 jobject jweb_contents); 71 jobject jweb_contents);
38 72
73 // Fetches the icon at the give URL.
74 // Returns |false| if this couldn't be kicked off.
75 bool FetchIcon(JNIEnv* env,
76 jobject obj,
77 jstring jimage_url);
78
39 // WebContentsObserver overrides. 79 // WebContentsObserver overrides.
40 virtual void DidNavigateMainFrame( 80 virtual void DidNavigateMainFrame(
41 const content::LoadCommittedDetails& details, 81 const content::LoadCommittedDetails& details,
42 const content::FrameNavigateParams& params) OVERRIDE; 82 const content::FrameNavigateParams& params) OVERRIDE;
43 83
84 // BitmapFetcherDelegate overrides.
85 virtual void OnFetchComplete(const GURL url, const SkBitmap* bitmap) OVERRIDE;
86
44 private: 87 private:
45 // Kicks off the process of showing a banner for the package designated by 88 // Kicks off the process of showing a banner for the package designated by
46 // |tag_content| on the page at the |expected_url|. 89 // |tag_content| on the page at the |expected_url|.
47 virtual void HandleMetaTagContent(const std::string& tag_content, 90 virtual void HandleMetaTagContent(const std::string& tag_content,
48 const GURL& expected_url) OVERRIDE; 91 const GURL& expected_url) OVERRIDE;
49 92
93 // Fetches the icon for an app.
94 scoped_ptr<chrome::BitmapFetcher> fetcher_;
95
96 // AppBannerManager on the Java side.
50 JavaObjectWeakGlobalRef weak_java_banner_view_manager_; 97 JavaObjectWeakGlobalRef weak_java_banner_view_manager_;
51 98
52 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); 99 DISALLOW_COPY_AND_ASSIGN(AppBannerManager);
53 }; // class AppBannerManager 100 }; // class AppBannerManager
54 101
55 // Register native methods 102 // Register native methods
56 bool RegisterAppBannerManager(JNIEnv* env); 103 bool RegisterAppBannerManager(JNIEnv* env);
57 104
58 #endif // CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_H_ 105 #endif // CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698