| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/shared_worker/shared_worker_instance.h" | 5 #include "content/browser/shared_worker/shared_worker_instance.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 | 8 |
| 9 namespace content { | 9 namespace content { |
| 10 | 10 |
| 11 SharedWorkerInstance::SharedWorkerInstance( | 11 SharedWorkerInstance::SharedWorkerInstance( |
| 12 const GURL& url, | 12 const GURL& url, |
| 13 const base::string16& name, | 13 const base::string16& name, |
| 14 const base::string16& content_security_policy, | 14 const base::string16& content_security_policy, |
| 15 blink::WebContentSecurityPolicyType security_policy_type, | 15 blink::WebContentSecurityPolicyType security_policy_type, |
| 16 ResourceContext* resource_context, | 16 ResourceContext* resource_context, |
| 17 const WorkerStoragePartition& partition) | 17 const WorkerStoragePartition& partition) |
| 18 : url_(url), | 18 : url_(url), |
| 19 name_(name), | 19 name_(name), |
| 20 content_security_policy_(content_security_policy), | 20 content_security_policy_(content_security_policy), |
| 21 security_policy_type_(security_policy_type), | 21 security_policy_type_(security_policy_type), |
| 22 resource_context_(resource_context), | 22 resource_context_(resource_context), |
| 23 partition_(partition) { | 23 partition_(partition) { |
| 24 DCHECK(resource_context_); | 24 DCHECK(resource_context_); |
| 25 } | 25 } |
| 26 | 26 |
| 27 SharedWorkerInstance::~SharedWorkerInstance() { | 27 SharedWorkerInstance::SharedWorkerInstance(const SharedWorkerInstance& other) |
| 28 } | 28 : url_(other.url_), |
| 29 name_(other.name_), |
| 30 content_security_policy_(other.content_security_policy_), |
| 31 security_policy_type_(other.security_policy_type_), |
| 32 resource_context_(other.resource_context_), |
| 33 partition_(other.partition_) {} |
| 34 |
| 35 SharedWorkerInstance::~SharedWorkerInstance() {} |
| 29 | 36 |
| 30 bool SharedWorkerInstance::Matches(const GURL& match_url, | 37 bool SharedWorkerInstance::Matches(const GURL& match_url, |
| 31 const base::string16& match_name, | 38 const base::string16& match_name, |
| 32 const WorkerStoragePartition& partition, | 39 const WorkerStoragePartition& partition, |
| 33 ResourceContext* resource_context) const { | 40 ResourceContext* resource_context) const { |
| 34 // ResourceContext equivalence is being used as a proxy to ensure we only | 41 // ResourceContext equivalence is being used as a proxy to ensure we only |
| 35 // matched shared workers within the same BrowserContext. | 42 // matched shared workers within the same BrowserContext. |
| 36 if (resource_context_ != resource_context) | 43 if (resource_context_ != resource_context) |
| 37 return false; | 44 return false; |
| 38 | 45 |
| 39 // We must be in the same storage partition otherwise sharing will violate | 46 // We must be in the same storage partition otherwise sharing will violate |
| 40 // isolation. | 47 // isolation. |
| 41 if (!partition_.Equals(partition)) | 48 if (!partition_.Equals(partition)) |
| 42 return false; | 49 return false; |
| 43 | 50 |
| 44 if (url_.GetOrigin() != match_url.GetOrigin()) | 51 if (url_.GetOrigin() != match_url.GetOrigin()) |
| 45 return false; | 52 return false; |
| 46 | 53 |
| 47 if (name_.empty() && match_name.empty()) | 54 if (name_.empty() && match_name.empty()) |
| 48 return url_ == match_url; | 55 return url_ == match_url; |
| 49 | 56 |
| 50 return name_ == match_name; | 57 return name_ == match_name; |
| 51 } | 58 } |
| 52 | 59 |
| 60 bool SharedWorkerInstance::Matches(const SharedWorkerInstance& other) const { |
| 61 return Matches( |
| 62 other.url(), other.name(), other.partition(), other.resource_context()); |
| 63 } |
| 64 |
| 53 } // namespace content | 65 } // namespace content |
| OLD | NEW |