Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: content/browser/shared_worker/shared_worker_instance.cc

Issue 177043003: Implement SharedWorkerServiceImpl::CreateWorker and SharedWorkerInstance and SharedWorkerHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use std::string and base::StringPiece Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 #include "content/browser/shared_worker/shared_worker_instance.h"
6
7 #include "base/logging.h"
8 #include "content/browser/worker_host/worker_document_set.h"
9
10 namespace content {
11
12 SharedWorkerInstance::SharedWorkerInstance(
13 const GURL& url,
14 const base::string16& name,
15 const base::string16& content_security_policy,
16 blink::WebContentSecurityPolicyType security_policy_type,
17 ResourceContext* resource_context,
18 const WorkerStoragePartition& partition)
19 : url_(url),
20 closed_(false),
21 name_(name),
22 content_security_policy_(content_security_policy),
23 security_policy_type_(security_policy_type),
24 worker_document_set_(new WorkerDocumentSet()),
25 resource_context_(resource_context),
26 partition_(partition),
27 load_failed_(false) {
28 DCHECK(resource_context_);
29 }
30
31 SharedWorkerInstance::~SharedWorkerInstance() {
32 }
33
34 void SharedWorkerInstance::SetMessagePortID(
35 SharedWorkerMessageFilter* filter,
36 int route_id,
37 int message_port_id) {
38 for (FilterList::iterator i = filters_.begin(); i != filters_.end(); ++i) {
39 if (i->filter() == filter && i->route_id() == route_id) {
40 i->set_message_port_id(message_port_id);
41 return;
42 }
43 }
44 }
45
46 bool SharedWorkerInstance::Matches(const GURL& match_url,
47 const base::string16& match_name,
48 const WorkerStoragePartition& partition,
49 ResourceContext* resource_context) const {
50 // Only match open shared workers.
51 if (closed_)
52 return false;
53
54 // ResourceContext equivalence is being used as a proxy to ensure we only
55 // matched shared workers within the same BrowserContext.
56 if (resource_context_ != resource_context)
57 return false;
58
59 // We must be in the same storage partition otherwise sharing will violate
60 // isolation.
61 if (!partition_.Equals(partition))
62 return false;
63
64 if (url_.GetOrigin() != match_url.GetOrigin())
65 return false;
66
67 if (name_.empty() && match_name.empty())
68 return url_ == match_url;
69
70 return name_ == match_name;
71 }
72
73 void SharedWorkerInstance::AddFilter(SharedWorkerMessageFilter* filter,
74 int route_id) {
75 CHECK(filter);
76 if (!HasFilter(filter, route_id)) {
77 FilterInfo info(filter, route_id);
78 filters_.push_back(info);
79 }
80 }
81
82 void SharedWorkerInstance::RemoveFilters(SharedWorkerMessageFilter* filter) {
83 for (FilterList::iterator i = filters_.begin(); i != filters_.end();) {
84 if (i->filter() == filter)
85 i = filters_.erase(i);
86 else
87 ++i;
88 }
89 }
90
91 bool SharedWorkerInstance::HasFilter(SharedWorkerMessageFilter* filter,
92 int route_id) const {
93 for (FilterList::const_iterator i = filters_.begin(); i != filters_.end();
94 ++i) {
95 if (i->filter() == filter && i->route_id() == route_id)
96 return true;
97 }
98 return false;
99 }
100
101 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698