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

Unified Diff: chrome/browser/ui/webui/options/content_settings_handler.cc

Issue 2237823003: Site Settings Desktop: Implement USB devices section. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback Created 4 years, 4 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/ui/webui/options/content_settings_handler.cc
diff --git a/chrome/browser/ui/webui/options/content_settings_handler.cc b/chrome/browser/ui/webui/options/content_settings_handler.cc
index 4649e6484ce4095d68a62841ab65c34c31187cb5..2fd75f0100e7f90863107faff77e2021f6d1dfa3 100644
--- a/chrome/browser/ui/webui/options/content_settings_handler.cc
+++ b/chrome/browser/ui/webui/options/content_settings_handler.cc
@@ -84,14 +84,6 @@ using extensions::APIPermission;
namespace options {
-// This struct is declared early so that it can used by functions below.
-struct ContentSettingsHandler::ChooserTypeNameEntry {
- ContentSettingsType type;
- ChooserContextBase* (*get_context)(Profile*);
- const char* name;
- const char* ui_name_key;
-};
-
namespace {
struct ContentSettingWithExceptions {
@@ -101,15 +93,6 @@ struct ContentSettingWithExceptions {
UserMetricsAction uma;
};
-// Maps from the UI string to the object it represents (for sorting purposes).
-typedef std::multimap<std::string, const base::DictionaryValue*> SortedObjects;
-// Maps from a secondary URL to the set of objects it has permission to access.
-typedef std::map<GURL, SortedObjects> OneOriginObjects;
-// Maps from a primary URL/source pair to a OneOriginObjects. All the mappings
-// in OneOriginObjects share the given primary URL and source.
-typedef std::map<std::pair<GURL, std::string>, OneOriginObjects>
- AllOriginObjects;
-
// The AppFilter is used in AddExceptionsGrantedByHostedApps() to choose
// extensions which should have their extent displayed.
typedef bool (*AppFilter)(const extensions::Extension& app,
@@ -121,17 +104,6 @@ const char kExceptionsLearnMoreUrl[] =
const char kAppName[] = "appName";
const char kAppId[] = "appId";
const char kZoom[] = "zoom";
-const char kObject[] = "object";
-const char kObjectName[] = "objectName";
-
-ChooserContextBase* GetUsbChooserContext(Profile* profile) {
- return UsbChooserContextFactory::GetForProfile(profile);
-}
-
-const ContentSettingsHandler::ChooserTypeNameEntry kChooserTypeGroupNames[] = {
- {CONTENT_SETTINGS_TYPE_USB_CHOOSER_DATA, &GetUsbChooserContext,
- "usb-devices", "name"},
-};
// A pseudo content type. We use it to display data like a content setting even
// though it is not a real content setting.
@@ -240,15 +212,6 @@ content::BrowserContext* GetBrowserContext(content::WebUI* web_ui) {
return web_ui->GetWebContents()->GetBrowserContext();
}
-const ContentSettingsHandler::ChooserTypeNameEntry* ChooserTypeFromGroupName(
- const std::string& name) {
- for (const auto& chooser_type : kChooserTypeGroupNames) {
- if (chooser_type.name == name)
- return &chooser_type;
- }
- return nullptr;
-}
-
// Create a DictionaryValue* that will act as a data source for a single row
// in the Geolocation exceptions table.
std::unique_ptr<base::DictionaryValue> GetGeolocationExceptionForPage(
@@ -292,32 +255,6 @@ std::unique_ptr<base::DictionaryValue> GetNotificationExceptionForPage(
return base::WrapUnique(exception);
}
-// Create a DictionaryValue* that will act as a data source for a single row
-// in a chooser permission exceptions table.
-std::unique_ptr<base::DictionaryValue> GetChooserExceptionForPage(
- const GURL& requesting_origin,
- const GURL& embedding_origin,
- const std::string& provider_name,
- const std::string& name,
- const base::DictionaryValue* object) {
- std::unique_ptr<base::DictionaryValue> exception(new base::DictionaryValue());
-
- std::string setting_string =
- content_settings::ContentSettingToString(CONTENT_SETTING_DEFAULT);
- DCHECK(!setting_string.empty());
-
- exception->SetString(site_settings::kSetting, setting_string);
- exception->SetString(site_settings::kOrigin, requesting_origin.spec());
- exception->SetString(
- site_settings::kEmbeddingOrigin, embedding_origin.spec());
- exception->SetString(site_settings::kSource, provider_name);
- if (object) {
- exception->SetString(kObjectName, name);
- exception->Set(kObject, object->CreateDeepCopy());
- }
- return exception;
-}
-
// Returns true whenever the |extension| is hosted and has |permission|.
// Must have the AppFilter signature.
template <APIPermission::ID permission>
@@ -1050,19 +987,22 @@ void ContentSettingsHandler::UpdateMIDISysExExceptionsView() {
}
void ContentSettingsHandler::UpdateAllChooserExceptionsViewsFromModel() {
- for (const ChooserTypeNameEntry& chooser_type : kChooserTypeGroupNames)
+ for (const site_settings::ChooserTypeNameEntry& chooser_type :
+ site_settings::kChooserTypeGroupNames)
UpdateChooserExceptionsViewFromModel(chooser_type);
}
void ContentSettingsHandler::UpdateAllOTRChooserExceptionsViewsFromModel() {
- for (const ChooserTypeNameEntry& chooser_type : kChooserTypeGroupNames)
+ for (const site_settings::ChooserTypeNameEntry& chooser_type :
+ site_settings::kChooserTypeGroupNames)
UpdateOTRChooserExceptionsViewFromModel(chooser_type);
}
void ContentSettingsHandler::UpdateChooserExceptionsViewFromModel(
- const ChooserTypeNameEntry& chooser_type) {
+ const site_settings::ChooserTypeNameEntry& chooser_type) {
base::ListValue exceptions;
- GetChooserExceptionsFromProfile(false, chooser_type, &exceptions);
+ site_settings::GetChooserExceptionsFromProfile(
+ Profile::FromWebUI(web_ui()), false, chooser_type, &exceptions);
base::StringValue type_string(chooser_type.name);
web_ui()->CallJavascriptFunctionUnsafe("ContentSettings.setExceptions",
type_string, exceptions);
@@ -1071,12 +1011,13 @@ void ContentSettingsHandler::UpdateChooserExceptionsViewFromModel(
}
void ContentSettingsHandler::UpdateOTRChooserExceptionsViewFromModel(
- const ChooserTypeNameEntry& chooser_type) {
+ const site_settings::ChooserTypeNameEntry& chooser_type) {
if (!Profile::FromWebUI(web_ui())->HasOffTheRecordProfile())
return;
base::ListValue exceptions;
- GetChooserExceptionsFromProfile(true, chooser_type, &exceptions);
+ site_settings::GetChooserExceptionsFromProfile(
+ Profile::FromWebUI(web_ui()), true, chooser_type, &exceptions);
base::StringValue type_string(chooser_type.name);
web_ui()->CallJavascriptFunctionUnsafe("ContentSettings.setOTRExceptions",
type_string, exceptions);
@@ -1196,97 +1137,6 @@ void ContentSettingsHandler::UpdateExceptionsViewFromOTRHostContentSettingsMap(
type_string, exceptions);
}
-void ContentSettingsHandler::GetChooserExceptionsFromProfile(
- bool incognito,
- const ChooserTypeNameEntry& chooser_type,
- base::ListValue* exceptions) {
- Profile* profile = Profile::FromWebUI(web_ui());
- if (incognito) {
- if (profile->HasOffTheRecordProfile())
- profile = profile->GetOffTheRecordProfile();
- else
- return;
- }
-
- ChooserContextBase* chooser_context = chooser_type.get_context(profile);
- std::vector<std::unique_ptr<ChooserContextBase::Object>> objects =
- chooser_context->GetAllGrantedObjects();
- AllOriginObjects all_origin_objects;
- for (const auto& object : objects) {
- std::string name;
- bool found = object->object.GetString(chooser_type.ui_name_key, &name);
- DCHECK(found);
- // It is safe for this structure to hold references into |objects| because
- // they are both destroyed at the end of this function.
- all_origin_objects[make_pair(object->requesting_origin,
- object->source)][object->embedding_origin]
- .insert(make_pair(name, &object->object));
- }
-
- // Keep the exceptions sorted by provider so they will be displayed in
- // precedence order.
- std::vector<std::unique_ptr<base::DictionaryValue>>
- all_provider_exceptions[HostContentSettingsMap::NUM_PROVIDER_TYPES];
-
- for (const auto& all_origin_objects_entry : all_origin_objects) {
- const GURL& requesting_origin = all_origin_objects_entry.first.first;
- const std::string& source = all_origin_objects_entry.first.second;
- const OneOriginObjects& one_origin_objects =
- all_origin_objects_entry.second;
-
- auto& this_provider_exceptions = all_provider_exceptions
- [HostContentSettingsMap::GetProviderTypeFromSource(source)];
-
- // Add entries for any non-embedded origins.
- bool has_embedded_entries = false;
- for (const auto& one_origin_objects_entry : one_origin_objects) {
- const GURL& embedding_origin = one_origin_objects_entry.first;
- const SortedObjects& sorted_objects = one_origin_objects_entry.second;
-
- // Skip the embedded settings which will be added below.
- if (requesting_origin != embedding_origin) {
- has_embedded_entries = true;
- continue;
- }
-
- for (const auto& sorted_objects_entry : sorted_objects) {
- this_provider_exceptions.push_back(GetChooserExceptionForPage(
- requesting_origin, embedding_origin, source,
- sorted_objects_entry.first, sorted_objects_entry.second));
- }
- }
-
- if (has_embedded_entries) {
- // Add a "parent" entry that simply acts as a heading for all entries
- // where |requesting_origin| has been embedded.
- this_provider_exceptions.push_back(
- GetChooserExceptionForPage(requesting_origin, requesting_origin,
- source, std::string(), nullptr));
-
- // Add the "children" for any embedded settings.
- for (const auto& one_origin_objects_entry : one_origin_objects) {
- const GURL& embedding_origin = one_origin_objects_entry.first;
- const SortedObjects& sorted_objects = one_origin_objects_entry.second;
-
- // Skip the non-embedded setting which we already added above.
- if (requesting_origin == embedding_origin)
- continue;
-
- for (const auto& sorted_objects_entry : sorted_objects) {
- this_provider_exceptions.push_back(GetChooserExceptionForPage(
- requesting_origin, embedding_origin, source,
- sorted_objects_entry.first, sorted_objects_entry.second));
- }
- }
- }
- }
-
- for (auto& one_provider_exceptions : all_provider_exceptions) {
- for (auto& exception : one_provider_exceptions)
- exceptions->Append(std::move(exception));
- }
-}
-
void ContentSettingsHandler::RemoveExceptionFromHostContentSettingsMap(
const base::ListValue* args,
ContentSettingsType type) {
@@ -1350,7 +1200,7 @@ void ContentSettingsHandler::RemoveZoomLevelException(
}
void ContentSettingsHandler::RemoveChooserException(
- const ChooserTypeNameEntry* chooser_type,
+ const site_settings::ChooserTypeNameEntry* chooser_type,
const base::ListValue* args) {
std::string mode;
bool rv = args->GetString(1, &mode);
@@ -1445,8 +1295,8 @@ void ContentSettingsHandler::RemoveException(const base::ListValue* args) {
return;
}
- const ChooserTypeNameEntry* chooser_type =
- ChooserTypeFromGroupName(type_string);
+ const site_settings::ChooserTypeNameEntry* chooser_type =
+ site_settings::ChooserTypeFromGroupName(type_string);
if (chooser_type) {
RemoveChooserException(chooser_type, args);
return;

Powered by Google App Engine
This is Rietveld 408576698