Implement WebKit2 callback equivalent to - [WebUIDelegate webView:setStatusText:]
[WebKit.git] / WebKit2 / WebProcess / WebCoreSupport / WebChromeClient.cpp
1 /*
2  * Copyright (C) 2010 Apple Inc. All rights reserved.
3  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24  * THE POSSIBILITY OF SUCH DAMAGE.
25  */
26
27 #include "WebChromeClient.h"
28
29 #define DISABLE_NOT_IMPLEMENTED_WARNINGS 1
30 #include "NotImplemented.h"
31
32 #include "DrawingArea.h"
33 #include "WebCoreArgumentCoders.h"
34 #include "WebFrame.h"
35 #include "WebFrameLoaderClient.h"
36 #include "WebPage.h"
37 #include "WebPageProxyMessageKinds.h"
38 #include "WebPopupMenu.h"
39 #include "WebPreferencesStore.h"
40 #include "WebProcess.h"
41 #include "WebProcessProxyMessageKinds.h"
42 #include "WebSearchPopupMenu.h"
43 #include <WebCore/FileChooser.h>
44 #include <WebCore/Frame.h>
45 #include <WebCore/FrameLoader.h>
46 #include <WebCore/Page.h>
47 #include <WebCore/SecurityOrigin.h>
48
49 using namespace WebCore;
50
51 namespace WebKit {
52
53 void WebChromeClient::chromeDestroyed()
54 {
55     delete this;
56 }
57
58 void WebChromeClient::setWindowRect(const FloatRect&)
59 {
60     notImplemented();
61 }
62
63 FloatRect WebChromeClient::windowRect()
64 {
65     notImplemented();
66     return FloatRect();
67 }
68
69 FloatRect WebChromeClient::pageRect()
70 {
71     notImplemented();
72     return FloatRect();
73 }
74
75 float WebChromeClient::scaleFactor()
76 {
77     notImplemented();
78     return 1.0;
79 }
80
81 void WebChromeClient::focus()
82 {
83     notImplemented();
84 }
85
86 void WebChromeClient::unfocus()
87 {
88     notImplemented();
89 }
90
91 bool WebChromeClient::canTakeFocus(FocusDirection)
92 {
93     notImplemented();
94     return true;
95 }
96
97 void WebChromeClient::takeFocus(FocusDirection direction)
98 {
99     WebProcess::shared().connection()->send(WebPageProxyMessage::TakeFocus, m_page->pageID(),
100                                             direction == FocusDirectionForward ? true : false);
101 }
102
103 void WebChromeClient::focusedNodeChanged(Node*)
104 {
105     notImplemented();
106 }
107
108 Page* WebChromeClient::createWindow(Frame*, const FrameLoadRequest&, const WindowFeatures&)
109 {
110     uint64_t newPageID = 0;
111     IntSize viewSize;
112     WebPreferencesStore store;
113     DrawingAreaBase::DrawingAreaInfo drawingAreaInfo;
114     if (!WebProcess::shared().connection()->sendSync(WebPageProxyMessage::CreateNewPage,
115                                                      m_page->pageID(), CoreIPC::In(),
116                                                      CoreIPC::Out(newPageID, viewSize, store, drawingAreaInfo),
117                                                      CoreIPC::Connection::NoTimeout)) {
118         return 0;
119     }
120
121     if (!newPageID)
122         return 0;
123
124     WebPage* newWebPage = WebProcess::shared().createWebPage(newPageID, viewSize, store, drawingAreaInfo);
125     return newWebPage->corePage();
126 }
127
128 void WebChromeClient::show()
129 {
130     m_page->show();
131 }
132
133 bool WebChromeClient::canRunModal()
134 {
135     notImplemented();
136     return false;
137 }
138
139 void WebChromeClient::runModal()
140 {
141     notImplemented();
142 }
143
144 void WebChromeClient::setToolbarsVisible(bool)
145 {
146     notImplemented();
147 }
148
149 bool WebChromeClient::toolbarsVisible()
150 {
151     notImplemented();
152     return true;
153 }
154
155 void WebChromeClient::setStatusbarVisible(bool)
156 {
157     notImplemented();
158 }
159
160 bool WebChromeClient::statusbarVisible()
161 {
162     notImplemented();
163     return true;
164 }
165
166 void WebChromeClient::setScrollbarsVisible(bool)
167 {
168     notImplemented();
169 }
170
171 bool WebChromeClient::scrollbarsVisible()
172 {
173     notImplemented();
174     return true;
175 }
176
177 void WebChromeClient::setMenubarVisible(bool)
178 {
179     notImplemented();
180 }
181
182 bool WebChromeClient::menubarVisible()
183 {
184     notImplemented();
185     return true;
186 }
187
188 void WebChromeClient::setResizable(bool)
189 {
190     notImplemented();
191 }
192
193 void WebChromeClient::addMessageToConsole(MessageSource, MessageType, MessageLevel, const String& message, unsigned int lineNumber, const String& sourceID)
194 {
195     // Notify the bundle client.
196     m_page->injectedBundleUIClient().willAddMessageToConsole(m_page, message, lineNumber);
197
198     notImplemented();
199 }
200
201 bool WebChromeClient::canRunBeforeUnloadConfirmPanel()
202 {
203     notImplemented();
204     return false;
205 }
206
207 bool WebChromeClient::runBeforeUnloadConfirmPanel(const String& message, Frame* frame)
208 {
209     notImplemented();
210     return false;
211 }
212
213 void WebChromeClient::closeWindowSoon()
214 {
215     // FIXME: This code assumes that the client will respond to a close page
216     // message by actually closing the page. Safari does this, but there is
217     // no guarantee that other applications will, which will leave this page
218     // half detached. This approach is an inherent limitation making parts of
219     // a close execute synchronously as part of window.close, but other parts
220     // later on.
221
222     m_page->corePage()->setGroupName(String());
223
224     if (WebFrame* frame = m_page->mainFrame()) {
225         if (Frame* coreFrame = frame->coreFrame())
226             coreFrame->loader()->stopForUserCancel();
227     }
228
229     m_page->sendClose();
230 }
231
232 void WebChromeClient::runJavaScriptAlert(Frame* frame, const String& alertText)
233 {
234     WebFrame* webFrame =  static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame();
235
236     // Notify the bundle client.
237     m_page->injectedBundleUIClient().willRunJavaScriptAlert(m_page, alertText, webFrame);
238
239     WebProcess::shared().connection()->sendSync(WebPageProxyMessage::RunJavaScriptAlert, m_page->pageID(),
240                                                 CoreIPC::In(webFrame->frameID(), alertText),
241                                                 CoreIPC::Out(),
242                                                 CoreIPC::Connection::NoTimeout);
243 }
244
245 bool WebChromeClient::runJavaScriptConfirm(Frame* frame, const String& message)
246 {
247     WebFrame* webFrame =  static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame();
248
249     // Notify the bundle client.
250     m_page->injectedBundleUIClient().willRunJavaScriptConfirm(m_page, message, webFrame);
251
252     bool result = false;
253     if (!WebProcess::shared().connection()->sendSync(WebPageProxyMessage::RunJavaScriptConfirm, m_page->pageID(),
254                                                      CoreIPC::In(webFrame->frameID(), message),
255                                                      CoreIPC::Out(result),
256                                                      CoreIPC::Connection::NoTimeout)) {
257         return false;
258     }
259
260     return result;
261 }
262
263 bool WebChromeClient::runJavaScriptPrompt(Frame* frame, const String& message, const String& defaultValue, String& result)
264 {
265     WebFrame* webFrame =  static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame();
266
267     // Notify the bundle client.
268     m_page->injectedBundleUIClient().willRunJavaScriptPrompt(m_page, message, defaultValue, webFrame);
269
270     if (!WebProcess::shared().connection()->sendSync(WebPageProxyMessage::RunJavaScriptPrompt, m_page->pageID(),
271                                                      CoreIPC::In(webFrame->frameID(), message, defaultValue),
272                                                      CoreIPC::Out(result),
273                                                      CoreIPC::Connection::NoTimeout)) {
274         return false;
275     }
276
277     return !result.isNull();
278 }
279
280 void WebChromeClient::setStatusbarText(const String& statusbarText)
281 {
282     // Notify the bundle client.
283     m_page->injectedBundleUIClient().willSetStatusbarText(m_page, statusbarText);
284
285     WebProcess::shared().connection()->send(WebPageProxyMessage::SetStatusText, m_page->pageID(), statusbarText);
286 }
287
288 bool WebChromeClient::shouldInterruptJavaScript()
289 {
290     notImplemented();
291     return false;
292 }
293
294 bool WebChromeClient::tabsToLinks() const
295 {
296     notImplemented();
297     return false;
298 }
299
300 IntRect WebChromeClient::windowResizerRect() const
301 {
302     IntSize pageSize = m_page->size();
303     
304     static const int windowResizerSize = 15;
305     
306     return IntRect(pageSize.width() - windowResizerSize, pageSize.height() - windowResizerSize, 
307                    windowResizerSize, windowResizerSize);
308 }
309
310 void WebChromeClient::invalidateWindow(const IntRect& rect, bool immediate)
311 {
312     m_page->drawingArea()->invalidateWindow(rect, immediate);
313 }
314
315 void WebChromeClient::invalidateContentsAndWindow(const IntRect& rect, bool immediate)
316 {
317     m_page->drawingArea()->invalidateContentsAndWindow(rect, immediate);
318 }
319
320 void WebChromeClient::invalidateContentsForSlowScroll(const IntRect& rect, bool immediate)
321 {
322     m_page->drawingArea()->invalidateContentsForSlowScroll(rect, immediate);
323 }
324
325 void WebChromeClient::scroll(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect)
326 {
327     m_page->drawingArea()->scroll(scrollDelta, rectToScroll, clipRect);
328 }
329
330 IntPoint WebChromeClient::screenToWindow(const IntPoint&) const
331 {
332     notImplemented();
333     return IntPoint();
334 }
335
336 IntRect WebChromeClient::windowToScreen(const IntRect&) const
337 {
338     notImplemented();
339     return IntRect();
340 }
341
342 PlatformPageClient WebChromeClient::platformPageClient() const
343 {
344     notImplemented();
345     return 0;
346 }
347
348 void WebChromeClient::contentsSizeChanged(Frame* frame, const IntSize& size) const
349 {
350     WebFrame* webFrame =  static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame();
351     WebProcess::shared().connection()->send(WebPageProxyMessage::ContentsSizeChanged, m_page->pageID(),
352                                             CoreIPC::In(webFrame->frameID(), size));
353 }
354
355 void WebChromeClient::scrollRectIntoView(const IntRect&, const ScrollView*) const
356 {
357     notImplemented();
358 }
359
360 void WebChromeClient::scrollbarsModeDidChange() const
361 {
362     notImplemented();
363 }
364
365 void WebChromeClient::mouseDidMoveOverElement(const HitTestResult&, unsigned modifierFlags)
366 {
367     notImplemented();
368 }
369
370 void WebChromeClient::setToolTip(const String& toolTip, TextDirection)
371 {
372     // Only send a tool tip to the WebProcess if it has changed since the last time this function was called.
373
374     if (toolTip == m_cachedToolTip)
375         return;
376     m_cachedToolTip = toolTip;
377
378     WebProcess::shared().connection()->send(WebPageProxyMessage::SetToolTip, m_page->pageID(), CoreIPC::In(m_cachedToolTip));
379 }
380
381 void WebChromeClient::print(Frame*)
382 {
383     notImplemented();
384 }
385
386 #if ENABLE(DATABASE)
387 void WebChromeClient::exceededDatabaseQuota(Frame*, const String& databaseName)
388 {
389     notImplemented();
390 }
391 #endif
392
393
394 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
395 void WebChromeClient::reachedMaxAppCacheSize(int64_t)
396 {
397     notImplemented();
398 }
399
400 void WebChromeClient::reachedApplicationCacheOriginQuota(SecurityOrigin*)
401 {
402     notImplemented();
403 }
404 #endif
405
406 #if ENABLE(DASHBOARD_SUPPORT)
407 void WebChromeClient::dashboardRegionsChanged()
408 {
409     notImplemented();
410 }
411 #endif
412
413 void WebChromeClient::populateVisitedLinks()
414 {
415 }
416
417 FloatRect WebChromeClient::customHighlightRect(Node*, const AtomicString& type, const FloatRect& lineRect)
418 {
419     notImplemented();
420     return FloatRect();
421 }
422
423 void WebChromeClient::paintCustomHighlight(Node*, const AtomicString& type, const FloatRect& boxRect, const FloatRect& lineRect,
424                                   bool behindText, bool entireLine)
425 {
426     notImplemented();
427 }
428
429 bool WebChromeClient::shouldReplaceWithGeneratedFileForUpload(const String& path, String& generatedFilename)
430 {
431     notImplemented();
432     return false;
433 }
434
435 String WebChromeClient::generateReplacementFile(const String& path)
436 {
437     notImplemented();
438     return String();
439 }
440
441 bool WebChromeClient::paintCustomScrollbar(GraphicsContext*, const FloatRect&, ScrollbarControlSize, 
442                                            ScrollbarControlState, ScrollbarPart pressedPart, bool vertical,
443                                            float value, float proportion, ScrollbarControlPartMask)
444 {
445     notImplemented();
446     return false;
447 }
448
449 bool WebChromeClient::paintCustomScrollCorner(GraphicsContext*, const FloatRect&)
450 {
451     notImplemented();
452     return false;
453 }
454
455 void WebChromeClient::requestGeolocationPermissionForFrame(Frame*, Geolocation*)
456 {
457     notImplemented();
458 }
459
460 void WebChromeClient::cancelGeolocationPermissionRequestForFrame(Frame*, Geolocation*)
461 {
462     notImplemented();
463 }
464
465 void WebChromeClient::runOpenPanel(Frame*, PassRefPtr<FileChooser>)
466 {
467     notImplemented();
468 }
469
470 void WebChromeClient::chooseIconForFiles(const Vector<String>&, FileChooser*)
471 {
472     notImplemented();
473 }
474
475 void WebChromeClient::setCursor(const Cursor& cursor)
476 {
477 #if USE(LAZY_NATIVE_CURSOR)
478     WebProcess::shared().connection()->send(WebPageProxyMessage::SetCursor, m_page->pageID(), CoreIPC::In(cursor));
479 #endif
480 }
481
482 void WebChromeClient::formStateDidChange(const Node*)
483 {
484     notImplemented();
485 }
486
487 void WebChromeClient::formDidFocus(const Node*)
488
489     notImplemented();
490 }
491
492 void WebChromeClient::formDidBlur(const Node*)
493 {
494     notImplemented();
495 }
496
497 bool WebChromeClient::selectItemWritingDirectionIsNatural()
498 {
499     return true;
500 }
501
502 PassRefPtr<WebCore::PopupMenu> WebChromeClient::createPopupMenu(WebCore::PopupMenuClient* client) const
503 {
504     return WebPopupMenu::create(client);
505 }
506
507 PassRefPtr<WebCore::SearchPopupMenu> WebChromeClient::createSearchPopupMenu(WebCore::PopupMenuClient* client) const
508 {
509     return WebSearchPopupMenu::create(client);
510 }
511
512 PassOwnPtr<HTMLParserQuirks> WebChromeClient::createHTMLParserQuirks()
513 {
514     notImplemented();
515     return 0;
516 }
517
518 #if USE(ACCELERATED_COMPOSITING)
519 void WebChromeClient::attachRootGraphicsLayer(Frame*, GraphicsLayer* layer)
520 {
521     if (layer)
522         m_page->enterAcceleratedCompositingMode(layer);
523     else
524         m_page->exitAcceleratedCompositingMode();
525 }
526
527 void WebChromeClient::setNeedsOneShotDrawingSynchronization()
528 {
529     notImplemented();
530 }
531
532 void WebChromeClient::scheduleCompositingLayerSync()
533 {
534     m_page->drawingArea()->scheduleCompositingLayerSync();
535 }
536
537 #endif
538
539 #if ENABLE(NOTIFICATIONS)
540 WebCore::NotificationPresenter* WebChromeClient::notificationPresenter() const
541 {
542     return 0;
543 }
544 #endif
545
546 #if ENABLE(TOUCH_EVENTS)
547 void WebChromeClient::needTouchEvents(bool)
548 {
549 }
550 #endif
551
552 #if PLATFORM(WIN)
553 void WebChromeClient::setLastSetCursorToCurrentCursor()
554 {
555 }
556 #endif
557
558
559 } // namespace WebKit