Upstream version 7.35.139.0
[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 loadURLExternally(blink::WebFrame* frame, const blink::WebURLRequest& request, blink::WebNavigationPolicy policy, const blink::WebString& suggested_name)
53     {
54         m_baseProxy->loadURLExternally(frame, request, policy, suggested_name);
55         Base::loadURLExternally(frame, request, policy, suggested_name);
56     }
57     virtual void didStartProvisionalLoad(blink::WebFrame* frame)
58     {
59         if (m_version > 2)
60             m_baseProxy->didStartProvisionalLoad(frame);
61         Base::didStartProvisionalLoad(frame);
62     }
63     virtual void didReceiveServerRedirectForProvisionalLoad(blink::WebFrame* frame)
64     {
65         m_baseProxy->didReceiveServerRedirectForProvisionalLoad(frame);
66         Base::didReceiveServerRedirectForProvisionalLoad(frame);
67     }
68     virtual void didFailProvisionalLoad(blink::WebFrame* frame, const blink::WebURLError& error)
69     {
70         Base::didFailProvisionalLoad(frame, error);
71     }
72     virtual void didCommitProvisionalLoad(blink::WebFrame* frame, bool isNewNavigation)
73     {
74         Base::didCommitProvisionalLoad(frame, isNewNavigation);
75     }
76     virtual void didReceiveTitle(blink::WebFrame* frame, const blink::WebString& title, blink::WebTextDirection direction)
77     {
78         Base::didReceiveTitle(frame, title, direction);
79     }
80     virtual void didChangeIcon(blink::WebFrame* frame, blink::WebIconURL::Type iconType)
81     {
82         Base::didChangeIcon(frame, iconType);
83     }
84     virtual void didFinishDocumentLoad(blink::WebFrame* frame)
85     {
86         Base::didFinishDocumentLoad(frame);
87     }
88     virtual void didHandleOnloadEvents(blink::WebFrame* frame)
89     {
90         Base::didHandleOnloadEvents(frame);
91     }
92     virtual void didFailLoad(blink::WebFrame* frame, const blink::WebURLError& error)
93     {
94         Base::didFailLoad(frame, error);
95     }
96     virtual void didFinishLoad(blink::WebFrame* frame)
97     {
98         Base::didFinishLoad(frame);
99     }
100     virtual void didChangeSelection(bool is_selection_empty) {
101         m_baseProxy->didChangeSelection(is_selection_empty);
102         Base::didChangeSelection(is_selection_empty);
103     }
104     virtual void showContextMenu(const blink::WebContextMenuData& contextMenuData) {
105         m_baseProxy->showContextMenu(Base::GetWebFrame(), contextMenuData);
106         Base::showContextMenu(contextMenuData);
107     }
108     virtual void didDetectXSS(blink::WebFrame* frame, const blink::WebURL& insecureURL, bool didBlockEntirePage)
109     {
110         // This is not implemented in RenderFrameImpl, so need to explicitly call
111         // into the base proxy.
112         m_baseProxy->didDetectXSS(frame, insecureURL, didBlockEntirePage);
113         Base::didDetectXSS(frame, insecureURL, didBlockEntirePage);
114     }
115     virtual void didDispatchPingLoader(blink::WebFrame* frame, const blink::WebURL& url)
116     {
117         // This is not implemented in RenderFrameImpl, so need to explicitly call
118         // into the base proxy.
119         m_baseProxy->didDispatchPingLoader(frame, url);
120         Base::didDispatchPingLoader(frame, url);
121     }
122     virtual void willRequestResource(blink::WebFrame* frame, const blink::WebCachedURLRequest& request)
123     {
124         // This is not implemented in RenderFrameImpl, so need to explicitly call
125         // into the base proxy.
126         m_baseProxy->willRequestResource(frame, request);
127         Base::willRequestResource(frame, request);
128     }
129     virtual void didCreateDataSource(blink::WebFrame* frame, blink::WebDataSource* ds)
130     {
131         Base::didCreateDataSource(frame, ds);
132     }
133     virtual void willSendRequest(blink::WebFrame* frame, unsigned identifier, blink::WebURLRequest& request, const blink::WebURLResponse& redirectResponse)
134     {
135         m_baseProxy->willSendRequest(frame, identifier, request, redirectResponse);
136         Base::willSendRequest(frame, identifier, request, redirectResponse);
137     }
138     virtual void didReceiveResponse(blink::WebFrame* frame, unsigned identifier, const blink::WebURLResponse& response)
139     {
140         m_baseProxy->didReceiveResponse(frame, identifier, response);
141         Base::didReceiveResponse(frame, identifier, response);
142     }
143     virtual void didChangeResourcePriority(blink::WebFrame* frame, unsigned identifier, const blink::WebURLRequest::Priority& priority)
144     {
145         // This is not implemented in RenderFrameImpl, so need to explicitly call
146         // into the base proxy.
147         m_baseProxy->didChangeResourcePriority(frame, identifier, priority);
148         Base::didChangeResourcePriority(frame, identifier, priority);
149     }
150     virtual void didFinishResourceLoad(blink::WebFrame* frame, unsigned identifier)
151     {
152         Base::didFinishResourceLoad(frame, identifier);
153     }
154     virtual blink::WebNavigationPolicy decidePolicyForNavigation(blink::WebFrame* frame, blink::WebDataSource::ExtraData* extraData, const blink::WebURLRequest& request, blink::WebNavigationType type, blink::WebNavigationPolicy defaultPolicy, bool isRedirect)
155     {
156         blink::WebNavigationPolicy policy = m_baseProxy->decidePolicyForNavigation(frame, extraData, request, type, defaultPolicy, isRedirect);
157         if (policy == blink::WebNavigationPolicyIgnore)
158             return policy;
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     virtual void didStopLoading()
169     {
170         m_baseProxy->didStopLoading();
171         Base::didStopLoading();
172     }
173
174 private:
175     WebTestProxyBase* m_baseProxy;
176
177     // This is used to incrementally change code between Blink and Chromium.
178     // It is used instead of a #define and is set by layouttest_support when
179     // creating this object.
180     int m_version;
181
182     DISALLOW_COPY_AND_ASSIGN(WebFrameTestProxy);
183 };
184
185 }
186
187 #endif // WebTestProxy_h