initial import
[vuplus_webkit] / Source / WebKit / wx / WebKitSupport / ChromeClientWx.cpp
1 /*
2  * Copyright (C) 2007 Kevin Ollivier <kevino@theolliviers.com>
3  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4  *
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28
29 #include "config.h"
30 #include "ChromeClientWx.h"
31 #include "Console.h"
32 #if ENABLE(DATABASE)
33 #include "DatabaseTracker.h"
34 #endif
35 #include "FileChooser.h"
36 #include "FileIconLoader.h"
37 #include "FloatRect.h"
38 #include "Frame.h"
39 #include "FrameLoadRequest.h"
40 #include "Icon.h"
41 #include "NavigationAction.h"
42 #include "NotImplemented.h"
43 #include "PlatformString.h"
44 #include "SecurityOrigin.h"
45 #include "PopupMenuWx.h"
46 #include "SearchPopupMenuWx.h"
47 #include "WindowFeatures.h"
48
49 #include <stdio.h>
50
51 #include <wx/wxprec.h>
52 #ifndef WX_PRECOMP
53     #include <wx/wx.h>
54 #endif
55 #include <wx/textdlg.h>
56 #include <wx/tooltip.h>
57
58 #include "WebBrowserShell.h"
59 #include "WebView.h"
60 #include "WebViewPrivate.h"
61
62 namespace WebCore {
63
64 wxWebKitWindowFeatures wkFeaturesforWindowFeatures(const WindowFeatures& features)
65 {
66     wxWebKitWindowFeatures wkFeatures;
67     wkFeatures.menuBarVisible = features.menuBarVisible;
68     wkFeatures.statusBarVisible = features.statusBarVisible;
69     wkFeatures.toolBarVisible = features.toolBarVisible;
70     wkFeatures.locationBarVisible = features.locationBarVisible;
71     wkFeatures.scrollbarsVisible = features.scrollbarsVisible;
72     wkFeatures.resizable = features.resizable;
73     wkFeatures.fullscreen = features.fullscreen;
74     wkFeatures.dialog = features.dialog;
75     
76     return wkFeatures;
77 }
78
79 ChromeClientWx::ChromeClientWx(wxWebView* webView)
80 {
81     m_webView = webView;
82 }
83
84 ChromeClientWx::~ChromeClientWx()
85 {
86 }
87
88 void ChromeClientWx::chromeDestroyed()
89 {
90     notImplemented();
91 }
92
93 void ChromeClientWx::setWindowRect(const FloatRect&)
94 {
95     notImplemented();
96 }
97
98 FloatRect ChromeClientWx::windowRect()
99 {
100     notImplemented();
101     return FloatRect();
102 }
103
104 FloatRect ChromeClientWx::pageRect()
105 {
106     notImplemented();
107     return FloatRect();
108 }
109
110 void ChromeClientWx::focus()
111 {
112     notImplemented();
113 }
114
115 void ChromeClientWx::unfocus()
116 {
117     notImplemented();
118 }
119
120 bool ChromeClientWx::canTakeFocus(FocusDirection)
121 {
122     notImplemented();
123     return false;
124 }
125
126 void ChromeClientWx::takeFocus(FocusDirection)
127 {
128     notImplemented();
129 }
130
131 void ChromeClientWx::focusedNodeChanged(Node*)
132 {
133 }
134
135 void ChromeClientWx::focusedFrameChanged(Frame*)
136 {
137 }
138
139 Page* ChromeClientWx::createWindow(Frame*, const FrameLoadRequest&, const WindowFeatures& features, const NavigationAction&)
140 {
141     Page* myPage = 0;
142     wxWebViewNewWindowEvent wkEvent(m_webView);
143     
144     wxWebKitWindowFeatures wkFeatures = wkFeaturesforWindowFeatures(features);
145     wkEvent.SetWindowFeatures(wkFeatures);
146     
147     if (m_webView->GetEventHandler()->ProcessEvent(wkEvent)) {
148         if (wxWebView* webView = wkEvent.GetWebView()) {
149             WebViewPrivate* impl = webView->m_impl;
150             if (impl)
151                 myPage = impl->page;
152         }
153     }
154     
155     return myPage;
156 }
157
158 Page* ChromeClientWx::createModalDialog(Frame*, const FrameLoadRequest&)
159 {
160     notImplemented();
161     return 0;
162 }
163
164 void ChromeClientWx::show()
165 {
166     notImplemented();
167 }
168
169 bool ChromeClientWx::canRunModal()
170 {
171     notImplemented();
172     return false;
173 }
174
175 void ChromeClientWx::runModal()
176 {
177     notImplemented();
178 }
179
180 void ChromeClientWx::setToolbarsVisible(bool)
181 {
182     notImplemented();
183 }
184
185 bool ChromeClientWx::toolbarsVisible()
186 {
187     notImplemented();
188     return false;
189 }
190
191 void ChromeClientWx::setStatusbarVisible(bool)
192 {
193     notImplemented();
194 }
195
196 bool ChromeClientWx::statusbarVisible()
197 {
198     notImplemented();
199     return false;
200 }
201
202 void ChromeClientWx::setScrollbarsVisible(bool)
203 {
204     notImplemented();
205 }
206
207 bool ChromeClientWx::scrollbarsVisible()
208 {
209     notImplemented();
210     return false;
211 }
212
213 void ChromeClientWx::setMenubarVisible(bool)
214 {
215     notImplemented();
216 }
217
218 bool ChromeClientWx::menubarVisible()
219 {
220     notImplemented();
221     return false;
222 }
223
224 void ChromeClientWx::setResizable(bool)
225 {
226     notImplemented();
227 }
228
229 void ChromeClientWx::addMessageToConsole(MessageSource source,
230                                           MessageType type,
231                                           MessageLevel level,
232                                           const String& message,
233                                           unsigned int lineNumber,
234                                           const String& sourceID)
235 {
236     if (m_webView) {
237         wxWebViewConsoleMessageEvent wkEvent(m_webView);
238         wkEvent.SetMessage(message);
239         wkEvent.SetLineNumber(lineNumber);
240         wkEvent.SetSourceID(sourceID);
241         wkEvent.SetLevel(static_cast<wxWebViewConsoleMessageLevel>(level));
242         m_webView->GetEventHandler()->ProcessEvent(wkEvent);
243     }
244 }
245
246 bool ChromeClientWx::canRunBeforeUnloadConfirmPanel()
247 {
248     notImplemented();
249     return true;
250 }
251
252 bool ChromeClientWx::runBeforeUnloadConfirmPanel(const String& string,
253                                                   Frame* frame)
254 {
255     wxMessageDialog dialog(NULL, string, wxT("Confirm Action?"), wxYES_NO);
256     return dialog.ShowModal() == wxYES;
257 }
258
259 void ChromeClientWx::closeWindowSoon()
260 {
261     notImplemented();
262 }
263
264 /*
265     Sites for testing prompts: 
266     Alert - just type in a bad web address or http://www.htmlite.com/JS002.php
267     Prompt - http://www.htmlite.com/JS007.php
268     Confirm - http://www.htmlite.com/JS006.php
269 */
270
271 void ChromeClientWx::runJavaScriptAlert(Frame* frame, const String& string)
272 {
273     if (m_webView) {
274         wxWebViewAlertEvent wkEvent(m_webView);
275         wkEvent.SetMessage(string);
276         if (!m_webView->GetEventHandler()->ProcessEvent(wkEvent))
277             wxMessageBox(string, wxT("JavaScript Alert"), wxOK);
278     }
279 }
280
281 bool ChromeClientWx::runJavaScriptConfirm(Frame* frame, const String& string)
282 {
283     bool result = false;
284     if (m_webView) {
285         wxWebViewConfirmEvent wkEvent(m_webView);
286         wkEvent.SetMessage(string);
287         if (m_webView->GetEventHandler()->ProcessEvent(wkEvent))
288             result = wkEvent.GetReturnCode() == wxID_YES;
289         else {
290             wxMessageDialog dialog(NULL, string, wxT("JavaScript Confirm"), wxYES_NO);
291             dialog.Centre();
292             result = (dialog.ShowModal() == wxID_YES);
293         }
294     }
295     return result;
296 }
297
298 bool ChromeClientWx::runJavaScriptPrompt(Frame* frame, const String& message, const String& defaultValue, String& result)
299 {
300     if (m_webView) {
301         wxWebViewPromptEvent wkEvent(m_webView);
302         wkEvent.SetMessage(message);
303         wkEvent.SetResponse(defaultValue);
304         if (m_webView->GetEventHandler()->ProcessEvent(wkEvent)) {
305             result = wkEvent.GetResponse();
306             return true;
307         }
308         else {
309             wxTextEntryDialog dialog(NULL, message, wxT("JavaScript Prompt"), wxEmptyString, wxOK | wxCANCEL);
310             dialog.Centre();
311             if (dialog.ShowModal() == wxID_OK) {
312                 result = dialog.GetValue();
313                 return true;
314             }
315         }
316     }
317     return false;
318 }
319
320 void ChromeClientWx::setStatusbarText(const String&)
321 {
322     notImplemented();
323 }
324
325 bool ChromeClientWx::shouldInterruptJavaScript()
326 {
327     notImplemented();
328     return false;
329 }
330
331 KeyboardUIMode ChromeClientWx::keyboardUIMode()
332 {
333     notImplemented();
334     return KeyboardAccessDefault;
335 }
336
337 IntRect ChromeClientWx::windowResizerRect() const
338 {
339     notImplemented();
340     return IntRect();
341 }
342
343 void ChromeClientWx::invalidateWindow(const IntRect& rect, bool immediate)
344 {
345     if (immediate)
346         m_webView->Update();
347 }
348
349 void ChromeClientWx::invalidateContentsForSlowScroll(const IntRect& rect, bool immediate)
350 {
351     invalidateContentsAndWindow(rect, immediate);
352 }
353
354 void ChromeClientWx::invalidateContentsAndWindow(const IntRect& rect, bool immediate)
355 {
356     if (!m_webView)
357         return;
358
359     m_webView->RefreshRect(rect);
360
361     if (immediate) {
362         m_webView->Update();
363     }
364 }
365
366 IntRect ChromeClientWx::windowToScreen(const IntRect& rect) const
367 {
368     notImplemented();
369     return rect;
370 }
371
372 IntPoint ChromeClientWx::screenToWindow(const IntPoint& point) const
373 {
374     notImplemented();
375     return point;
376 }
377
378 PlatformPageClient ChromeClientWx::platformPageClient() const
379 {
380     return m_webView;
381 }
382
383 void ChromeClientWx::contentsSizeChanged(Frame*, const IntSize&) const
384 {
385     notImplemented();
386 }
387
388 void ChromeClientWx::scrollBackingStore(int dx, int dy, 
389                     const IntRect& scrollViewRect, 
390                     const IntRect& clipRect)
391 {
392     notImplemented();
393 }
394
395 void ChromeClientWx::updateBackingStore()
396 {
397     notImplemented();
398 }
399
400 void ChromeClientWx::mouseDidMoveOverElement(const HitTestResult&, unsigned modifierFlags)
401 {
402     notImplemented();
403 }
404
405 void ChromeClientWx::setToolTip(const String& tip, TextDirection)
406 {
407     wxToolTip* tooltip = m_webView->GetToolTip();
408     if (!tooltip || tooltip->GetTip() != wxString(tip))
409         m_webView->SetToolTip(tip);
410 }
411
412 void ChromeClientWx::print(Frame* frame)
413 {
414     wxWebFrame* webFrame = kit(frame);
415     if (webFrame) {
416         wxWebViewPrintFrameEvent event(m_webView);
417         event.SetWebFrame(webFrame);
418         if (!m_webView->GetEventHandler()->ProcessEvent(event))
419             webFrame->Print(true);
420     }
421 }
422
423 #if ENABLE(DATABASE)
424 void ChromeClientWx::exceededDatabaseQuota(Frame*, const String&)
425 {
426     unsigned long long quota = 5 * 1024 * 1024;
427
428     if (wxWebFrame* webFrame = m_webView->GetMainFrame())
429         if (Frame* frame = webFrame->GetFrame())
430             if (Document* document = frame->document())
431                 if (!DatabaseTracker::tracker().hasEntryForOrigin(document->securityOrigin()))
432                     DatabaseTracker::tracker().setQuota(document->securityOrigin(), quota);
433 }
434 #endif
435
436 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
437 void ChromeClientWx::reachedMaxAppCacheSize(int64_t spaceNeeded)
438 {
439     notImplemented();
440 }
441
442 void ChromeClientWx::reachedApplicationCacheOriginQuota(SecurityOrigin*, int64_t)
443 {
444     notImplemented();
445 }
446 #endif
447
448 void ChromeClientWx::scroll(const IntSize&, const IntRect&, const IntRect&)
449 {
450     m_webView->Refresh();
451     notImplemented();
452 }
453
454 void ChromeClientWx::runOpenPanel(Frame*, PassRefPtr<FileChooser>)
455 {
456     notImplemented();
457 }
458
459 void ChromeClientWx::loadIconForFiles(const Vector<String>& filenames, FileIconLoader* loader)
460 {
461     loader->notifyFinished(Icon::createIconForFiles(filenames));
462 }
463
464 void ChromeClientWx::setCursor(const Cursor& cursor)
465 {
466     if (m_webView && cursor.impl())
467         m_webView->SetCursor(*cursor.impl());
468 }
469
470 void ChromeClientWx::requestGeolocationPermissionForFrame(Frame*, Geolocation*)
471 {
472     // See the comment in WebCore/page/ChromeClient.h
473     notImplemented();
474 }
475
476 bool ChromeClientWx::selectItemWritingDirectionIsNatural()
477 {
478     return false;
479 }
480
481 bool ChromeClientWx::selectItemAlignmentFollowsMenuWritingDirection()
482 {
483     return false;
484 }
485
486 PassRefPtr<PopupMenu> ChromeClientWx::createPopupMenu(PopupMenuClient* client) const
487 {
488     return adoptRef(new PopupMenuWx(client));
489 }
490
491 PassRefPtr<SearchPopupMenu> ChromeClientWx::createSearchPopupMenu(PopupMenuClient* client) const
492 {
493     return adoptRef(new SearchPopupMenuWx(client));
494 }
495
496 }