[EFL] Share resources installed for inspector
[WebKit.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 "WebProcessProxy.h"
32 #include "ewk_settings.h"
33 #include "ewk_view.h"
34 #include "ewk_view_private.h"
35 #include <WebCore/NotImplemented.h>
36 #include <unistd.h>
37 #include <wtf/text/CString.h>
38 #include <wtf/text/StringBuilder.h>
39 #include <wtf/text/WTFString.h>
40
41 namespace WebKit {
42
43 static void resizeInspectorWindow(Ecore_Evas* inspectorWindow)
44 {
45     Evas_Object* inspectorView = evas_object_name_find(ecore_evas_get(inspectorWindow), "inspector");
46     if (!inspectorView)
47         return;
48
49     int width, height;
50     ecore_evas_geometry_get(inspectorWindow, 0, 0, &width, &height);
51
52     evas_object_move(inspectorView, 0, 0);
53     evas_object_resize(inspectorView, width, height);
54 }
55
56 static void destroyInspectorWindow(Ecore_Evas* inspectorWindow)
57 {
58     Evas_Object* inspectorView = evas_object_name_find(ecore_evas_get(inspectorWindow), "inspector");
59     if (inspectorView)
60         evas_object_smart_callback_call(inspectorView, "inspector,view,close", 0);
61 }
62
63 static void closeInspectorWindow(void* userData, Evas_Object*, void*)
64 {
65     WebInspectorProxy* inspectorProxy = static_cast<WebInspectorProxy*>(userData);
66
67     inspectorProxy->close();
68 }
69
70 void WebInspectorProxy::createInspectorWindow()
71 {
72     ecore_evas_title_set(m_inspectorWindow, "Web Inspector");
73     ecore_evas_callback_resize_set(m_inspectorWindow, resizeInspectorWindow);
74     ecore_evas_callback_delete_request_set(m_inspectorWindow, destroyInspectorWindow);
75     ecore_evas_show(m_inspectorWindow);
76
77     evas_object_name_set(m_inspectorView, "inspector");
78     evas_object_move(m_inspectorView, 0, 0);
79     evas_object_resize(m_inspectorView, initialWindowWidth, initialWindowHeight);
80     evas_object_show(m_inspectorView);
81
82     evas_object_focus_set(m_inspectorView, true);
83 }
84
85 WebPageProxy* WebInspectorProxy::platformCreateInspectorPage()
86 {
87     ASSERT(m_page);
88
89     m_inspectorWindow = ecore_evas_new(0, 0, 0, initialWindowWidth, initialWindowHeight, 0);
90     if (!m_inspectorWindow)
91         return 0;
92
93     m_inspectorView = ewk_view_base_add(ecore_evas_get(m_inspectorWindow), toAPI(page()->process()->context()), toAPI(inspectorPageGroup()));
94     ewk_view_theme_set(m_inspectorView, TEST_THEME_DIR"/default.edj");
95
96     Ewk_Settings* settings = ewk_view_settings_get(m_inspectorView);
97     ewk_settings_file_access_from_file_urls_allowed_set(settings, true);
98
99     return ewk_view_page_get(m_inspectorView);
100 }
101
102 void WebInspectorProxy::platformOpen()
103 {
104     if (m_isAttached)
105         platformAttach();
106     else
107         createInspectorWindow();
108
109     evas_object_smart_callback_add(m_inspectorView, "inspector,view,close", closeInspectorWindow, this);
110 }
111
112 void WebInspectorProxy::platformDidClose()
113 {
114     if (m_inspectorView) {
115         evas_object_del(m_inspectorView);
116         m_inspectorView = 0;
117     }
118
119     if (m_inspectorWindow) {
120         ecore_evas_free(m_inspectorWindow);
121         m_inspectorWindow = 0;
122     }
123 }
124
125 void WebInspectorProxy::platformBringToFront()
126 {
127     notImplemented();
128 }
129
130 bool WebInspectorProxy::platformIsFront()
131 {
132     notImplemented();
133     return false;
134 }
135
136 void WebInspectorProxy::platformInspectedURLChanged(const String&)
137 {
138     notImplemented();
139 }
140
141 String WebInspectorProxy::inspectorPageURL() const
142 {
143     StringBuilder builder;
144     builder.append(inspectorPageURL());
145     builder.appendLiteral("/inspector.html");
146
147     return builder.toString();
148 }
149
150 String WebInspectorProxy::inspectorBaseURL() const
151 {
152     String inspectorFilesPath = ASCIILiteral("file://" WEB_INSPECTOR_INSTALL_DIR);
153     if (access(inspectorFilesPath.utf8().data(), R_OK))
154         inspectorFilesPath = ASCIILiteral("file://" WEB_INSPECTOR_DIR);
155
156     return inspectorFilesPath;
157 }
158
159 unsigned WebInspectorProxy::platformInspectedWindowHeight()
160 {
161     notImplemented();
162     return 0;
163 }
164
165 void WebInspectorProxy::platformAttach()
166 {
167     notImplemented();
168 }
169
170 void WebInspectorProxy::platformDetach()
171 {
172     notImplemented();
173 }
174
175 void WebInspectorProxy::platformSetAttachedWindowHeight(unsigned)
176 {
177     notImplemented();
178 }
179
180 } // namespace WebKit
181
182 #endif // ENABLE(INSPECTOR)