• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 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  *
8  * 1.  Redistributions of source code must retain the above copyright
9  *     notice, this list of conditions and the following disclaimer.
10  * 2.  Redistributions in binary form must reproduce the above copyright
11  *     notice, this list of conditions and the following disclaimer in the
12  *     documentation and/or other materials provided with the distribution.
13  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14  *     its contributors may be used to endorse or promote products derived
15  *     from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef ResourceLoadDelegate_h
30 #define ResourceLoadDelegate_h
31 
32 #include <WebKit/WebKit.h>
33 #include <string>
34 #include <wtf/HashMap.h>
35 
36 class ResourceLoadDelegate : public IWebResourceLoadDelegate, public IWebResourceLoadDelegatePrivate2 {
37 public:
38     ResourceLoadDelegate();
39     virtual ~ResourceLoadDelegate();
40 
41     // IUnknown
42     virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject);
43     virtual ULONG STDMETHODCALLTYPE AddRef(void);
44     virtual ULONG STDMETHODCALLTYPE Release(void);
45 
46     // IWebResourceLoadDelegate
47     virtual HRESULT STDMETHODCALLTYPE identifierForInitialRequest(
48         /* [in] */ IWebView *webView,
49         /* [in] */ IWebURLRequest *request,
50         /* [in] */ IWebDataSource *dataSource,
51         /* [in] */ unsigned long identifier);
52 
53     virtual HRESULT STDMETHODCALLTYPE willSendRequest(
54         /* [in] */ IWebView *webView,
55         /* [in] */ unsigned long identifier,
56         /* [in] */ IWebURLRequest *request,
57         /* [in] */ IWebURLResponse *redirectResponse,
58         /* [in] */ IWebDataSource *dataSource,
59         /* [retval][out] */ IWebURLRequest **newRequest);
60 
61     virtual HRESULT STDMETHODCALLTYPE didReceiveAuthenticationChallenge(
62         /* [in] */ IWebView *webView,
63         /* [in] */ unsigned long identifier,
64         /* [in] */ IWebURLAuthenticationChallenge *challenge,
65         /* [in] */ IWebDataSource *dataSource);
66 
didCancelAuthenticationChallenge(IWebView * webView,unsigned long identifier,IWebURLAuthenticationChallenge * challenge,IWebDataSource * dataSource)67     virtual HRESULT STDMETHODCALLTYPE didCancelAuthenticationChallenge(
68         /* [in] */ IWebView *webView,
69         /* [in] */ unsigned long identifier,
70         /* [in] */ IWebURLAuthenticationChallenge *challenge,
71         /* [in] */ IWebDataSource *dataSource) { return E_NOTIMPL; }
72 
73     virtual HRESULT STDMETHODCALLTYPE didReceiveResponse(
74         /* [in] */ IWebView *webView,
75         /* [in] */ unsigned long identifier,
76         /* [in] */ IWebURLResponse *response,
77         /* [in] */ IWebDataSource *dataSource);
78 
didReceiveContentLength(IWebView * webView,unsigned long identifier,UINT length,IWebDataSource * dataSource)79     virtual HRESULT STDMETHODCALLTYPE didReceiveContentLength(
80         /* [in] */ IWebView *webView,
81         /* [in] */ unsigned long identifier,
82         /* [in] */ UINT length,
83         /* [in] */ IWebDataSource *dataSource) { return E_NOTIMPL; }
84 
85     virtual HRESULT STDMETHODCALLTYPE didFinishLoadingFromDataSource(
86         /* [in] */ IWebView *webView,
87         /* [in] */ unsigned long identifier,
88         /* [in] */ IWebDataSource *dataSource);
89 
90     virtual HRESULT STDMETHODCALLTYPE didFailLoadingWithError(
91         /* [in] */ IWebView *webView,
92         /* [in] */ unsigned long identifier,
93         /* [in] */ IWebError *error,
94         /* [in] */ IWebDataSource *dataSource);
95 
plugInFailedWithError(IWebView * webView,IWebError * error,IWebDataSource * dataSource)96     virtual HRESULT STDMETHODCALLTYPE plugInFailedWithError(
97         /* [in] */ IWebView *webView,
98         /* [in] */ IWebError *error,
99         /* [in] */ IWebDataSource *dataSource) { return E_NOTIMPL; }
100 
101     // IWebResourceLoadDelegatePrivate2
102     virtual HRESULT STDMETHODCALLTYPE removeIdentifierForRequest(
103         /* [in] */ IWebView *webView,
104         /* [in] */ unsigned long identifier);
105 
106 private:
107     static std::wstring descriptionSuitableForTestResult(IWebURLRequest*);
108     static std::wstring descriptionSuitableForTestResult(IWebURLResponse*);
109     std::wstring descriptionSuitableForTestResult(unsigned long) const;
110     std::wstring descriptionSuitableForTestResult(IWebError*, unsigned long) const;
111 
112     typedef HashMap<unsigned long, std::wstring> IdentifierMap;
urlMap()113     IdentifierMap& urlMap() { return m_urlMap; }
114     IdentifierMap m_urlMap;
115 
116     ULONG m_refCount;
117 };
118 
119 #endif // ResourceLoadDelegate_h
120