2 * Copyright (C) 2012 Samsung Electronics
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "WebInspectorProxy.h"
32 #include "WebProcessProxy.h"
33 #include "ewk_context_private.h"
34 #include "ewk_page_group_private.h"
35 #include "ewk_settings.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>
51 static void resizeInspectorWindow(Ecore_Evas* inspectorWindow)
53 Evas_Object* inspectorView = evas_object_name_find(ecore_evas_get(inspectorWindow), "inspector");
58 ecore_evas_geometry_get(inspectorWindow, 0, 0, &width, &height);
60 evas_object_move(inspectorView, 0, 0);
61 evas_object_resize(inspectorView, width, height);
64 static void destroyInspectorWindow(Ecore_Evas* inspectorWindow)
66 Evas_Object* inspectorView = evas_object_name_find(ecore_evas_get(inspectorWindow), "inspector");
68 evas_object_smart_callback_call(inspectorView, "inspector,view,close", 0);
71 static void closeInspectorWindow(void* userData, Evas_Object*, void*)
73 WebInspectorProxy* inspectorProxy = static_cast<WebInspectorProxy*>(userData);
75 inspectorProxy->close();
78 void WebInspectorProxy::createInspectorWindow()
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);
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);
90 evas_object_focus_set(m_inspectorView, true);
93 WebPageProxy* WebInspectorProxy::platformCreateInspectorPage()
98 const char* engine = "opengl_x11";
99 m_inspectorWindow = ecore_evas_new(engine, 0, 0, initialWindowWidth, initialWindowHeight, 0);
101 // Gracefully fall back to software if evas_gl engine is not available.
102 if (!m_inspectorWindow)
104 m_inspectorWindow = ecore_evas_new(0, 0, 0, initialWindowWidth, initialWindowHeight, 0);
105 if (!m_inspectorWindow)
108 WKContextRef wkContext = toAPI(page()->process()->context());
109 WKPageGroupRef wkPageGroup = toAPI(inspectorPageGroup());
111 m_inspectorView = EWKViewCreate(wkContext, wkPageGroup, ecore_evas_get(m_inspectorWindow), /* smart */ 0);
112 WKViewRef wkView = EWKViewGetWKView(m_inspectorView);
114 WKRetainPtr<WKStringRef> wkTheme = adoptWK(WKStringCreateWithUTF8CString(TEST_THEME_DIR "/default.edj"));
115 WKViewSetThemePath(wkView, wkTheme.get());
117 WKPreferencesRef wkPreferences = WKPageGroupGetPreferences(wkPageGroup);
118 WKPreferencesSetFileAccessFromFileURLsAllowed(wkPreferences, true);
120 return toImpl(WKViewGetPage(wkView));
123 void WebInspectorProxy::platformOpen()
128 createInspectorWindow();
130 evas_object_smart_callback_add(m_inspectorView, "inspector,view,close", closeInspectorWindow, this);
133 void WebInspectorProxy::platformDidClose()
135 if (m_inspectorView) {
136 evas_object_del(m_inspectorView);
140 if (m_inspectorWindow) {
141 ecore_evas_free(m_inspectorWindow);
142 m_inspectorWindow = 0;
146 void WebInspectorProxy::platformHide()
151 void WebInspectorProxy::platformBringToFront()
156 bool WebInspectorProxy::platformIsFront()
162 void WebInspectorProxy::platformInspectedURLChanged(const String& url)
164 if (!m_inspectorWindow)
167 String title = "WebInspector - " + url;
168 ecore_evas_title_set(m_inspectorWindow, title.utf8().data());
171 String WebInspectorProxy::inspectorPageURL() const
173 StringBuilder builder;
174 builder.append(inspectorBaseURL());
175 builder.appendLiteral("/inspector.html");
177 return builder.toString();
180 String WebInspectorProxy::inspectorBaseURL() const
182 return "file://" + WebCore::inspectorResourcePath();
185 unsigned WebInspectorProxy::platformInspectedWindowHeight()
191 unsigned WebInspectorProxy::platformInspectedWindowWidth()
197 void WebInspectorProxy::platformAttach()
202 void WebInspectorProxy::platformDetach()
207 void WebInspectorProxy::platformSetAttachedWindowHeight(unsigned)
212 void WebInspectorProxy::platformSetAttachedWindowWidth(unsigned)
217 void WebInspectorProxy::platformSetToolbarHeight(unsigned)
222 void WebInspectorProxy::platformSave(const String&, const String&, bool, bool)
227 void WebInspectorProxy::platformAppend(const String&, const String&)
232 void WebInspectorProxy::platformAttachAvailabilityChanged(bool)
237 } // namespace WebKit
239 #endif // ENABLE(INSPECTOR)