Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 // Group Names. | |
| 39 const char kGroupNameGeolocation[] = "location"; | |
| 40 const char kGroupNameNotifications[] = "notifications"; | |
|
Finnur
2016/08/12 15:36:39
I don't think you need to define these again. You
dschuyler
2016/08/12 19:21:13
Yeah, I like that better.
Done.
| |
| 41 | |
| 42 // Return an appropriate API Permission ID for the given string name. | |
| 43 extensions::APIPermission::APIPermission::ID APIPermissionFromGroupName( | |
| 44 std::string type) { | |
| 45 // Once there are more than two groups to consider, this should be changed to | |
| 46 // something better than if's. | |
| 47 | |
| 48 if (type == kGroupNameGeolocation) | |
| 49 return extensions::APIPermission::APIPermission::kGeolocation; | |
| 50 | |
| 51 if (type == kGroupNameNotifications) | |
| 52 return extensions::APIPermission::APIPermission::kNotifications; | |
| 53 | |
| 54 return extensions::APIPermission::APIPermission::kInvalid; | |
| 55 } | |
| 56 | |
| 57 // Add an "Allow"-entry to the list of |exceptions| for a |url_pattern| from | |
| 58 // the web extent of a hosted |app|. | |
| 59 void AddExceptionForHostedApp(const std::string& url_pattern, | |
|
dschuyler
2016/08/12 01:15:49
Much of the following is only slightly modified fr
Finnur
2016/08/12 15:36:39
We seem to have different views on how to migrate
dschuyler
2016/08/12 19:21:13
I think either way is valid. I believe Dan's call
| |
| 60 const extensions::Extension& app, base::ListValue* exceptions) { | |
| 61 std::unique_ptr<base::DictionaryValue> exception(new base::DictionaryValue()); | |
| 62 | |
| 63 std::string setting_string = | |
| 64 content_settings::ContentSettingToString(CONTENT_SETTING_ALLOW); | |
| 65 DCHECK(!setting_string.empty()); | |
| 66 | |
| 67 exception->SetString(site_settings::kSetting, setting_string); | |
| 68 exception->SetString(site_settings::kOrigin, url_pattern); | |
| 69 exception->SetString(site_settings::kEmbeddingOrigin, url_pattern); | |
| 70 exception->SetString(site_settings::kSource, "HostedApp"); | |
| 71 exception->SetString(kAppName, app.name()); | |
| 72 exception->SetString(kAppId, app.id()); | |
| 73 exceptions->Append(std::move(exception)); | |
| 74 } | |
| 75 | |
| 76 // Asks the |profile| for hosted apps which have the |permission| set, and | |
| 77 // adds their web extent and launch URL to the |exceptions| list. | |
| 78 void AddExceptionsGrantedByHostedApps(content::BrowserContext* context, | |
| 79 extensions::APIPermission::APIPermission::ID permission, | |
| 80 base::ListValue* exceptions) { | |
| 81 const extensions::ExtensionSet& extensions = | |
| 82 extensions::ExtensionRegistry::Get(context)->enabled_extensions(); | |
| 83 for (extensions::ExtensionSet::const_iterator extension = extensions.begin(); | |
| 84 extension != extensions.end(); ++extension) { | |
| 85 if (!(*extension)->is_hosted_app() || | |
| 86 !(*extension)->permissions_data()->HasAPIPermission(permission)) | |
| 87 continue; | |
| 88 | |
| 89 extensions::URLPatternSet web_extent = (*extension)->web_extent(); | |
| 90 // Add patterns from web extent. | |
| 91 for (extensions::URLPatternSet::const_iterator pattern = web_extent.begin(); | |
| 92 pattern != web_extent.end(); ++pattern) { | |
| 93 std::string url_pattern = pattern->GetAsString(); | |
| 94 AddExceptionForHostedApp(url_pattern, *extension->get(), exceptions); | |
| 95 } | |
| 96 // Retrieve the launch URL. | |
| 97 GURL launch_url = | |
| 98 extensions::AppLaunchInfo::GetLaunchWebURL(extension->get()); | |
| 99 // Skip adding the launch URL if it is part of the web extent. | |
| 100 if (web_extent.MatchesURL(launch_url)) | |
| 101 continue; | |
| 102 AddExceptionForHostedApp(launch_url.spec(), *extension->get(), exceptions); | |
| 103 } | |
| 104 } | |
| 105 | |
| 106 } // namespace | |
| 107 | |
| 108 | |
| 22 SiteSettingsHandler::SiteSettingsHandler(Profile* profile) | 109 SiteSettingsHandler::SiteSettingsHandler(Profile* profile) |
| 23 : profile_(profile), observer_(this) { | 110 : profile_(profile), observer_(this) { |
| 24 } | 111 } |
| 25 | 112 |
| 26 SiteSettingsHandler::~SiteSettingsHandler() { | 113 SiteSettingsHandler::~SiteSettingsHandler() { |
| 27 } | 114 } |
| 28 | 115 |
| 29 void SiteSettingsHandler::RegisterMessages() { | 116 void SiteSettingsHandler::RegisterMessages() { |
| 30 web_ui()->RegisterMessageCallback( | 117 web_ui()->RegisterMessageCallback( |
| 31 "fetchUsageTotal", | 118 "fetchUsageTotal", |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 CHECK(args->Get(0, &callback_id)); | 306 CHECK(args->Get(0, &callback_id)); |
| 220 std::string type; | 307 std::string type; |
| 221 CHECK(args->GetString(1, &type)); | 308 CHECK(args->GetString(1, &type)); |
| 222 ContentSettingsType content_type = | 309 ContentSettingsType content_type = |
| 223 static_cast<ContentSettingsType>(static_cast<int>( | 310 static_cast<ContentSettingsType>(static_cast<int>( |
| 224 site_settings::ContentSettingsTypeFromGroupName(type))); | 311 site_settings::ContentSettingsTypeFromGroupName(type))); |
| 225 | 312 |
| 226 HostContentSettingsMap* map = | 313 HostContentSettingsMap* map = |
| 227 HostContentSettingsMapFactory::GetForProfile(profile_); | 314 HostContentSettingsMapFactory::GetForProfile(profile_); |
| 228 std::unique_ptr<base::ListValue> exceptions(new base::ListValue); | 315 std::unique_ptr<base::ListValue> exceptions(new base::ListValue); |
| 316 | |
| 317 AddExceptionsGrantedByHostedApps(profile_, APIPermissionFromGroupName(type), | |
| 318 exceptions.get()); | |
| 319 | |
| 229 site_settings::GetExceptionsFromHostContentSettingsMap( | 320 site_settings::GetExceptionsFromHostContentSettingsMap( |
| 230 map, content_type, web_ui(), exceptions.get()); | 321 map, content_type, web_ui(), exceptions.get()); |
| 231 ResolveJavascriptCallback(*callback_id, *exceptions.get()); | 322 ResolveJavascriptCallback(*callback_id, *exceptions.get()); |
| 232 } | 323 } |
| 233 | 324 |
| 234 void SiteSettingsHandler::HandleResetCategoryPermissionForOrigin( | 325 void SiteSettingsHandler::HandleResetCategoryPermissionForOrigin( |
| 235 const base::ListValue* args) { | 326 const base::ListValue* args) { |
| 236 CHECK_EQ(3U, args->GetSize()); | 327 CHECK_EQ(3U, args->GetSize()); |
| 237 std::string primary_pattern; | 328 std::string primary_pattern; |
| 238 CHECK(args->GetString(0, &primary_pattern)); | 329 CHECK(args->GetString(0, &primary_pattern)); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 std::string pattern_string; | 382 std::string pattern_string; |
| 292 CHECK(args->GetString(1, &pattern_string)); | 383 CHECK(args->GetString(1, &pattern_string)); |
| 293 | 384 |
| 294 ContentSettingsPattern pattern = | 385 ContentSettingsPattern pattern = |
| 295 ContentSettingsPattern::FromString(pattern_string); | 386 ContentSettingsPattern::FromString(pattern_string); |
| 296 ResolveJavascriptCallback( | 387 ResolveJavascriptCallback( |
| 297 *callback_id, base::FundamentalValue(pattern.IsValid())); | 388 *callback_id, base::FundamentalValue(pattern.IsValid())); |
| 298 } | 389 } |
| 299 | 390 |
| 300 } // namespace settings | 391 } // namespace settings |
| OLD | NEW |