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 = adoptRefCountedWillBeRefCountedGarbageCo llected(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 // NOTE: oilpan: if the Worker fails to fully construct (e.g., invalid URL), |
sof
2014/02/24 12:53:29
I'll remove this comment before finalizing; just w
| |
107 // it'll be without a 'context proxy' object but in the heap. If the documen t | |
108 // is detached prior to the next GC, it stops active DOM objects, which | |
109 // will run into a null ptr crash here. Hence, the need for the check. | |
110 if (m_contextProxy) | |
111 m_contextProxy->terminateWorkerGlobalScope(); | |
haraken
2014/02/24 13:28:36
Don't you need to clear m_contextProxy in terminat
| |
107 } | 112 } |
108 | 113 |
109 void Worker::stop() | 114 void Worker::stop() |
110 { | 115 { |
111 terminate(); | 116 terminate(); |
112 } | 117 } |
113 | 118 |
114 bool Worker::hasPendingActivity() const | 119 bool Worker::hasPendingActivity() const |
115 { | 120 { |
116 return m_contextProxy->hasPendingActivity() || ActiveDOMObject::hasPendingAc tivity(); | 121 return m_contextProxy->hasPendingActivity() || ActiveDOMObject::hasPendingAc tivity(); |
(...skipping 13 matching lines...) Expand all Loading... | |
130 if (InspectorInstrumentation::shouldPauseDedicatedWorkerOnStart(executio nContext())) | 135 if (InspectorInstrumentation::shouldPauseDedicatedWorkerOnStart(executio nContext())) |
131 startMode = PauseWorkerGlobalScopeOnStart; | 136 startMode = PauseWorkerGlobalScopeOnStart; |
132 m_contextProxy->startWorkerGlobalScope(m_scriptLoader->url(), executionC ontext()->userAgent(m_scriptLoader->url()), m_scriptLoader->script(), startMode) ; | 137 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()); | 138 InspectorInstrumentation::scriptImported(executionContext(), m_scriptLoa der->identifier(), m_scriptLoader->script()); |
134 } | 139 } |
135 m_scriptLoader = nullptr; | 140 m_scriptLoader = nullptr; |
136 | 141 |
137 unsetPendingActivity(this); | 142 unsetPendingActivity(this); |
138 } | 143 } |
139 | 144 |
145 void Worker::trace(Visitor* visitor) | |
146 { | |
147 visitor->trace(m_scriptLoader); | |
148 } | |
149 | |
140 } // namespace WebCore | 150 } // namespace WebCore |
OLD | NEW |