Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "extensions/common/permissions/permissions_data.h" | 5 #include "extensions/common/permissions/permissions_data.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/threading/thread_checker.h" | |
| 8 #include "content/public/common/url_constants.h" | 9 #include "content/public/common/url_constants.h" |
| 9 #include "extensions/common/constants.h" | 10 #include "extensions/common/constants.h" |
| 10 #include "extensions/common/error_utils.h" | 11 #include "extensions/common/error_utils.h" |
| 11 #include "extensions/common/extension.h" | 12 #include "extensions/common/extension.h" |
| 12 #include "extensions/common/extensions_client.h" | 13 #include "extensions/common/extensions_client.h" |
| 13 #include "extensions/common/manifest.h" | 14 #include "extensions/common/manifest.h" |
| 14 #include "extensions/common/manifest_constants.h" | 15 #include "extensions/common/manifest_constants.h" |
| 15 #include "extensions/common/manifest_handlers/permissions_parser.h" | 16 #include "extensions/common/manifest_handlers/permissions_parser.h" |
| 16 #include "extensions/common/permissions/permission_message_provider.h" | 17 #include "extensions/common/permissions/permission_message_provider.h" |
| 17 #include "extensions/common/switches.h" | 18 #include "extensions/common/switches.h" |
| 18 #include "extensions/common/url_pattern_set.h" | 19 #include "extensions/common/url_pattern_set.h" |
| 19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 20 #include "url/url_constants.h" | 21 #include "url/url_constants.h" |
| 21 | 22 |
| 22 namespace extensions { | 23 namespace extensions { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 PermissionsData::PolicyDelegate* g_policy_delegate = NULL; | 27 PermissionsData::PolicyDelegate* g_policy_delegate = NULL; |
| 27 | 28 |
| 28 } // namespace | 29 } // namespace |
| 29 | 30 |
| 30 PermissionsData::PermissionsData(const Extension* extension) | 31 PermissionsData::PermissionsData(const Extension* extension) |
| 31 : extension_id_(extension->id()), manifest_type_(extension->GetType()) { | 32 : extension_id_(extension->id()), manifest_type_(extension->GetType()) { |
| 32 base::AutoLock auto_lock(runtime_lock_); | 33 base::AutoLock auto_lock(runtime_lock_); |
|
not at google - send to devlin
2015/09/22 21:51:26
I know the code is like this already, but it seems
Devlin
2015/09/23 17:09:00
heh, true. Removed.
| |
| 33 scoped_refptr<const PermissionSet> required_permissions = | 34 const PermissionSet* required_permissions = |
| 34 PermissionsParser::GetRequiredPermissions(extension); | 35 PermissionsParser::GetRequiredPermissions(extension); |
| 35 active_permissions_unsafe_ = | 36 active_permissions_unsafe_.reset( |
| 36 new PermissionSet(required_permissions->apis(), | 37 new PermissionSet(required_permissions->apis(), |
| 37 required_permissions->manifest_permissions(), | 38 required_permissions->manifest_permissions(), |
| 38 required_permissions->explicit_hosts(), | 39 required_permissions->explicit_hosts(), |
| 39 required_permissions->scriptable_hosts()); | 40 required_permissions->scriptable_hosts())); |
| 40 withheld_permissions_unsafe_ = new PermissionSet(); | 41 withheld_permissions_unsafe_.reset(new PermissionSet()); |
| 41 } | 42 } |
| 42 | 43 |
| 43 PermissionsData::~PermissionsData() { | 44 PermissionsData::~PermissionsData() { |
| 44 } | 45 } |
| 45 | 46 |
| 46 // static | 47 // static |
| 47 void PermissionsData::SetPolicyDelegate(PolicyDelegate* delegate) { | 48 void PermissionsData::SetPolicyDelegate(PolicyDelegate* delegate) { |
| 48 g_policy_delegate = delegate; | 49 g_policy_delegate = delegate; |
| 49 } | 50 } |
| 50 | 51 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 67 // An extension may require user action to execute scripts iff the extension | 68 // An extension may require user action to execute scripts iff the extension |
| 68 // shows up in chrome:extensions (so the user can grant withheld permissions), | 69 // shows up in chrome:extensions (so the user can grant withheld permissions), |
| 69 // is not part of chrome or corporate policy, not on the scripting whitelist, | 70 // is not part of chrome or corporate policy, not on the scripting whitelist, |
| 70 // and requires enough permissions that we should withhold them. | 71 // and requires enough permissions that we should withhold them. |
| 71 return extension->ShouldDisplayInExtensionSettings() && | 72 return extension->ShouldDisplayInExtensionSettings() && |
| 72 !Manifest::IsPolicyLocation(extension->location()) && | 73 !Manifest::IsPolicyLocation(extension->location()) && |
| 73 !Manifest::IsComponentLocation(extension->location()) && | 74 !Manifest::IsComponentLocation(extension->location()) && |
| 74 !CanExecuteScriptEverywhere(extension) && | 75 !CanExecuteScriptEverywhere(extension) && |
| 75 permissions->ShouldWarnAllHosts(); | 76 permissions->ShouldWarnAllHosts(); |
| 76 } | 77 } |
| 77 | 78 |
|
not at google - send to devlin
2015/09/22 21:51:26
Cleanup: add // static here.
Devlin
2015/09/23 17:08:59
Done.
| |
| 78 bool PermissionsData::ShouldSkipPermissionWarnings( | 79 bool PermissionsData::ShouldSkipPermissionWarnings( |
| 79 const std::string& extension_id) { | 80 const std::string& extension_id) { |
| 80 // See http://b/4946060 for more details. | 81 // See http://b/4946060 for more details. |
| 81 return extension_id == extension_misc::kProdHangoutsExtensionId; | 82 return extension_id == extension_misc::kProdHangoutsExtensionId; |
| 82 } | 83 } |
| 83 | 84 |
| 84 // static | 85 // static |
| 85 bool PermissionsData::IsRestrictedUrl(const GURL& document_url, | 86 bool PermissionsData::IsRestrictedUrl(const GURL& document_url, |
| 86 const Extension* extension, | 87 const Extension* extension, |
| 87 std::string* error) { | 88 std::string* error) { |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 114 if (extension && document_url.SchemeIs(kExtensionScheme) && | 115 if (extension && document_url.SchemeIs(kExtensionScheme) && |
| 115 document_url.host() != extension->id() && !allow_on_chrome_urls) { | 116 document_url.host() != extension->id() && !allow_on_chrome_urls) { |
| 116 if (error) | 117 if (error) |
| 117 *error = manifest_errors::kCannotAccessExtensionUrl; | 118 *error = manifest_errors::kCannotAccessExtensionUrl; |
| 118 return true; | 119 return true; |
| 119 } | 120 } |
| 120 | 121 |
| 121 return false; | 122 return false; |
| 122 } | 123 } |
| 123 | 124 |
| 125 void PermissionsData::LockToThread() const { | |
| 126 DCHECK(!thread_checker_); | |
| 127 thread_checker_.reset(new base::ThreadChecker()); | |
| 128 } | |
| 129 | |
| 124 void PermissionsData::SetPermissions( | 130 void PermissionsData::SetPermissions( |
| 125 const scoped_refptr<const PermissionSet>& active, | 131 scoped_ptr<const PermissionSet> active, |
| 126 const scoped_refptr<const PermissionSet>& withheld) const { | 132 scoped_ptr<const PermissionSet> withheld) const { |
| 133 CHECK(CalledOnValidThread()); | |
| 127 base::AutoLock auto_lock(runtime_lock_); | 134 base::AutoLock auto_lock(runtime_lock_); |
| 128 active_permissions_unsafe_ = active; | 135 active_permissions_unsafe_ = active.Pass(); |
| 129 withheld_permissions_unsafe_ = withheld; | 136 withheld_permissions_unsafe_ = withheld.Pass(); |
| 137 } | |
| 138 | |
| 139 void PermissionsData::SetActivePermissions( | |
| 140 scoped_ptr<const PermissionSet> active) const { | |
| 141 CHECK(CalledOnValidThread()); | |
| 142 base::AutoLock auto_lock(runtime_lock_); | |
| 143 active_permissions_unsafe_ = active.Pass(); | |
| 130 } | 144 } |
| 131 | 145 |
| 132 void PermissionsData::UpdateTabSpecificPermissions( | 146 void PermissionsData::UpdateTabSpecificPermissions( |
| 133 int tab_id, | 147 int tab_id, |
| 134 scoped_refptr<const PermissionSet> permissions) const { | 148 const PermissionSet& permissions) const { |
| 149 CHECK(CalledOnValidThread()); | |
| 135 base::AutoLock auto_lock(runtime_lock_); | 150 base::AutoLock auto_lock(runtime_lock_); |
| 136 CHECK_GE(tab_id, 0); | 151 CHECK_GE(tab_id, 0); |
| 137 TabPermissionsMap::iterator iter = tab_specific_permissions_.find(tab_id); | 152 TabPermissionsMap::const_iterator iter = |
| 138 if (iter == tab_specific_permissions_.end()) | 153 tab_specific_permissions_.find(tab_id); |
| 139 tab_specific_permissions_[tab_id] = permissions; | 154 scoped_ptr<const PermissionSet> new_permissions = PermissionSet::CreateUnion( |
| 140 else | 155 iter == tab_specific_permissions_.end() ? PermissionSet() : *iter->second, |
| 141 iter->second = PermissionSet::CreateUnion(*(iter->second), *permissions); | 156 permissions); |
| 157 tab_specific_permissions_.set(tab_id, new_permissions.Pass()); | |
| 142 } | 158 } |
| 143 | 159 |
| 144 void PermissionsData::ClearTabSpecificPermissions(int tab_id) const { | 160 void PermissionsData::ClearTabSpecificPermissions(int tab_id) const { |
| 161 CHECK(CalledOnValidThread()); | |
| 145 base::AutoLock auto_lock(runtime_lock_); | 162 base::AutoLock auto_lock(runtime_lock_); |
|
not at google - send to devlin
2015/09/22 21:51:26
Thought: you could tighten this up a bit with a cl
Devlin
2015/09/23 17:08:59
Done.
| |
| 146 CHECK_GE(tab_id, 0); | 163 CHECK_GE(tab_id, 0); |
| 147 tab_specific_permissions_.erase(tab_id); | 164 tab_specific_permissions_.erase(tab_id); |
| 148 } | 165 } |
| 149 | 166 |
| 150 bool PermissionsData::HasAPIPermission(APIPermission::ID permission) const { | 167 bool PermissionsData::HasAPIPermission(APIPermission::ID permission) const { |
| 151 return active_permissions()->HasAPIPermission(permission); | 168 base::AutoLock auto_lock(runtime_lock_); |
| 169 return active_permissions_unsafe_->HasAPIPermission(permission); | |
| 152 } | 170 } |
| 153 | 171 |
| 154 bool PermissionsData::HasAPIPermission( | 172 bool PermissionsData::HasAPIPermission( |
| 155 const std::string& permission_name) const { | 173 const std::string& permission_name) const { |
| 156 return active_permissions()->HasAPIPermission(permission_name); | 174 base::AutoLock auto_lock(runtime_lock_); |
| 175 return active_permissions_unsafe_->HasAPIPermission(permission_name); | |
| 157 } | 176 } |
| 158 | 177 |
| 159 bool PermissionsData::HasAPIPermissionForTab( | 178 bool PermissionsData::HasAPIPermissionForTab( |
| 160 int tab_id, | 179 int tab_id, |
| 161 APIPermission::ID permission) const { | 180 APIPermission::ID permission) const { |
| 162 if (HasAPIPermission(permission)) | 181 if (HasAPIPermission(permission)) |
| 163 return true; | 182 return true; |
| 164 | 183 |
| 165 scoped_refptr<const PermissionSet> tab_permissions = | 184 // Place autolock below the HasAPIPermission() since it already acquires the |
| 166 GetTabSpecificPermissions(tab_id); | 185 // lock. |
|
not at google - send to devlin
2015/09/22 21:51:26
I'd be more comfortable if locks were held for the
Devlin
2015/09/23 17:08:59
Done.
| |
| 167 | |
| 168 // Place autolock below the HasAPIPermission() and | |
| 169 // GetTabSpecificPermissions(), since each already acquires the lock. | |
| 170 base::AutoLock auto_lock(runtime_lock_); | 186 base::AutoLock auto_lock(runtime_lock_); |
| 171 return tab_permissions.get() && tab_permissions->HasAPIPermission(permission); | 187 const PermissionSet* tab_permissions = GetTabSpecificPermissions(tab_id); |
| 188 return tab_permissions && tab_permissions->HasAPIPermission(permission); | |
| 172 } | 189 } |
| 173 | 190 |
| 174 bool PermissionsData::CheckAPIPermissionWithParam( | 191 bool PermissionsData::CheckAPIPermissionWithParam( |
| 175 APIPermission::ID permission, | 192 APIPermission::ID permission, |
| 176 const APIPermission::CheckParam* param) const { | 193 const APIPermission::CheckParam* param) const { |
| 177 return active_permissions()->CheckAPIPermissionWithParam(permission, param); | 194 base::AutoLock auto_lock(runtime_lock_); |
| 195 return active_permissions_unsafe_->CheckAPIPermissionWithParam(permission, | |
| 196 param); | |
| 178 } | 197 } |
| 179 | 198 |
| 180 URLPatternSet PermissionsData::GetEffectiveHostPermissions() const { | 199 URLPatternSet PermissionsData::GetEffectiveHostPermissions() const { |
| 181 base::AutoLock auto_lock(runtime_lock_); | 200 base::AutoLock auto_lock(runtime_lock_); |
| 182 URLPatternSet effective_hosts = active_permissions_unsafe_->effective_hosts(); | 201 URLPatternSet effective_hosts = active_permissions_unsafe_->effective_hosts(); |
| 183 for (const auto& val : tab_specific_permissions_) | 202 for (const auto& val : tab_specific_permissions_) |
| 184 effective_hosts.AddPatterns(val.second->effective_hosts()); | 203 effective_hosts.AddPatterns(val.second->effective_hosts()); |
| 185 return effective_hosts; | 204 return effective_hosts; |
| 186 } | 205 } |
| 187 | 206 |
| 188 bool PermissionsData::HasHostPermission(const GURL& url) const { | 207 bool PermissionsData::HasHostPermission(const GURL& url) const { |
| 189 return active_permissions()->HasExplicitAccessToOrigin(url); | 208 base::AutoLock auto_lock(runtime_lock_); |
| 209 return active_permissions_unsafe_->HasExplicitAccessToOrigin(url); | |
| 190 } | 210 } |
| 191 | 211 |
| 192 bool PermissionsData::HasEffectiveAccessToAllHosts() const { | 212 bool PermissionsData::HasEffectiveAccessToAllHosts() const { |
| 193 return active_permissions()->HasEffectiveAccessToAllHosts(); | 213 base::AutoLock auto_lock(runtime_lock_); |
| 214 return active_permissions_unsafe_->HasEffectiveAccessToAllHosts(); | |
| 194 } | 215 } |
| 195 | 216 |
| 196 PermissionMessages PermissionsData::GetPermissionMessages() const { | 217 PermissionMessages PermissionsData::GetPermissionMessages() const { |
| 218 base::AutoLock auto_lock(runtime_lock_); | |
| 197 return PermissionMessageProvider::Get()->GetPermissionMessages( | 219 return PermissionMessageProvider::Get()->GetPermissionMessages( |
| 198 PermissionMessageProvider::Get()->GetAllPermissionIDs( | 220 PermissionMessageProvider::Get()->GetAllPermissionIDs( |
| 199 active_permissions().get(), manifest_type_)); | 221 active_permissions_unsafe_.get(), manifest_type_)); |
| 200 } | 222 } |
| 201 | 223 |
| 202 bool PermissionsData::HasWithheldImpliedAllHosts() const { | 224 bool PermissionsData::HasWithheldImpliedAllHosts() const { |
| 225 base::AutoLock auto_lock(runtime_lock_); | |
| 203 // Since we currently only withhold all_hosts, it's sufficient to check | 226 // Since we currently only withhold all_hosts, it's sufficient to check |
| 204 // that either set is not empty. | 227 // that either set is not empty. |
| 205 return !withheld_permissions()->explicit_hosts().is_empty() || | 228 return !withheld_permissions_unsafe_->explicit_hosts().is_empty() || |
| 206 !withheld_permissions()->scriptable_hosts().is_empty(); | 229 !withheld_permissions_unsafe_->scriptable_hosts().is_empty(); |
| 207 } | 230 } |
| 208 | 231 |
| 209 bool PermissionsData::CanAccessPage(const Extension* extension, | 232 bool PermissionsData::CanAccessPage(const Extension* extension, |
| 210 const GURL& document_url, | 233 const GURL& document_url, |
| 211 int tab_id, | 234 int tab_id, |
| 212 int process_id, | 235 int process_id, |
| 213 std::string* error) const { | 236 std::string* error) const { |
| 214 AccessType result = CanRunOnPage(extension, | 237 base::AutoLock auto_lock(runtime_lock_); |
| 215 document_url, | 238 AccessType result = |
| 216 tab_id, | 239 CanRunOnPage(extension, document_url, tab_id, process_id, |
| 217 process_id, | 240 active_permissions_unsafe_->explicit_hosts(), |
| 218 active_permissions()->explicit_hosts(), | 241 withheld_permissions_unsafe_->explicit_hosts(), error); |
| 219 withheld_permissions()->explicit_hosts(), | |
| 220 error); | |
| 221 // TODO(rdevlin.cronin) Update callers so that they only need ACCESS_ALLOWED. | 242 // TODO(rdevlin.cronin) Update callers so that they only need ACCESS_ALLOWED. |
| 222 return result == ACCESS_ALLOWED || result == ACCESS_WITHHELD; | 243 return result == ACCESS_ALLOWED || result == ACCESS_WITHHELD; |
| 223 } | 244 } |
| 224 | 245 |
| 225 PermissionsData::AccessType PermissionsData::GetPageAccess( | 246 PermissionsData::AccessType PermissionsData::GetPageAccess( |
| 226 const Extension* extension, | 247 const Extension* extension, |
| 227 const GURL& document_url, | 248 const GURL& document_url, |
| 228 int tab_id, | 249 int tab_id, |
| 229 int process_id, | 250 int process_id, |
| 230 std::string* error) const { | 251 std::string* error) const { |
| 231 return CanRunOnPage(extension, | 252 base::AutoLock auto_lock(runtime_lock_); |
| 232 document_url, | 253 return CanRunOnPage(extension, document_url, tab_id, process_id, |
| 233 tab_id, | 254 active_permissions_unsafe_->explicit_hosts(), |
| 234 process_id, | 255 withheld_permissions_unsafe_->explicit_hosts(), error); |
| 235 active_permissions()->explicit_hosts(), | |
| 236 withheld_permissions()->explicit_hosts(), | |
| 237 error); | |
| 238 } | 256 } |
| 239 | 257 |
| 240 bool PermissionsData::CanRunContentScriptOnPage(const Extension* extension, | 258 bool PermissionsData::CanRunContentScriptOnPage(const Extension* extension, |
| 241 const GURL& document_url, | 259 const GURL& document_url, |
| 242 int tab_id, | 260 int tab_id, |
| 243 int process_id, | 261 int process_id, |
| 244 std::string* error) const { | 262 std::string* error) const { |
| 245 AccessType result = CanRunOnPage(extension, | 263 base::AutoLock auto_lock(runtime_lock_); |
| 246 document_url, | 264 AccessType result = |
| 247 tab_id, | 265 CanRunOnPage(extension, document_url, tab_id, process_id, |
| 248 process_id, | 266 active_permissions_unsafe_->scriptable_hosts(), |
| 249 active_permissions()->scriptable_hosts(), | 267 withheld_permissions_unsafe_->scriptable_hosts(), error); |
| 250 withheld_permissions()->scriptable_hosts(), | |
| 251 error); | |
| 252 // TODO(rdevlin.cronin) Update callers so that they only need ACCESS_ALLOWED. | 268 // TODO(rdevlin.cronin) Update callers so that they only need ACCESS_ALLOWED. |
| 253 return result == ACCESS_ALLOWED || result == ACCESS_WITHHELD; | 269 return result == ACCESS_ALLOWED || result == ACCESS_WITHHELD; |
| 254 } | 270 } |
| 255 | 271 |
| 256 PermissionsData::AccessType PermissionsData::GetContentScriptAccess( | 272 PermissionsData::AccessType PermissionsData::GetContentScriptAccess( |
| 257 const Extension* extension, | 273 const Extension* extension, |
| 258 const GURL& document_url, | 274 const GURL& document_url, |
| 259 int tab_id, | 275 int tab_id, |
| 260 int process_id, | 276 int process_id, |
| 261 std::string* error) const { | 277 std::string* error) const { |
| 262 return CanRunOnPage(extension, | 278 base::AutoLock auto_lock(runtime_lock_); |
| 263 document_url, | 279 return CanRunOnPage(extension, document_url, tab_id, process_id, |
| 264 tab_id, | 280 active_permissions_unsafe_->scriptable_hosts(), |
| 265 process_id, | 281 withheld_permissions_unsafe_->scriptable_hosts(), error); |
| 266 active_permissions()->scriptable_hosts(), | |
| 267 withheld_permissions()->scriptable_hosts(), | |
| 268 error); | |
| 269 } | 282 } |
| 270 | 283 |
| 271 bool PermissionsData::CanCaptureVisiblePage(int tab_id, | 284 bool PermissionsData::CanCaptureVisiblePage(int tab_id, |
| 272 std::string* error) const { | 285 std::string* error) const { |
| 273 const URLPattern all_urls(URLPattern::SCHEME_ALL, | 286 const URLPattern all_urls(URLPattern::SCHEME_ALL, |
| 274 URLPattern::kAllUrlsPattern); | 287 URLPattern::kAllUrlsPattern); |
| 275 | 288 |
| 276 if (active_permissions()->explicit_hosts().ContainsPattern(all_urls)) | 289 base::AutoLock auto_lock(runtime_lock_); |
| 290 if (active_permissions_unsafe_->explicit_hosts().ContainsPattern(all_urls)) | |
| 277 return true; | 291 return true; |
| 278 | 292 |
| 279 if (tab_id >= 0) { | 293 if (tab_id >= 0) { |
| 280 scoped_refptr<const PermissionSet> tab_permissions = | 294 const PermissionSet* tab_permissions = GetTabSpecificPermissions(tab_id); |
| 281 GetTabSpecificPermissions(tab_id); | 295 if (tab_permissions && |
| 282 if (tab_permissions.get() && | |
| 283 tab_permissions->HasAPIPermission(APIPermission::kTab)) { | 296 tab_permissions->HasAPIPermission(APIPermission::kTab)) { |
| 284 return true; | 297 return true; |
| 285 } | 298 } |
| 286 if (error) | 299 if (error) |
| 287 *error = manifest_errors::kActiveTabPermissionNotGranted; | 300 *error = manifest_errors::kActiveTabPermissionNotGranted; |
| 288 return false; | 301 return false; |
| 289 } | 302 } |
| 290 | 303 |
| 291 if (error) | 304 if (error) |
| 292 *error = manifest_errors::kAllURLOrActiveTabNeeded; | 305 *error = manifest_errors::kAllURLOrActiveTabNeeded; |
| 293 return false; | 306 return false; |
| 294 } | 307 } |
| 295 | 308 |
| 296 PermissionsData::TabPermissionsMap | 309 bool PermissionsData::CalledOnValidThread() const { |
| 297 PermissionsData::CopyTabSpecificPermissionsMap() const { | 310 return !thread_checker_ || thread_checker_->CalledOnValidThread(); |
|
not at google - send to devlin
2015/09/22 21:51:26
I'd find "return thread_checker_ && thread_checker
Devlin
2015/09/22 22:08:45
It's not bound to a thread during construction, be
| |
| 298 base::AutoLock auto_lock(runtime_lock_); | |
| 299 return tab_specific_permissions_; | |
| 300 } | 311 } |
| 301 | 312 |
| 302 scoped_refptr<const PermissionSet> PermissionsData::GetTabSpecificPermissions( | 313 const PermissionSet* PermissionsData::GetTabSpecificPermissions( |
| 303 int tab_id) const { | 314 int tab_id) const { |
| 304 base::AutoLock auto_lock(runtime_lock_); | |
| 305 CHECK_GE(tab_id, 0); | 315 CHECK_GE(tab_id, 0); |
| 316 runtime_lock_.AssertAcquired(); | |
| 306 TabPermissionsMap::const_iterator iter = | 317 TabPermissionsMap::const_iterator iter = |
| 307 tab_specific_permissions_.find(tab_id); | 318 tab_specific_permissions_.find(tab_id); |
| 308 return (iter != tab_specific_permissions_.end()) ? iter->second : NULL; | 319 return (iter != tab_specific_permissions_.end()) ? iter->second : nullptr; |
| 309 } | 320 } |
| 310 | 321 |
| 311 bool PermissionsData::HasTabSpecificPermissionToExecuteScript( | 322 bool PermissionsData::HasTabSpecificPermissionToExecuteScript( |
| 312 int tab_id, | 323 int tab_id, |
| 313 const GURL& url) const { | 324 const GURL& url) const { |
| 325 runtime_lock_.AssertAcquired(); | |
| 314 if (tab_id >= 0) { | 326 if (tab_id >= 0) { |
| 315 scoped_refptr<const PermissionSet> tab_permissions = | 327 const PermissionSet* tab_permissions = GetTabSpecificPermissions(tab_id); |
| 316 GetTabSpecificPermissions(tab_id); | 328 if (tab_permissions && |
| 317 if (tab_permissions.get() && | |
| 318 tab_permissions->explicit_hosts().MatchesSecurityOrigin(url)) { | 329 tab_permissions->explicit_hosts().MatchesSecurityOrigin(url)) { |
| 319 return true; | 330 return true; |
| 320 } | 331 } |
| 321 } | 332 } |
| 322 return false; | 333 return false; |
| 323 } | 334 } |
| 324 | 335 |
| 325 PermissionsData::AccessType PermissionsData::CanRunOnPage( | 336 PermissionsData::AccessType PermissionsData::CanRunOnPage( |
| 326 const Extension* extension, | 337 const Extension* extension, |
| 327 const GURL& document_url, | 338 const GURL& document_url, |
| 328 int tab_id, | 339 int tab_id, |
| 329 int process_id, | 340 int process_id, |
| 330 const URLPatternSet& permitted_url_patterns, | 341 const URLPatternSet& permitted_url_patterns, |
| 331 const URLPatternSet& withheld_url_patterns, | 342 const URLPatternSet& withheld_url_patterns, |
| 332 std::string* error) const { | 343 std::string* error) const { |
| 344 runtime_lock_.AssertAcquired(); | |
| 333 if (g_policy_delegate && | 345 if (g_policy_delegate && |
| 334 !g_policy_delegate->CanExecuteScriptOnPage( | 346 !g_policy_delegate->CanExecuteScriptOnPage( |
| 335 extension, document_url, tab_id, process_id, error)) { | 347 extension, document_url, tab_id, process_id, error)) { |
| 336 return ACCESS_DENIED; | 348 return ACCESS_DENIED; |
| 337 } | 349 } |
| 338 | 350 |
| 339 if (IsRestrictedUrl(document_url, extension, error)) | 351 if (IsRestrictedUrl(document_url, extension, error)) |
| 340 return ACCESS_DENIED; | 352 return ACCESS_DENIED; |
| 341 | 353 |
| 342 if (HasTabSpecificPermissionToExecuteScript(tab_id, document_url)) | 354 if (HasTabSpecificPermissionToExecuteScript(tab_id, document_url)) |
| 343 return ACCESS_ALLOWED; | 355 return ACCESS_ALLOWED; |
| 344 | 356 |
| 345 if (permitted_url_patterns.MatchesURL(document_url)) | 357 if (permitted_url_patterns.MatchesURL(document_url)) |
| 346 return ACCESS_ALLOWED; | 358 return ACCESS_ALLOWED; |
| 347 | 359 |
| 348 if (withheld_url_patterns.MatchesURL(document_url)) | 360 if (withheld_url_patterns.MatchesURL(document_url)) |
| 349 return ACCESS_WITHHELD; | 361 return ACCESS_WITHHELD; |
| 350 | 362 |
| 351 if (error) { | 363 if (error) { |
| 352 *error = ErrorUtils::FormatErrorMessage(manifest_errors::kCannotAccessPage, | 364 *error = ErrorUtils::FormatErrorMessage(manifest_errors::kCannotAccessPage, |
| 353 document_url.spec()); | 365 document_url.spec()); |
| 354 } | 366 } |
| 355 return ACCESS_DENIED; | 367 return ACCESS_DENIED; |
| 356 } | 368 } |
| 357 | 369 |
| 358 } // namespace extensions | 370 } // namespace extensions |
| OLD | NEW |