| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/android/fullscreen/fullscreen_infobar_delegate.h" | 5 #include "chrome/browser/android/fullscreen/fullscreen_infobar_delegate.h" |
| 6 | 6 |
| 7 #include "base/android/jni_string.h" | 7 #include "base/android/jni_string.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "chrome/browser/android/tab_android.h" | 10 #include "chrome/browser/android/tab_android.h" |
| 11 #include "chrome/browser/infobars/infobar_service.h" | 11 #include "chrome/browser/infobars/infobar_service.h" |
| 12 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
| 13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 14 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 15 #include "components/infobars/core/infobar.h" | 15 #include "components/infobars/core/infobar.h" |
| 16 #include "components/url_formatter/url_formatter.h" |
| 16 #include "grit/components_strings.h" | 17 #include "grit/components_strings.h" |
| 17 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
| 18 #include "jni/FullscreenInfoBarDelegate_jni.h" | 19 #include "jni/FullscreenInfoBarDelegate_jni.h" |
| 19 #include "net/base/net_util.h" | |
| 20 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 21 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 22 | 22 |
| 23 // static | 23 // static |
| 24 jlong LaunchFullscreenInfoBar( | 24 jlong LaunchFullscreenInfoBar( |
| 25 JNIEnv* env, jobject obj, jobject tab) { | 25 JNIEnv* env, jobject obj, jobject tab) { |
| 26 TabAndroid* tab_android = TabAndroid::GetNativeTab(env, tab); | 26 TabAndroid* tab_android = TabAndroid::GetNativeTab(env, tab); |
| 27 GURL origin = tab_android->GetURL().GetOrigin(); | 27 GURL origin = tab_android->GetURL().GetOrigin(); |
| 28 FullscreenInfoBarDelegate* delegate = new FullscreenInfoBarDelegate( | 28 FullscreenInfoBarDelegate* delegate = new FullscreenInfoBarDelegate( |
| 29 env, obj, origin); | 29 env, obj, origin); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 int FullscreenInfoBarDelegate::GetIconID() const { | 62 int FullscreenInfoBarDelegate::GetIconID() const { |
| 63 return IDR_INFOBAR_FULLSCREEN; | 63 return IDR_INFOBAR_FULLSCREEN; |
| 64 } | 64 } |
| 65 | 65 |
| 66 base::string16 FullscreenInfoBarDelegate::GetMessageText() const { | 66 base::string16 FullscreenInfoBarDelegate::GetMessageText() const { |
| 67 Profile* profile = | 67 Profile* profile = |
| 68 ProfileManager::GetActiveUserProfile()->GetOriginalProfile(); | 68 ProfileManager::GetActiveUserProfile()->GetOriginalProfile(); |
| 69 std::string language = | 69 std::string language = |
| 70 profile->GetPrefs()->GetString(prefs::kAcceptLanguages); | 70 profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
| 71 return l10n_util::GetStringFUTF16( | 71 return l10n_util::GetStringFUTF16( |
| 72 IDS_FULLSCREEN_INFOBAR_TEXT, net::FormatUrl(GURL(origin_), language)); | 72 IDS_FULLSCREEN_INFOBAR_TEXT, |
| 73 url_formatter::FormatUrl(GURL(origin_), language)); |
| 73 } | 74 } |
| 74 | 75 |
| 75 base::string16 FullscreenInfoBarDelegate::GetButtonLabel( | 76 base::string16 FullscreenInfoBarDelegate::GetButtonLabel( |
| 76 InfoBarButton button) const { | 77 InfoBarButton button) const { |
| 77 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | 78 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? |
| 78 IDS_FULLSCREEN_INFOBAR_ALLOW_BUTTON : | 79 IDS_FULLSCREEN_INFOBAR_ALLOW_BUTTON : |
| 79 IDS_FULLSCREEN_INFOBAR_EXIT_FULLSCREEN_BUTTON); | 80 IDS_FULLSCREEN_INFOBAR_EXIT_FULLSCREEN_BUTTON); |
| 80 } | 81 } |
| 81 | 82 |
| 82 bool FullscreenInfoBarDelegate::Accept() { | 83 bool FullscreenInfoBarDelegate::Accept() { |
| 83 JNIEnv* env = base::android::AttachCurrentThread(); | 84 JNIEnv* env = base::android::AttachCurrentThread(); |
| 84 ScopedJavaLocalRef<jstring> j_origin = | 85 ScopedJavaLocalRef<jstring> j_origin = |
| 85 base::android::ConvertUTF8ToJavaString(env, origin_.spec()); | 86 base::android::ConvertUTF8ToJavaString(env, origin_.spec()); |
| 86 Java_FullscreenInfoBarDelegate_onFullscreenAllowed( | 87 Java_FullscreenInfoBarDelegate_onFullscreenAllowed( |
| 87 env, j_delegate_.obj(), j_origin.obj()); | 88 env, j_delegate_.obj(), j_origin.obj()); |
| 88 return true; | 89 return true; |
| 89 } | 90 } |
| 90 | 91 |
| 91 bool FullscreenInfoBarDelegate::Cancel() { | 92 bool FullscreenInfoBarDelegate::Cancel() { |
| 92 Java_FullscreenInfoBarDelegate_onFullscreenCancelled( | 93 Java_FullscreenInfoBarDelegate_onFullscreenCancelled( |
| 93 base::android::AttachCurrentThread(), j_delegate_.obj()); | 94 base::android::AttachCurrentThread(), j_delegate_.obj()); |
| 94 return true; | 95 return true; |
| 95 } | 96 } |
| OLD | NEW |