fef3218e7c148fb51c2897b52955d2d2d7b56597
[platform/framework/web/crosswalk.git] / src / content / shell / renderer / test_runner / WebFrameTestProxy.h
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBFRAMETESTPROXY_H_
6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBFRAMETESTPROXY_H_
7
8 #include "base/basictypes.h"
9 #include "content/shell/renderer/test_runner/WebTestProxy.h"
10 #include "third_party/WebKit/public/platform/WebString.h"
11
12 namespace WebTestRunner {
13
14 // Templetized wrapper around RenderFrameImpl objects, which implement
15 // the WebFrameClient interface.
16 template<class Base, typename P, typename R>
17 class WebFrameTestProxy : public Base {
18 public:
19     WebFrameTestProxy(P p, R r)
20         : Base(p, r)
21         , m_baseProxy(0)
22         , m_version(0) { }
23
24     virtual ~WebFrameTestProxy() { }
25
26     void setBaseProxy(WebTestProxyBase* proxy)
27     {
28         m_baseProxy = proxy;
29     }
30
31     void setVersion(int version)
32     {
33         m_version = version;
34     }
35
36     blink::WebPlugin* createPlugin(blink::WebFrame* frame, const blink::WebPluginParams& params)
37     {
38         blink::WebPlugin* plugin = m_baseProxy->createPlugin(frame, params);
39         if (plugin)
40             return plugin;
41         return Base::createPlugin(frame, params);
42     }
43
44     // WebFrameClient implementation.
45     virtual bool canCreatePluginWithoutRenderer(const blink::WebString& mimeType)
46     {
47         using blink::WebString;
48
49         const CR_DEFINE_STATIC_LOCAL(WebString, suffix, ("-can-create-without-renderer"));
50         return mimeType.utf8().find(suffix.utf8()) != std::string::npos;
51     }
52     virtual void didStartProvisionalLoad(blink::WebFrame* frame)
53     {
54         if (m_version > 2)
55             m_baseProxy->didStartProvisionalLoad(frame);
56         Base::didStartProvisionalLoad(frame);
57     }
58     virtual void didReceiveServerRedirectForProvisionalLoad(blink::WebFrame* frame)
59     {
60         m_baseProxy->didReceiveServerRedirectForProvisionalLoad(frame);
61         Base::didReceiveServerRedirectForProvisionalLoad(frame);
62     }
63     virtual void didFailProvisionalLoad(blink::WebFrame* frame, const blink::WebURLError& error)
64     {
65         Base::didFailProvisionalLoad(frame, error);
66     }
67     virtual void didCommitProvisionalLoad(blink::WebFrame* frame, bool isNewNavigation)
68     {
69         Base::didCommitProvisionalLoad(frame, isNewNavigation);
70     }
71     virtual void didReceiveTitle(blink::WebFrame* frame, const blink::WebString& title, blink::WebTextDirection direction)
72     {
73         Base::didReceiveTitle(frame, title, direction);
74     }
75     virtual void didChangeIcon(blink::WebFrame* frame, blink::WebIconURL::Type iconType)
76     {
77         Base::didChangeIcon(frame, iconType);
78     }
79     virtual void didFinishDocumentLoad(blink::WebFrame* frame)
80     {
81         Base::didFinishDocumentLoad(frame);
82     }
83     virtual void didHandleOnloadEvents(blink::WebFrame* frame)
84     {
85         Base::didHandleOnloadEvents(frame);
86     }
87     virtual void didFailLoad(blink::WebFrame* frame, const blink::WebURLError& error)
88     {
89         Base::didFailLoad(frame, error);
90     }
91     virtual void didFinishLoad(blink::WebFrame* frame)
92     {
93         Base::didFinishLoad(frame);
94     }
95     virtual void didChangeSelection(bool is_selection_empty) {
96         m_baseProxy->didChangeSelection(is_selection_empty);
97         Base::didChangeSelection(is_selection_empty);
98     }
99     virtual void showContextMenu(const blink::WebContextMenuData& contextMenuData) {
100         m_baseProxy->showContextMenu(Base::GetWebFrame(), contextMenuData);
101         Base::showContextMenu(contextMenuData);
102     }
103     virtual void didDetectXSS(blink::WebFrame* frame, const blink::WebURL& insecureURL, bool didBlockEntirePage)
104     {
105         // This is not implemented in RenderFrameImpl, so need to explicitly call
106         // into the base proxy.
107         m_baseProxy->didDetectXSS(frame, insecureURL, didBlockEntirePage);
108         Base::didDetectXSS(frame, insecureURL, didBlockEntirePage);
109     }
110     virtual void didDispatchPingLoader(blink::WebFrame* frame, const blink::WebURL& url)
111     {
112         // This is not implemented in RenderFrameImpl, so need to explicitly call
113         // into the base proxy.
114         m_baseProxy->didDispatchPingLoader(frame, url);
115         Base::didDispatchPingLoader(frame, url);
116     }
117     virtual void willRequestResource(blink::WebFrame* frame, const blink::WebCachedURLRequest& request)
118     {
119         // This is not implemented in RenderFrameImpl, so need to explicitly call
120         // into the base proxy.
121         m_baseProxy->willRequestResource(frame, request);
122         Base::willRequestResource(frame, request);
123     }
124     virtual void didCreateDataSource(blink::WebFrame* frame, blink::WebDataSource* ds)
125     {
126         Base::didCreateDataSource(frame, ds);
127     }
128     virtual void willSendRequest(blink::WebFrame* frame, unsigned identifier, blink::WebURLRequest& request, const blink::WebURLResponse& redirectResponse)
129     {
130         m_baseProxy->willSendRequest(frame, identifier, request, redirectResponse);
131         Base::willSendRequest(frame, identifier, request, redirectResponse);
132     }
133     virtual void didReceiveResponse(blink::WebFrame* frame, unsigned identifier, const blink::WebURLResponse& response)
134     {
135         m_baseProxy->didReceiveResponse(frame, identifier, response);
136         Base::didReceiveResponse(frame, identifier, response);
137     }
138     virtual void didChangeResourcePriority(blink::WebFrame* frame, unsigned identifier, const blink::WebURLRequest::Priority& priority)
139     {
140         // This is not implemented in RenderFrameImpl, so need to explicitly call
141         // into the base proxy.
142         m_baseProxy->didChangeResourcePriority(frame, identifier, priority);
143         Base::didChangeResourcePriority(frame, identifier, priority);
144     }
145     virtual void didFinishResourceLoad(blink::WebFrame* frame, unsigned identifier)
146     {
147         Base::didFinishResourceLoad(frame, identifier);
148     }
149     virtual blink::WebNavigationPolicy decidePolicyForNavigation(blink::WebFrame* frame, blink::WebDataSource::ExtraData* extraData, const blink::WebURLRequest& request, blink::WebNavigationType type, blink::WebNavigationPolicy defaultPolicy, bool isRedirect)
150     {
151         blink::WebNavigationPolicy policy = m_baseProxy->decidePolicyForNavigation(frame, extraData, request, type, defaultPolicy, isRedirect);
152         if (policy == blink::WebNavigationPolicyIgnore)
153             return policy;
154
155         return Base::decidePolicyForNavigation(frame, extraData, request, type, defaultPolicy, isRedirect);
156     }
157     virtual bool willCheckAndDispatchMessageEvent(blink::WebFrame* sourceFrame, blink::WebFrame* targetFrame, blink::WebSecurityOrigin target, blink::WebDOMMessageEvent event)
158     {
159         if (m_baseProxy->willCheckAndDispatchMessageEvent(sourceFrame, targetFrame, target, event))
160             return true;
161         return Base::willCheckAndDispatchMessageEvent(sourceFrame, targetFrame, target, event);
162     }
163     virtual void didStopLoading()
164     {
165         m_baseProxy->didStopLoading();
166         Base::didStopLoading();
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     DISALLOW_COPY_AND_ASSIGN(WebFrameTestProxy);
178 };
179
180 }
181
182 #endif // WebTestProxy_h