OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 #include "public/web/WebSharedWorker.h" | 49 #include "public/web/WebSharedWorker.h" |
50 #include "public/web/WebSharedWorkerCreationErrors.h" | 50 #include "public/web/WebSharedWorkerCreationErrors.h" |
51 #include "public/web/WebSharedWorkerRepositoryClient.h" | 51 #include "public/web/WebSharedWorkerRepositoryClient.h" |
52 #include "web/WebLocalFrameImpl.h" | 52 #include "web/WebLocalFrameImpl.h" |
53 | 53 |
54 namespace blink { | 54 namespace blink { |
55 | 55 |
56 // Callback class that keeps the SharedWorker and WebSharedWorker objects alive
while connecting. | 56 // Callback class that keeps the SharedWorker and WebSharedWorker objects alive
while connecting. |
57 class SharedWorkerConnector : private WebSharedWorkerConnector::ConnectListener
{ | 57 class SharedWorkerConnector : private WebSharedWorkerConnector::ConnectListener
{ |
58 public: | 58 public: |
59 SharedWorkerConnector(SharedWorker* worker, const KURL& url, const String& n
ame, PassOwnPtr<WebMessagePortChannel> channel, PassOwnPtr<WebSharedWorkerConnec
tor> webWorkerConnector) | 59 SharedWorkerConnector(SharedWorker* worker, const KURL& url, const String& n
ame, WebMessagePortChannelUniquePtr channel, PassOwnPtr<WebSharedWorkerConnector
> webWorkerConnector) |
60 : m_worker(worker) | 60 : m_worker(worker) |
61 , m_url(url) | 61 , m_url(url) |
62 , m_name(name) | 62 , m_name(name) |
63 , m_webWorkerConnector(std::move(webWorkerConnector)) | 63 , m_webWorkerConnector(std::move(webWorkerConnector)) |
64 , m_channel(std::move(channel)) { } | 64 , m_channel(std::move(channel)) { } |
65 | 65 |
66 virtual ~SharedWorkerConnector(); | 66 virtual ~SharedWorkerConnector(); |
67 void connect(); | 67 void connect(); |
68 | 68 |
69 private: | 69 private: |
70 // WebSharedWorkerConnector::ConnectListener overrides. | 70 // WebSharedWorkerConnector::ConnectListener overrides. |
71 void connected() override; | 71 void connected() override; |
72 void scriptLoadFailed() override; | 72 void scriptLoadFailed() override; |
73 | 73 |
74 Persistent<SharedWorker> m_worker; | 74 Persistent<SharedWorker> m_worker; |
75 KURL m_url; | 75 KURL m_url; |
76 String m_name; | 76 String m_name; |
77 OwnPtr<WebSharedWorkerConnector> m_webWorkerConnector; | 77 OwnPtr<WebSharedWorkerConnector> m_webWorkerConnector; |
78 OwnPtr<WebMessagePortChannel> m_channel; | 78 WebMessagePortChannelUniquePtr m_channel; |
79 }; | 79 }; |
80 | 80 |
81 SharedWorkerConnector::~SharedWorkerConnector() | 81 SharedWorkerConnector::~SharedWorkerConnector() |
82 { | 82 { |
83 m_worker->setIsBeingConnected(false); | 83 m_worker->setIsBeingConnected(false); |
84 } | 84 } |
85 | 85 |
86 void SharedWorkerConnector::connect() | 86 void SharedWorkerConnector::connect() |
87 { | 87 { |
88 m_worker->setIsBeingConnected(true); | 88 m_worker->setIsBeingConnected(true); |
89 m_webWorkerConnector->connect(m_channel.leakPtr(), this); | 89 m_webWorkerConnector->connect(m_channel.release(), this); |
90 } | 90 } |
91 | 91 |
92 void SharedWorkerConnector::connected() | 92 void SharedWorkerConnector::connected() |
93 { | 93 { |
94 // Free ourselves (this releases the SharedWorker so it can be freed as well
if unreferenced). | 94 // Free ourselves (this releases the SharedWorker so it can be freed as well
if unreferenced). |
95 delete this; | 95 delete this; |
96 } | 96 } |
97 | 97 |
98 void SharedWorkerConnector::scriptLoadFailed() | 98 void SharedWorkerConnector::scriptLoadFailed() |
99 { | 99 { |
100 m_worker->dispatchEvent(Event::createCancelable(EventTypeNames::error)); | 100 m_worker->dispatchEvent(Event::createCancelable(EventTypeNames::error)); |
101 // Free ourselves (this releases the SharedWorker so it can be freed as well
if unreferenced). | 101 // Free ourselves (this releases the SharedWorker so it can be freed as well
if unreferenced). |
102 delete this; | 102 delete this; |
103 } | 103 } |
104 | 104 |
105 static WebSharedWorkerRepositoryClient::DocumentID getId(void* document) | 105 static WebSharedWorkerRepositoryClient::DocumentID getId(void* document) |
106 { | 106 { |
107 DCHECK(document); | 107 DCHECK(document); |
108 return reinterpret_cast<WebSharedWorkerRepositoryClient::DocumentID>(documen
t); | 108 return reinterpret_cast<WebSharedWorkerRepositoryClient::DocumentID>(documen
t); |
109 } | 109 } |
110 | 110 |
111 void SharedWorkerRepositoryClientImpl::connect(SharedWorker* worker, PassOwnPtr<
WebMessagePortChannel> port, const KURL& url, const String& name, ExceptionState
& exceptionState) | 111 void SharedWorkerRepositoryClientImpl::connect(SharedWorker* worker, WebMessageP
ortChannelUniquePtr port, const KURL& url, const String& name, ExceptionState& e
xceptionState) |
112 { | 112 { |
113 DCHECK(m_client); | 113 DCHECK(m_client); |
114 | 114 |
115 // No nested workers (for now) - connect() should only be called from docume
nt context. | 115 // No nested workers (for now) - connect() should only be called from docume
nt context. |
116 DCHECK(worker->getExecutionContext()->isDocument()); | 116 DCHECK(worker->getExecutionContext()->isDocument()); |
117 Document* document = toDocument(worker->getExecutionContext()); | 117 Document* document = toDocument(worker->getExecutionContext()); |
118 | 118 |
119 // TODO(estark): this is broken, as it only uses the first header | 119 // TODO(estark): this is broken, as it only uses the first header |
120 // when multiple might have been sent. Fix by making the | 120 // when multiple might have been sent. Fix by making the |
121 // SharedWorkerConnector interface take a map that can contain | 121 // SharedWorkerConnector interface take a map that can contain |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 DCHECK(m_client); | 158 DCHECK(m_client); |
159 m_client->documentDetached(getId(document)); | 159 m_client->documentDetached(getId(document)); |
160 } | 160 } |
161 | 161 |
162 SharedWorkerRepositoryClientImpl::SharedWorkerRepositoryClientImpl(WebSharedWork
erRepositoryClient* client) | 162 SharedWorkerRepositoryClientImpl::SharedWorkerRepositoryClientImpl(WebSharedWork
erRepositoryClient* client) |
163 : m_client(client) | 163 : m_client(client) |
164 { | 164 { |
165 } | 165 } |
166 | 166 |
167 } // namespace blink | 167 } // namespace blink |
OLD | NEW |