[Release] Webkit-EFL Ver. 2.0_beta_118996_0.6.24
[framework/web/webkit-efl.git] / Tools / WinLauncher / WinLauncher.cpp
1 /*
2  * Copyright (C) 2006, 2008 Apple Computer, Inc.  All rights reserved.
3  * Copyright (C) 2009, 2011 Brent Fulgham.  All rights reserved.
4  * Copyright (C) 2009, 2010, 2011 Appcelerator, Inc. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
26  */
27
28 #include "stdafx.h"
29 #include "WinLauncher.h"
30
31 #include "DOMDefaultImpl.h"
32 #include "PrintWebUIDelegate.h"
33 #include <WebKit/WebKitCOMAPI.h>
34
35 #include <commctrl.h>
36 #include <commdlg.h>
37 #include <objbase.h>
38 #include <shellapi.h>
39 #include <shlwapi.h>
40 #include <string>
41 #include <wininet.h>
42
43 #define MAX_LOADSTRING 100
44 #define URLBAR_HEIGHT  24
45
46 // Global Variables:
47 HINSTANCE hInst;                                // current instance
48 HWND hMainWnd;
49 HWND hURLBarWnd;
50 WNDPROC DefEditProc = 0;
51 WNDPROC DefWebKitProc = 0;
52 IWebView* gWebView = 0;
53 IWebViewPrivate* gWebViewPrivate = 0;
54 HWND gViewWindow = 0;
55 WinLauncherWebHost* gWebHost = 0;
56 PrintWebUIDelegate* gPrintDelegate = 0;
57 TCHAR szTitle[MAX_LOADSTRING];                    // The title bar text
58 TCHAR szWindowClass[MAX_LOADSTRING];            // the main window class name
59
60 // Support moving the transparent window
61 POINT s_windowPosition = { 100, 100 };
62 SIZE s_windowSize = { 800, 400 };
63 bool s_usesLayeredWebView = false;
64 bool s_fullDesktop = false;
65
66 // Forward declarations of functions included in this code module:
67 ATOM                MyRegisterClass(HINSTANCE hInstance);
68 LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
69 INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
70 LRESULT CALLBACK    MyEditProc(HWND, UINT, WPARAM, LPARAM);
71
72 static void loadURL(BSTR urlBStr);
73
74 static bool usesLayeredWebView()
75 {
76     return s_usesLayeredWebView;
77 }
78
79 static bool shouldUseFullDesktop()
80 {
81     return s_fullDesktop;
82 }
83
84 class SimpleEventListener : public DOMEventListener {
85 public:
86     SimpleEventListener(LPWSTR type)
87     {
88         wcsncpy_s(m_eventType, 100, type, 100);
89         m_eventType[99] = 0;
90     }
91
92     virtual HRESULT STDMETHODCALLTYPE handleEvent(IDOMEvent* evt)
93     {
94         wchar_t message[255];
95         wcscpy_s(message, 255, m_eventType);
96         wcscat_s(message, 255, L" event fired!");
97         ::MessageBox(0, message, L"Event Handler", MB_OK);
98         return S_OK;
99     }
100
101 private:
102     wchar_t m_eventType[100];
103 };
104
105 HRESULT WinLauncherWebHost::updateAddressBar(IWebView* webView)
106 {
107     IWebFrame* mainFrame = 0;
108     IWebDataSource* dataSource = 0;
109     IWebMutableURLRequest* request = 0;
110     BSTR frameURL = 0;
111
112     HRESULT hr = S_OK;
113
114     hr = webView->mainFrame(&mainFrame);
115     if (FAILED(hr))
116         goto exit;
117
118     hr = mainFrame->dataSource(&dataSource);
119     if (FAILED(hr) || !dataSource)
120         hr = mainFrame->provisionalDataSource(&dataSource);
121     if (FAILED(hr) || !dataSource)
122         goto exit;
123
124     hr = dataSource->request(&request);
125     if (FAILED(hr) || !request)
126         goto exit;
127
128     hr = request->mainDocumentURL(&frameURL);
129     if (FAILED(hr))
130         goto exit;
131
132     SendMessage(hURLBarWnd, (UINT)WM_SETTEXT, 0, (LPARAM)frameURL);
133
134 exit:
135     if (mainFrame)
136         mainFrame->Release();
137     if (dataSource)
138         dataSource->Release();
139     if (request)
140         request->Release();
141     SysFreeString(frameURL);
142     return 0;
143 }
144
145 HRESULT STDMETHODCALLTYPE WinLauncherWebHost::QueryInterface(REFIID riid, void** ppvObject)
146 {
147     *ppvObject = 0;
148     if (IsEqualGUID(riid, IID_IUnknown))
149         *ppvObject = static_cast<IWebFrameLoadDelegate*>(this);
150     else if (IsEqualGUID(riid, IID_IWebFrameLoadDelegate))
151         *ppvObject = static_cast<IWebFrameLoadDelegate*>(this);
152     else
153         return E_NOINTERFACE;
154
155     AddRef();
156     return S_OK;
157 }
158
159 ULONG STDMETHODCALLTYPE WinLauncherWebHost::AddRef(void)
160 {
161     return ++m_refCount;
162 }
163
164 ULONG STDMETHODCALLTYPE WinLauncherWebHost::Release(void)
165 {
166     ULONG newRef = --m_refCount;
167     if (!newRef)
168         delete(this);
169
170     return newRef;
171 }
172
173 HRESULT WinLauncherWebHost::didFinishLoadForFrame(IWebView* webView, IWebFrame* frame)
174 {
175     IDOMDocument* doc = 0;
176     frame->DOMDocument(&doc);
177
178     IDOMElement* element = 0;
179     IDOMEventTarget* target = 0;
180     HRESULT hr = doc->getElementById(L"webkit logo", &element);
181     if (!SUCCEEDED(hr))
182         goto exit;
183
184     hr = element->QueryInterface(IID_IDOMEventTarget, reinterpret_cast<void**>(&target));
185     if (!SUCCEEDED(hr))
186         goto exit;
187
188     hr = target->addEventListener(L"click", new SimpleEventListener (L"webkit logo click"), FALSE);
189     if (!SUCCEEDED(hr))
190         goto exit;
191
192 exit:
193     if (target)
194         target->Release();
195     if (element)
196         element->Release();
197     if (doc)
198         doc->Release();
199
200     return hr;
201 }
202
203 static void resizeSubViews()
204 {
205     if (usesLayeredWebView() || !gViewWindow)
206         return;
207
208     RECT rcClient;
209     GetClientRect(hMainWnd, &rcClient);
210     MoveWindow(hURLBarWnd, 0, 0, rcClient.right, URLBAR_HEIGHT, TRUE);
211     MoveWindow(gViewWindow, 0, URLBAR_HEIGHT, rcClient.right, rcClient.bottom - URLBAR_HEIGHT, TRUE);
212 }
213
214 static void subclassForLayeredWindow()
215 {
216     hMainWnd = gViewWindow;
217     DefWebKitProc = reinterpret_cast<WNDPROC>(::GetWindowLongPtr(hMainWnd, GWL_WNDPROC));
218     ::SetWindowLongPtr(hMainWnd, GWL_WNDPROC, reinterpret_cast<LONG_PTR>(WndProc));
219 }
220
221 static void computeFullDesktopFrame()
222 {
223     RECT desktop;
224     if (!::SystemParametersInfo(SPI_GETWORKAREA, 0, static_cast<void*>(&desktop), 0))
225         return;
226
227     s_windowPosition.x = 0;
228     s_windowPosition.y = 0;
229     s_windowSize.cx = desktop.right - desktop.left;
230     s_windowSize.cy = desktop.bottom - desktop.top;
231 }
232
233 BOOL WINAPI DllMain(HINSTANCE dllInstance, DWORD reason, LPVOID)
234 {
235     if (reason == DLL_PROCESS_ATTACH)
236         hInst = dllInstance;
237
238     return TRUE;
239 }
240
241 extern "C" __declspec(dllexport) int WINAPI dllLauncherEntryPoint(HINSTANCE, HINSTANCE, LPTSTR, int nCmdShow)
242 {
243 #ifdef _CRTDBG_MAP_ALLOC
244     _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
245     _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
246 #endif
247
248      // TODO: Place code here.
249     MSG msg = {0};
250     HACCEL hAccelTable;
251
252     INITCOMMONCONTROLSEX InitCtrlEx;
253
254     InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX);
255     InitCtrlEx.dwICC  = 0x00004000; //ICC_STANDARD_CLASSES;
256     InitCommonControlsEx(&InitCtrlEx);
257
258     int argc = 0;
259     WCHAR** argv = CommandLineToArgvW(GetCommandLineW(), &argc);
260     for (int i = 1; i < argc; ++i) {
261         if (!wcsicmp(argv[i], L"--transparent"))
262             s_usesLayeredWebView = true;
263         else if (!wcsicmp(argv[i], L"--desktop"))
264             s_fullDesktop = true;
265     }
266
267     // Initialize global strings
268     LoadString(hInst, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
269     LoadString(hInst, IDC_WINLAUNCHER, szWindowClass, MAX_LOADSTRING);
270     MyRegisterClass(hInst);
271
272     if (shouldUseFullDesktop())
273         computeFullDesktopFrame();
274
275     // Init COM
276     OleInitialize(NULL);
277
278     if (usesLayeredWebView()) {
279         hURLBarWnd = CreateWindow(L"EDIT", L"Type URL Here",
280                     WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOVSCROLL, 
281                     s_windowPosition.x, s_windowPosition.y + s_windowSize.cy, s_windowSize.cx, URLBAR_HEIGHT,
282                     0,
283                     0,
284                     hInst, 0);
285     } else {
286         hMainWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
287                        CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0, 0, hInst, 0);
288
289         if (!hMainWnd)
290             return FALSE;
291
292         hURLBarWnd = CreateWindow(L"EDIT", 0,
293                     WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOVSCROLL, 
294                     0, 0, 0, 0,
295                     hMainWnd,
296                     0,
297                     hInst, 0);
298
299         ShowWindow(hMainWnd, nCmdShow);
300         UpdateWindow(hMainWnd);
301     }
302
303     DefEditProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(hURLBarWnd, GWL_WNDPROC));
304     SetWindowLongPtr(hURLBarWnd, GWL_WNDPROC, reinterpret_cast<LONG_PTR>(MyEditProc));
305     SetFocus(hURLBarWnd);
306
307     RECT clientRect = { s_windowPosition.x, s_windowPosition.y, s_windowPosition.x + s_windowSize.cx, s_windowPosition.y + s_windowSize.cy };
308
309     IWebPreferences* tmpPreferences = 0;
310     IWebPreferences* standardPreferences = 0;
311     if (FAILED(WebKitCreateInstance(CLSID_WebPreferences, 0, IID_IWebPreferences, reinterpret_cast<void**>(&tmpPreferences))))
312         goto exit;
313
314     if (FAILED(tmpPreferences->standardPreferences(&standardPreferences)))
315         goto exit;
316
317     standardPreferences->setAcceleratedCompositingEnabled(TRUE);
318
319     HRESULT hr = WebKitCreateInstance(CLSID_WebView, 0, IID_IWebView, reinterpret_cast<void**>(&gWebView));
320     if (FAILED(hr))
321         goto exit;
322
323     hr = gWebView->QueryInterface(IID_IWebViewPrivate, reinterpret_cast<void**>(&gWebViewPrivate));
324     if (FAILED(hr))
325         goto exit;
326
327     gWebHost = new WinLauncherWebHost();
328     gWebHost->AddRef();
329     hr = gWebView->setFrameLoadDelegate(gWebHost);
330     if (FAILED(hr))
331         goto exit;
332
333     gPrintDelegate = new PrintWebUIDelegate;
334     gPrintDelegate->AddRef();
335     hr = gWebView->setUIDelegate(gPrintDelegate);
336     if (FAILED (hr))
337         goto exit;
338
339     hr = gWebView->setHostWindow(reinterpret_cast<OLE_HANDLE>(hMainWnd));
340     if (FAILED(hr))
341         goto exit;
342
343     hr = gWebView->initWithFrame(clientRect, 0, 0);
344     if (FAILED(hr))
345         goto exit;
346
347     IWebFrame* frame;
348     hr = gWebView->mainFrame(&frame);
349     if (FAILED(hr))
350         goto exit;
351
352     static BSTR defaultHTML = SysAllocString(TEXT("<p style=\"background-color: #00FF00\">Testing</p><img id=\"webkit logo\" src=\"http://webkit.org/images/icon-gold.png\" alt=\"Face\"><div style=\"border: solid blue; background: white;\" contenteditable=\"true\">div with blue border</div><ul><li>foo<li>bar<li>baz</ul>"));
353     frame->loadHTMLString(defaultHTML, 0);
354     frame->Release();
355
356     hr = gWebViewPrivate->setTransparent(usesLayeredWebView());
357     if (FAILED(hr))
358         goto exit;
359
360     hr = gWebViewPrivate->setUsesLayeredWindow(usesLayeredWebView());
361     if (FAILED(hr))
362         goto exit;
363
364     hr = gWebViewPrivate->viewWindow(reinterpret_cast<OLE_HANDLE*>(&gViewWindow));
365     if (FAILED(hr) || !gViewWindow)
366         goto exit;
367
368     if (usesLayeredWebView())
369         subclassForLayeredWindow();
370
371     resizeSubViews();
372
373     ShowWindow(gViewWindow, nCmdShow);
374     UpdateWindow(gViewWindow);
375
376     hAccelTable = LoadAccelerators(hInst, MAKEINTRESOURCE(IDC_WINLAUNCHER));
377
378     // Main message loop:
379     while (GetMessage(&msg, NULL, 0, 0)) {
380         if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
381             TranslateMessage(&msg);
382             DispatchMessage(&msg);
383         }
384     }
385
386 exit:
387     gPrintDelegate->Release();
388     if (gWebViewPrivate)
389         gWebViewPrivate->Release();
390     gWebView->Release();
391     if (standardPreferences)
392         standardPreferences->Release();
393     tmpPreferences->Release();
394
395     shutDownWebKit();
396 #ifdef _CRTDBG_MAP_ALLOC
397     _CrtDumpMemoryLeaks();
398 #endif
399
400     // Shut down COM.
401     OleUninitialize();
402     
403     return static_cast<int>(msg.wParam);
404 }
405
406 ATOM MyRegisterClass(HINSTANCE hInstance)
407 {
408     WNDCLASSEX wcex;
409
410     wcex.cbSize = sizeof(WNDCLASSEX);
411
412     wcex.style          = CS_HREDRAW | CS_VREDRAW;
413     wcex.lpfnWndProc    = WndProc;
414     wcex.cbClsExtra     = 0;
415     wcex.cbWndExtra     = 0;
416     wcex.hInstance      = hInstance;
417     wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WINLAUNCHER));
418     wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
419     wcex.hbrBackground  = 0;
420     wcex.lpszMenuName   = MAKEINTRESOURCE(IDC_WINLAUNCHER);
421     wcex.lpszClassName  = szWindowClass;
422     wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
423
424     return RegisterClassEx(&wcex);
425 }
426
427 static BOOL CALLBACK AbortProc(HDC hDC, int Error)
428 {
429     MSG msg;
430     while (::PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
431         ::TranslateMessage(&msg);
432         ::DispatchMessage(&msg);
433     }
434
435     return TRUE;
436 }
437
438 static HDC getPrinterDC()
439 {
440     PRINTDLG pdlg;
441     memset(&pdlg, 0, sizeof(PRINTDLG));
442     pdlg.lStructSize = sizeof(PRINTDLG);
443     pdlg.Flags = PD_PRINTSETUP | PD_RETURNDC;
444
445     ::PrintDlg(&pdlg);
446
447     return pdlg.hDC;
448 }
449
450 static void initDocStruct(DOCINFO* di, TCHAR* docname)
451 {
452     memset(di, 0, sizeof(DOCINFO));
453     di->cbSize = sizeof(DOCINFO);
454     di->lpszDocName = docname;
455 }
456
457 void PrintView(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
458 {
459     HDC printDC = getPrinterDC();
460     if (!printDC) {
461         ::MessageBoxW(0, L"Error creating printing DC", L"Error", MB_APPLMODAL | MB_OK);
462         return;
463     }
464
465     if (::SetAbortProc(printDC, AbortProc) == SP_ERROR) {
466         ::MessageBoxW(0, L"Error setting up AbortProc", L"Error", MB_APPLMODAL | MB_OK);
467         return;
468     }
469
470     IWebFrame* frame = 0;
471     IWebFramePrivate* framePrivate = 0;
472     if (FAILED(gWebView->mainFrame(&frame)))
473         goto exit;
474
475     if (FAILED(frame->QueryInterface(&framePrivate)))
476         goto exit;
477
478     framePrivate->setInPrintingMode(TRUE, printDC);
479
480     UINT pageCount = 0;
481     framePrivate->getPrintedPageCount(printDC, &pageCount);
482
483     DOCINFO di;
484     initDocStruct(&di, L"WebKit Doc");
485     ::StartDoc(printDC, &di);
486
487     // FIXME: Need CoreGraphics implementation
488     void* graphicsContext = 0;
489     for (size_t page = 1; page <= pageCount; ++page) {
490         ::StartPage(printDC);
491         framePrivate->spoolPages(printDC, page, page, graphicsContext);
492         ::EndPage(printDC);
493     }
494
495     framePrivate->setInPrintingMode(FALSE, printDC);
496
497     ::EndDoc(printDC);
498     ::DeleteDC(printDC);
499
500 exit:
501     if (frame)
502         frame->Release();
503     if (framePrivate)
504         framePrivate->Release();
505 }
506
507 static const int dragBarHeight = 30;
508
509 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
510 {
511     WNDPROC parentProc = usesLayeredWebView() ? DefWebKitProc : DefWindowProc;
512
513     switch (message) {
514     case WM_NCHITTEST:
515         if (usesLayeredWebView()) {
516             RECT window;
517             ::GetWindowRect(hWnd, &window);
518             // For testing our transparent window, we need a region to use as a handle for
519             // dragging. The right way to do this would be to query the web view to see what's
520             // under the mouse. However, for testing purposes we just use an arbitrary
521             // 30 pixel band at the top of the view as an arbitrary gripping location.
522             //
523             // When we are within this bad, return HT_CAPTION to tell Windows we want to
524             // treat this region as if it were the title bar on a normal window.
525             int y = HIWORD(lParam);
526
527             if ((y > window.top) && (y < window.top + dragBarHeight))
528                 return HTCAPTION;
529         }
530         return CallWindowProc(parentProc, hWnd, message, wParam, lParam);
531     case WM_COMMAND: {
532         int wmId = LOWORD(wParam);
533         int wmEvent = HIWORD(wParam);
534         // Parse the menu selections:
535         switch (wmId) {
536         case IDM_ABOUT:
537             DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
538             break;
539         case IDM_EXIT:
540             DestroyWindow(hWnd);
541             break;
542         case IDM_PRINT:
543             PrintView(hWnd, message, wParam, lParam);
544             break;
545         default:
546             return CallWindowProc(parentProc, hWnd, message, wParam, lParam);
547         }
548         }
549         break;
550     case WM_DESTROY:
551         PostQuitMessage(0);
552         break;
553     case WM_SIZE:
554         if (!gWebView || usesLayeredWebView())
555            return CallWindowProc(parentProc, hWnd, message, wParam, lParam);
556
557         resizeSubViews();
558         break;
559     default:
560         return CallWindowProc(parentProc, hWnd, message, wParam, lParam);
561     }
562
563     return 0;
564 }
565
566 #define MAX_URL_LENGTH  1024
567
568 LRESULT CALLBACK MyEditProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
569 {
570     switch (message) {
571         case WM_CHAR:
572             if (wParam == 13) { // Enter Key
573                 wchar_t strPtr[MAX_URL_LENGTH];
574                 *((LPWORD)strPtr) = MAX_URL_LENGTH; 
575                 int strLen = SendMessage(hDlg, EM_GETLINE, 0, (LPARAM)strPtr);
576
577                 BSTR bstr = SysAllocStringLen(strPtr, strLen);
578                 loadURL(bstr);
579                 SysFreeString(bstr);
580
581                 return 0;
582             } else
583                 return (LRESULT)CallWindowProc((WNDPROC)DefEditProc,hDlg,message,wParam,lParam);
584             break;
585         default:
586              return (LRESULT)CallWindowProc((WNDPROC)DefEditProc,hDlg,message,wParam,lParam);
587         break;
588     }
589 }
590
591
592 // Message handler for about box.
593 INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
594 {
595     UNREFERENCED_PARAMETER(lParam);
596     switch (message) {
597     case WM_INITDIALOG:
598         return (INT_PTR)TRUE;
599
600     case WM_COMMAND:
601         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
602             EndDialog(hDlg, LOWORD(wParam));
603             return (INT_PTR)TRUE;
604         }
605         break;
606     }
607     return (INT_PTR)FALSE;
608 }
609
610 static void loadURL(BSTR urlBStr)
611 {
612     IWebFrame* frame = 0;
613     IWebMutableURLRequest* request = 0;
614
615     static BSTR methodBStr = SysAllocString(TEXT("GET"));
616
617     if (urlBStr && urlBStr[0] && (PathFileExists(urlBStr) || PathIsUNC(urlBStr))) {
618         TCHAR fileURL[INTERNET_MAX_URL_LENGTH];
619         DWORD fileURLLength = sizeof(fileURL)/sizeof(fileURL[0]);
620
621         if (SUCCEEDED(UrlCreateFromPath(urlBStr, fileURL, &fileURLLength, 0)))
622             SysReAllocString(&urlBStr, fileURL);
623     }
624
625     HRESULT hr = gWebView->mainFrame(&frame);
626     if (FAILED(hr))
627         goto exit;
628
629     hr = WebKitCreateInstance(CLSID_WebMutableURLRequest, 0, IID_IWebMutableURLRequest, (void**)&request);
630     if (FAILED(hr))
631         goto exit;
632
633     hr = request->initWithURL(urlBStr, WebURLRequestUseProtocolCachePolicy, 60);
634     if (FAILED(hr))
635         goto exit;
636
637     hr = request->setHTTPMethod(methodBStr);
638     if (FAILED(hr))
639         goto exit;
640
641     hr = frame->loadRequest(request);
642     if (FAILED(hr))
643         goto exit;
644
645     SetFocus(gViewWindow);
646
647 exit:
648     if (frame)
649         frame->Release();
650     if (request)
651         request->Release();
652 }