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

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

Issue 2350303004: Site Settings Desktop: Fix crash when altering exception. (Closed)
Patch Set: Address feedback Created 4 years, 3 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
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 <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 22 matching lines...) Expand all
33 #include "extensions/common/permissions/permissions_data.h" 33 #include "extensions/common/permissions/permissions_data.h"
34 #include "storage/browser/quota/quota_manager.h" 34 #include "storage/browser/quota/quota_manager.h"
35 #include "storage/common/quota/quota_status_code.h" 35 #include "storage/common/quota/quota_status_code.h"
36 #include "ui/base/l10n/l10n_util.h" 36 #include "ui/base/l10n/l10n_util.h"
37 #include "ui/base/text/bytes_formatting.h" 37 #include "ui/base/text/bytes_formatting.h"
38 38
39 namespace settings { 39 namespace settings {
40 40
41 namespace { 41 namespace {
42 42
43 const char kAppName[] = "appName";
44 const char kAppId[] = "appId";
45 const char kZoom[] = "zoom"; 43 const char kZoom[] = "zoom";
46 44
47 // Return an appropriate API Permission ID for the given string name. 45 // Return an appropriate API Permission ID for the given string name.
48 extensions::APIPermission::APIPermission::ID APIPermissionFromGroupName( 46 extensions::APIPermission::APIPermission::ID APIPermissionFromGroupName(
49 std::string type) { 47 std::string type) {
50 // Once there are more than two groups to consider, this should be changed to 48 // Once there are more than two groups to consider, this should be changed to
51 // something better than if's. 49 // something better than if's.
52 50
53 if (site_settings::ContentSettingsTypeFromGroupName(type) == 51 if (site_settings::ContentSettingsTypeFromGroupName(type) ==
54 CONTENT_SETTINGS_TYPE_GEOLOCATION) 52 CONTENT_SETTINGS_TYPE_GEOLOCATION)
55 return extensions::APIPermission::APIPermission::kGeolocation; 53 return extensions::APIPermission::APIPermission::kGeolocation;
56 54
57 if (site_settings::ContentSettingsTypeFromGroupName(type) == 55 if (site_settings::ContentSettingsTypeFromGroupName(type) ==
58 CONTENT_SETTINGS_TYPE_NOTIFICATIONS) 56 CONTENT_SETTINGS_TYPE_NOTIFICATIONS)
59 return extensions::APIPermission::APIPermission::kNotifications; 57 return extensions::APIPermission::APIPermission::kNotifications;
60 58
61 return extensions::APIPermission::APIPermission::kInvalid; 59 return extensions::APIPermission::APIPermission::kInvalid;
62 } 60 }
63 61
64 // Add an "Allow"-entry to the list of |exceptions| for a |url_pattern| from
65 // the web extent of a hosted |app|.
66 void AddExceptionForHostedApp(const std::string& url_pattern,
67 const extensions::Extension& app, base::ListValue* exceptions) {
68 std::unique_ptr<base::DictionaryValue> exception(new base::DictionaryValue());
69
70 std::string setting_string =
71 content_settings::ContentSettingToString(CONTENT_SETTING_ALLOW);
72 DCHECK(!setting_string.empty());
73
74 exception->SetString(site_settings::kSetting, setting_string);
75 exception->SetString(site_settings::kOrigin, url_pattern);
76 exception->SetString(site_settings::kEmbeddingOrigin, url_pattern);
77 exception->SetString(site_settings::kSource, "HostedApp");
78 exception->SetString(kAppName, app.name());
79 exception->SetString(kAppId, app.id());
80 exceptions->Append(std::move(exception));
81 }
82
83 // Asks the |profile| for hosted apps which have the |permission| set, and 62 // Asks the |profile| for hosted apps which have the |permission| set, and
84 // adds their web extent and launch URL to the |exceptions| list. 63 // adds their web extent and launch URL to the |exceptions| list.
85 void AddExceptionsGrantedByHostedApps(content::BrowserContext* context, 64 void AddExceptionsGrantedByHostedApps(content::BrowserContext* context,
86 extensions::APIPermission::APIPermission::ID permission, 65 extensions::APIPermission::APIPermission::ID permission,
87 base::ListValue* exceptions) { 66 base::ListValue* exceptions) {
88 const extensions::ExtensionSet& extensions = 67 const extensions::ExtensionSet& extensions =
89 extensions::ExtensionRegistry::Get(context)->enabled_extensions(); 68 extensions::ExtensionRegistry::Get(context)->enabled_extensions();
90 for (extensions::ExtensionSet::const_iterator extension = extensions.begin(); 69 for (extensions::ExtensionSet::const_iterator extension = extensions.begin();
91 extension != extensions.end(); ++extension) { 70 extension != extensions.end(); ++extension) {
92 if (!(*extension)->is_hosted_app() || 71 if (!(*extension)->is_hosted_app() ||
93 !(*extension)->permissions_data()->HasAPIPermission(permission)) 72 !(*extension)->permissions_data()->HasAPIPermission(permission))
94 continue; 73 continue;
95 74
96 extensions::URLPatternSet web_extent = (*extension)->web_extent(); 75 extensions::URLPatternSet web_extent = (*extension)->web_extent();
97 // Add patterns from web extent. 76 // Add patterns from web extent.
98 for (extensions::URLPatternSet::const_iterator pattern = web_extent.begin(); 77 for (extensions::URLPatternSet::const_iterator pattern = web_extent.begin();
99 pattern != web_extent.end(); ++pattern) { 78 pattern != web_extent.end(); ++pattern) {
100 std::string url_pattern = pattern->GetAsString(); 79 std::string url_pattern = pattern->GetAsString();
101 AddExceptionForHostedApp(url_pattern, *extension->get(), exceptions); 80 site_settings::AddExceptionForHostedApp(
81 url_pattern, *extension->get(), exceptions);
102 } 82 }
103 // Retrieve the launch URL. 83 // Retrieve the launch URL.
104 GURL launch_url = 84 GURL launch_url =
105 extensions::AppLaunchInfo::GetLaunchWebURL(extension->get()); 85 extensions::AppLaunchInfo::GetLaunchWebURL(extension->get());
106 // Skip adding the launch URL if it is part of the web extent. 86 // Skip adding the launch URL if it is part of the web extent.
107 if (web_extent.MatchesURL(launch_url)) 87 if (web_extent.MatchesURL(launch_url))
108 continue; 88 continue;
109 AddExceptionForHostedApp(launch_url.spec(), *extension->get(), exceptions); 89 site_settings::AddExceptionForHostedApp(
90 launch_url.spec(), *extension->get(), exceptions);
110 } 91 }
111 } 92 }
112 93
113 } // namespace 94 } // namespace
114 95
115 96
116 SiteSettingsHandler::SiteSettingsHandler(Profile* profile) 97 SiteSettingsHandler::SiteSettingsHandler(Profile* profile)
117 : profile_(profile), observer_(this) { 98 : profile_(profile), observer_(this) {
118 } 99 }
119 100
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 origin = content::kUnreachableWebDataURL; 690 origin = content::kUnreachableWebDataURL;
710 } 691 }
711 692
712 content::HostZoomMap* host_zoom_map; 693 content::HostZoomMap* host_zoom_map;
713 host_zoom_map = content::HostZoomMap::GetDefaultForBrowserContext(profile_); 694 host_zoom_map = content::HostZoomMap::GetDefaultForBrowserContext(profile_);
714 double default_level = host_zoom_map->GetDefaultZoomLevel(); 695 double default_level = host_zoom_map->GetDefaultZoomLevel();
715 host_zoom_map->SetZoomLevelForHost(origin, default_level); 696 host_zoom_map->SetZoomLevelForHost(origin, default_level);
716 } 697 }
717 698
718 } // namespace settings 699 } // namespace settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698