summaryrefslogtreecommitdiffstats
path: root/chrome/browser/android/fullscreen
diff options
context:
space:
mode:
authorqinmin <qinmin@chromium.org>2015-03-20 17:33:52 -0700
committerCommit bot <commit-bot@chromium.org>2015-03-21 00:35:00 +0000
commit95ccf94d5e5f47b4b4fca37cddd4cdca51c01e51 (patch)
treeb026d0d0ee26449bb9a6b6a9c6ab26de9849e6a6 /chrome/browser/android/fullscreen
parenta1a3db25697c8cbc046a77a0c0a4e706f7f31be6 (diff)
downloadchromium_src-95ccf94d5e5f47b4b4fca37cddd4cdca51c01e51.zip
chromium_src-95ccf94d5e5f47b4b4fca37cddd4cdca51c01e51.tar.gz
chromium_src-95ccf94d5e5f47b4b4fca37cddd4cdca51c01e51.tar.bz2
Add fullscreen permission controls to settings
See http://crbug/378412 for details This change adds fullscreen permission control to site settings. For fullscreen, the settings has to be either ASK or ALLOW. The settings behavior should match that of the desktop: 1. when a site enters fullscreen, an infobar will be shown to user if permission is not ALLOW. 2. The infobar will be dismissed when user click any button on it, or site leaves fullscreen. TBR=grt@chromium.org BUG=378412 Review URL: https://codereview.chromium.org/986653004 Cr-Commit-Position: refs/heads/master@{#321669}
Diffstat (limited to 'chrome/browser/android/fullscreen')
-rw-r--r--chrome/browser/android/fullscreen/fullscreen_infobar_delegate.cc95
-rw-r--r--chrome/browser/android/fullscreen/fullscreen_infobar_delegate.h43
2 files changed, 138 insertions, 0 deletions
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 0000000..73178ff
--- /dev/null
+++ b/chrome/browser/android/fullscreen/fullscreen_infobar_delegate.cc
@@ -0,0 +1,95 @@
+// 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"
+
+// static
+jlong LaunchFullscreenInfoBar(
+ JNIEnv* env, jobject obj, jobject tab) {
+ TabAndroid* tab_android = TabAndroid::GetNativeTab(env, tab);
+ GURL origin = tab_android->GetURL().GetOrigin();
+ 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, GURL 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);
+ InfoBarService::FromWebContents(tab_android->web_contents())->RemoveInfoBar(
+ 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::ConvertUTF8ToJavaString(env, origin_.spec());
+ 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;
+}
diff --git a/chrome/browser/android/fullscreen/fullscreen_infobar_delegate.h b/chrome/browser/android/fullscreen/fullscreen_infobar_delegate.h
new file mode 100644
index 0000000..0ec2968
--- /dev/null
+++ b/chrome/browser/android/fullscreen/fullscreen_infobar_delegate.h
@@ -0,0 +1,43 @@
+// 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.
+
+#ifndef CHROME_BROWSER_ANDROID_FULLSCREEN_INFOBAR_DELEGATE_H_
+#define CHROME_BROWSER_ANDROID_FULLSCREEN_INFOBAR_DELEGATE_H_
+
+#include <string>
+
+#include "base/android/jni_android.h"
+#include "base/android/scoped_java_ref.h"
+#include "components/infobars/core/confirm_infobar_delegate.h"
+#include "url/gurl.h"
+
+class InfoBarService;
+
+// Native part of FullscreenInfoBarDelegate.java. This class is responsible
+// for adding and removing the fullscreen infobar.
+class FullscreenInfoBarDelegate : public ConfirmInfoBarDelegate {
+ public:
+ static bool RegisterFullscreenInfoBarDelegate(JNIEnv* env);
+
+ FullscreenInfoBarDelegate(JNIEnv* env, jobject obj, GURL origin);
+ ~FullscreenInfoBarDelegate() override;
+
+ // Called to close the infobar.
+ void CloseFullscreenInfoBar(JNIEnv* env, jobject obj, jobject tab);
+
+ // ConfirmInfoBarDelegate:
+ int GetIconID() const override;
+ base::string16 GetMessageText() const override;
+ base::string16 GetButtonLabel(InfoBarButton button) const override;
+ bool Accept() override;
+ bool Cancel() override;
+
+ private:
+ base::android::ScopedJavaGlobalRef<jobject> j_delegate_;
+ GURL origin_;
+
+ DISALLOW_COPY_AND_ASSIGN(FullscreenInfoBarDelegate);
+};
+
+#endif // CHROME_BROWSER_ANDROID_FULLSCREEN_INFOBAR_DELEGATE_H_