e72f3fe0f20d0586d9002c6c42af991cc7b8ec6c
[WebKit-https.git] / Tools / MiniBrowser / win / ResourceLoadDelegate.cpp
1 /*
2 * Copyright (C) 2014-2015 Apple 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 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
15 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
16 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
17 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
18 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
19 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
20 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25 #include "stdafx.h"
26 #include "ResourceLoadDelegate.h"
27
28 #include "PageLoadTestClient.h"
29 #include "MiniBrowser.h"
30 #include <WebKit/WebKitCOMAPI.h>
31 #include <comip.h>
32 #include <commctrl.h>
33 #include <commdlg.h>
34 #include <objbase.h>
35 #include <shlwapi.h>
36 #include <wininet.h>
37
38 HRESULT ResourceLoadDelegate::QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppvObject)
39 {
40     if (!ppvObject)
41         return E_POINTER;
42     *ppvObject = nullptr;
43     if (IsEqualIID(riid, IID_IUnknown))
44         *ppvObject = static_cast<IWebResourceLoadDelegate*>(this);
45     else if (IsEqualIID(riid, IID_IWebResourceLoadDelegate))
46         *ppvObject = static_cast<IWebResourceLoadDelegate*>(this);
47     else
48         return E_NOINTERFACE;
49
50     AddRef();
51     return S_OK;
52 }
53
54 ULONG ResourceLoadDelegate::AddRef()
55 {
56     return ++m_refCount;
57 }
58
59 ULONG ResourceLoadDelegate::Release()
60 {
61     ULONG newRef = --m_refCount;
62     if (!newRef)
63         delete this;
64
65     return newRef;
66 }
67
68 HRESULT ResourceLoadDelegate::identifierForInitialRequest(_In_opt_ IWebView*, _In_opt_ IWebURLRequest*, _In_opt_ IWebDataSource*, unsigned long identifier)
69 {
70     if (!m_client)
71         return E_FAIL;
72
73     m_client->pageLoadTestClient().didInitiateResourceLoad(identifier);
74
75     return S_OK;
76 }
77
78 HRESULT ResourceLoadDelegate::willSendRequest(_In_opt_ IWebView*, unsigned long, _In_opt_ IWebURLRequest*, _In_opt_ IWebURLResponse*, _In_opt_ IWebDataSource*, _COM_Outptr_opt_ IWebURLRequest** result)
79 {
80     if (!result)
81         return E_POINTER;
82     *result = nullptr;
83     return E_NOTIMPL;
84 }
85
86 HRESULT ResourceLoadDelegate::didReceiveAuthenticationChallenge(_In_opt_ IWebView*, unsigned long, _In_opt_ IWebURLAuthenticationChallenge*, _In_opt_ IWebDataSource*)
87 {
88     return E_NOTIMPL;
89 }
90
91 HRESULT ResourceLoadDelegate::didCancelAuthenticationChallenge(_In_opt_ IWebView*, unsigned long, _In_opt_ IWebURLAuthenticationChallenge*, _In_opt_ IWebDataSource*)
92 {
93     return E_NOTIMPL;
94 }
95
96 HRESULT ResourceLoadDelegate::didReceiveResponse(_In_opt_ IWebView*, unsigned long, _In_opt_ IWebURLResponse*, _In_opt_ IWebDataSource*)
97 {
98     return E_NOTIMPL;
99 }
100
101 HRESULT ResourceLoadDelegate::didReceiveContentLength(_In_opt_ IWebView*, unsigned long, UINT, _In_opt_ IWebDataSource*)
102 {
103     return E_NOTIMPL;
104 }
105
106 HRESULT ResourceLoadDelegate::didFinishLoadingFromDataSource(_In_opt_ IWebView*, unsigned long identifier, _In_opt_ IWebDataSource*)
107 {
108     if (!m_client)
109         return E_FAIL;
110
111     m_client->pageLoadTestClient().didEndResourceLoad(identifier);
112
113     return S_OK;
114 }
115
116 HRESULT ResourceLoadDelegate::didFailLoadingWithError(_In_opt_ IWebView*, unsigned long identifier, _In_opt_ IWebError*, _In_opt_ IWebDataSource*)
117 {
118     if (!m_client)
119         return E_FAIL;
120
121     m_client->pageLoadTestClient().didEndResourceLoad(identifier);
122
123     return S_OK;
124 }
125
126 HRESULT ResourceLoadDelegate::plugInFailedWithError(_In_opt_ IWebView*, _In_opt_ IWebError*, _In_opt_ IWebDataSource*)
127 {
128     return E_NOTIMPL;
129 }