Skip to content

Commit

Permalink
Remove using embedding origin in chooser exception
Browse files Browse the repository at this point in the history
As chooser permission is now using permission delegation on top level
origin, there is no need to have the concept of embedding origin and
requesting origin anymore. This change removes using embedding origin in
chooser exception.

Bug: 1307670
Change-Id: I4979bb93676d3432698d385dc89ab4465c4ed6bf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3840212
Commit-Queue: Jack Hsieh <chengweih@chromium.org>
Reviewed-by: Colin Blundell <blundell@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1085073}
  • Loading branch information
chengweih001 authored and Chromium LUCI CQ committed Dec 19, 2022
1 parent b293ee9 commit 3c0fa80
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 141 deletions.
Expand Up @@ -246,8 +246,7 @@ export class SiteListEntryElement extends SiteListEntryElementBase {
// Use the appropriate method to reset a chooser exception.
if (this.chooserType !== ChooserType.NONE && this.chooserObject !== null) {
this.browserProxy.resetChooserExceptionForSite(
this.chooserType, this.model.origin, this.model.embeddingOrigin,
this.chooserObject);
this.chooserType, this.model.origin, this.chooserObject);
return;
}

Expand Down
Expand Up @@ -300,12 +300,10 @@ export interface SiteSettingsPrefsBrowserProxy {
* origin.
* @param chooserType The chooser exception type
* @param origin The origin to look up the permission for.
* @param embeddingOrigin the embedding origin to look up.
* @param exception The exception to revoke permission for.
*/
resetChooserExceptionForSite(
chooserType: ChooserType, origin: string, embeddingOrigin: string,
exception: Object): void;
chooserType: ChooserType, origin: string, exception: Object): void;

/**
* Sets the category permission for a given origin (expressed as primary and
Expand Down Expand Up @@ -557,11 +555,9 @@ export class SiteSettingsPrefsBrowserProxyImpl implements
}

resetChooserExceptionForSite(
chooserType: ChooserType, origin: string, embeddingOrigin: string,
exception: Object) {
chooserType: ChooserType, origin: string, exception: Object) {
chrome.send(
'resetChooserExceptionForSite',
[chooserType, origin, embeddingOrigin, exception]);
'resetChooserExceptionForSite', [chooserType, origin, exception]);
}

setCategoryPermissionForPattern(
Expand Down
13 changes: 4 additions & 9 deletions chrome/browser/ui/webui/settings/site_settings_handler.cc
Expand Up @@ -1651,25 +1651,20 @@ void SiteSettingsHandler::HandleSetCategoryPermissionForPattern(

void SiteSettingsHandler::HandleResetChooserExceptionForSite(
const base::Value::List& args) {
CHECK_EQ(4U, args.size());
CHECK_EQ(3U, args.size());

const std::string& chooser_type_str = args[0].GetString();
const site_settings::ChooserTypeNameEntry* chooser_type =
site_settings::ChooserTypeFromGroupName(chooser_type_str);
CHECK(chooser_type);

const std::string& origin_str = args[1].GetString();
GURL requesting_origin(origin_str);
CHECK(requesting_origin.is_valid());

const std::string& embedding_origin_str = args[2].GetString();
GURL embedding_origin(embedding_origin_str);
CHECK(embedding_origin.is_valid());
GURL origin(origin_str);
CHECK(origin.is_valid());

permissions::ObjectPermissionContextBase* chooser_context =
chooser_type->get_context(profile_);
chooser_context->RevokeObjectPermission(url::Origin::Create(embedding_origin),
args[3]);
chooser_context->RevokeObjectPermission(url::Origin::Create(origin), args[2]);
}

void SiteSettingsHandler::HandleIgnoreOriginsForNotificationPermissionReview(
Expand Down
Expand Up @@ -2629,7 +2629,6 @@ TEST_F(SiteSettingsHandlerChooserExceptionTest,
// from the list.
base::Value::List args;
args.Append(kUsbChooserGroupName);
args.Append("https://unused.com");
args.Append(kGoogleOriginStr);
args.Append(UsbChooserContext::DeviceInfoToValue(*persistent_device_info_));

Expand Down Expand Up @@ -2663,7 +2662,6 @@ TEST_F(SiteSettingsHandlerChooserExceptionTest,
// be able to be reset.
args.clear();
args.Append(kUsbChooserGroupName);
args.Append("https://unused.com");
args.Append(kChromiumOriginStr);
args.Append(UsbChooserContext::DeviceInfoToValue(*persistent_device_info_));

Expand Down Expand Up @@ -2715,7 +2713,6 @@ TEST_F(SiteSettingsHandlerChooserExceptionTest,
// when the exception only has one site exception granted to it..
args.clear();
args.Append(kUsbChooserGroupName);
args.Append("https://unused.com");
args.Append(kAndroidOriginStr);
args.Append(UsbChooserContext::DeviceInfoToValue(*user_granted_device_info_));

Expand Down
39 changes: 14 additions & 25 deletions chrome/browser/ui/webui/settings/site_settings_helper.cc
Expand Up @@ -940,28 +940,22 @@ base::Value::Dict CreateChooserExceptionObject(
std::vector<base::Value::Dict>
all_provider_sites[HostContentSettingsMap::NUM_PROVIDER_TYPES];
for (const auto& details : chooser_exception_details) {
const GURL& requesting_origin = details.first.first;
const std::string& source = details.first.second;
const GURL& origin = std::get<0>(details);
const std::string& source = std::get<1>(details);
const bool incognito = std::get<2>(details);

std::string site_display_name = origin.spec();

auto& this_provider_sites =
all_provider_sites[HostContentSettingsMap::GetProviderTypeFromSource(
source)];

for (const auto& embedding_origin_incognito_pair : details.second) {
const GURL& embedding_origin = embedding_origin_incognito_pair.first;
const bool incognito = embedding_origin_incognito_pair.second;
base::Value::Dict site;

site.Set(kOrigin, requesting_origin.spec());
site.Set(kDisplayName, requesting_origin.spec());
site.Set(kEmbeddingOrigin, embedding_origin.is_empty()
? std::string()
: embedding_origin.spec());
site.Set(kSetting, setting_string);
site.Set(kSource, source);
site.Set(kIncognito, incognito);
this_provider_sites.push_back(std::move(site));
}
base::Value::Dict site;
site.Set(kOrigin, origin.spec());
site.Set(kDisplayName, site_display_name);
site.Set(kSetting, setting_string);
site.Set(kSource, source);
site.Set(kIncognito, incognito);
this_provider_sites.push_back(std::move(site));
}

base::Value::List sites;
Expand Down Expand Up @@ -1024,13 +1018,8 @@ base::Value::List GetChooserExceptionListFromProfile(
std::string source = GetSourceStringForChooserException(
profile, content_type, object->source);

const auto origin_source_pair = std::make_pair(object->origin, source);
auto& origin_incognito_pair_set =
chooser_exception_details[origin_source_pair];

const auto origin_incognito_pair =
std::make_pair(object->origin, object->incognito);
origin_incognito_pair_set.insert(origin_incognito_pair);
chooser_exception_details.insert(
{object->origin, source, object->incognito});
}

for (const auto& all_chooser_objects_entry : all_chooser_objects) {
Expand Down
10 changes: 3 additions & 7 deletions chrome/browser/ui/webui/settings/site_settings_helper.h
Expand Up @@ -45,13 +45,9 @@ typedef std::map<std::pair<ContentSettingsPattern, std::string>,
OnePatternSettings>
AllPatternsSettings;

// TODO(https://crbug.com/854329): Once the Site Settings WebUI is capable of
// displaying the new chooser exception object format, remove the typedefs that
// are currently used for organizing the chooser exceptions.
// Maps from a primary URL pattern/source pair to a set of secondary URL
// patterns/incognito status pair.
using ChooserExceptionDetails =
std::map<std::pair<GURL, std::string>, std::set<std::pair<GURL, bool>>>;
// A set of <origin, source, incognito> tuple for organizing granted permission
// objects that belong to the same device.
using ChooserExceptionDetails = std::set<std::tuple<GURL, std::string, bool>>;

constexpr char kChooserType[] = "chooserType";
constexpr char kDisplayName[] = "displayName";
Expand Down

0 comments on commit 3c0fa80

Please sign in to comment.