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

Side by Side Diff: WebCore/bindings/generic/ActiveDOMCallback.cpp

Issue 9572031: Don't be so CRASH happy in the bindings layer. (Closed) Base URL: http://svn.webkit.org/repository/webkit/trunk/Source/
Patch Set: Created 8 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 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 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 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "ActiveDOMCallback.h" 32 #include "ActiveDOMCallback.h"
33 33
34 #include "ActiveDOMObject.h" 34 #include "ActiveDOMObject.h"
35 #include "ScriptExecutionContext.h" 35 #include "ScriptExecutionContext.h"
36 #include <wtf/PassOwnPtr.h> 36 #include "WorkerContext.h"
37 #include <wtf/ThreadingPrimitives.h>
38 37
39 namespace WebCore { 38 namespace WebCore {
40 39
41 static void destroyOnContextThread(PassOwnPtr<ActiveDOMObjectCallbackImpl>); 40 ActiveDOMCallback::ActiveDOMCallback(ScriptExecutionContext* context)
42 41 : ContextDestructionObserver(context)
43 class DestroyOnContextThreadTask : public ScriptExecutionContext::Task {
44 public:
45 static PassOwnPtr<DestroyOnContextThreadTask> create(PassOwnPtr<ActiveDOMObj ectCallbackImpl> impl)
46 {
47 return adoptPtr(new DestroyOnContextThreadTask(impl));
48 }
49
50 virtual void performTask(ScriptExecutionContext*)
51 {
52 destroyOnContextThread(m_impl.release());
53 }
54
55 private:
56 DestroyOnContextThreadTask(PassOwnPtr<ActiveDOMObjectCallbackImpl> impl)
57 : m_impl(impl)
58 {
59 }
60
61 OwnPtr<ActiveDOMObjectCallbackImpl> m_impl;
62 };
63
64 class ActiveDOMObjectCallbackImpl : public ActiveDOMObject {
65 public:
66 ActiveDOMObjectCallbackImpl(ScriptExecutionContext* context)
67 : ActiveDOMObject(context, this)
68 , m_suspended(false)
69 , m_stopped(false)
70 {
71 }
72
73 virtual void contextDestroyed()
74 {
75 MutexLocker locker(m_mutex);
76 ActiveDOMObject::contextDestroyed();
77 }
78 virtual bool canSuspend() const { return false; }
79 virtual void suspend(ReasonForSuspension)
80 {
81 MutexLocker locker(m_mutex);
82 m_suspended = true;
83 }
84 virtual void resume()
85 {
86 MutexLocker locker(m_mutex);
87 m_suspended = false;
88 }
89 virtual void stop()
90 {
91 MutexLocker locker(m_mutex);
92 m_stopped = true;
93 }
94 bool canInvokeCallback()
95 {
96 MutexLocker locker(m_mutex);
97 return (!m_suspended && !m_stopped);
98 }
99 ScriptExecutionContext* scriptExecutionContext()
100 {
101 MutexLocker locker(m_mutex);
102 return ActiveDOMObject::scriptExecutionContext();
103 }
104 Mutex& mutex() { return m_mutex; }
105
106 private:
107 Mutex m_mutex;
108 bool m_suspended;
109 bool m_stopped;
110 };
111
112 static void destroyOnContextThread(PassOwnPtr<ActiveDOMObjectCallbackImpl> impl)
113 { 42 {
114 OwnPtr<ActiveDOMObjectCallbackImpl> implOwnPtr = impl;
115
116 ScriptExecutionContext* context = implOwnPtr->scriptExecutionContext();
117 MutexLocker locker(implOwnPtr->mutex());
118 if (context && !context->isContextThread())
119 context->postTask(DestroyOnContextThreadTask::create(implOwnPtr.release( )));
120 }
121
122 ActiveDOMCallback::ActiveDOMCallback(ScriptExecutionContext* context)
123 : m_impl(adoptPtr(new ActiveDOMObjectCallbackImpl(context)))
124 {
125 m_impl->suspendIfNeeded();
126 } 43 }
127 44
128 ActiveDOMCallback::~ActiveDOMCallback() 45 ActiveDOMCallback::~ActiveDOMCallback()
129 { 46 {
130 destroyOnContextThread(m_impl.release());
131 } 47 }
132 48
133 bool ActiveDOMCallback::canInvokeCallback() const 49 bool ActiveDOMCallback::canInvokeCallback() const
134 { 50 {
135 return m_impl->canInvokeCallback(); 51 ScriptExecutionContext* context = scriptExecutionContext();
52 return context && !context->activeDOMObjectsAreSuspended() && !context->acti veDOMObjectsAreStopped();
136 } 53 }
137 54
138 ScriptExecutionContext* ActiveDOMCallback::scriptExecutionContext() const 55 bool ActiveDOMCallback::isScriptControllerTerminating() const
139 { 56 {
140 return m_impl->scriptExecutionContext(); 57 ScriptExecutionContext* context = scriptExecutionContext();
58 if (context && context->isWorkerContext()) {
59 WorkerScriptController* scriptController = static_cast<WorkerContext*>(c ontext)->script();
60 if (!scriptController || scriptController->isExecutionForbidden() || scr iptController->isExecutionTerminating())
61 return true;
62 }
63 return false;
141 } 64 }
142 65
143 } // namespace WebCore 66 } // namespace WebCore
OLDNEW
« no previous file with comments | « WebCore/bindings/generic/ActiveDOMCallback.h ('k') | WebCore/bindings/js/WorkerScriptController.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698