Commit acf8c151 authored by dschuyler's avatar dschuyler Committed by Commit bot

[MD settings] add getSiteDetails to site settings browser proxy

This CL is a step toward deep linking to site details in the site
settings. This CL adds the c++ handler backend and does show the
exceptions in the UI. The page title is not updated with the subject URL,
but that is not a regression and will be addressed in a future CL.

BUG=635874
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2338163004
Cr-Commit-Position: refs/heads/master@{#419071}
parent ee46aaa2
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
Polymer({ Polymer({
is: 'site-details', is: 'site-details',
behaviors: [SiteSettingsBehavior], behaviors: [SiteSettingsBehavior, settings.RouteObserverBehavior],
properties: { properties: {
/** /**
...@@ -44,13 +44,33 @@ Polymer({ ...@@ -44,13 +44,33 @@ Polymer({
this.ContentSettingsTypes = settings.ContentSettingsTypes; this.ContentSettingsTypes = settings.ContentSettingsTypes;
}, },
/**
* settings.RouteObserverBehavior
* @param {!settings.Route} route
* @protected
*/
currentRouteChanged: function(route) {
var site = settings.getQueryParameters().get('site');
if (!site)
return;
this.browserProxy.getSiteDetails(site).then(function(siteInfo) {
this.site = siteInfo;
// TODO(dschuyler): set originForDisplay for fetchUsageTotal.
// TODO(dschuyler): set the page title to originForDisplay.
}.bind(this));
},
/** /**
* Handler for when the origin changes. * Handler for when the origin changes.
*/ */
onSiteChanged_: function() { onSiteChanged_: function() {
// Using originForDisplay avoids the [*.] prefix that some exceptions use. // originForDisplay may be initially undefined if the user follows a direct
var url = new URL(this.ensureUrlHasScheme(this.site.originForDisplay)); // link (URL) to this page.
this.$.usageApi.fetchUsageTotal(url.hostname); if (this.site.originForDisplay !== undefined) {
// Using originForDisplay avoids the [*.] prefix that some exceptions use.
var url = new URL(this.ensureUrlHasScheme(this.site.originForDisplay));
this.$.usageApi.fetchUsageTotal(url.hostname);
}
}, },
/** /**
......
...@@ -367,12 +367,12 @@ Polymer({ ...@@ -367,12 +367,12 @@ Polymer({
} }
return comparison; return comparison;
}); });
var results = /** @type {!Array<SiteException>} */ []; var results = /** @type {!Array<SiteException>} */([]);
var lastOrigin = ''; var lastOrigin = '';
var lastEmbeddingOrigin = ''; var lastEmbeddingOrigin = '';
for (var i = 0; i < sites.length; ++i) { for (var i = 0; i < sites.length; ++i) {
var origin = sites[i].origin; var origin = sites[i].origin;
var originForDisplay = this.sanitizePort(origin.replace('[*.]', '')); var originForDisplay = this.sanitizePort(this.toUrl_(origin).origin);
var embeddingOrigin = sites[i].embeddingOrigin; var embeddingOrigin = sites[i].embeddingOrigin;
var embeddingOriginForDisplay = ''; var embeddingOriginForDisplay = '';
...@@ -393,6 +393,7 @@ Polymer({ ...@@ -393,6 +393,7 @@ Polymer({
embeddingOrigin: embeddingOrigin, embeddingOrigin: embeddingOrigin,
embeddingOriginForDisplay: embeddingOriginForDisplay, embeddingOriginForDisplay: embeddingOriginForDisplay,
incognito: sites[i].incognito, incognito: sites[i].incognito,
setting: sites[i].setting,
source: sites[i].source, source: sites[i].source,
}); });
...@@ -440,7 +441,8 @@ Polymer({ ...@@ -440,7 +441,8 @@ Polymer({
if (this.isPolicyControlled_(this.selectedSite.source)) if (this.isPolicyControlled_(this.selectedSite.source))
return; return;
settings.navigateTo(settings.Route.SITE_SETTINGS_SITE_DETAILS); settings.navigateTo(settings.Route.SITE_SETTINGS_SITE_DETAILS,
new URLSearchParams('site=' + this.selectedSite.origin));
}, },
/** /**
......
...@@ -100,6 +100,13 @@ cr.define('settings', function() { ...@@ -100,6 +100,13 @@ cr.define('settings', function() {
*/ */
getExceptionList: function(contentType) {}, getExceptionList: function(contentType) {},
/**
* Gets the exception details for a particular site.
* @param {string} site The name of the site.
* @return {Promise<SiteException>}
*/
getSiteDetails: function(site) {},
/** /**
* Resets the category permission for a given origin (expressed as primary * Resets the category permission for a given origin (expressed as primary
* and secondary patterns). * and secondary patterns).
...@@ -264,6 +271,11 @@ cr.define('settings', function() { ...@@ -264,6 +271,11 @@ cr.define('settings', function() {
return cr.sendWithPromise('getExceptionList', contentType); return cr.sendWithPromise('getExceptionList', contentType);
}, },
/** @override */
getSiteDetails: function(site) {
return cr.sendWithPromise('getSiteDetails', site);
},
/** @override */ /** @override */
resetCategoryPermissionForOrigin: function( resetCategoryPermissionForOrigin: function(
primaryPattern, secondaryPattern, contentType, incognito) { primaryPattern, secondaryPattern, contentType, incognito) {
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <stddef.h> #include <stddef.h>
#include <algorithm> #include <algorithm>
#include <map>
#include <utility> #include <utility>
#include <vector> #include <vector>
...@@ -948,7 +949,7 @@ void ContentSettingsHandler::CompareMediaExceptionsWithFlash( ...@@ -948,7 +949,7 @@ void ContentSettingsHandler::CompareMediaExceptionsWithFlash(
base::ListValue exceptions; base::ListValue exceptions;
site_settings::GetExceptionsFromHostContentSettingsMap(settings_map, type, site_settings::GetExceptionsFromHostContentSettingsMap(settings_map, type,
web_ui(), /*incognito=*/ false, &exceptions); web_ui(), /*incognito=*/false, /*filter=*/nullptr, &exceptions);
settings.exceptions.clear(); settings.exceptions.clear();
for (base::ListValue::const_iterator entry = exceptions.begin(); for (base::ListValue::const_iterator entry = exceptions.begin();
...@@ -1093,7 +1094,7 @@ void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap( ...@@ -1093,7 +1094,7 @@ void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap(
HostContentSettingsMap* settings_map = HostContentSettingsMap* settings_map =
HostContentSettingsMapFactory::GetForProfile(GetProfile()); HostContentSettingsMapFactory::GetForProfile(GetProfile());
site_settings::GetExceptionsFromHostContentSettingsMap(settings_map, type, site_settings::GetExceptionsFromHostContentSettingsMap(settings_map, type,
web_ui(), /*incognito=*/ false, &exceptions); web_ui(), /*incognito=*/false, /*filter=*/nullptr, &exceptions);
base::StringValue type_string( base::StringValue type_string(
site_settings::ContentSettingsTypeToGroupName(type)); site_settings::ContentSettingsTypeToGroupName(type));
web_ui()->CallJavascriptFunctionUnsafe("ContentSettings.setExceptions", web_ui()->CallJavascriptFunctionUnsafe("ContentSettings.setExceptions",
...@@ -1128,7 +1129,7 @@ void ContentSettingsHandler::UpdateExceptionsViewFromOTRHostContentSettingsMap( ...@@ -1128,7 +1129,7 @@ void ContentSettingsHandler::UpdateExceptionsViewFromOTRHostContentSettingsMap(
return; return;
base::ListValue exceptions; base::ListValue exceptions;
site_settings::GetExceptionsFromHostContentSettingsMap(otr_settings_map, type, site_settings::GetExceptionsFromHostContentSettingsMap(otr_settings_map, type,
web_ui(), /*incognito=*/ true, &exceptions); web_ui(), /*incognito=*/true, /*filter=*/nullptr, &exceptions);
base::StringValue type_string( base::StringValue type_string(
site_settings::ContentSettingsTypeToGroupName(type)); site_settings::ContentSettingsTypeToGroupName(type));
web_ui()->CallJavascriptFunctionUnsafe("ContentSettings.setOTRExceptions", web_ui()->CallJavascriptFunctionUnsafe("ContentSettings.setOTRExceptions",
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chrome/browser/ui/webui/settings/site_settings_handler.h" #include "chrome/browser/ui/webui/settings/site_settings_handler.h"
#include <algorithm>
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility> #include <utility>
...@@ -156,6 +157,10 @@ void SiteSettingsHandler::RegisterMessages() { ...@@ -156,6 +157,10 @@ void SiteSettingsHandler::RegisterMessages() {
"setCategoryPermissionForOrigin", "setCategoryPermissionForOrigin",
base::Bind(&SiteSettingsHandler::HandleSetCategoryPermissionForOrigin, base::Bind(&SiteSettingsHandler::HandleSetCategoryPermissionForOrigin,
base::Unretained(this))); base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"getSiteDetails",
base::Bind(&SiteSettingsHandler::HandleGetSiteDetails,
base::Unretained(this)));
web_ui()->RegisterMessageCallback( web_ui()->RegisterMessageCallback(
"isPatternValid", "isPatternValid",
base::Bind(&SiteSettingsHandler::HandleIsPatternValid, base::Bind(&SiteSettingsHandler::HandleIsPatternValid,
...@@ -436,13 +441,15 @@ void SiteSettingsHandler::HandleGetExceptionList(const base::ListValue* args) { ...@@ -436,13 +441,15 @@ void SiteSettingsHandler::HandleGetExceptionList(const base::ListValue* args) {
AddExceptionsGrantedByHostedApps(profile_, APIPermissionFromGroupName(type), AddExceptionsGrantedByHostedApps(profile_, APIPermissionFromGroupName(type),
exceptions.get()); exceptions.get());
site_settings::GetExceptionsFromHostContentSettingsMap( site_settings::GetExceptionsFromHostContentSettingsMap(
map, content_type, web_ui(), false, exceptions.get()); map, content_type, web_ui(), /*incognito=*/false, /*filter=*/nullptr,
exceptions.get());
if (profile_->HasOffTheRecordProfile()) { if (profile_->HasOffTheRecordProfile()) {
Profile* incognito = profile_->GetOffTheRecordProfile(); Profile* incognito = profile_->GetOffTheRecordProfile();
map = HostContentSettingsMapFactory::GetForProfile(incognito); map = HostContentSettingsMapFactory::GetForProfile(incognito);
site_settings::GetExceptionsFromHostContentSettingsMap( site_settings::GetExceptionsFromHostContentSettingsMap(
map, content_type, web_ui(), true, exceptions.get()); map, content_type, web_ui(), /*incognito=*/true, /*filter=*/nullptr,
exceptions.get());
} }
ResolveJavascriptCallback(*callback_id, *exceptions.get()); ResolveJavascriptCallback(*callback_id, *exceptions.get());
...@@ -522,6 +529,68 @@ void SiteSettingsHandler::HandleSetCategoryPermissionForOrigin( ...@@ -522,6 +529,68 @@ void SiteSettingsHandler::HandleSetCategoryPermissionForOrigin(
content_type, "", setting); content_type, "", setting);
} }
void SiteSettingsHandler::HandleGetSiteDetails(
const base::ListValue* args) {
AllowJavascript();
CHECK_EQ(2U, args->GetSize());
const base::Value* callback_id;
CHECK(args->Get(0, &callback_id));
std::string site;
CHECK(args->GetString(1, &site));
// A subset of the ContentSettingsType enum that we show in the settings UI.
const ContentSettingsType kSettingsDetailTypes[] = {
CONTENT_SETTINGS_TYPE_COOKIES,
CONTENT_SETTINGS_TYPE_IMAGES,
CONTENT_SETTINGS_TYPE_JAVASCRIPT,
CONTENT_SETTINGS_TYPE_PLUGINS,
CONTENT_SETTINGS_TYPE_POPUPS,
CONTENT_SETTINGS_TYPE_GEOLOCATION,
CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
CONTENT_SETTINGS_TYPE_FULLSCREEN,
CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS,
CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS,
CONTENT_SETTINGS_TYPE_KEYGEN,
CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC,
CONTENT_SETTINGS_TYPE_USB_CHOOSER_DATA,
CONTENT_SETTINGS_TYPE_PROMPT_NO_DECISION_COUNT,
};
// Create a list to be consistent with existing API, we are expecting a single
// element (or none).
std::unique_ptr<base::ListValue> exceptions(new base::ListValue);
for (size_t type = 0; type < arraysize(kSettingsDetailTypes); ++type) {
ContentSettingsType content_type = kSettingsDetailTypes[type];
HostContentSettingsMap* map =
HostContentSettingsMapFactory::GetForProfile(profile_);
site_settings::GetExceptionsFromHostContentSettingsMap(
map, content_type, web_ui(), /*incognito=*/false, /*filter=*/&site,
exceptions.get());
if (profile_->HasOffTheRecordProfile()) {
Profile* incognito = profile_->GetOffTheRecordProfile();
map = HostContentSettingsMapFactory::GetForProfile(incognito);
site_settings::GetExceptionsFromHostContentSettingsMap(
map, content_type, web_ui(), /*incognito=*/true, /*filter=*/&site,
exceptions.get());
}
}
if (!exceptions->GetSize()) {
RejectJavascriptCallback(*callback_id, *base::Value::CreateNullValue());
return;
}
// We only need a single response element.
const base::DictionaryValue* exception = nullptr;
exceptions->GetDictionary(0, &exception);
ResolveJavascriptCallback(*callback_id, *exception);
}
void SiteSettingsHandler::HandleIsPatternValid( void SiteSettingsHandler::HandleIsPatternValid(
const base::ListValue* args) { const base::ListValue* args) {
CHECK_EQ(2U, args->GetSize()); CHECK_EQ(2U, args->GetSize());
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_UI_WEBUI_SETTINGS_SITE_SETTINGS_HANDLER_H_ #ifndef CHROME_BROWSER_UI_WEBUI_SETTINGS_SITE_SETTINGS_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_SETTINGS_SITE_SETTINGS_HANDLER_H_ #define CHROME_BROWSER_UI_WEBUI_SETTINGS_SITE_SETTINGS_HANDLER_H_
#include <memory>
#include <string>
#include <vector> #include <vector>
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
...@@ -87,6 +89,9 @@ class SiteSettingsHandler : public SettingsPageUIHandler, ...@@ -87,6 +89,9 @@ class SiteSettingsHandler : public SettingsPageUIHandler,
void HandleResetCategoryPermissionForOrigin(const base::ListValue* args); void HandleResetCategoryPermissionForOrigin(const base::ListValue* args);
void HandleSetCategoryPermissionForOrigin(const base::ListValue* args); void HandleSetCategoryPermissionForOrigin(const base::ListValue* args);
// Return site exceptions for a single site.
void HandleGetSiteDetails(const base::ListValue* args);
// Returns whether a given pattern is valid. // Returns whether a given pattern is valid.
void HandleIsPatternValid(const base::ListValue* args); void HandleIsPatternValid(const base::ListValue* args);
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
#include "chrome/browser/ui/webui/site_settings_helper.h" #include "chrome/browser/ui/webui/site_settings_helper.h"
#include <functional>
#include <string>
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/permissions/chooser_context_base.h" #include "chrome/browser/permissions/chooser_context_base.h"
...@@ -104,6 +107,7 @@ void GetExceptionsFromHostContentSettingsMap(const HostContentSettingsMap* map, ...@@ -104,6 +107,7 @@ void GetExceptionsFromHostContentSettingsMap(const HostContentSettingsMap* map,
ContentSettingsType type, ContentSettingsType type,
content::WebUI* web_ui, content::WebUI* web_ui,
bool incognito, bool incognito,
const std::string* filter,
base::ListValue* exceptions) { base::ListValue* exceptions) {
ContentSettingsForOneType entries; ContentSettingsForOneType entries;
map->GetSettingsForOneType(type, std::string(), &entries); map->GetSettingsForOneType(type, std::string(), &entries);
...@@ -124,6 +128,9 @@ void GetExceptionsFromHostContentSettingsMap(const HostContentSettingsMap* map, ...@@ -124,6 +128,9 @@ void GetExceptionsFromHostContentSettingsMap(const HostContentSettingsMap* map,
if (map->is_off_the_record() && !i->incognito) if (map->is_off_the_record() && !i->incognito)
continue; continue;
if (filter && i->primary_pattern.ToString() != *filter)
continue;
all_patterns_settings[std::make_pair(i->primary_pattern, i->source)] all_patterns_settings[std::make_pair(i->primary_pattern, i->source)]
[i->secondary_pattern] = i->setting; [i->secondary_pattern] = i->setting;
} }
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include <map> #include <map>
#include <memory> #include <memory>
#include <string>
#include <utility>
#include <vector> #include <vector>
#include "components/content_settings/core/common/content_settings.h" #include "components/content_settings/core/common/content_settings.h"
...@@ -54,11 +56,14 @@ ContentSettingsType ContentSettingsTypeFromGroupName(const std::string& name); ...@@ -54,11 +56,14 @@ ContentSettingsType ContentSettingsTypeFromGroupName(const std::string& name);
std::string ContentSettingsTypeToGroupName(ContentSettingsType type); std::string ContentSettingsTypeToGroupName(ContentSettingsType type);
// Fills in |exceptions| with Values for the given |type| from |map|. // Fills in |exceptions| with Values for the given |type| from |map|.
// If |filter| is not null then only exceptions with matching primary patterns
// will be returned.
void GetExceptionsFromHostContentSettingsMap( void GetExceptionsFromHostContentSettingsMap(
const HostContentSettingsMap* map, const HostContentSettingsMap* map,
ContentSettingsType type, ContentSettingsType type,
content::WebUI* web_ui, content::WebUI* web_ui,
bool incognito, bool incognito,
const std::string* filter,
base::ListValue* exceptions); base::ListValue* exceptions);
// Returns exceptions constructed from the policy-set allowed URLs // Returns exceptions constructed from the policy-set allowed URLs
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment