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

Side by Side Diff: chrome/browser/ui/webui/settings/site_settings_handler.cc

Issue 2240023002: [MD settings] extension exceptions in site settings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review changes 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/resources/settings/site_settings/site_list.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/settings/site_settings_handler.h" 5 #include "chrome/browser/ui/webui/settings/site_settings_handler.h"
6 6
7 #include <memory>
8 #include <string>
9 #include <utility>
10
7 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/macros.h"
13 #include "base/values.h"
8 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" 14 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
10 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/webui/site_settings_helper.h" 17 #include "chrome/browser/ui/webui/site_settings_helper.h"
18 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
12 #include "components/content_settings/core/browser/host_content_settings_map.h" 19 #include "components/content_settings/core/browser/host_content_settings_map.h"
13 #include "components/content_settings/core/common/content_settings_types.h" 20 #include "components/content_settings/core/common/content_settings_types.h"
14 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/web_ui.h" 22 #include "content/public/browser/web_ui.h"
23 #include "extensions/browser/extension_registry.h"
24 #include "extensions/common/permissions/api_permission.h"
25 #include "extensions/common/permissions/permissions_data.h"
16 #include "storage/browser/quota/quota_manager.h" 26 #include "storage/browser/quota/quota_manager.h"
17 #include "storage/common/quota/quota_status_code.h" 27 #include "storage/common/quota/quota_status_code.h"
18 #include "ui/base/text/bytes_formatting.h" 28 #include "ui/base/text/bytes_formatting.h"
19 29
30
20 namespace settings { 31 namespace settings {
21 32
33 namespace {
34
35 const char kAppName[] = "appName";
36 const char kAppId[] = "appId";
37
38 // Return an appropriate API Permission ID for the given string name.
39 extensions::APIPermission::APIPermission::ID APIPermissionFromGroupName(
40 std::string type) {
41 // Once there are more than two groups to consider, this should be changed to
42 // something better than if's.
43
44 if (site_settings::ContentSettingsTypeFromGroupName(type) ==
45 CONTENT_SETTINGS_TYPE_GEOLOCATION)
46 return extensions::APIPermission::APIPermission::kGeolocation;
47
48 if (site_settings::ContentSettingsTypeFromGroupName(type) ==
49 CONTENT_SETTINGS_TYPE_NOTIFICATIONS)
50 return extensions::APIPermission::APIPermission::kNotifications;
51
52 return extensions::APIPermission::APIPermission::kInvalid;
53 }
54
55 // Add an "Allow"-entry to the list of |exceptions| for a |url_pattern| from
56 // the web extent of a hosted |app|.
57 void AddExceptionForHostedApp(const std::string& url_pattern,
58 const extensions::Extension& app, base::ListValue* exceptions) {
59 std::unique_ptr<base::DictionaryValue> exception(new base::DictionaryValue());
60
61 std::string setting_string =
62 content_settings::ContentSettingToString(CONTENT_SETTING_ALLOW);
63 DCHECK(!setting_string.empty());
64
65 exception->SetString(site_settings::kSetting, setting_string);
66 exception->SetString(site_settings::kOrigin, url_pattern);
67 exception->SetString(site_settings::kEmbeddingOrigin, url_pattern);
68 exception->SetString(site_settings::kSource, "HostedApp");
69 exception->SetString(kAppName, app.name());
70 exception->SetString(kAppId, app.id());
71 exceptions->Append(std::move(exception));
72 }
73
74 // Asks the |profile| for hosted apps which have the |permission| set, and
75 // adds their web extent and launch URL to the |exceptions| list.
76 void AddExceptionsGrantedByHostedApps(content::BrowserContext* context,
77 extensions::APIPermission::APIPermission::ID permission,
78 base::ListValue* exceptions) {
79 const extensions::ExtensionSet& extensions =
80 extensions::ExtensionRegistry::Get(context)->enabled_extensions();
81 for (extensions::ExtensionSet::const_iterator extension = extensions.begin();
82 extension != extensions.end(); ++extension) {
83 if (!(*extension)->is_hosted_app() ||
84 !(*extension)->permissions_data()->HasAPIPermission(permission))
85 continue;
86
87 extensions::URLPatternSet web_extent = (*extension)->web_extent();
88 // Add patterns from web extent.
89 for (extensions::URLPatternSet::const_iterator pattern = web_extent.begin();
90 pattern != web_extent.end(); ++pattern) {
91 std::string url_pattern = pattern->GetAsString();
92 AddExceptionForHostedApp(url_pattern, *extension->get(), exceptions);
93 }
94 // Retrieve the launch URL.
95 GURL launch_url =
96 extensions::AppLaunchInfo::GetLaunchWebURL(extension->get());
97 // Skip adding the launch URL if it is part of the web extent.
98 if (web_extent.MatchesURL(launch_url))
99 continue;
100 AddExceptionForHostedApp(launch_url.spec(), *extension->get(), exceptions);
101 }
102 }
103
104 } // namespace
105
106
22 SiteSettingsHandler::SiteSettingsHandler(Profile* profile) 107 SiteSettingsHandler::SiteSettingsHandler(Profile* profile)
23 : profile_(profile), observer_(this) { 108 : profile_(profile), observer_(this) {
24 } 109 }
25 110
26 SiteSettingsHandler::~SiteSettingsHandler() { 111 SiteSettingsHandler::~SiteSettingsHandler() {
27 } 112 }
28 113
29 void SiteSettingsHandler::RegisterMessages() { 114 void SiteSettingsHandler::RegisterMessages() {
30 web_ui()->RegisterMessageCallback( 115 web_ui()->RegisterMessageCallback(
31 "fetchUsageTotal", 116 "fetchUsageTotal",
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 CHECK(args->Get(0, &callback_id)); 304 CHECK(args->Get(0, &callback_id));
220 std::string type; 305 std::string type;
221 CHECK(args->GetString(1, &type)); 306 CHECK(args->GetString(1, &type));
222 ContentSettingsType content_type = 307 ContentSettingsType content_type =
223 static_cast<ContentSettingsType>(static_cast<int>( 308 static_cast<ContentSettingsType>(static_cast<int>(
224 site_settings::ContentSettingsTypeFromGroupName(type))); 309 site_settings::ContentSettingsTypeFromGroupName(type)));
225 310
226 HostContentSettingsMap* map = 311 HostContentSettingsMap* map =
227 HostContentSettingsMapFactory::GetForProfile(profile_); 312 HostContentSettingsMapFactory::GetForProfile(profile_);
228 std::unique_ptr<base::ListValue> exceptions(new base::ListValue); 313 std::unique_ptr<base::ListValue> exceptions(new base::ListValue);
314
315 AddExceptionsGrantedByHostedApps(profile_, APIPermissionFromGroupName(type),
316 exceptions.get());
317
229 site_settings::GetExceptionsFromHostContentSettingsMap( 318 site_settings::GetExceptionsFromHostContentSettingsMap(
230 map, content_type, web_ui(), exceptions.get()); 319 map, content_type, web_ui(), exceptions.get());
231 ResolveJavascriptCallback(*callback_id, *exceptions.get()); 320 ResolveJavascriptCallback(*callback_id, *exceptions.get());
232 } 321 }
233 322
234 void SiteSettingsHandler::HandleResetCategoryPermissionForOrigin( 323 void SiteSettingsHandler::HandleResetCategoryPermissionForOrigin(
235 const base::ListValue* args) { 324 const base::ListValue* args) {
236 CHECK_EQ(3U, args->GetSize()); 325 CHECK_EQ(3U, args->GetSize());
237 std::string primary_pattern; 326 std::string primary_pattern;
238 CHECK(args->GetString(0, &primary_pattern)); 327 CHECK(args->GetString(0, &primary_pattern));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 std::string pattern_string; 380 std::string pattern_string;
292 CHECK(args->GetString(1, &pattern_string)); 381 CHECK(args->GetString(1, &pattern_string));
293 382
294 ContentSettingsPattern pattern = 383 ContentSettingsPattern pattern =
295 ContentSettingsPattern::FromString(pattern_string); 384 ContentSettingsPattern::FromString(pattern_string);
296 ResolveJavascriptCallback( 385 ResolveJavascriptCallback(
297 *callback_id, base::FundamentalValue(pattern.IsValid())); 386 *callback_id, base::FundamentalValue(pattern.IsValid()));
298 } 387 }
299 388
300 } // namespace settings 389 } // namespace settings
OLDNEW
« no previous file with comments | « chrome/browser/resources/settings/site_settings/site_list.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698