| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008, 2010 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008, 2010 Apple Inc. All Rights Reserved. |
| 3 * Copyright (C) 2009 Google Inc. All Rights Reserved. | 3 * Copyright (C) 2009 Google Inc. All Rights Reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 namespace WebCore { | 44 namespace WebCore { |
| 45 | 45 |
| 46 inline Worker::Worker(ExecutionContext* context) | 46 inline Worker::Worker(ExecutionContext* context) |
| 47 : AbstractWorker(context) | 47 : AbstractWorker(context) |
| 48 , m_contextProxy(0) | 48 , m_contextProxy(0) |
| 49 { | 49 { |
| 50 ScriptWrappable::init(this); | 50 ScriptWrappable::init(this); |
| 51 } | 51 } |
| 52 | 52 |
| 53 PassRefPtr<Worker> Worker::create(ExecutionContext* context, const String& url,
ExceptionState& exceptionState) | 53 PassRefPtrWillBeRawPtr<Worker> Worker::create(ExecutionContext* context, const S
tring& url, ExceptionState& exceptionState) |
| 54 { | 54 { |
| 55 ASSERT(isMainThread()); | 55 ASSERT(isMainThread()); |
| 56 Document* document = toDocument(context); | 56 Document* document = toDocument(context); |
| 57 UseCounter::count(context, UseCounter::WorkerStart); | 57 UseCounter::count(context, UseCounter::WorkerStart); |
| 58 if (!document->page()) { | 58 if (!document->page()) { |
| 59 exceptionState.throwDOMException(InvalidAccessError, "The context provid
ed is invalid."); | 59 exceptionState.throwDOMException(InvalidAccessError, "The context provid
ed is invalid."); |
| 60 return nullptr; | 60 return nullptr; |
| 61 } | 61 } |
| 62 WorkerGlobalScopeProxyProvider* proxyProvider = WorkerGlobalScopeProxyProvid
er::from(*document->page()); | 62 WorkerGlobalScopeProxyProvider* proxyProvider = WorkerGlobalScopeProxyProvid
er::from(*document->page()); |
| 63 ASSERT(proxyProvider); | 63 ASSERT(proxyProvider); |
| 64 | 64 |
| 65 RefPtr<Worker> worker = adoptRef(new Worker(context)); | 65 RefPtrWillBeRawPtr<Worker> worker = adoptRefWillBeRefCountedGarbageCollected
(new Worker(context)); |
| 66 | 66 |
| 67 worker->suspendIfNeeded(); | 67 worker->suspendIfNeeded(); |
| 68 | 68 |
| 69 KURL scriptURL = worker->resolveURL(url, exceptionState); | 69 KURL scriptURL = worker->resolveURL(url, exceptionState); |
| 70 if (scriptURL.isEmpty()) | 70 if (scriptURL.isEmpty()) |
| 71 return nullptr; | 71 return nullptr; |
| 72 | 72 |
| 73 // The worker context does not exist while loading, so we must ensure that t
he worker object is not collected, nor are its event listeners. | 73 // The worker context does not exist while loading, so we must ensure that t
he worker object is not collected, nor are its event listeners. |
| 74 worker->setPendingActivity(worker.get()); | 74 worker->setPendingActivity(worker.get()); |
| 75 | 75 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 96 { | 96 { |
| 97 // Disentangle the port in preparation for sending it to the remote context. | 97 // Disentangle the port in preparation for sending it to the remote context. |
| 98 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(por
ts, exceptionState); | 98 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(por
ts, exceptionState); |
| 99 if (exceptionState.hadException()) | 99 if (exceptionState.hadException()) |
| 100 return; | 100 return; |
| 101 m_contextProxy->postMessageToWorkerGlobalScope(message, channels.release()); | 101 m_contextProxy->postMessageToWorkerGlobalScope(message, channels.release()); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void Worker::terminate() | 104 void Worker::terminate() |
| 105 { | 105 { |
| 106 m_contextProxy->terminateWorkerGlobalScope(); | 106 if (m_contextProxy) |
| 107 m_contextProxy->terminateWorkerGlobalScope(); |
| 107 } | 108 } |
| 108 | 109 |
| 109 void Worker::stop() | 110 void Worker::stop() |
| 110 { | 111 { |
| 111 terminate(); | 112 terminate(); |
| 112 } | 113 } |
| 113 | 114 |
| 114 bool Worker::hasPendingActivity() const | 115 bool Worker::hasPendingActivity() const |
| 115 { | 116 { |
| 116 return m_contextProxy->hasPendingActivity() || ActiveDOMObject::hasPendingAc
tivity(); | 117 return m_contextProxy->hasPendingActivity() || ActiveDOMObject::hasPendingAc
tivity(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 130 if (InspectorInstrumentation::shouldPauseDedicatedWorkerOnStart(executio
nContext())) | 131 if (InspectorInstrumentation::shouldPauseDedicatedWorkerOnStart(executio
nContext())) |
| 131 startMode = PauseWorkerGlobalScopeOnStart; | 132 startMode = PauseWorkerGlobalScopeOnStart; |
| 132 m_contextProxy->startWorkerGlobalScope(m_scriptLoader->url(), executionC
ontext()->userAgent(m_scriptLoader->url()), m_scriptLoader->script(), startMode)
; | 133 m_contextProxy->startWorkerGlobalScope(m_scriptLoader->url(), executionC
ontext()->userAgent(m_scriptLoader->url()), m_scriptLoader->script(), startMode)
; |
| 133 InspectorInstrumentation::scriptImported(executionContext(), m_scriptLoa
der->identifier(), m_scriptLoader->script()); | 134 InspectorInstrumentation::scriptImported(executionContext(), m_scriptLoa
der->identifier(), m_scriptLoader->script()); |
| 134 } | 135 } |
| 135 m_scriptLoader = nullptr; | 136 m_scriptLoader = nullptr; |
| 136 | 137 |
| 137 unsetPendingActivity(this); | 138 unsetPendingActivity(this); |
| 138 } | 139 } |
| 139 | 140 |
| 141 void Worker::trace(Visitor* visitor) |
| 142 { |
| 143 AbstractWorker::trace(visitor); |
| 144 } |
| 145 |
| 140 } // namespace WebCore | 146 } // namespace WebCore |
| OLD | NEW |