OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extensions/permissions_updater.h" | 5 #include "chrome/browser/extensions/permissions_updater.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/extensions/api/permissions/permissions_api_helpers.h" | 11 #include "chrome/browser/extensions/api/permissions/permissions_api_helpers.h" |
12 #include "chrome/browser/extensions/extension_util.h" | 12 #include "chrome/browser/extensions/extension_util.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/common/extensions/api/permissions.h" | 14 #include "chrome/common/extensions/api/permissions.h" |
15 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
16 #include "content/public/browser/notification_registrar.h" | 16 #include "content/public/browser/notification_registrar.h" |
17 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
18 #include "content/public/browser/render_process_host.h" | 18 #include "content/public/browser/render_process_host.h" |
19 #include "extensions/browser/event_router.h" | 19 #include "extensions/browser/event_router.h" |
20 #include "extensions/browser/extension_prefs.h" | 20 #include "extensions/browser/extension_prefs.h" |
21 #include "extensions/common/extension.h" | 21 #include "extensions/common/extension.h" |
22 #include "extensions/common/extension_messages.h" | 22 #include "extensions/common/extension_messages.h" |
23 #include "extensions/common/feature_switch.h" | |
24 #include "extensions/common/manifest_handlers/permissions_parser.h" | 23 #include "extensions/common/manifest_handlers/permissions_parser.h" |
25 #include "extensions/common/permissions/permission_set.h" | 24 #include "extensions/common/permissions/permission_set.h" |
26 #include "extensions/common/permissions/permissions_data.h" | 25 #include "extensions/common/permissions/permissions_data.h" |
27 #include "extensions/common/url_pattern.h" | 26 #include "extensions/common/url_pattern.h" |
28 #include "extensions/common/url_pattern_set.h" | 27 #include "extensions/common/url_pattern_set.h" |
29 | 28 |
30 using content::RenderProcessHost; | 29 using content::RenderProcessHost; |
31 using extensions::permissions_api_helpers::PackPermissionSet; | 30 using extensions::permissions_api_helpers::PackPermissionSet; |
32 | 31 |
33 namespace extensions { | 32 namespace extensions { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 extension->permissions_data()->active_permissions().get()); | 162 extension->permissions_data()->active_permissions().get()); |
164 } | 163 } |
165 | 164 |
166 void PermissionsUpdater::InitializePermissions(const Extension* extension) { | 165 void PermissionsUpdater::InitializePermissions(const Extension* extension) { |
167 scoped_refptr<const PermissionSet> active_permissions = | 166 scoped_refptr<const PermissionSet> active_permissions = |
168 ExtensionPrefs::Get(browser_context_) | 167 ExtensionPrefs::Get(browser_context_) |
169 ->GetActivePermissions(extension->id()); | 168 ->GetActivePermissions(extension->id()); |
170 scoped_refptr<const PermissionSet> bounded_active = | 169 scoped_refptr<const PermissionSet> bounded_active = |
171 GetBoundedActivePermissions(extension, active_permissions); | 170 GetBoundedActivePermissions(extension, active_permissions); |
172 | 171 |
173 // We withhold permissions iff the switch to do so is enabled, the extension | 172 // Withhold permissions only if the switch applies to this extension and the |
174 // shows up in chrome:extensions (so the user can grant withheld permissions), | 173 // extension doesn't have the preference to allow scripting on all urls. |
175 // the extension is not part of chrome or corporate policy, and also not on | |
176 // the scripting whitelist. Additionally, we don't withhold if the extension | |
177 // has the preference to allow scripting on all urls. | |
178 bool should_withhold_permissions = | 174 bool should_withhold_permissions = |
179 FeatureSwitch::scripts_require_action()->IsEnabled() && | 175 util::ScriptsMayRequireActionForExtension(extension) && |
180 extension->ShouldDisplayInExtensionSettings() && | |
181 !Manifest::IsPolicyLocation(extension->location()) && | |
182 !Manifest::IsComponentLocation(extension->location()) && | |
183 !PermissionsData::CanExecuteScriptEverywhere(extension) && | |
184 !util::AllowedScriptingOnAllUrls(extension->id(), browser_context_); | 176 !util::AllowedScriptingOnAllUrls(extension->id(), browser_context_); |
185 | 177 |
186 URLPatternSet granted_explicit_hosts; | 178 URLPatternSet granted_explicit_hosts; |
187 URLPatternSet withheld_explicit_hosts; | 179 URLPatternSet withheld_explicit_hosts; |
188 SegregateUrlPermissions(bounded_active->explicit_hosts(), | 180 SegregateUrlPermissions(bounded_active->explicit_hosts(), |
189 should_withhold_permissions, | 181 should_withhold_permissions, |
190 &granted_explicit_hosts, | 182 &granted_explicit_hosts, |
191 &withheld_explicit_hosts); | 183 &withheld_explicit_hosts); |
192 | 184 |
193 URLPatternSet granted_scriptable_hosts; | 185 URLPatternSet granted_scriptable_hosts; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 Profile::FromBrowserContext(host->GetBrowserContext()))) { | 349 Profile::FromBrowserContext(host->GetBrowserContext()))) { |
358 host->Send(new ExtensionMsg_UpdatePermissions(params)); | 350 host->Send(new ExtensionMsg_UpdatePermissions(params)); |
359 } | 351 } |
360 } | 352 } |
361 | 353 |
362 // Trigger the onAdded and onRemoved events in the extension. | 354 // Trigger the onAdded and onRemoved events in the extension. |
363 DispatchEvent(extension->id(), event_name, changed); | 355 DispatchEvent(extension->id(), event_name, changed); |
364 } | 356 } |
365 | 357 |
366 } // namespace extensions | 358 } // namespace extensions |
OLD | NEW |