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
3 // found in the LICENSE file.
5 #include "content/browser/shared_worker/shared_worker_instance.h"
7 #include "base/logging.h"
11 SharedWorkerInstance::SharedWorkerInstance(
13 const base::string16
& name
,
14 const base::string16
& content_security_policy
,
15 blink::WebContentSecurityPolicyType security_policy_type
,
16 ResourceContext
* resource_context
,
17 const WorkerStoragePartitionId
& partition_id
)
20 content_security_policy_(content_security_policy
),
21 security_policy_type_(security_policy_type
),
22 resource_context_(resource_context
),
23 partition_id_(partition_id
) {
24 DCHECK(resource_context_
);
27 SharedWorkerInstance::SharedWorkerInstance(const SharedWorkerInstance
& other
)
30 content_security_policy_(other
.content_security_policy_
),
31 security_policy_type_(other
.security_policy_type_
),
32 resource_context_(other
.resource_context_
),
33 partition_id_(other
.partition_id_
) {
36 SharedWorkerInstance::~SharedWorkerInstance() {}
38 bool SharedWorkerInstance::Matches(const GURL
& match_url
,
39 const base::string16
& match_name
,
40 const WorkerStoragePartitionId
& partition_id
,
41 ResourceContext
* resource_context
) const {
42 // ResourceContext equivalence is being used as a proxy to ensure we only
43 // matched shared workers within the same BrowserContext.
44 if (resource_context_
!= resource_context
)
47 // We must be in the same storage partition otherwise sharing will violate
49 if (!partition_id_
.Equals(partition_id
))
52 if (url_
.GetOrigin() != match_url
.GetOrigin())
55 if (name_
.empty() && match_name
.empty())
56 return url_
== match_url
;
58 return name_
== match_name
;
61 bool SharedWorkerInstance::Matches(const SharedWorkerInstance
& other
) const {
62 return Matches(other
.url(),
65 other
.resource_context());
68 } // namespace content