OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/android/banners/app_banner_manager.h" |
| 6 |
| 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" |
| 9 #include "base/command_line.h" |
| 10 #include "chrome/browser/android/banners/app_banner_settings_helper.h" |
| 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/common/chrome_switches.h" |
| 13 #include "content/public/browser/android/content_view_core.h" |
| 14 #include "content/public/browser/navigation_details.h" |
| 15 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/common/frame_navigate_params.h" |
| 17 #include "jni/AppBannerManager_jni.h" |
| 18 #include "ui/gfx/android/java_bitmap.h" |
| 19 |
| 20 using base::android::ConvertJavaStringToUTF8; |
| 21 using base::android::ConvertUTF8ToJavaString; |
| 22 |
| 23 namespace { |
| 24 const char kBannerTag[] = "google-play-id"; |
| 25 } |
| 26 |
| 27 AppBannerManager::AppBannerManager(JNIEnv* env, jobject obj) |
| 28 : MetaTagObserver(kBannerTag), |
| 29 weak_java_banner_view_manager_(env, obj) {} |
| 30 |
| 31 AppBannerManager::~AppBannerManager() { |
| 32 } |
| 33 |
| 34 void AppBannerManager::Destroy(JNIEnv* env, jobject obj) { |
| 35 delete this; |
| 36 } |
| 37 |
| 38 void AppBannerManager::ReplaceWebContents(JNIEnv* env, |
| 39 jobject obj, |
| 40 jobject jweb_contents) { |
| 41 content::WebContents* web_contents = |
| 42 content::WebContents::FromJavaWebContents(jweb_contents); |
| 43 Observe(web_contents); |
| 44 } |
| 45 |
| 46 void AppBannerManager::DidNavigateMainFrame( |
| 47 const content::LoadCommittedDetails& details, |
| 48 const content::FrameNavigateParams& params) { |
| 49 // TODO(dfalcantara): Get rid of the current banner. |
| 50 } |
| 51 |
| 52 void AppBannerManager::HandleMetaTagContent(const std::string& tag_content, |
| 53 const GURL& expected_url) { |
| 54 DCHECK(web_contents()); |
| 55 |
| 56 if (!AppBannerSettingsHelper::IsAllowed(web_contents(), |
| 57 expected_url, |
| 58 tag_content)) { |
| 59 return; |
| 60 } |
| 61 |
| 62 // TODO(dfalcantara): Send the info to the Java side to begin building the |
| 63 // app banner. |
| 64 } |
| 65 |
| 66 jlong Init(JNIEnv* env, jobject obj) { |
| 67 AppBannerManager* manager = new AppBannerManager(env, obj); |
| 68 return reinterpret_cast<intptr_t>(manager); |
| 69 } |
| 70 |
| 71 jboolean IsEnabled(JNIEnv* env, jclass clazz) { |
| 72 return false; |
| 73 |
| 74 // TODO(dfalcantara): Enable this when more of the pipeline is checked in. |
| 75 // return !CommandLine::ForCurrentProcess()->HasSwitch( |
| 76 // switches::kDisableAppBanners); |
| 77 } |
| 78 |
| 79 // Register native methods |
| 80 bool RegisterAppBannerManager(JNIEnv* env) { |
| 81 return RegisterNativesImpl(env); |
| 82 } |
OLD | NEW |