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

Unified Diff: chrome/browser/android/fullscreen/fullscreen_infobar_delegate.cc

Issue 986653004: Add fullscreen permission controls to settings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/fullscreen/fullscreen_infobar_delegate.cc
diff --git a/chrome/browser/android/fullscreen/fullscreen_infobar_delegate.cc b/chrome/browser/android/fullscreen/fullscreen_infobar_delegate.cc
new file mode 100644
index 0000000000000000000000000000000000000000..942338ad1cac43fcbff31e502d1cd8dfcd5c8bf1
--- /dev/null
+++ b/chrome/browser/android/fullscreen/fullscreen_infobar_delegate.cc
@@ -0,0 +1,100 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/android/fullscreen/fullscreen_infobar_delegate.h"
+
+#include "base/android/jni_string.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/prefs/pref_service.h"
+#include "chrome/browser/android/tab_android.h"
+#include "chrome/browser/infobars/infobar_service.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/grit/generated_resources.h"
+#include "components/infobars/core/infobar.h"
+#include "grit/components_strings.h"
+#include "grit/theme_resources.h"
+#include "jni/FullscreenInfoBarDelegate_jni.h"
+#include "net/base/net_util.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "url/gurl.h"
+
+
+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.
+ JNIEnv* env, jobject obj, jobject tab, jstring j_origin) {
+ TabAndroid* tab_android = TabAndroid::GetNativeTab(env, tab);
+ 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.
+ return 0;
+ base::string16 origin =
+ base::android::ConvertJavaStringToUTF16(env, j_origin);
+ FullscreenInfoBarDelegate* delegate = new FullscreenInfoBarDelegate(
+ env, obj, origin);
+ InfoBarService* infobar_service =
+ InfoBarService::FromWebContents(tab_android->web_contents());
+ infobar_service->AddInfoBar(
+ infobar_service->CreateConfirmInfoBar(make_scoped_ptr(delegate)));
+ return reinterpret_cast<intptr_t>(delegate);
+}
+
+bool FullscreenInfoBarDelegate::RegisterFullscreenInfoBarDelegate(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+FullscreenInfoBarDelegate::FullscreenInfoBarDelegate(
+ JNIEnv* env, jobject obj, base::string16 origin)
+ : origin_(origin) {
+ j_delegate_.Reset(env, obj);
+}
+
+FullscreenInfoBarDelegate::~FullscreenInfoBarDelegate() {
+ if (!j_delegate_.is_null()) {
+ Java_FullscreenInfoBarDelegate_onInfoBarDismissed(
+ base::android::AttachCurrentThread(), j_delegate_.obj());
+ }
+}
+
+void FullscreenInfoBarDelegate::CloseFullscreenInfoBar(
+ JNIEnv* env, jobject obj, jobject tab) {
+ j_delegate_.Reset();
+ TabAndroid* tab_android = TabAndroid::GetNativeTab(env, tab);
+ if (!tab_android)
+ return;
+ 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
+ infobar());
+}
+
+int FullscreenInfoBarDelegate::GetIconID() const {
+ return IDR_INFOBAR_FULLSCREEN;
+}
+
+base::string16 FullscreenInfoBarDelegate::GetMessageText() const {
+ Profile* profile =
+ ProfileManager::GetActiveUserProfile()->GetOriginalProfile();
+ std::string language =
+ profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
+ return l10n_util::GetStringFUTF16(
+ IDS_FULLSCREEN_INFOBAR_TEXT, net::FormatUrl(GURL(origin_), language));
+}
+
+base::string16 FullscreenInfoBarDelegate::GetButtonLabel(
+ InfoBarButton button) const {
+ return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
+ IDS_FULLSCREEN_INFOBAR_ALLOW_BUTTON :
+ IDS_FULLSCREEN_INFOBAR_EXIT_FULLSCREEN_BUTTON);
+}
+
+bool FullscreenInfoBarDelegate::Accept() {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ ScopedJavaLocalRef<jstring> j_origin =
+ base::android::ConvertUTF16ToJavaString(env, origin_);
+ Java_FullscreenInfoBarDelegate_onFullscreenAllowed(
+ env, j_delegate_.obj(), j_origin.obj());
+ return true;
+}
+
+bool FullscreenInfoBarDelegate::Cancel() {
+ Java_FullscreenInfoBarDelegate_onFullscreenCancelled(
+ base::android::AttachCurrentThread(), j_delegate_.obj());
+ return true;
+}

Powered by Google App Engine
This is Rietveld 408576698