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.
4
5#ifndef CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_INSTANCE_H_
6#define CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_INSTANCE_H_
7
8#include <string>
9
10#include "base/basictypes.h"
11#include "content/browser/shared_worker/worker_storage_partition.h"
12#include "content/common/content_export.h"
13#include "third_party/WebKit/public/web/WebContentSecurityPolicy.h"
14#include "url/gurl.h"
15
16namespace content {
17class ResourceContext;
18
19// SharedWorkerInstance is copyable value-type data type. It could be passed to
20// the UI thread and be used for comparison in EmbeddedWorkerDevToolsManager.
21class CONTENT_EXPORT SharedWorkerInstance {
22 public:
23  SharedWorkerInstance(const GURL& url,
24                       const base::string16& name,
25                       const base::string16& content_security_policy,
26                       blink::WebContentSecurityPolicyType security_policy_type,
27                       ResourceContext* resource_context,
28                       const WorkerStoragePartitionId& partition_id);
29  SharedWorkerInstance(const SharedWorkerInstance& other);
30  ~SharedWorkerInstance();
31
32  // Checks if this SharedWorkerInstance matches the passed url/name params
33  // based on the algorithm in the WebWorkers spec - an instance matches if the
34  // origins of the URLs match, and:
35  // a) the names are non-empty and equal.
36  // -or-
37  // b) the names are both empty, and the urls are equal.
38  bool Matches(const GURL& url,
39               const base::string16& name,
40               const WorkerStoragePartitionId& partition,
41               ResourceContext* resource_context) const;
42  bool Matches(const SharedWorkerInstance& other) const;
43
44  // Accessors.
45  const GURL& url() const { return url_; }
46  const base::string16 name() const { return name_; }
47  const base::string16 content_security_policy() const {
48    return content_security_policy_;
49  }
50  blink::WebContentSecurityPolicyType security_policy_type() const {
51    return security_policy_type_;
52  }
53  ResourceContext* resource_context() const {
54    return resource_context_;
55  }
56  const WorkerStoragePartitionId& partition_id() const { return partition_id_; }
57
58 private:
59  const GURL url_;
60  const base::string16 name_;
61  const base::string16 content_security_policy_;
62  const blink::WebContentSecurityPolicyType security_policy_type_;
63  ResourceContext* const resource_context_;
64  const WorkerStoragePartitionId partition_id_;
65};
66
67}  // namespace content
68
69
70#endif  // CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_INSTANCE_H_
71