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

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

Issue 177043003: Implement SharedWorkerServiceImpl::CreateWorker and SharedWorkerInstance and SharedWorkerHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add test for SharedWorkerInstance Created 6 years, 9 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
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 #ifndef CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_MESSAGE_FILTER_H_ 5 #ifndef CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_INSTANCE_H_
6 #define CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_MESSAGE_FILTER_H_ 6 #define CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_INSTANCE_H_
7 7
8 #include <list>
9 #include <string>
10
11 #include "base/basictypes.h"
12 #include "content/browser/worker_host/worker_document_set.h"
8 #include "content/browser/worker_host/worker_storage_partition.h" 13 #include "content/browser/worker_host/worker_storage_partition.h"
9 #include "content/public/browser/browser_message_filter.h" 14 #include "content/common/content_export.h"
10 15 #include "third_party/WebKit/public/web/WebContentSecurityPolicy.h"
11 class GURL; 16 #include "url/gurl.h"
12 struct ViewHostMsg_CreateWorker_Params;
13 17
14 namespace content { 18 namespace content {
15 class MessagePortMessageFilter;
16 class ResourceContext; 19 class ResourceContext;
20 class SharedWorkerMessageFilter;
17 21
18 // If "enable-embedded-shared-worker" is set this class will be used instead of 22 class CONTENT_EXPORT SharedWorkerInstance {
19 // WorkerMessageFilter.
20 class SharedWorkerMessageFilter : public BrowserMessageFilter {
21 public: 23 public:
22 SharedWorkerMessageFilter(int render_process_id, 24 // Unique identifier for a worker client.
23 ResourceContext* resource_context, 25 class FilterInfo {
24 const WorkerStoragePartition& partition, 26 public:
25 MessagePortMessageFilter* message_port_filter); 27 FilterInfo(SharedWorkerMessageFilter* filter, int route_id)
28 : filter_(filter), route_id_(route_id), message_port_id_(0) { }
29 SharedWorkerMessageFilter* filter() const { return filter_; }
30 int route_id() const { return route_id_; }
31 int message_port_id() const { return message_port_id_; }
32 void set_message_port_id(int id) { message_port_id_ = id; }
26 33
27 // BrowserMessageFilter implementation. 34 private:
28 virtual void OnChannelClosing() OVERRIDE; 35 SharedWorkerMessageFilter* filter_;
29 virtual bool OnMessageReceived(const IPC::Message& message, 36 int route_id_;
30 bool* message_was_ok) OVERRIDE; 37 int message_port_id_;
38 };
31 39
32 int GetNextRoutingID(); 40 typedef std::list<FilterInfo> FilterList;
33 int render_process_id() const { return render_process_id_; }
34 41
35 MessagePortMessageFilter* message_port_message_filter() const { 42 SharedWorkerInstance(const GURL& url,
36 return message_port_message_filter_; 43 const base::string16& name,
44 const base::string16& content_security_policy,
45 blink::WebContentSecurityPolicyType security_policy_type,
46 ResourceContext* resource_context,
47 const WorkerStoragePartition& partition);
48 ~SharedWorkerInstance();
49
50 void AddFilter(SharedWorkerMessageFilter* filter, int route_id);
51 void RemoveFilters(SharedWorkerMessageFilter* filter);
52 bool HasFilter(SharedWorkerMessageFilter* filter, int route_id) const;
53 void SetMessagePortID(SharedWorkerMessageFilter* filter,
54 int route_id,
55 int message_port_id);
56 const FilterList& filters() const { return filters_; }
57
58 // Checks if this SharedWorkerInstance matches the passed url/name params
59 // based on the algorithm in the WebWorkers spec - an instance matches if the
60 // origins of the URLs match, and:
61 // a) the names are non-empty and equal.
62 // -or-
63 // b) the names are both empty, and the urls are equal.
64 bool Matches(
65 const GURL& url,
66 const base::string16& name,
67 const WorkerStoragePartition& partition,
68 ResourceContext* resource_context) const;
69
70 // Accessors.
71 bool closed() const { return closed_; }
72 void set_closed(bool closed) { closed_ = closed; }
73 const GURL& url() const { return url_; }
74 const base::string16 name() const { return name_; }
75 const base::string16 content_security_policy() const {
76 return content_security_policy_;
37 } 77 }
78 blink::WebContentSecurityPolicyType security_policy_type() const {
79 return security_policy_type_;
80 }
81 WorkerDocumentSet* worker_document_set() const {
82 return worker_document_set_.get();
83 }
84 ResourceContext* resource_context() const {
85 return resource_context_;
86 }
87 const WorkerStoragePartition& partition() const {
88 return partition_;
89 }
90 void set_load_failed(bool failed) { load_failed_ = failed; }
91 bool load_failed() { return load_failed_; }
38 92
39 private: 93 private:
40 virtual ~SharedWorkerMessageFilter(); 94 GURL url_;
41 95 bool closed_;
42 // Message handlers. 96 base::string16 name_;
43 void OnCreateWorker(const ViewHostMsg_CreateWorker_Params& params, 97 base::string16 content_security_policy_;
44 int* route_id); 98 blink::WebContentSecurityPolicyType security_policy_type_;
45 void OnForwardToWorker(const IPC::Message& message); 99 FilterList filters_;
46 void OnDocumentDetached(unsigned long long document_id); 100 scoped_refptr<WorkerDocumentSet> worker_document_set_;
47 void OnWorkerContextClosed(int worker_route_id);
48 void OnWorkerContextDestroyed(int worker_route_id);
49 void OnWorkerScriptLoaded(int worker_route_id);
50 void OnWorkerScriptLoadFailed(int worker_route_id);
51 void OnWorkerConnected(int message_port_id, int worker_route_id);
52 void OnAllowDatabase(int worker_route_id,
53 const GURL& url,
54 const base::string16& name,
55 const base::string16& display_name,
56 unsigned long estimated_size,
57 bool* result);
58 void OnAllowFileSystem(int worker_route_id,
59 const GURL& url,
60 bool* result);
61 void OnAllowIndexedDB(int worker_route_id,
62 const GURL& url,
63 const base::string16& name,
64 bool* result);
65
66 const int render_process_id_;
67 ResourceContext* const resource_context_; 101 ResourceContext* const resource_context_;
68 const WorkerStoragePartition partition_; 102 WorkerStoragePartition partition_;
69 MessagePortMessageFilter* const message_port_message_filter_; 103 bool load_failed_;
70
71 DISALLOW_IMPLICIT_CONSTRUCTORS(SharedWorkerMessageFilter);
72 }; 104 };
73 105
74 } // namespace content 106 } // namespace content
75 107
76 #endif // CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_MESSAGE_FILTER_H_ 108
109 #endif // CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_INSTANCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698