[EFL] WebInspector: Move to new webinspector
[WebKit-https.git] / Source / WebKit2 / UIProcess / efl / WebInspectorProxyEfl.cpp
1 /*
2  * Copyright (C) 2012 Samsung Electronics
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  * 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.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "config.h"
27 #include "WebInspectorProxy.h"
28
29 #if ENABLE(INSPECTOR)
30
31 #include "EwkView.h"
32 #include "WebProcessProxy.h"
33 #include "ewk_context_private.h"
34 #include "ewk_page_group_private.h"
35 #include "ewk_settings.h"
36 #include "ewk_view.h"
37 #include "ewk_view_private.h"
38 #include <WebCore/EflInspectorUtilities.h>
39 #include <WebCore/NotImplemented.h>
40 #include <WebKit2/WKPage.h>
41 #include <WebKit2/WKPageGroup.h>
42 #include <WebKit2/WKPreferencesPrivate.h>
43 #include <WebKit2/WKString.h>
44 #include <WebKit2/WKViewEfl.h>
45 #include <wtf/text/CString.h>
46 #include <wtf/text/StringBuilder.h>
47 #include <wtf/text/WTFString.h>
48
49 namespace WebKit {
50
51 static void resizeInspectorWindow(Ecore_Evas* inspectorWindow)
52 {
53     Evas_Object* inspectorView = evas_object_name_find(ecore_evas_get(inspectorWindow), "inspector");
54     if (!inspectorView)
55         return;
56
57     int width, height;
58     ecore_evas_geometry_get(inspectorWindow, 0, 0, &width, &height);
59
60     evas_object_move(inspectorView, 0, 0);
61     evas_object_resize(inspectorView, width, height);
62 }
63
64 static void destroyInspectorWindow(Ecore_Evas* inspectorWindow)
65 {
66     Evas_Object* inspectorView = evas_object_name_find(ecore_evas_get(inspectorWindow), "inspector");
67     if (inspectorView)
68         evas_object_smart_callback_call(inspectorView, "inspector,view,close", 0);
69 }
70
71 static void closeInspectorWindow(void* userData, Evas_Object*, void*)
72 {
73     WebInspectorProxy* inspectorProxy = static_cast<WebInspectorProxy*>(userData);
74
75     inspectorProxy->close();
76 }
77
78 void WebInspectorProxy::createInspectorWindow()
79 {
80     ecore_evas_title_set(m_inspectorWindow, "Web Inspector");
81     ecore_evas_callback_resize_set(m_inspectorWindow, resizeInspectorWindow);
82     ecore_evas_callback_delete_request_set(m_inspectorWindow, destroyInspectorWindow);
83     ecore_evas_show(m_inspectorWindow);
84
85     evas_object_name_set(m_inspectorView, "inspector");
86     evas_object_move(m_inspectorView, 0, 0);
87     evas_object_resize(m_inspectorView, initialWindowWidth, initialWindowHeight);
88     evas_object_show(m_inspectorView);
89
90     evas_object_focus_set(m_inspectorView, true);
91 }
92
93 WebPageProxy* WebInspectorProxy::platformCreateInspectorPage()
94 {
95     ASSERT(m_page);
96
97 #ifdef HAVE_ECORE_X
98     const char* engine = "opengl_x11";
99     m_inspectorWindow = ecore_evas_new(engine, 0, 0, initialWindowWidth, initialWindowHeight, 0);
100
101     // Gracefully fall back to software if evas_gl engine is not available.
102     if (!m_inspectorWindow)
103 #endif
104     m_inspectorWindow = ecore_evas_new(0, 0, 0, initialWindowWidth, initialWindowHeight, 0);
105     if (!m_inspectorWindow)
106         return 0;
107
108     WKContextRef wkContext = toAPI(page()->process()->context());
109     WKPageGroupRef wkPageGroup = toAPI(inspectorPageGroup());
110
111     m_inspectorView = EWKViewCreate(wkContext, wkPageGroup, ecore_evas_get(m_inspectorWindow), /* smart */ 0);
112     WKViewRef wkView = EWKViewGetWKView(m_inspectorView);
113
114     WKRetainPtr<WKStringRef> wkTheme = adoptWK(WKStringCreateWithUTF8CString(TEST_THEME_DIR "/default.edj"));
115     WKViewSetThemePath(wkView, wkTheme.get());
116
117     WKPreferencesRef wkPreferences = WKPageGroupGetPreferences(wkPageGroup);
118     WKPreferencesSetFileAccessFromFileURLsAllowed(wkPreferences, true);
119
120     return toImpl(WKViewGetPage(wkView));
121 }
122
123 void WebInspectorProxy::platformOpen()
124 {
125     if (m_isAttached)
126         platformAttach();
127     else
128         createInspectorWindow();
129
130     evas_object_smart_callback_add(m_inspectorView, "inspector,view,close", closeInspectorWindow, this);
131 }
132
133 void WebInspectorProxy::platformDidClose()
134 {
135     if (m_inspectorView) {
136         evas_object_del(m_inspectorView);
137         m_inspectorView = 0;
138     }
139
140     if (m_inspectorWindow) {
141         ecore_evas_free(m_inspectorWindow);
142         m_inspectorWindow = 0;
143     }
144 }
145
146 void WebInspectorProxy::platformHide()
147 {
148     notImplemented();
149 }
150
151 void WebInspectorProxy::platformBringToFront()
152 {
153     notImplemented();
154 }
155
156 bool WebInspectorProxy::platformIsFront()
157 {
158     notImplemented();
159     return false;
160 }
161
162 void WebInspectorProxy::platformInspectedURLChanged(const String& url)
163 {
164     if (!m_inspectorWindow)
165         return;
166
167     String title = "WebInspector - " + url;
168     ecore_evas_title_set(m_inspectorWindow, title.utf8().data());
169 }
170
171 String WebInspectorProxy::inspectorPageURL() const
172 {
173     StringBuilder builder;
174     builder.append(inspectorBaseURL());
175     builder.appendLiteral("/Main.html");
176
177     return builder.toString();
178 }
179
180 String WebInspectorProxy::inspectorBaseURL() const
181 {
182     return "file://" + WebCore::inspectorResourcePath();
183 }
184
185 unsigned WebInspectorProxy::platformInspectedWindowHeight()
186 {
187     notImplemented();
188     return 0;
189 }
190
191 unsigned WebInspectorProxy::platformInspectedWindowWidth()
192 {
193     notImplemented();
194     return 0;
195 }
196
197 void WebInspectorProxy::platformAttach()
198 {
199     notImplemented();
200 }
201
202 void WebInspectorProxy::platformDetach()
203 {
204     notImplemented();
205 }
206
207 void WebInspectorProxy::platformSetAttachedWindowHeight(unsigned)
208 {
209     notImplemented();
210 }
211
212 void WebInspectorProxy::platformSetAttachedWindowWidth(unsigned)
213 {
214     notImplemented();
215 }
216
217 void WebInspectorProxy::platformSetToolbarHeight(unsigned)
218 {
219     notImplemented();
220 }
221
222 void WebInspectorProxy::platformSave(const String&, const String&, bool, bool)
223 {
224     notImplemented();
225 }
226
227 void WebInspectorProxy::platformAppend(const String&, const String&)
228 {
229     notImplemented();
230 }
231
232 void WebInspectorProxy::platformAttachAvailabilityChanged(bool)
233 {
234     notImplemented();
235 }
236
237 } // namespace WebKit
238
239 #endif // ENABLE(INSPECTOR)