1 /* 2 * Copyright (C) 2013 Google 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 are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google Inc. nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #ifndef WebFrameTestProxy_h 32 #define WebFrameTestProxy_h 33 34 #include "WebTestProxy.h" 35 #include "public/platform/WebNonCopyable.h" 36 37 namespace WebTestRunner { 38 39 // Templetized wrapper around RenderFrameImpl objects, which implement 40 // the WebFrameClient interface. 41 template<class Base, typename P, typename R> 42 class WebFrameTestProxy : public Base, public blink::WebNonCopyable { 43 public: 44 WebFrameTestProxy(P p, R r) 45 : Base(p, r) 46 , m_baseProxy(0) 47 , m_version(0) { } 48 49 virtual ~WebFrameTestProxy() { } 50 51 void setBaseProxy(WebTestProxyBase* proxy) 52 { 53 m_baseProxy = proxy; 54 } 55 56 void setVersion(int version) 57 { 58 m_version = version; 59 } 60 61 blink::WebPlugin* createPlugin(blink::WebFrame* frame, const blink::WebPluginParams& params) 62 { 63 blink::WebPlugin* plugin = m_baseProxy->createPlugin(frame, params); 64 if (plugin) 65 return plugin; 66 return Base::createPlugin(frame, params); 67 } 68 69 // WebFrameClient implementation. 70 virtual void didStartProvisionalLoad(blink::WebFrame* frame) 71 { 72 if (m_version > 2) 73 m_baseProxy->didStartProvisionalLoad(frame); 74 Base::didStartProvisionalLoad(frame); 75 } 76 virtual void didReceiveServerRedirectForProvisionalLoad(blink::WebFrame* frame) 77 { 78 Base::didReceiveServerRedirectForProvisionalLoad(frame); 79 } 80 virtual void didFailProvisionalLoad(blink::WebFrame* frame, const blink::WebURLError& error) 81 { 82 Base::didFailProvisionalLoad(frame, error); 83 } 84 virtual void didCommitProvisionalLoad(blink::WebFrame* frame, bool isNewNavigation) 85 { 86 Base::didCommitProvisionalLoad(frame, isNewNavigation); 87 } 88 virtual void didReceiveTitle(blink::WebFrame* frame, const blink::WebString& title, blink::WebTextDirection direction) 89 { 90 Base::didReceiveTitle(frame, title, direction); 91 } 92 virtual void didChangeIcon(blink::WebFrame* frame, blink::WebIconURL::Type iconType) 93 { 94 Base::didChangeIcon(frame, iconType); 95 } 96 virtual void didFinishDocumentLoad(blink::WebFrame* frame) 97 { 98 Base::didFinishDocumentLoad(frame); 99 } 100 virtual void didHandleOnloadEvents(blink::WebFrame* frame) 101 { 102 Base::didHandleOnloadEvents(frame); 103 } 104 virtual void didFailLoad(blink::WebFrame* frame, const blink::WebURLError& error) 105 { 106 Base::didFailLoad(frame, error); 107 } 108 virtual void didFinishLoad(blink::WebFrame* frame) 109 { 110 Base::didFinishLoad(frame); 111 } 112 virtual void didDetectXSS(blink::WebFrame* frame, const blink::WebURL& insecureURL, bool didBlockEntirePage) 113 { 114 // This is not implemented in RenderFrameImpl, so need to explicitly call 115 // into the base proxy. 116 m_baseProxy->didDetectXSS(frame, insecureURL, didBlockEntirePage); 117 Base::didDetectXSS(frame, insecureURL, didBlockEntirePage); 118 } 119 virtual void didDispatchPingLoader(blink::WebFrame* frame, const blink::WebURL& url) 120 { 121 // This is not implemented in RenderFrameImpl, so need to explicitly call 122 // into the base proxy. 123 m_baseProxy->didDispatchPingLoader(frame, url); 124 Base::didDispatchPingLoader(frame, url); 125 } 126 virtual void willRequestResource(blink::WebFrame* frame, const blink::WebCachedURLRequest& request) 127 { 128 // This is not implemented in RenderFrameImpl, so need to explicitly call 129 // into the base proxy. 130 m_baseProxy->willRequestResource(frame, request); 131 Base::willRequestResource(frame, request); 132 } 133 virtual void didCreateDataSource(blink::WebFrame* frame, blink::WebDataSource* ds) 134 { 135 Base::didCreateDataSource(frame, ds); 136 } 137 virtual void willSendRequest(blink::WebFrame* frame, unsigned identifier, blink::WebURLRequest& request, const blink::WebURLResponse& redirectResponse) 138 { 139 m_baseProxy->willSendRequest(frame, identifier, request, redirectResponse); 140 Base::willSendRequest(frame, identifier, request, redirectResponse); 141 } 142 virtual void didReceiveResponse(blink::WebFrame* frame, unsigned identifier, const blink::WebURLResponse& response) 143 { 144 m_baseProxy->didReceiveResponse(frame, identifier, response); 145 Base::didReceiveResponse(frame, identifier, response); 146 } 147 virtual void didChangeResourcePriority(blink::WebFrame* frame, unsigned identifier, const blink::WebURLRequest::Priority& priority) 148 { 149 // This is not implemented in RenderFrameImpl, so need to explicitly call 150 // into the base proxy. 151 m_baseProxy->didChangeResourcePriority(frame, identifier, priority); 152 Base::didChangeResourcePriority(frame, identifier, priority); 153 } 154 virtual void didFinishResourceLoad(blink::WebFrame* frame, unsigned identifier) 155 { 156 Base::didFinishResourceLoad(frame, identifier); 157 } 158 virtual blink::WebNavigationPolicy decidePolicyForNavigation(blink::WebFrame* frame, blink::WebDataSource::ExtraData* extraData, const blink::WebURLRequest& request, blink::WebNavigationType type, blink::WebNavigationPolicy defaultPolicy, bool isRedirect) 159 { 160 return Base::decidePolicyForNavigation(frame, extraData, request, type, defaultPolicy, isRedirect); 161 } 162 virtual bool willCheckAndDispatchMessageEvent(blink::WebFrame* sourceFrame, blink::WebFrame* targetFrame, blink::WebSecurityOrigin target, blink::WebDOMMessageEvent event) 163 { 164 if (m_baseProxy->willCheckAndDispatchMessageEvent(sourceFrame, targetFrame, target, event)) 165 return true; 166 return Base::willCheckAndDispatchMessageEvent(sourceFrame, targetFrame, target, event); 167 } 168 169 private: 170 WebTestProxyBase* m_baseProxy; 171 172 // This is used to incrementally change code between Blink and Chromium. 173 // It is used instead of a #define and is set by layouttest_support when 174 // creating this object. 175 int m_version; 176 }; 177 178 } 179 180 #endif // WebTestProxy_h 181