Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / android / website_settings_popup_android.cc
blob37c45d59cf50c1503513bab30bd12c23a1555b3e
1 // Copyright (c) 2013 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.
5 #include "chrome/browser/ui/android/website_settings_popup_android.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_array.h"
9 #include "base/android/jni_string.h"
10 #include "chrome/browser/infobars/infobar_service.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/website_settings/website_settings.h"
13 #include "chrome/browser/ui/website_settings/website_settings_ui.h"
14 #include "components/content_settings/core/common/content_settings.h"
15 #include "components/content_settings/core/common/content_settings_types.h"
16 #include "content/public/browser/browser_context.h"
17 #include "content/public/browser/cert_store.h"
18 #include "content/public/browser/navigation_controller.h"
19 #include "content/public/browser/navigation_entry.h"
20 #include "content/public/browser/web_contents.h"
21 #include "grit/generated_resources.h"
22 #include "jni/WebsiteSettingsPopup_jni.h"
23 #include "ui/base/l10n/l10n_util.h"
25 using base::android::ConvertUTF16ToJavaString;
26 using base::android::ConvertUTF8ToJavaString;
28 // static
29 static jlong Init(JNIEnv* env,
30 jclass clazz,
31 jobject obj,
32 jobject java_web_contents) {
33 content::WebContents* web_contents =
34 content::WebContents::FromJavaWebContents(java_web_contents);
36 return reinterpret_cast<intptr_t>(
37 new WebsiteSettingsPopupAndroid(env, obj, web_contents));
40 WebsiteSettingsPopupAndroid::WebsiteSettingsPopupAndroid(
41 JNIEnv* env,
42 jobject java_website_settings_pop,
43 content::WebContents* web_contents) {
44 // Important to use GetVisibleEntry to match what's showing in the omnibox.
45 content::NavigationEntry* nav_entry =
46 web_contents->GetController().GetVisibleEntry();
47 if (nav_entry == NULL)
48 return;
50 url_ = nav_entry->GetURL();
52 popup_jobject_.Reset(env, java_website_settings_pop);
54 presenter_.reset(new WebsiteSettings(
55 this,
56 Profile::FromBrowserContext(web_contents->GetBrowserContext()),
57 TabSpecificContentSettings::FromWebContents(web_contents),
58 InfoBarService::FromWebContents(web_contents),
59 nav_entry->GetURL(),
60 nav_entry->GetSSL(),
61 content::CertStore::GetInstance()));
64 WebsiteSettingsPopupAndroid::~WebsiteSettingsPopupAndroid() {}
66 void WebsiteSettingsPopupAndroid::Destroy(JNIEnv* env, jobject obj) {
67 delete this;
70 void WebsiteSettingsPopupAndroid::OnPermissionSettingChanged(JNIEnv* env,
71 jobject obj,
72 jint type,
73 jint setting) {
74 ContentSettingsType content_setting_type =
75 static_cast<ContentSettingsType>(type);
76 ContentSetting content_setting = static_cast<ContentSetting>(setting);
77 presenter_->OnSitePermissionChanged(content_setting_type, content_setting);
80 void WebsiteSettingsPopupAndroid::SetIdentityInfo(
81 const IdentityInfo& identity_info) {
82 JNIEnv* env = base::android::AttachCurrentThread();
83 Java_WebsiteSettingsPopup_showDialog(env, popup_jobject_.obj());
86 void WebsiteSettingsPopupAndroid::SetCookieInfo(
87 const CookieInfoList& cookie_info_list) {
88 NOTIMPLEMENTED();
91 void WebsiteSettingsPopupAndroid::SetPermissionInfo(
92 const PermissionInfoList& permission_info_list) {
93 JNIEnv* env = base::android::AttachCurrentThread();
95 // On Android, we only want to display a subset of the available options in a
96 // particular order, but only if their value is different from the default.
97 std::vector<ContentSettingsType> permissions_to_display;
98 permissions_to_display.push_back(CONTENT_SETTINGS_TYPE_GEOLOCATION);
99 permissions_to_display.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
100 permissions_to_display.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
101 permissions_to_display.push_back(CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
102 permissions_to_display.push_back(CONTENT_SETTINGS_TYPE_IMAGES);
103 permissions_to_display.push_back(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
104 permissions_to_display.push_back(CONTENT_SETTINGS_TYPE_POPUPS);
106 std::map<ContentSettingsType, ContentSetting>
107 user_specified_settings_to_display;
109 for (const auto& permission : permission_info_list) {
110 if (std::find(permissions_to_display.begin(),
111 permissions_to_display.end(),
112 permission.type) != permissions_to_display.end() &&
113 permission.setting != CONTENT_SETTING_DEFAULT) {
114 user_specified_settings_to_display[permission.type] = permission.setting;
118 for (const auto& permission : permissions_to_display) {
119 if (ContainsKey(user_specified_settings_to_display, permission)) {
120 base::string16 setting_title =
121 WebsiteSettingsUI::PermissionTypeToUIString(permission);
123 Java_WebsiteSettingsPopup_addPermissionSection(
124 env,
125 popup_jobject_.obj(),
126 ConvertUTF16ToJavaString(env, setting_title).obj(),
127 static_cast<jint>(permission),
128 static_cast<jint>(user_specified_settings_to_display[permission]));
133 void WebsiteSettingsPopupAndroid::SetSelectedTab(
134 WebsiteSettingsUI::TabId tab_id) {
135 // There's no tab UI on Android - only connection info is shown.
136 NOTIMPLEMENTED();
139 void WebsiteSettingsPopupAndroid::SetFirstVisit(
140 const base::string16& first_visit) {
141 NOTIMPLEMENTED();
144 // static
145 bool WebsiteSettingsPopupAndroid::RegisterWebsiteSettingsPopupAndroid(
146 JNIEnv* env) {
147 return RegisterNativesImpl(env);