| 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(const SharedWorkerInstance& other) | 27 SharedWorkerInstance::~SharedWorkerInstance() { |
| 28 : url_(other.url_), | 28 } |
| 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() {} | |
| 36 | 29 |
| 37 bool SharedWorkerInstance::Matches(const GURL& match_url, | 30 bool SharedWorkerInstance::Matches(const GURL& match_url, |
| 38 const base::string16& match_name, | 31 const base::string16& match_name, |
| 39 const WorkerStoragePartition& partition, | 32 const WorkerStoragePartition& partition, |
| 40 ResourceContext* resource_context) const { | 33 ResourceContext* resource_context) const { |
| 41 // ResourceContext equivalence is being used as a proxy to ensure we only | 34 // ResourceContext equivalence is being used as a proxy to ensure we only |
| 42 // matched shared workers within the same BrowserContext. | 35 // matched shared workers within the same BrowserContext. |
| 43 if (resource_context_ != resource_context) | 36 if (resource_context_ != resource_context) |
| 44 return false; | 37 return false; |
| 45 | 38 |
| 46 // We must be in the same storage partition otherwise sharing will violate | 39 // We must be in the same storage partition otherwise sharing will violate |
| 47 // isolation. | 40 // isolation. |
| 48 if (!partition_.Equals(partition)) | 41 if (!partition_.Equals(partition)) |
| 49 return false; | 42 return false; |
| 50 | 43 |
| 51 if (url_.GetOrigin() != match_url.GetOrigin()) | 44 if (url_.GetOrigin() != match_url.GetOrigin()) |
| 52 return false; | 45 return false; |
| 53 | 46 |
| 54 if (name_.empty() && match_name.empty()) | 47 if (name_.empty() && match_name.empty()) |
| 55 return url_ == match_url; | 48 return url_ == match_url; |
| 56 | 49 |
| 57 return name_ == match_name; | 50 return name_ == match_name; |
| 58 } | 51 } |
| 59 | 52 |
| 60 bool SharedWorkerInstance::Matches(const SharedWorkerInstance& other) const { | |
| 61 return Matches( | |
| 62 other.url(), other.name(), other.partition(), other.resource_context()); | |
| 63 } | |
| 64 | |
| 65 } // namespace content | 53 } // namespace content |
| OLD | NEW |