Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/android/fullscreen/fullscreen_infobar_delegate.h" | |
| 6 | |
| 7 #include <memory> | |
| 8 | |
| 9 #include "base/android/jni_string.h" | |
| 10 #include "base/memory/ptr_util.h" | |
| 11 #include "chrome/browser/android/android_theme_resources.h" | |
| 12 #include "chrome/browser/android/tab_android.h" | |
| 13 #include "chrome/browser/infobars/infobar_service.h" | |
| 14 #include "chrome/grit/generated_resources.h" | |
| 15 #include "components/infobars/core/infobar.h" | |
| 16 #include "components/url_formatter/elide_url.h" | |
| 17 #include "grit/components_strings.h" | |
| 18 #include "jni/FullscreenInfoBarDelegate_jni.h" | |
| 19 #include "ui/base/l10n/l10n_util.h" | |
| 20 #include "url/gurl.h" | |
| 21 | |
| 22 // static | |
| 23 jlong LaunchFullscreenInfoBar(JNIEnv* env, | |
| 24 const JavaParamRef<jobject>& obj, | |
| 25 const JavaParamRef<jobject>& tab) { | |
| 26 TabAndroid* tab_android = TabAndroid::GetNativeTab(env, tab); | |
| 27 GURL origin = tab_android->GetURL().GetOrigin(); | |
| 28 FullscreenInfoBarDelegate* delegate = new FullscreenInfoBarDelegate( | |
| 29 env, obj, origin); | |
| 30 InfoBarService* infobar_service = | |
| 31 InfoBarService::FromWebContents(tab_android->web_contents()); | |
| 32 infobar_service->AddInfoBar( | |
| 33 infobar_service->CreateConfirmInfoBar(base::WrapUnique(delegate))); | |
| 34 return reinterpret_cast<intptr_t>(delegate); | |
| 35 } | |
| 36 | |
| 37 bool FullscreenInfoBarDelegate::RegisterFullscreenInfoBarDelegate(JNIEnv* env) { | |
| 38 return RegisterNativesImpl(env); | |
| 39 } | |
| 40 | |
| 41 FullscreenInfoBarDelegate::FullscreenInfoBarDelegate( | |
| 42 JNIEnv* env, jobject obj, GURL origin) | |
| 43 : origin_(origin) { | |
| 44 j_delegate_.Reset(env, obj); | |
| 45 } | |
| 46 | |
| 47 FullscreenInfoBarDelegate::~FullscreenInfoBarDelegate() { | |
| 48 if (!j_delegate_.is_null()) { | |
| 49 Java_FullscreenInfoBarDelegate_onInfoBarDismissed( | |
| 50 base::android::AttachCurrentThread(), j_delegate_.obj()); | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 void FullscreenInfoBarDelegate::CloseFullscreenInfoBar( | |
| 55 JNIEnv* env, | |
| 56 const JavaParamRef<jobject>& obj) { | |
| 57 j_delegate_.Reset(); | |
| 58 if (infobar() && infobar()->owner()) | |
| 59 infobar()->owner()->RemoveInfoBar(infobar()); | |
| 60 } | |
| 61 | |
| 62 infobars::InfoBarDelegate::InfoBarIdentifier | |
| 63 FullscreenInfoBarDelegate::GetIdentifier() const { | |
| 64 return FULLSCREEN_INFOBAR_DELEGATE; | |
|
Ted C
2016/06/13 22:48:45
can this be deleted?
Matt Giuca
2016/06/14 05:03:32
Done.
| |
| 65 } | |
| 66 | |
| 67 int FullscreenInfoBarDelegate::GetIconId() const { | |
| 68 return IDR_ANDROID_INFOBAR_FULLSCREEN; | |
|
Ted C
2016/06/13 22:48:44
can this be cleaned up?
https://cs.chromium.org/c
Matt Giuca
2016/06/14 05:03:32
Done.
Thanks for spotting these.
| |
| 69 } | |
| 70 | |
| 71 base::string16 FullscreenInfoBarDelegate::GetMessageText() const { | |
| 72 return l10n_util::GetStringFUTF16( | |
| 73 IDS_FULLSCREEN_INFOBAR_TEXT, | |
|
Ted C
2016/06/13 22:48:45
are any of these specific to android such that we
Matt Giuca
2016/06/14 05:03:32
Done. Yes, all of them.
| |
| 74 url_formatter::FormatUrlForSecurityDisplay(origin_)); | |
| 75 } | |
| 76 | |
| 77 base::string16 FullscreenInfoBarDelegate::GetButtonLabel( | |
| 78 InfoBarButton button) const { | |
| 79 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | |
| 80 IDS_FULLSCREEN_INFOBAR_ALLOW_BUTTON : | |
| 81 IDS_FULLSCREEN_INFOBAR_EXIT_FULLSCREEN_BUTTON); | |
| 82 } | |
| 83 | |
| 84 bool FullscreenInfoBarDelegate::Accept() { | |
| 85 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 86 ScopedJavaLocalRef<jstring> j_origin = | |
| 87 base::android::ConvertUTF8ToJavaString(env, origin_.spec()); | |
| 88 Java_FullscreenInfoBarDelegate_onFullscreenAllowed( | |
| 89 env, j_delegate_.obj(), j_origin.obj()); | |
| 90 return true; | |
| 91 } | |
| 92 | |
| 93 bool FullscreenInfoBarDelegate::Cancel() { | |
| 94 Java_FullscreenInfoBarDelegate_onFullscreenCancelled( | |
| 95 base::android::AttachCurrentThread(), j_delegate_.obj()); | |
| 96 return true; | |
| 97 } | |
| OLD | NEW |