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 "base/android/jni_string.h" | |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "base/prefs/pref_service.h" | |
10 #include "chrome/browser/android/tab_android.h" | |
11 #include "chrome/browser/infobars/infobar_service.h" | |
12 #include "chrome/browser/profiles/profile_manager.h" | |
13 #include "chrome/common/pref_names.h" | |
14 #include "chrome/grit/generated_resources.h" | |
15 #include "components/infobars/core/infobar.h" | |
16 #include "grit/components_strings.h" | |
17 #include "grit/theme_resources.h" | |
18 #include "jni/FullscreenInfoBarDelegate_jni.h" | |
19 #include "net/base/net_util.h" | |
20 #include "ui/base/l10n/l10n_util.h" | |
21 #include "url/gurl.h" | |
22 | |
23 | |
24 jlong LaunchFullscreenInfoBar( | |
Ted C
2015/03/12 21:21:35
I think we usually put
// static
above functions l
qinmin
2015/03/17 23:49:30
Done.
| |
25 JNIEnv* env, jobject obj, jobject tab, jstring j_origin) { | |
26 TabAndroid* tab_android = TabAndroid::GetNativeTab(env, tab); | |
27 if (!tab_android) | |
Ted C
2015/03/12 21:21:35
We shouldn't allow this on a null tab. We should
qinmin
2015/03/17 23:49:30
Done.
| |
28 return 0; | |
29 base::string16 origin = | |
30 base::android::ConvertJavaStringToUTF16(env, j_origin); | |
31 FullscreenInfoBarDelegate* delegate = new FullscreenInfoBarDelegate( | |
32 env, obj, origin); | |
33 InfoBarService* infobar_service = | |
34 InfoBarService::FromWebContents(tab_android->web_contents()); | |
35 infobar_service->AddInfoBar( | |
36 infobar_service->CreateConfirmInfoBar(make_scoped_ptr(delegate))); | |
37 return reinterpret_cast<intptr_t>(delegate); | |
38 } | |
39 | |
40 bool FullscreenInfoBarDelegate::RegisterFullscreenInfoBarDelegate(JNIEnv* env) { | |
41 return RegisterNativesImpl(env); | |
42 } | |
43 | |
44 FullscreenInfoBarDelegate::FullscreenInfoBarDelegate( | |
45 JNIEnv* env, jobject obj, base::string16 origin) | |
46 : origin_(origin) { | |
47 j_delegate_.Reset(env, obj); | |
48 } | |
49 | |
50 FullscreenInfoBarDelegate::~FullscreenInfoBarDelegate() { | |
51 if (!j_delegate_.is_null()) { | |
52 Java_FullscreenInfoBarDelegate_onInfoBarDismissed( | |
53 base::android::AttachCurrentThread(), j_delegate_.obj()); | |
54 } | |
55 } | |
56 | |
57 void FullscreenInfoBarDelegate::CloseFullscreenInfoBar( | |
58 JNIEnv* env, jobject obj, jobject tab) { | |
59 j_delegate_.Reset(); | |
60 TabAndroid* tab_android = TabAndroid::GetNativeTab(env, tab); | |
61 if (!tab_android) | |
62 return; | |
63 InfoBarService::FromWebContents(tab_android->web_contents())->RemoveInfoBar( | |
Ted C
2015/03/12 21:21:35
what happens if this isn't called?
Should this cl
qinmin
2015/03/17 23:49:30
Not necessary.
InfoBarService is already a WebCon
| |
64 infobar()); | |
65 } | |
66 | |
67 int FullscreenInfoBarDelegate::GetIconID() const { | |
68 return IDR_INFOBAR_FULLSCREEN; | |
69 } | |
70 | |
71 base::string16 FullscreenInfoBarDelegate::GetMessageText() const { | |
72 Profile* profile = | |
73 ProfileManager::GetActiveUserProfile()->GetOriginalProfile(); | |
74 std::string language = | |
75 profile->GetPrefs()->GetString(prefs::kAcceptLanguages); | |
76 return l10n_util::GetStringFUTF16( | |
77 IDS_FULLSCREEN_INFOBAR_TEXT, net::FormatUrl(GURL(origin_), language)); | |
78 } | |
79 | |
80 base::string16 FullscreenInfoBarDelegate::GetButtonLabel( | |
81 InfoBarButton button) const { | |
82 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | |
83 IDS_FULLSCREEN_INFOBAR_ALLOW_BUTTON : | |
84 IDS_FULLSCREEN_INFOBAR_EXIT_FULLSCREEN_BUTTON); | |
85 } | |
86 | |
87 bool FullscreenInfoBarDelegate::Accept() { | |
88 JNIEnv* env = base::android::AttachCurrentThread(); | |
89 ScopedJavaLocalRef<jstring> j_origin = | |
90 base::android::ConvertUTF16ToJavaString(env, origin_); | |
91 Java_FullscreenInfoBarDelegate_onFullscreenAllowed( | |
92 env, j_delegate_.obj(), j_origin.obj()); | |
93 return true; | |
94 } | |
95 | |
96 bool FullscreenInfoBarDelegate::Cancel() { | |
97 Java_FullscreenInfoBarDelegate_onFullscreenCancelled( | |
98 base::android::AttachCurrentThread(), j_delegate_.obj()); | |
99 return true; | |
100 } | |
OLD | NEW |