OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 } | 45 } |
46 | 46 |
47 IntentRequest::IntentRequest(ScriptExecutionContext* context, | 47 IntentRequest::IntentRequest(ScriptExecutionContext* context, |
48 PassRefPtr<Intent> intent, | 48 PassRefPtr<Intent> intent, |
49 PassRefPtr<IntentResultCallback> successCallback, | 49 PassRefPtr<IntentResultCallback> successCallback, |
50 PassRefPtr<IntentResultCallback> errorCallback) | 50 PassRefPtr<IntentResultCallback> errorCallback) |
51 : ActiveDOMObject(context, this) | 51 : ActiveDOMObject(context, this) |
52 , m_intent(intent) | 52 , m_intent(intent) |
53 , m_successCallback(successCallback) | 53 , m_successCallback(successCallback) |
54 , m_errorCallback(errorCallback) | 54 , m_errorCallback(errorCallback) |
| 55 , m_stopped(false) |
55 { | 56 { |
56 } | 57 } |
57 | 58 |
58 void IntentRequest::contextDestroyed() | 59 void IntentRequest::contextDestroyed() |
59 { | 60 { |
60 ContextDestructionObserver::contextDestroyed(); | 61 ContextDestructionObserver::contextDestroyed(); |
61 m_successCallback.clear(); | 62 m_stopped = true; |
62 m_errorCallback.clear(); | |
63 } | 63 } |
64 | 64 |
65 void IntentRequest::stop() | 65 void IntentRequest::stop() |
66 { | 66 { |
67 m_successCallback.clear(); | 67 m_stopped = true; |
68 m_errorCallback.clear(); | |
69 } | 68 } |
70 | 69 |
71 void IntentRequest::postResult(SerializedScriptValue* data) | 70 void IntentRequest::postResult(SerializedScriptValue* data) |
72 { | 71 { |
| 72 if (m_stopped) |
| 73 return; |
| 74 |
73 // Callback could lead to deletion of this. | 75 // Callback could lead to deletion of this. |
74 RefPtr<IntentRequest> protector(this); | 76 RefPtr<IntentRequest> protector(this); |
75 | 77 |
76 if (!m_successCallback) | 78 if (!m_successCallback) |
77 return; | 79 return; |
78 | 80 |
79 m_successCallback->handleEvent(data); | 81 m_successCallback->handleEvent(data); |
80 | 82 |
81 m_successCallback.clear(); | 83 m_successCallback.clear(); |
82 m_errorCallback.clear(); | 84 m_errorCallback.clear(); |
83 } | 85 } |
84 | 86 |
85 void IntentRequest::postFailure(SerializedScriptValue* data) | 87 void IntentRequest::postFailure(SerializedScriptValue* data) |
86 { | 88 { |
| 89 if (m_stopped) |
| 90 return; |
| 91 |
87 // Callback could lead to deletion of this. | 92 // Callback could lead to deletion of this. |
88 RefPtr<IntentRequest> protector(this); | 93 RefPtr<IntentRequest> protector(this); |
89 | 94 |
90 if (!m_errorCallback) | 95 if (!m_errorCallback) |
91 return; | 96 return; |
92 | 97 |
93 m_errorCallback->handleEvent(data); | 98 m_errorCallback->handleEvent(data); |
94 | 99 |
95 m_successCallback.clear(); | 100 m_successCallback.clear(); |
96 m_errorCallback.clear(); | 101 m_errorCallback.clear(); |
97 } | 102 } |
98 | 103 |
99 } // namespace WebCore | 104 } // namespace WebCore |
100 | 105 |
101 #endif // ENABLE(WEB_INTENTS) | 106 #endif // ENABLE(WEB_INTENTS) |
OLD | NEW |