| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 #include "public/web/WebKit.h" | 48 #include "public/web/WebKit.h" |
| 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 #include "wtf/PtrUtil.h" | 53 #include "wtf/PtrUtil.h" |
| 54 #include <memory> | 54 #include <memory> |
| 55 | 55 |
| 56 namespace blink { | 56 namespace blink { |
| 57 | 57 |
| 58 // Callback class that keeps the SharedWorker and WebSharedWorker objects alive
while connecting. | 58 // Callback class that keeps the SharedWorker and WebSharedWorker objects alive |
| 59 // while connecting. |
| 59 class SharedWorkerConnector | 60 class SharedWorkerConnector |
| 60 : private WebSharedWorkerConnector::ConnectListener { | 61 : private WebSharedWorkerConnector::ConnectListener { |
| 61 public: | 62 public: |
| 62 SharedWorkerConnector( | 63 SharedWorkerConnector( |
| 63 SharedWorker* worker, | 64 SharedWorker* worker, |
| 64 const KURL& url, | 65 const KURL& url, |
| 65 const String& name, | 66 const String& name, |
| 66 WebMessagePortChannelUniquePtr channel, | 67 WebMessagePortChannelUniquePtr channel, |
| 67 std::unique_ptr<WebSharedWorkerConnector> webWorkerConnector) | 68 std::unique_ptr<WebSharedWorkerConnector> webWorkerConnector) |
| 68 : m_worker(worker), | 69 : m_worker(worker), |
| (...skipping 20 matching lines...) Expand all Loading... |
| 89 SharedWorkerConnector::~SharedWorkerConnector() { | 90 SharedWorkerConnector::~SharedWorkerConnector() { |
| 90 m_worker->setIsBeingConnected(false); | 91 m_worker->setIsBeingConnected(false); |
| 91 } | 92 } |
| 92 | 93 |
| 93 void SharedWorkerConnector::connect() { | 94 void SharedWorkerConnector::connect() { |
| 94 m_worker->setIsBeingConnected(true); | 95 m_worker->setIsBeingConnected(true); |
| 95 m_webWorkerConnector->connect(m_channel.release(), this); | 96 m_webWorkerConnector->connect(m_channel.release(), this); |
| 96 } | 97 } |
| 97 | 98 |
| 98 void SharedWorkerConnector::connected() { | 99 void SharedWorkerConnector::connected() { |
| 99 // Free ourselves (this releases the SharedWorker so it can be freed as well i
f unreferenced). | 100 // Free ourselves (this releases the SharedWorker so it can be freed as well |
| 101 // if unreferenced). |
| 100 delete this; | 102 delete this; |
| 101 } | 103 } |
| 102 | 104 |
| 103 void SharedWorkerConnector::scriptLoadFailed() { | 105 void SharedWorkerConnector::scriptLoadFailed() { |
| 104 m_worker->dispatchEvent(Event::createCancelable(EventTypeNames::error)); | 106 m_worker->dispatchEvent(Event::createCancelable(EventTypeNames::error)); |
| 105 // Free ourselves (this releases the SharedWorker so it can be freed as well i
f unreferenced). | 107 // Free ourselves (this releases the SharedWorker so it can be freed as well |
| 108 // if unreferenced). |
| 106 delete this; | 109 delete this; |
| 107 } | 110 } |
| 108 | 111 |
| 109 static WebSharedWorkerRepositoryClient::DocumentID getId(void* document) { | 112 static WebSharedWorkerRepositoryClient::DocumentID getId(void* document) { |
| 110 DCHECK(document); | 113 DCHECK(document); |
| 111 return reinterpret_cast<WebSharedWorkerRepositoryClient::DocumentID>( | 114 return reinterpret_cast<WebSharedWorkerRepositoryClient::DocumentID>( |
| 112 document); | 115 document); |
| 113 } | 116 } |
| 114 | 117 |
| 115 void SharedWorkerRepositoryClientImpl::connect( | 118 void SharedWorkerRepositoryClientImpl::connect( |
| 116 SharedWorker* worker, | 119 SharedWorker* worker, |
| 117 WebMessagePortChannelUniquePtr port, | 120 WebMessagePortChannelUniquePtr port, |
| 118 const KURL& url, | 121 const KURL& url, |
| 119 const String& name, | 122 const String& name, |
| 120 ExceptionState& exceptionState) { | 123 ExceptionState& exceptionState) { |
| 121 DCHECK(m_client); | 124 DCHECK(m_client); |
| 122 | 125 |
| 123 // No nested workers (for now) - connect() should only be called from document
context. | 126 // No nested workers (for now) - connect() should only be called from document |
| 127 // context. |
| 124 DCHECK(worker->getExecutionContext()->isDocument()); | 128 DCHECK(worker->getExecutionContext()->isDocument()); |
| 125 Document* document = toDocument(worker->getExecutionContext()); | 129 Document* document = toDocument(worker->getExecutionContext()); |
| 126 | 130 |
| 127 // TODO(estark): this is broken, as it only uses the first header | 131 // TODO(estark): this is broken, as it only uses the first header |
| 128 // when multiple might have been sent. Fix by making the | 132 // when multiple might have been sent. Fix by making the |
| 129 // SharedWorkerConnector interface take a map that can contain | 133 // SharedWorkerConnector interface take a map that can contain |
| 130 // multiple headers. | 134 // multiple headers. |
| 131 std::unique_ptr<Vector<CSPHeaderAndType>> headers = | 135 std::unique_ptr<Vector<CSPHeaderAndType>> headers = |
| 132 worker->getExecutionContext()->contentSecurityPolicy()->headers(); | 136 worker->getExecutionContext()->contentSecurityPolicy()->headers(); |
| 133 WebString header; | 137 WebString header; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 145 worker->getExecutionContext()->isSecureContext(unusedSecureContextError); | 149 worker->getExecutionContext()->isSecureContext(unusedSecureContextError); |
| 146 std::unique_ptr<WebSharedWorkerConnector> webWorkerConnector = | 150 std::unique_ptr<WebSharedWorkerConnector> webWorkerConnector = |
| 147 wrapUnique(m_client->createSharedWorkerConnector( | 151 wrapUnique(m_client->createSharedWorkerConnector( |
| 148 url, name, getId(document), header, headerType, | 152 url, name, getId(document), header, headerType, |
| 149 worker->getExecutionContext()->securityContext().addressSpace(), | 153 worker->getExecutionContext()->securityContext().addressSpace(), |
| 150 isSecureContext ? WebSharedWorkerCreationContextTypeSecure | 154 isSecureContext ? WebSharedWorkerCreationContextTypeSecure |
| 151 : WebSharedWorkerCreationContextTypeNonsecure, | 155 : WebSharedWorkerCreationContextTypeNonsecure, |
| 152 &creationError)); | 156 &creationError)); |
| 153 if (creationError != WebWorkerCreationErrorNone) { | 157 if (creationError != WebWorkerCreationErrorNone) { |
| 154 if (creationError == WebWorkerCreationErrorURLMismatch) { | 158 if (creationError == WebWorkerCreationErrorURLMismatch) { |
| 155 // Existing worker does not match this url, so return an error back to the
caller. | 159 // Existing worker does not match this url, so return an error back to the |
| 160 // caller. |
| 156 exceptionState.throwDOMException( | 161 exceptionState.throwDOMException( |
| 157 URLMismatchError, "The location of the SharedWorker named '" + name + | 162 URLMismatchError, "The location of the SharedWorker named '" + name + |
| 158 "' does not exactly match the provided URL ('" + | 163 "' does not exactly match the provided URL ('" + |
| 159 url.elidedString() + "')."); | 164 url.elidedString() + "')."); |
| 160 return; | 165 return; |
| 161 } else if (creationError == WebWorkerCreationErrorSecureContextMismatch) { | 166 } else if (creationError == WebWorkerCreationErrorSecureContextMismatch) { |
| 162 if (isSecureContext) { | 167 if (isSecureContext) { |
| 163 UseCounter::count( | 168 UseCounter::count( |
| 164 document, | 169 document, |
| 165 UseCounter::NonSecureSharedWorkerAccessedFromSecureContext); | 170 UseCounter::NonSecureSharedWorkerAccessedFromSecureContext); |
| 166 } else { | 171 } else { |
| 167 UseCounter::count( | 172 UseCounter::count( |
| 168 document, | 173 document, |
| 169 UseCounter::SecureSharedWorkerAccessedFromNonSecureContext); | 174 UseCounter::SecureSharedWorkerAccessedFromNonSecureContext); |
| 170 } | 175 } |
| 171 } | 176 } |
| 172 } | 177 } |
| 173 | 178 |
| 174 // The connector object manages its own lifecycle (and the lifecycles of the t
wo worker objects). | 179 // The connector object manages its own lifecycle (and the lifecycles of the |
| 175 // It will free itself once connecting is completed. | 180 // two worker objects). It will free itself once connecting is completed. |
| 176 SharedWorkerConnector* connector = new SharedWorkerConnector( | 181 SharedWorkerConnector* connector = new SharedWorkerConnector( |
| 177 worker, url, name, std::move(port), std::move(webWorkerConnector)); | 182 worker, url, name, std::move(port), std::move(webWorkerConnector)); |
| 178 connector->connect(); | 183 connector->connect(); |
| 179 } | 184 } |
| 180 | 185 |
| 181 void SharedWorkerRepositoryClientImpl::documentDetached(Document* document) { | 186 void SharedWorkerRepositoryClientImpl::documentDetached(Document* document) { |
| 182 DCHECK(m_client); | 187 DCHECK(m_client); |
| 183 m_client->documentDetached(getId(document)); | 188 m_client->documentDetached(getId(document)); |
| 184 } | 189 } |
| 185 | 190 |
| 186 SharedWorkerRepositoryClientImpl::SharedWorkerRepositoryClientImpl( | 191 SharedWorkerRepositoryClientImpl::SharedWorkerRepositoryClientImpl( |
| 187 WebSharedWorkerRepositoryClient* client) | 192 WebSharedWorkerRepositoryClient* client) |
| 188 : m_client(client) {} | 193 : m_client(client) {} |
| 189 | 194 |
| 190 } // namespace blink | 195 } // namespace blink |
| OLD | NEW |