| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/scripting_permissions_modifier.h" | 5 #include "chrome/browser/extensions/scripting_permissions_modifier.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/extension_util.h" | 7 #include "chrome/browser/extensions/extension_util.h" |
| 8 #include "chrome/browser/extensions/permissions_updater.h" | 8 #include "chrome/browser/extensions/permissions_updater.h" |
| 9 #include "extensions/browser/extension_prefs.h" | 9 #include "extensions/browser/extension_prefs.h" |
| 10 #include "extensions/browser/extension_registry.h" | 10 #include "extensions/browser/extension_registry.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 bool ScriptingPermissionsModifier::HasGrantedHostPermission( | 80 bool ScriptingPermissionsModifier::HasGrantedHostPermission( |
| 81 const GURL& url) const { | 81 const GURL& url) const { |
| 82 GURL origin = url.GetOrigin(); | 82 GURL origin = url.GetOrigin(); |
| 83 const PermissionSet& required_permissions = | 83 const PermissionSet& required_permissions = |
| 84 PermissionsParser::GetRequiredPermissions(extension_.get()); | 84 PermissionsParser::GetRequiredPermissions(extension_.get()); |
| 85 if (!extension_->permissions_data() | 85 if (!extension_->permissions_data() |
| 86 ->active_permissions() | 86 ->active_permissions() |
| 87 .effective_hosts() | 87 .effective_hosts() |
| 88 .MatchesURL(origin)) | 88 .MatchesURL(origin)) |
| 89 return false; | 89 return false; |
| 90 scoped_ptr<const PermissionSet> granted_permissions; | 90 std::unique_ptr<const PermissionSet> granted_permissions; |
| 91 scoped_ptr<const PermissionSet> withheld_permissions; | 91 std::unique_ptr<const PermissionSet> withheld_permissions; |
| 92 WithholdPermissions(required_permissions, &granted_permissions, | 92 WithholdPermissions(required_permissions, &granted_permissions, |
| 93 &withheld_permissions, true); | 93 &withheld_permissions, true); |
| 94 if (!granted_permissions->effective_hosts().MatchesURL(origin) && | 94 if (!granted_permissions->effective_hosts().MatchesURL(origin) && |
| 95 withheld_permissions->effective_hosts().MatchesURL(origin)) | 95 withheld_permissions->effective_hosts().MatchesURL(origin)) |
| 96 return true; | 96 return true; |
| 97 | 97 |
| 98 return false; | 98 return false; |
| 99 } | 99 } |
| 100 | 100 |
| 101 void ScriptingPermissionsModifier::RemoveGrantedHostPermission( | 101 void ScriptingPermissionsModifier::RemoveGrantedHostPermission( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 115 PermissionsUpdater(browser_context_) | 115 PermissionsUpdater(browser_context_) |
| 116 .RemovePermissions( | 116 .RemovePermissions( |
| 117 extension_.get(), | 117 extension_.get(), |
| 118 PermissionSet(APIPermissionSet(), ManifestPermissionSet(), | 118 PermissionSet(APIPermissionSet(), ManifestPermissionSet(), |
| 119 explicit_hosts, scriptable_hosts), | 119 explicit_hosts, scriptable_hosts), |
| 120 PermissionsUpdater::REMOVE_HARD); | 120 PermissionsUpdater::REMOVE_HARD); |
| 121 } | 121 } |
| 122 | 122 |
| 123 void ScriptingPermissionsModifier::WithholdPermissions( | 123 void ScriptingPermissionsModifier::WithholdPermissions( |
| 124 const PermissionSet& permissions, | 124 const PermissionSet& permissions, |
| 125 scoped_ptr<const PermissionSet>* granted_permissions_out, | 125 std::unique_ptr<const PermissionSet>* granted_permissions_out, |
| 126 scoped_ptr<const PermissionSet>* withheld_permissions_out, | 126 std::unique_ptr<const PermissionSet>* withheld_permissions_out, |
| 127 bool use_initial_state) const { | 127 bool use_initial_state) const { |
| 128 bool should_withhold = false; | 128 bool should_withhold = false; |
| 129 if (CanAffectExtension(permissions)) { | 129 if (CanAffectExtension(permissions)) { |
| 130 if (use_initial_state) { | 130 if (use_initial_state) { |
| 131 // If the user ever set the extension's "all-urls" preference, then the | 131 // If the user ever set the extension's "all-urls" preference, then the |
| 132 // initial state was withheld. This is important, since the all-urls | 132 // initial state was withheld. This is important, since the all-urls |
| 133 // permission should be shown as revokable. Otherwise, default to whatever | 133 // permission should be shown as revokable. Otherwise, default to whatever |
| 134 // the system setting is. | 134 // the system setting is. |
| 135 should_withhold = | 135 should_withhold = |
| 136 util::HasSetAllowedScriptingOnAllUrls(extension_->id(), | 136 util::HasSetAllowedScriptingOnAllUrls(extension_->id(), |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 PermissionSet permissions( | 195 PermissionSet permissions( |
| 196 APIPermissionSet(), ManifestPermissionSet(), | 196 APIPermissionSet(), ManifestPermissionSet(), |
| 197 FilterImpliedAllHostsPatterns(active.explicit_hosts()), | 197 FilterImpliedAllHostsPatterns(active.explicit_hosts()), |
| 198 FilterImpliedAllHostsPatterns(active.scriptable_hosts())); | 198 FilterImpliedAllHostsPatterns(active.scriptable_hosts())); |
| 199 PermissionsUpdater(browser_context_) | 199 PermissionsUpdater(browser_context_) |
| 200 .RemovePermissions(extension_.get(), permissions, | 200 .RemovePermissions(extension_.get(), permissions, |
| 201 PermissionsUpdater::REMOVE_HARD); | 201 PermissionsUpdater::REMOVE_HARD); |
| 202 } | 202 } |
| 203 | 203 |
| 204 } // namespace extensions | 204 } // namespace extensions |
| OLD | NEW |