2 * Copyright (C) 2014-2015 Apple Inc. All Rights Reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #include "ResourceLoadDelegate.h"
28 #include "MiniBrowser.h"
29 #include "PageLoadTestClient.h"
31 #include <WebKit/WebKitCOMAPI.h>
40 extern HRESULT DisplayAuthDialog(std::wstring& username, std::wstring& password);
42 HRESULT ResourceLoadDelegate::QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppvObject)
47 if (IsEqualIID(riid, IID_IUnknown))
48 *ppvObject = static_cast<IWebResourceLoadDelegate*>(this);
49 else if (IsEqualIID(riid, IID_IWebResourceLoadDelegate))
50 *ppvObject = static_cast<IWebResourceLoadDelegate*>(this);
58 ULONG ResourceLoadDelegate::AddRef()
63 ULONG ResourceLoadDelegate::Release()
65 ULONG newRef = --m_refCount;
72 HRESULT ResourceLoadDelegate::identifierForInitialRequest(_In_opt_ IWebView*, _In_opt_ IWebURLRequest*, _In_opt_ IWebDataSource*, unsigned long identifier)
77 m_client->pageLoadTestClient().didInitiateResourceLoad(identifier);
82 HRESULT ResourceLoadDelegate::willSendRequest(_In_opt_ IWebView*, unsigned long, _In_opt_ IWebURLRequest*, _In_opt_ IWebURLResponse*, _In_opt_ IWebDataSource*, _COM_Outptr_opt_ IWebURLRequest** result)
90 HRESULT ResourceLoadDelegate::didReceiveAuthenticationChallenge(_In_opt_ IWebView*, unsigned long, _In_opt_ IWebURLAuthenticationChallenge* challenge, _In_opt_ IWebDataSource*)
92 COMPtr<IWebURLAuthenticationChallengeSender> sender;
93 if (!challenge || FAILED(challenge->sender(&sender)))
96 std::wstring username, password;
97 if (DisplayAuthDialog(username, password) != S_OK)
100 COMPtr<IWebURLCredential> credential;
101 if (FAILED(WebKitCreateInstance(CLSID_WebURLCredential, 0, IID_IWebURLCredential, (void**)&credential)))
103 credential->initWithUser(_bstr_t(username.c_str()), _bstr_t(password.c_str()), WebURLCredentialPersistenceForSession);
105 sender->useCredential(credential.get(), challenge);
109 HRESULT ResourceLoadDelegate::didCancelAuthenticationChallenge(_In_opt_ IWebView*, unsigned long, _In_opt_ IWebURLAuthenticationChallenge*, _In_opt_ IWebDataSource*)
114 HRESULT ResourceLoadDelegate::didReceiveResponse(_In_opt_ IWebView*, unsigned long, _In_opt_ IWebURLResponse*, _In_opt_ IWebDataSource*)
119 HRESULT ResourceLoadDelegate::didReceiveContentLength(_In_opt_ IWebView*, unsigned long, UINT, _In_opt_ IWebDataSource*)
124 HRESULT ResourceLoadDelegate::didFinishLoadingFromDataSource(_In_opt_ IWebView*, unsigned long identifier, _In_opt_ IWebDataSource*)
129 m_client->pageLoadTestClient().didEndResourceLoad(identifier);
134 HRESULT ResourceLoadDelegate::didFailLoadingWithError(_In_opt_ IWebView*, unsigned long identifier, _In_opt_ IWebError*, _In_opt_ IWebDataSource*)
139 m_client->pageLoadTestClient().didEndResourceLoad(identifier);
144 HRESULT ResourceLoadDelegate::plugInFailedWithError(_In_opt_ IWebView*, _In_opt_ IWebError*, _In_opt_ IWebDataSource*)