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

Side by Side Diff: Source/core/xml/XMLHttpRequest.h

Issue 104363002: [XHR] Use hasPendingActivity() to manage XHR's life time. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 6 years, 11 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
« no previous file with comments | « no previous file | Source/core/xml/XMLHttpRequest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003, 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2006, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2005, 2006 Alexey Proskuryakov <ap@nypop.com> 3 * Copyright (C) 2005, 2006 Alexey Proskuryakov <ap@nypop.com>
4 * Copyright (C) 2011 Google Inc. All rights reserved. 4 * Copyright (C) 2011 Google Inc. All rights reserved.
5 * Copyright (C) 2012 Intel Corporation 5 * Copyright (C) 2012 Intel Corporation
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public 8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 12 matching lines...) Expand all
23 #define XMLHttpRequest_h 23 #define XMLHttpRequest_h
24 24
25 #include "bindings/v8/ScriptString.h" 25 #include "bindings/v8/ScriptString.h"
26 #include "bindings/v8/ScriptWrappable.h" 26 #include "bindings/v8/ScriptWrappable.h"
27 #include "core/dom/ActiveDOMObject.h" 27 #include "core/dom/ActiveDOMObject.h"
28 #include "core/events/EventListener.h" 28 #include "core/events/EventListener.h"
29 #include "core/events/ThreadLocalEventNames.h" 29 #include "core/events/ThreadLocalEventNames.h"
30 #include "core/loader/ThreadableLoaderClient.h" 30 #include "core/loader/ThreadableLoaderClient.h"
31 #include "core/xml/XMLHttpRequestEventTarget.h" 31 #include "core/xml/XMLHttpRequestEventTarget.h"
32 #include "core/xml/XMLHttpRequestProgressEventThrottle.h" 32 #include "core/xml/XMLHttpRequestProgressEventThrottle.h"
33 #include "platform/AsyncMethodRunner.h"
34 #include "platform/network/FormData.h" 33 #include "platform/network/FormData.h"
35 #include "platform/network/ResourceResponse.h" 34 #include "platform/network/ResourceResponse.h"
36 #include "platform/weborigin/SecurityOrigin.h" 35 #include "platform/weborigin/SecurityOrigin.h"
37 #include "wtf/OwnPtr.h" 36 #include "wtf/OwnPtr.h"
38 #include "wtf/text/AtomicStringHash.h" 37 #include "wtf/text/AtomicStringHash.h"
39 #include "wtf/text/StringBuilder.h" 38 #include "wtf/text/StringBuilder.h"
40 39
41 namespace WebCore { 40 namespace WebCore {
42 41
43 class Blob; 42 class Blob;
44 class DOMFormData; 43 class DOMFormData;
45 class Document; 44 class Document;
46 class ExceptionState; 45 class ExceptionState;
47 class ResourceRequest; 46 class ResourceRequest;
48 class SecurityOrigin; 47 class SecurityOrigin;
49 class SharedBuffer; 48 class SharedBuffer;
50 class Stream; 49 class Stream;
51 class TextResourceDecoder; 50 class TextResourceDecoder;
52 class ThreadableLoader; 51 class ThreadableLoader;
53 52
54 typedef int ExceptionCode; 53 typedef int ExceptionCode;
55 54
56 class XMLHttpRequest FINAL : public ScriptWrappable, public RefCounted<XMLHttpRe quest>, public XMLHttpRequestEventTarget, private ThreadableLoaderClient, public ActiveDOMObject { 55 class XMLHttpRequest FINAL : public ScriptWrappable, public RefCounted<XMLHttpRe quest>, public XMLHttpRequestEventTarget, private ThreadableLoaderClient, public ActiveDOMObject {
57 WTF_MAKE_FAST_ALLOCATED; 56 WTF_MAKE_FAST_ALLOCATED;
58 REFCOUNTED_EVENT_TARGET(XMLHttpRequest); 57 REFCOUNTED_EVENT_TARGET(XMLHttpRequest);
59 public: 58 public:
59 // XMLHttpRequest instances must be used with a wrapper since this class's
60 // lifetime management is designed assuming the V8 holds a ref on it while
61 // hasPendingActivity() returns true.
60 static PassRefPtr<XMLHttpRequest> create(ExecutionContext*, PassRefPtr<Secur ityOrigin> = 0); 62 static PassRefPtr<XMLHttpRequest> create(ExecutionContext*, PassRefPtr<Secur ityOrigin> = 0);
61 virtual ~XMLHttpRequest(); 63 virtual ~XMLHttpRequest();
62 64
63 // These exact numeric values are important because JS expects them. 65 // These exact numeric values are important because JS expects them.
64 enum State { 66 enum State {
65 UNSENT = 0, 67 UNSENT = 0,
66 OPENED = 1, 68 OPENED = 1,
67 HEADERS_RECEIVED = 2, 69 HEADERS_RECEIVED = 2,
68 LOADING = 3, 70 LOADING = 3,
69 DONE = 4 71 DONE = 4
70 }; 72 };
71 73
72 enum ResponseTypeCode { 74 enum ResponseTypeCode {
73 ResponseTypeDefault, 75 ResponseTypeDefault,
74 ResponseTypeText, 76 ResponseTypeText,
75 ResponseTypeJSON, 77 ResponseTypeJSON,
76 ResponseTypeDocument, 78 ResponseTypeDocument,
77 ResponseTypeBlob, 79 ResponseTypeBlob,
78 ResponseTypeArrayBuffer, 80 ResponseTypeArrayBuffer,
79 ResponseTypeStream 81 ResponseTypeStream
80 }; 82 };
81 83
82 enum DropProtection { 84 // ActiveDOMObject implementaions
83 DropProtectionSync,
84 DropProtectionAsync,
85 };
86
87 virtual void contextDestroyed() OVERRIDE; 85 virtual void contextDestroyed() OVERRIDE;
86 // Keep the JavaScript wrapper alive while a request is in progress so that
87 // this object (which is a listener for m_loader) is also kept alive.
88 virtual bool hasPendingActivity() const OVERRIDE;
88 virtual void suspend() OVERRIDE; 89 virtual void suspend() OVERRIDE;
89 virtual void resume() OVERRIDE; 90 virtual void resume() OVERRIDE;
90 virtual void stop() OVERRIDE; 91 virtual void stop() OVERRIDE;
91 92
92 virtual const AtomicString& interfaceName() const OVERRIDE; 93 virtual const AtomicString& interfaceName() const OVERRIDE;
93 virtual ExecutionContext* executionContext() const OVERRIDE; 94 virtual ExecutionContext* executionContext() const OVERRIDE;
94 95
95 const KURL& url() const { return m_url; } 96 const KURL& url() const { return m_url; }
96 String statusText() const; 97 String statusText() const;
97 int status() const; 98 int status() const;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 170
170 const AtomicString& getRequestHeader(const AtomicString& name) const; 171 const AtomicString& getRequestHeader(const AtomicString& name) const;
171 void setRequestHeaderInternal(const AtomicString& name, const AtomicString& value); 172 void setRequestHeaderInternal(const AtomicString& name, const AtomicString& value);
172 173
173 void trackProgress(int dataLength); 174 void trackProgress(int dataLength);
174 // Changes m_state and dispatches a readyStateChange event if new m_state 175 // Changes m_state and dispatches a readyStateChange event if new m_state
175 // value is different from last one. 176 // value is different from last one.
176 void changeState(State newState); 177 void changeState(State newState);
177 void dispatchReadyStateChangeEvent(); 178 void dispatchReadyStateChangeEvent();
178 179
179 void dropProtectionSoon();
180 void dropProtection();
181 // Clears variables used only while the resource is being loaded. 180 // Clears variables used only while the resource is being loaded.
182 void clearVariablesForLoading(); 181 void clearVariablesForLoading();
183 // Returns false iff reentry happened and a new load is started. 182 // Returns false iff reentry happened and a new load is started. This
184 bool internalAbort(DropProtection = DropProtectionSync); 183 // instance may be destroyed after this method call. If you need do some
184 // work later, put a temporary reference on this instance before calling
185 // this method
186 bool internalAbort();
185 // Clears variables holding response header and body data. 187 // Clears variables holding response header and body data.
186 void clearResponse(); 188 void clearResponse();
187 void clearRequest(); 189 void clearRequest();
188 190
189 void createRequest(ExceptionState&); 191 void createRequest(ExceptionState&);
190 192
191 // Dispatches an event of the specified type to m_progressEventThrottle. 193 // Dispatches an event of the specified type to m_progressEventThrottle.
192 void dispatchEventAndLoadEnd(const AtomicString&, long long, long long); 194 void dispatchEventAndLoadEnd(const AtomicString&, long long, long long);
193 195
194 // Dispatches a response progress event to m_progressEventThrottle. 196 // Dispatches a response progress event to m_progressEventThrottle.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 String m_lastSendURL; 256 String m_lastSendURL;
255 // An exception to throw in synchronous mode. It's set when failure 257 // An exception to throw in synchronous mode. It's set when failure
256 // notification is received from m_loader and thrown at the end of send() if 258 // notification is received from m_loader and thrown at the end of send() if
257 // any. 259 // any.
258 ExceptionCode m_exceptionCode; 260 ExceptionCode m_exceptionCode;
259 261
260 XMLHttpRequestProgressEventThrottle m_progressEventThrottle; 262 XMLHttpRequestProgressEventThrottle m_progressEventThrottle;
261 263
262 // An enum corresponding to the allowed string values for the responseType a ttribute. 264 // An enum corresponding to the allowed string values for the responseType a ttribute.
263 ResponseTypeCode m_responseTypeCode; 265 ResponseTypeCode m_responseTypeCode;
264 AsyncMethodRunner<XMLHttpRequest> m_dropProtectionRunner;
265 RefPtr<SecurityOrigin> m_securityOrigin; 266 RefPtr<SecurityOrigin> m_securityOrigin;
266 }; 267 };
267 268
268 } // namespace WebCore 269 } // namespace WebCore
269 270
270 #endif // XMLHttpRequest_h 271 #endif // XMLHttpRequest_h
OLDNEW
« no previous file with comments | « no previous file | Source/core/xml/XMLHttpRequest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698