WebCore/ChangeLog

 12010-09-24 Patrick Gansterer <paroga@webkit.org>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 Remove dead code and fix headser includes in ResourceHandleWin
 6 https://bugs.webkit.org/show_bug.cgi?id=46479
 7
 8 * platform/network/ResourceHandle.h:
 9 * platform/network/ResourceHandleInternal.h:
 10 (WebCore::ResourceHandleInternal::ResourceHandleInternal):
 11 * platform/network/win/ResourceHandleWin.cpp:
 12 (WebCore::ResourceHandleInternal::~ResourceHandleInternal):
 13 (WebCore::ResourceHandle::~ResourceHandle):
 14 (WebCore::ResourceHandle::onRequestComplete):
 15 * platform/network/win/ResourceHandleWin.h: Removed.
 16
1172010-09-24 Andrey Kosyakov <caseq@chromium.org>
218
319 Reviewed by Pavel Feldman.
68266

WebCore/platform/network/ResourceHandle.h

@@typedef unsigned long DWORD;
4646typedef unsigned long DWORD_PTR;
4747typedef void* LPVOID;
4848typedef LPVOID HINTERNET;
49 typedef unsigned WPARAM;
50 typedef long LPARAM;
51 typedef struct HWND__* HWND;
52 typedef _W64 long LONG_PTR;
53 typedef LONG_PTR LRESULT;
5449#endif
5550
5651

@@public:
170165#if USE(WININET)
171166 void setSynchronousInternetHandle(HINTERNET);
172167 void fileLoadTimer(Timer<ResourceHandle>*);
173  void onHandleCreated(LPARAM);
174168 void onRedirect();
175169 bool onRequestComplete();
176170 static void CALLBACK internetStatusCallback(HINTERNET, DWORD_PTR, DWORD, LPVOID, DWORD);
177  friend void __stdcall transferJobStatusCallback(HINTERNET, DWORD_PTR, DWORD, LPVOID, DWORD);
178  friend LRESULT __stdcall ResourceHandleWndProc(HWND, unsigned message, WPARAM, LPARAM);
179171#endif
180172
181173#if PLATFORM(QT) || USE(CURL) || USE(SOUP) || PLATFORM(ANDROID)
68265

WebCore/platform/network/ResourceHandleInternal.h

@@namespace WebCore {
9292#endif
9393#if USE(WININET)
9494 , m_fileLoadTimer(loader, &ResourceHandle::fileLoadTimer)
95  , m_resourceHandle(0)
96  , m_secondaryHandle(0)
97  , m_jobId(0)
98  , m_threadId(0)
9995 , m_internetHandle(0)
10096 , m_connectHandle(0)
10197 , m_requestHandle(0)
10298 , m_sentEndRequest(false)
10399 , m_bytesRemainingToWrite(0)
 100 , m_loadSynchronously(false)
104101 , m_hasReceivedResponse(false)
105  , m_resend(false)
106102#endif
107103#if USE(CURL)
108104 , m_handle(0)

@@namespace WebCore {
168164#endif
169165#if USE(WININET)
170166 Timer<ResourceHandle> m_fileLoadTimer;
171  HINTERNET m_resourceHandle;
172  HINTERNET m_secondaryHandle;
173  unsigned m_jobId;
174  DWORD m_threadId;
175167 HINTERNET m_internetHandle;
176168 HINTERNET m_connectHandle;
177169 HINTERNET m_requestHandle;
178170 bool m_sentEndRequest;
179171 Vector<char> m_formData;
180  int m_bytesRemainingToWrite;
181  String m_postReferrer;
 172 size_t m_bytesRemainingToWrite;
 173 bool m_loadSynchronously;
182174 bool m_hasReceivedResponse;
183  bool m_resend;
184175 String m_redirectUrl;
185176#endif
186177#if USE(CURL)
68265

WebCore/platform/network/win/ResourceHandleWin.cpp

2727#include "config.h"
2828#include "ResourceHandle.h"
2929
30 #include "CachedResourceLoader.h"
31 #include "Document.h"
32 #include "Frame.h"
33 #include "FrameLoader.h"
34 #include "Page.h"
 30#include "HTTPParsers.h"
 31#include "MIMETypeRegistry.h"
 32#include "MainThread.h"
 33#include "NotImplemented.h"
3534#include "ResourceError.h"
3635#include "ResourceHandleClient.h"
3736#include "ResourceHandleInternal.h"
38 #include "ResourceHandleWin.h"
 37#include "SharedBuffer.h"
3938#include "Timer.h"
40 #include "WebCoreInstanceHandle.h"
41 
 39#include "UnusedParam.h"
4240#include <wtf/text/CString.h>
4341#include <windows.h>
4442#include <wininet.h>
4543
4644namespace WebCore {
4745
48 static unsigned transferJobId = 0;
49 static HashMap<int, ResourceHandle*>* jobIdMap = 0;
50 
51 static HWND transferJobWindowHandle = 0;
52 const LPCWSTR kResourceHandleWindowClassName = L"ResourceHandleWindowClass";
53 
54 // Message types for internal use (keep in sync with kMessageHandlers)
55 enum {
56  handleCreatedMessage = WM_USER,
57  requestRedirectedMessage,
58  requestCompleteMessage
59 };
60 
61 typedef void (ResourceHandle:: *ResourceHandleEventHandler)(LPARAM);
62 static const ResourceHandleEventHandler messageHandlers[] = {
63  &ResourceHandle::onHandleCreated,
64  &ResourceHandle::onRequestRedirected,
65  &ResourceHandle::onRequestComplete
66 };
67 
6846static inline HINTERNET createInternetHandle(const String& userAgent, bool asynchronous)
6947{
7048 String userAgentString = userAgent;

@@static String queryHTTPHeader(HINTERNET
9674 return String::adopt(characters);
9775}
9876
99 static int addToOutstandingJobs(ResourceHandle* job)
100 {
101  if (!jobIdMap)
102  jobIdMap = new HashMap<int, ResourceHandle*>;
103  transferJobId++;
104  jobIdMap->set(transferJobId, job);
105  return transferJobId;
106 }
107 
108 static void removeFromOutstandingJobs(int jobId)
109 {
110  if (!jobIdMap)
111  return;
112  jobIdMap->remove(jobId);
113 }
114 
115 static ResourceHandle* lookupResourceHandle(int jobId)
116 {
117  if (!jobIdMap)
118  return 0;
119  return jobIdMap->get(jobId);
120 }
121 
122 static LRESULT CALLBACK ResourceHandleWndProc(HWND hWnd, UINT message,
123  WPARAM wParam, LPARAM lParam)
124 {
125  if (message >= handleCreatedMessage) {
126  UINT index = message - handleCreatedMessage;
127  if (index < _countof(messageHandlers)) {
128  unsigned jobId = (unsigned) wParam;
129  ResourceHandle* job = lookupResourceHandle(jobId);
130  if (job) {
131  ASSERT(job->d->m_jobId == jobId);
132  ASSERT(job->d->m_threadId == GetCurrentThreadId());
133  (job->*(messageHandlers[index]))(lParam);
134  }
135  return 0;
136  }
137  }
138  return DefWindowProc(hWnd, message, wParam, lParam);
139 }
140 
141 static void initializeOffScreenResourceHandleWindow()
142 {
143  if (transferJobWindowHandle)
144  return;
145 
146  WNDCLASSEX wcex;
147  memset(&wcex, 0, sizeof(WNDCLASSEX));
148  wcex.cbSize = sizeof(WNDCLASSEX);
149  wcex.lpfnWndProc = ResourceHandleWndProc;
150  wcex.hInstance = WebCore::instanceHandle();
151  wcex.lpszClassName = kResourceHandleWindowClassName;
152  RegisterClassEx(&wcex);
153 
154  transferJobWindowHandle = CreateWindow(kResourceHandleWindowClassName, 0, 0, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
155  HWND_MESSAGE, 0, WebCore::instanceHandle(), 0);
156 }
157 
15877
15978class WebCoreSynchronousLoader : public ResourceHandleClient, public Noncopyable {
16079public:

@@void WebCoreSynchronousLoader::didFail(R
210129
211130ResourceHandleInternal::~ResourceHandleInternal()
212131{
213  if (m_fileHandle != INVALID_HANDLE_VALUE)
214  CloseHandle(m_fileHandle);
215132}
216133
217134ResourceHandle::~ResourceHandle()
218135{
219  if (d->m_jobId)
220  removeFromOutstandingJobs(d->m_jobId);
221 }
222 
223 void ResourceHandle::onHandleCreated(LPARAM lParam)
224 {
225  if (!d->m_resourceHandle) {
226  d->m_resourceHandle = HINTERNET(lParam);
227  if (d->status != 0) {
228  // We were canceled before Windows actually created a handle for us, close and delete now.
229  InternetCloseHandle(d->m_resourceHandle);
230  delete this;
231  return;
232  }
233 
234  if (request().httpMethod() == "POST") {
235  // FIXME: Too late to set referrer properly.
236  String urlStr = request().url().path();
237  int fragmentIndex = urlStr.find('#');
238  if (fragmentIndex != -1)
239  urlStr = urlStr.left(fragmentIndex);
240  static LPCSTR accept[2]={"*/*", NULL};
241  HINTERNET urlHandle = HttpOpenRequestA(d->m_resourceHandle,
242  "POST", urlStr.latin1().data(), 0, 0, accept,
243  INTERNET_FLAG_KEEP_CONNECTION |
244  INTERNET_FLAG_FORMS_SUBMIT |
245  INTERNET_FLAG_RELOAD |
246  INTERNET_FLAG_NO_CACHE_WRITE |
247  INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS |
248  INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP,
249  (DWORD_PTR)d->m_jobId);
250  if (urlHandle == INVALID_HANDLE_VALUE) {
251  InternetCloseHandle(d->m_resourceHandle);
252  delete this;
253  }
254  }
255  } else if (!d->m_secondaryHandle) {
256  assert(request().httpMethod() == "POST");
257  d->m_secondaryHandle = HINTERNET(lParam);
258 
259  // Need to actually send the request now.
260  String headers = "Content-Type: application/x-www-form-urlencoded\n";
261  headers += "Referer: ";
262  headers += d->m_postReferrer;
263  headers += "\n";
264  const CString& headersLatin1 = headers.latin1();
265  if (firstRequest().httpBody()) {
266  firstRequest().httpBody()->flatten(d->m_formData);
267  d->m_bytesRemainingToWrite = d->m_formData.size();
268  }
269  INTERNET_BUFFERSA buffers;
270  memset(&buffers, 0, sizeof(buffers));
271  buffers.dwStructSize = sizeof(INTERNET_BUFFERSA);
272  buffers.lpcszHeader = headersLatin1.data();
273  buffers.dwHeadersLength = headers.length();
274  buffers.dwBufferTotal = d->m_bytesRemainingToWrite;
275 
276  HttpSendRequestExA(d->m_secondaryHandle, &buffers, 0, 0, (DWORD_PTR)d->m_jobId);
277  // FIXME: add proper error handling
278  }
279136}
280137
281138static void callOnRedirect(void* context)

@@bool ResourceHandle::onRequestComplete()
346203 return true;
347204 }
348205
349  HINTERNET handle = (request().httpMethod() == "POST") ? d->m_secondaryHandle : d->m_resourceHandle;
350 
351206 static const int bufferSize = 32768;
352207 char buffer[bufferSize];
353208 INTERNET_BUFFERSA buffers;

@@bool ResourceHandle::onRequestComplete()
400255 InternetCloseHandle(d->m_connectHandle);
401256 deref(); // balances ref in start
402257 return false;
403 }
404 
405 static void __stdcall transferJobStatusCallback(HINTERNET internetHandle,
406  DWORD_PTR jobId,
407  DWORD internetStatus,
408  LPVOID statusInformation,
409  DWORD statusInformationLength)
410 {
411 #ifdef RESOURCE_LOADER_DEBUG
412  char buf[64];
413  _snprintf(buf, sizeof(buf), "status-callback: status=%u, job=%p\n",
414  internetStatus, jobId);
415  OutputDebugStringA(buf);
416 #endif
417 
418  UINT msg;
419  LPARAM lParam;
420 
421  switch (internetStatus) {
422  case INTERNET_STATUS_HANDLE_CREATED:
423  // tell the main thread about the newly created handle
424  msg = handleCreatedMessage;
425  lParam = (LPARAM) LPINTERNET_ASYNC_RESULT(statusInformation)->dwResult;
426  break;
427  case INTERNET_STATUS_REQUEST_COMPLETE:
428 #ifdef RESOURCE_LOADER_DEBUG
429  _snprintf(buf, sizeof(buf), "request-complete: result=%p, error=%u\n",
430  LPINTERNET_ASYNC_RESULT(statusInformation)->dwResult,
431  LPINTERNET_ASYNC_RESULT(statusInformation)->dwError);
432  OutputDebugStringA(buf);
433 #endif
434  // tell the main thread that the request is done
435  msg = requestCompleteMessage;
436  lParam = 0;
437  break;
438  case INTERNET_STATUS_REDIRECT:
439  // tell the main thread to observe this redirect (FIXME: we probably
440  // need to block the redirect at this point so the application can
441  // decide whether or not to follow the redirect)
442  msg = requestRedirectedMessage;
443  lParam = (LPARAM) StringImpl::create((const UChar*) statusInformation,
444  statusInformationLength).releaseRef();
445  break;
446  case INTERNET_STATUS_USER_INPUT_REQUIRED:
447  // FIXME: prompt the user if necessary
448  ResumeSuspendedDownload(internetHandle, 0);
449  case INTERNET_STATUS_STATE_CHANGE:
450  // may need to call ResumeSuspendedDownload here as well
451  default:
452  return;
453  }
454 
455  PostMessage(transferJobWindowHandle, msg, (WPARAM) jobId, lParam);
456258}
457259
458260bool ResourceHandle::start(NetworkingContext* context)
68265

WebCore/platform/network/win/ResourceHandleWin.h

1 /*
2  * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef ResourceHandleWin_h
27 #define ResourceHandleWin_h
28 
29 #include <windows.h>
30 
31 namespace WebCore {
32 
33 struct PlatformDataStruct
34 {
35  DWORD error;
36  BOOL loaded;
37  LPTSTR errorString;
38 };
39 
40 struct PlatformResponseStruct
41 {
42 };
43 
44 }
45 
46 #endif
68265