33381ffe59adb0342c87bd883f6246adc22ee3b0
[WebKit-https.git] / Source / WebKit2 / WebProcess / WebCoreSupport / WebChromeClient.cpp
1 /*
2  * Copyright (C) 2010, 2011, 2012 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 "config.h"
28 #include "WebChromeClient.h"
29
30 #include "DrawingArea.h"
31 #include "InjectedBundleNavigationAction.h"
32 #include "InjectedBundleUserMessageCoders.h"
33 #include "LayerTreeHost.h"
34 #include "WebColorChooser.h"
35 #include "WebCoreArgumentCoders.h"
36 #include "WebFrame.h"
37 #include "WebFrameLoaderClient.h"
38 #include "WebFullScreenManager.h"
39 #include "WebImage.h"
40 #include "WebOpenPanelParameters.h"
41 #include "WebOpenPanelResultListener.h"
42 #include "WebPage.h"
43 #include "WebPageCreationParameters.h"
44 #include "WebPageProxyMessages.h"
45 #include "WebPopupMenu.h"
46 #include "WebPreferencesStore.h"
47 #include "WebProcess.h"
48 #include "WebSearchPopupMenu.h"
49 #include "WebSecurityOrigin.h"
50 #include <WebCore/AXObjectCache.h>
51 #include <WebCore/ColorChooser.h>
52 #include <WebCore/DatabaseManager.h>
53 #include <WebCore/FileChooser.h>
54 #include <WebCore/FileIconLoader.h>
55 #include <WebCore/Frame.h>
56 #include <WebCore/FrameLoadRequest.h>
57 #include <WebCore/FrameLoader.h>
58 #include <WebCore/FrameView.h>
59 #include <WebCore/HTMLNames.h>
60 #include <WebCore/HTMLPlugInImageElement.h>
61 #include <WebCore/Icon.h>
62 #include <WebCore/NotImplemented.h>
63 #include <WebCore/Page.h>
64 #include <WebCore/SecurityOrigin.h>
65 #include <WebCore/Settings.h>
66
67 using namespace WebCore;
68 using namespace HTMLNames;
69
70 namespace WebKit {
71
72 static double area(WebFrame* frame)
73 {
74     IntSize size = frame->visibleContentBoundsExcludingScrollbars().size();
75     return static_cast<double>(size.height()) * size.width();
76 }
77
78
79 static WebFrame* findLargestFrameInFrameSet(WebPage* page)
80 {
81     // Approximate what a user could consider a default target frame for application menu operations.
82
83     WebFrame* mainFrame = page->mainWebFrame();
84     if (!mainFrame->isFrameSet())
85         return 0;
86
87     WebFrame* largestSoFar = 0;
88
89     RefPtr<ImmutableArray> frameChildren = mainFrame->childFrames();
90     size_t count = frameChildren->size();
91     for (size_t i = 0; i < count; ++i) {
92         WebFrame* childFrame = frameChildren->at<WebFrame>(i);
93         if (!largestSoFar || area(childFrame) > area(largestSoFar))
94             largestSoFar = childFrame;
95     }
96
97     return largestSoFar;
98 }
99
100 void WebChromeClient::chromeDestroyed()
101 {
102     delete this;
103 }
104
105 void WebChromeClient::setWindowRect(const FloatRect& windowFrame)
106 {
107     m_page->send(Messages::WebPageProxy::SetWindowFrame(windowFrame));
108 }
109
110 FloatRect WebChromeClient::windowRect()
111 {
112     FloatRect newWindowFrame;
113
114     if (!WebProcess::shared().connection()->sendSync(Messages::WebPageProxy::GetWindowFrame(), Messages::WebPageProxy::GetWindowFrame::Reply(newWindowFrame), m_page->pageID()))
115         return FloatRect();
116
117     return newWindowFrame;
118 }
119
120 FloatRect WebChromeClient::pageRect()
121 {
122 #if USE(TILED_BACKING_STORE)
123     return FloatRect(FloatPoint(), m_page->viewportSize());
124 #else
125     return FloatRect(FloatPoint(), m_page->size());
126 #endif
127 }
128
129 void WebChromeClient::focus()
130 {
131     m_page->send(Messages::WebPageProxy::SetFocus(true));
132 }
133
134 void WebChromeClient::unfocus()
135 {
136     m_page->send(Messages::WebPageProxy::SetFocus(false));
137 }
138
139 #if PLATFORM(MAC)
140 void WebChromeClient::makeFirstResponder()
141 {
142     m_page->send(Messages::WebPageProxy::MakeFirstResponder());
143 }    
144 #endif    
145
146 bool WebChromeClient::canTakeFocus(FocusDirection)
147 {
148     notImplemented();
149     return true;
150 }
151
152 void WebChromeClient::takeFocus(FocusDirection direction)
153 {
154     m_page->send(Messages::WebPageProxy::TakeFocus(direction));
155 }
156
157 void WebChromeClient::focusedNodeChanged(Node*)
158 {
159     notImplemented();
160 }
161
162 void WebChromeClient::focusedFrameChanged(Frame* frame)
163 {
164     WebFrame* webFrame = frame ? static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame() : 0;
165
166     WebProcess::shared().connection()->send(Messages::WebPageProxy::FocusedFrameChanged(webFrame ? webFrame->frameID() : 0), m_page->pageID());
167 }
168
169 Page* WebChromeClient::createWindow(Frame*, const FrameLoadRequest& request, const WindowFeatures& windowFeatures, const NavigationAction& navigationAction)
170 {
171     uint32_t modifiers = static_cast<uint32_t>(InjectedBundleNavigationAction::modifiersForNavigationAction(navigationAction));
172     int32_t mouseButton = static_cast<int32_t>(InjectedBundleNavigationAction::mouseButtonForNavigationAction(navigationAction));
173
174     uint64_t newPageID = 0;
175     WebPageCreationParameters parameters;
176     if (!WebProcess::shared().connection()->sendSync(Messages::WebPageProxy::CreateNewPage(request.resourceRequest(), windowFeatures, modifiers, mouseButton), Messages::WebPageProxy::CreateNewPage::Reply(newPageID, parameters), m_page->pageID()))
177         return 0;
178
179     if (!newPageID)
180         return 0;
181
182     WebProcess::shared().createWebPage(newPageID, parameters);
183     return WebProcess::shared().webPage(newPageID)->corePage();
184 }
185
186 void WebChromeClient::show()
187 {
188     m_page->show();
189 }
190
191 bool WebChromeClient::canRunModal()
192 {
193     return m_page->canRunModal();
194 }
195
196 void WebChromeClient::runModal()
197 {
198     m_page->runModal();
199 }
200
201 void WebChromeClient::setToolbarsVisible(bool toolbarsAreVisible)
202 {
203     m_page->send(Messages::WebPageProxy::SetToolbarsAreVisible(toolbarsAreVisible));
204 }
205
206 bool WebChromeClient::toolbarsVisible()
207 {
208     WKBundlePageUIElementVisibility toolbarsVisibility = m_page->injectedBundleUIClient().toolbarsAreVisible(m_page);
209     if (toolbarsVisibility != WKBundlePageUIElementVisibilityUnknown)
210         return toolbarsVisibility == WKBundlePageUIElementVisible;
211     
212     bool toolbarsAreVisible = true;
213     if (!WebProcess::shared().connection()->sendSync(Messages::WebPageProxy::GetToolbarsAreVisible(), Messages::WebPageProxy::GetToolbarsAreVisible::Reply(toolbarsAreVisible), m_page->pageID()))
214         return true;
215
216     return toolbarsAreVisible;
217 }
218
219 void WebChromeClient::setStatusbarVisible(bool statusBarIsVisible)
220 {
221     m_page->send(Messages::WebPageProxy::SetStatusBarIsVisible(statusBarIsVisible));
222 }
223
224 bool WebChromeClient::statusbarVisible()
225 {
226     WKBundlePageUIElementVisibility statusbarVisibility = m_page->injectedBundleUIClient().statusBarIsVisible(m_page);
227     if (statusbarVisibility != WKBundlePageUIElementVisibilityUnknown)
228         return statusbarVisibility == WKBundlePageUIElementVisible;
229
230     bool statusBarIsVisible = true;
231     if (!WebProcess::shared().connection()->sendSync(Messages::WebPageProxy::GetStatusBarIsVisible(), Messages::WebPageProxy::GetStatusBarIsVisible::Reply(statusBarIsVisible), m_page->pageID()))
232         return true;
233
234     return statusBarIsVisible;
235 }
236
237 void WebChromeClient::setScrollbarsVisible(bool)
238 {
239     notImplemented();
240 }
241
242 bool WebChromeClient::scrollbarsVisible()
243 {
244     notImplemented();
245     return true;
246 }
247
248 void WebChromeClient::setMenubarVisible(bool menuBarVisible)
249 {
250     m_page->send(Messages::WebPageProxy::SetMenuBarIsVisible(menuBarVisible));
251 }
252
253 bool WebChromeClient::menubarVisible()
254 {
255     WKBundlePageUIElementVisibility menubarVisibility = m_page->injectedBundleUIClient().menuBarIsVisible(m_page);
256     if (menubarVisibility != WKBundlePageUIElementVisibilityUnknown)
257         return menubarVisibility == WKBundlePageUIElementVisible;
258     
259     bool menuBarIsVisible = true;
260     if (!WebProcess::shared().connection()->sendSync(Messages::WebPageProxy::GetMenuBarIsVisible(), Messages::WebPageProxy::GetMenuBarIsVisible::Reply(menuBarIsVisible), m_page->pageID()))
261         return true;
262
263     return menuBarIsVisible;
264 }
265
266 void WebChromeClient::setResizable(bool resizable)
267 {
268     m_page->send(Messages::WebPageProxy::SetIsResizable(resizable));
269 }
270
271 void WebChromeClient::addMessageToConsole(MessageSource, MessageLevel, const String& message, unsigned lineNumber, const String& /*sourceID*/)
272 {
273     // Notify the bundle client.
274     m_page->injectedBundleUIClient().willAddMessageToConsole(m_page, message, lineNumber);
275
276     notImplemented();
277 }
278
279 bool WebChromeClient::canRunBeforeUnloadConfirmPanel()
280 {
281     return m_page->canRunBeforeUnloadConfirmPanel();
282 }
283
284 bool WebChromeClient::runBeforeUnloadConfirmPanel(const String& message, Frame* frame)
285 {
286     WebFrame* webFrame = static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame();
287
288     bool shouldClose = false;
289     if (!WebProcess::shared().connection()->sendSync(Messages::WebPageProxy::RunBeforeUnloadConfirmPanel(message, webFrame->frameID()), Messages::WebPageProxy::RunBeforeUnloadConfirmPanel::Reply(shouldClose), m_page->pageID()))
290         return false;
291
292     return shouldClose;
293 }
294
295 void WebChromeClient::closeWindowSoon()
296 {
297     // FIXME: This code assumes that the client will respond to a close page
298     // message by actually closing the page. Safari does this, but there is
299     // no guarantee that other applications will, which will leave this page
300     // half detached. This approach is an inherent limitation making parts of
301     // a close execute synchronously as part of window.close, but other parts
302     // later on.
303
304     m_page->corePage()->setGroupName(String());
305
306     if (WebFrame* frame = m_page->mainWebFrame()) {
307         if (Frame* coreFrame = frame->coreFrame())
308             coreFrame->loader()->stopForUserCancel();
309     }
310
311     m_page->sendClose();
312 }
313
314 void WebChromeClient::runJavaScriptAlert(Frame* frame, const String& alertText)
315 {
316     WebFrame* webFrame = static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame();
317
318     // Notify the bundle client.
319     m_page->injectedBundleUIClient().willRunJavaScriptAlert(m_page, alertText, webFrame);
320
321     unsigned syncSendFlags = (WebCore::AXObjectCache::accessibilityEnabled()) ? CoreIPC::SpinRunLoopWhileWaitingForReply : 0;
322     WebProcess::shared().connection()->sendSync(Messages::WebPageProxy::RunJavaScriptAlert(webFrame->frameID(), alertText), Messages::WebPageProxy::RunJavaScriptAlert::Reply(), m_page->pageID(), CoreIPC::Connection::NoTimeout, syncSendFlags);
323 }
324
325 bool WebChromeClient::runJavaScriptConfirm(Frame* frame, const String& message)
326 {
327     WebFrame* webFrame = static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame();
328
329     // Notify the bundle client.
330     m_page->injectedBundleUIClient().willRunJavaScriptConfirm(m_page, message, webFrame);
331
332     unsigned syncSendFlags = (WebCore::AXObjectCache::accessibilityEnabled()) ? CoreIPC::SpinRunLoopWhileWaitingForReply : 0;
333     bool result = false;
334     if (!WebProcess::shared().connection()->sendSync(Messages::WebPageProxy::RunJavaScriptConfirm(webFrame->frameID(), message), Messages::WebPageProxy::RunJavaScriptConfirm::Reply(result), m_page->pageID(), CoreIPC::Connection::NoTimeout, syncSendFlags))
335         return false;
336
337     return result;
338 }
339
340 bool WebChromeClient::runJavaScriptPrompt(Frame* frame, const String& message, const String& defaultValue, String& result)
341 {
342     WebFrame* webFrame = static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame();
343
344     // Notify the bundle client.
345     m_page->injectedBundleUIClient().willRunJavaScriptPrompt(m_page, message, defaultValue, webFrame);
346
347     unsigned syncSendFlags = (WebCore::AXObjectCache::accessibilityEnabled()) ? CoreIPC::SpinRunLoopWhileWaitingForReply : 0;
348     if (!WebProcess::shared().connection()->sendSync(Messages::WebPageProxy::RunJavaScriptPrompt(webFrame->frameID(), message, defaultValue), Messages::WebPageProxy::RunJavaScriptPrompt::Reply(result), m_page->pageID(), CoreIPC::Connection::NoTimeout, syncSendFlags))
349         return false;
350
351     return !result.isNull();
352 }
353
354 void WebChromeClient::setStatusbarText(const String& statusbarText)
355 {
356     // Notify the bundle client.
357     m_page->injectedBundleUIClient().willSetStatusbarText(m_page, statusbarText);
358
359     m_page->send(Messages::WebPageProxy::SetStatusText(statusbarText));
360 }
361
362 bool WebChromeClient::shouldInterruptJavaScript()
363 {
364     bool shouldInterrupt = false;
365     if (!WebProcess::shared().connection()->sendSync(Messages::WebPageProxy::ShouldInterruptJavaScript(), Messages::WebPageProxy::ShouldInterruptJavaScript::Reply(shouldInterrupt), m_page->pageID()))
366         return false;
367
368     return shouldInterrupt;
369 }
370
371 KeyboardUIMode WebChromeClient::keyboardUIMode()
372 {
373     return m_page->keyboardUIMode();
374 }
375
376 IntRect WebChromeClient::windowResizerRect() const
377 {
378     return m_page->windowResizerRect();
379 }
380
381 void WebChromeClient::invalidateRootView(const IntRect&, bool)
382 {
383     // Do nothing here, there's no concept of invalidating the window in the web process.
384 }
385
386 void WebChromeClient::invalidateContentsAndRootView(const IntRect& rect, bool)
387 {
388     if (Document* document = m_page->corePage()->mainFrame()->document()) {
389         if (document->printing())
390             return;
391     }
392
393     m_page->drawingArea()->setNeedsDisplay(rect);
394 }
395
396 void WebChromeClient::invalidateContentsForSlowScroll(const IntRect& rect, bool)
397 {
398     if (Document* document = m_page->corePage()->mainFrame()->document()) {
399         if (document->printing())
400             return;
401     }
402
403     m_page->pageDidScroll();
404     m_page->drawingArea()->setNeedsDisplay(rect);
405 }
406
407 void WebChromeClient::scroll(const IntSize& scrollOffset, const IntRect& scrollRect, const IntRect& clipRect)
408 {
409     m_page->pageDidScroll();
410     m_page->drawingArea()->scroll(intersection(scrollRect, clipRect), scrollOffset);
411 }
412
413 #if USE(TILED_BACKING_STORE)
414 void WebChromeClient::delegatedScrollRequested(const IntPoint& scrollOffset)
415 {
416     m_page->pageDidRequestScroll(scrollOffset);
417 }
418 #endif
419
420 IntPoint WebChromeClient::screenToRootView(const IntPoint& point) const
421 {
422     return m_page->screenToWindow(point);
423 }
424
425 IntRect WebChromeClient::rootViewToScreen(const IntRect& rect) const
426 {
427     return m_page->windowToScreen(rect);
428 }
429
430 PlatformPageClient WebChromeClient::platformPageClient() const
431 {
432     notImplemented();
433     return 0;
434 }
435
436 void WebChromeClient::contentsSizeChanged(Frame* frame, const IntSize& size) const
437 {
438     if (!m_page->corePage()->settings()->frameFlatteningEnabled()) {
439         WebFrame* largestFrame = findLargestFrameInFrameSet(m_page);
440         if (largestFrame != m_cachedFrameSetLargestFrame.get()) {
441             m_cachedFrameSetLargestFrame = largestFrame;
442             m_page->send(Messages::WebPageProxy::FrameSetLargestFrameChanged(largestFrame ? largestFrame->frameID() : 0));
443         }
444     }
445
446     if (frame->page()->mainFrame() != frame)
447         return;
448
449 #if PLATFORM(QT) || PLATFORM(EFL)
450     if (m_page->useFixedLayout()) {
451         // The below method updates the size().
452         m_page->resizeToContentsIfNeeded();
453         m_page->drawingArea()->layerTreeHost()->sizeDidChange(m_page->size());
454     }
455
456     m_page->send(Messages::WebPageProxy::DidChangeContentsSize(m_page->size()));
457 #endif
458
459     m_page->drawingArea()->mainFrameContentSizeChanged(size);
460
461     FrameView* frameView = frame->view();
462     if (frameView && !frameView->delegatesScrolling())  {
463         bool hasHorizontalScrollbar = frameView->horizontalScrollbar();
464         bool hasVerticalScrollbar = frameView->verticalScrollbar();
465
466         if (hasHorizontalScrollbar != m_cachedMainFrameHasHorizontalScrollbar || hasVerticalScrollbar != m_cachedMainFrameHasVerticalScrollbar) {
467             m_page->send(Messages::WebPageProxy::DidChangeScrollbarsForMainFrame(hasHorizontalScrollbar, hasVerticalScrollbar));
468
469             m_cachedMainFrameHasHorizontalScrollbar = hasHorizontalScrollbar;
470             m_cachedMainFrameHasVerticalScrollbar = hasVerticalScrollbar;
471         }
472     }
473 }
474
475 void WebChromeClient::scrollRectIntoView(const IntRect&) const
476 {
477     notImplemented();
478 }
479
480 bool WebChromeClient::shouldUnavailablePluginMessageBeButton(RenderEmbeddedObject::PluginUnavailabilityReason pluginUnavailabilityReason) const
481 {
482     switch (pluginUnavailabilityReason) {
483     case RenderEmbeddedObject::PluginMissing:
484         // FIXME: <rdar://problem/8794397> We should only return true when there is a
485         // missingPluginButtonClicked callback defined on the Page UI client.
486     case RenderEmbeddedObject::InsecurePluginVersion:
487     case RenderEmbeddedObject::PluginInactive:
488         return true;
489
490
491     case RenderEmbeddedObject::PluginCrashed:
492     case RenderEmbeddedObject::PluginBlockedByContentSecurityPolicy:
493         return false;
494     }
495
496     ASSERT_NOT_REACHED();
497     return false;
498 }
499     
500 void WebChromeClient::unavailablePluginButtonClicked(Element* element, RenderEmbeddedObject::PluginUnavailabilityReason pluginUnavailabilityReason) const
501 {
502     ASSERT(element->hasTagName(objectTag) || element->hasTagName(embedTag) || element->hasTagName(appletTag));
503     ASSERT(pluginUnavailabilityReason == RenderEmbeddedObject::PluginMissing || pluginUnavailabilityReason == RenderEmbeddedObject::InsecurePluginVersion || pluginUnavailabilityReason == RenderEmbeddedObject::PluginInactive);
504
505     HTMLPlugInImageElement* pluginElement = static_cast<HTMLPlugInImageElement*>(element);
506
507     m_page->send(Messages::WebPageProxy::UnavailablePluginButtonClicked(pluginUnavailabilityReason, pluginElement->serviceType(), pluginElement->url(), pluginElement->getAttribute(pluginspageAttr)));
508 }
509
510 void WebChromeClient::scrollbarsModeDidChange() const
511 {
512     notImplemented();
513 }
514
515 void WebChromeClient::mouseDidMoveOverElement(const HitTestResult& hitTestResult, unsigned modifierFlags)
516 {
517     RefPtr<APIObject> userData;
518
519     // Notify the bundle client.
520     m_page->injectedBundleUIClient().mouseDidMoveOverElement(m_page, hitTestResult, static_cast<WebEvent::Modifiers>(modifierFlags), userData);
521
522     // Notify the UIProcess.
523     WebHitTestResult::Data webHitTestResultData(hitTestResult);
524     m_page->send(Messages::WebPageProxy::MouseDidMoveOverElement(webHitTestResultData, modifierFlags, InjectedBundleUserMessageEncoder(userData.get())));
525 }
526
527 void WebChromeClient::setToolTip(const String& toolTip, TextDirection)
528 {
529     // Only send a tool tip to the WebProcess if it has changed since the last time this function was called.
530
531     if (toolTip == m_cachedToolTip)
532         return;
533     m_cachedToolTip = toolTip;
534
535     m_page->send(Messages::WebPageProxy::SetToolTip(m_cachedToolTip));
536 }
537
538 void WebChromeClient::print(Frame* frame)
539 {
540     WebFrame* webFrame = static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame();
541     m_page->sendSync(Messages::WebPageProxy::PrintFrame(webFrame->frameID()), Messages::WebPageProxy::PrintFrame::Reply());
542 }
543
544 #if ENABLE(SQL_DATABASE)
545 void WebChromeClient::exceededDatabaseQuota(Frame* frame, const String& databaseName, DatabaseDetails details)
546 {
547     WebFrame* webFrame = static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame();
548     SecurityOrigin* origin = frame->document()->securityOrigin();
549
550     DatabaseManager& dbManager = DatabaseManager::manager();
551     uint64_t currentQuota = dbManager.quotaForOrigin(origin);
552     uint64_t currentOriginUsage = dbManager.usageForOrigin(origin);
553     uint64_t newQuota = 0;
554     RefPtr<WebSecurityOrigin> webSecurityOrigin = WebSecurityOrigin::createFromDatabaseIdentifier(origin->databaseIdentifier());
555     newQuota = m_page->injectedBundleUIClient().didExceedDatabaseQuota(m_page, webSecurityOrigin.get(), databaseName, details.displayName(), currentQuota, currentOriginUsage, details.currentUsage(), details.expectedUsage());
556
557     if (!newQuota) {
558         WebProcess::shared().connection()->sendSync(
559             Messages::WebPageProxy::ExceededDatabaseQuota(webFrame->frameID(), origin->databaseIdentifier(), databaseName, details.displayName(), currentQuota, currentOriginUsage, details.currentUsage(), details.expectedUsage()),
560             Messages::WebPageProxy::ExceededDatabaseQuota::Reply(newQuota), m_page->pageID());
561     }
562
563     dbManager.setQuota(origin, newQuota);
564 }
565 #endif
566
567
568 void WebChromeClient::reachedMaxAppCacheSize(int64_t)
569 {
570     notImplemented();
571 }
572
573 void WebChromeClient::reachedApplicationCacheOriginQuota(SecurityOrigin* origin, int64_t totalBytesNeeded)
574 {
575     RefPtr<WebSecurityOrigin> webSecurityOrigin = WebSecurityOrigin::createFromString(origin->toString());
576     m_page->injectedBundleUIClient().didReachApplicationCacheOriginQuota(m_page, webSecurityOrigin.get(), totalBytesNeeded);
577 }
578
579 #if ENABLE(DASHBOARD_SUPPORT)
580 void WebChromeClient::annotatedRegionsChanged()
581 {
582     notImplemented();
583 }
584 #endif
585
586 void WebChromeClient::populateVisitedLinks()
587 {
588 }
589
590 FloatRect WebChromeClient::customHighlightRect(Node*, const AtomicString& /*type*/, const FloatRect& /*lineRect*/)
591 {
592     notImplemented();
593     return FloatRect();
594 }
595
596 void WebChromeClient::paintCustomHighlight(Node*, const AtomicString& /*type*/, const FloatRect& /*boxRect*/, const FloatRect& /*lineRect*/, 
597                                            bool /*behindText*/, bool /*entireLine*/)
598 {
599     notImplemented();
600 }
601
602 bool WebChromeClient::shouldReplaceWithGeneratedFileForUpload(const String& path, String& generatedFilename)
603 {
604     generatedFilename = m_page->injectedBundleUIClient().shouldGenerateFileForUpload(m_page, path);
605     return !generatedFilename.isNull();
606 }
607
608 String WebChromeClient::generateReplacementFile(const String& path)
609 {
610     return m_page->injectedBundleUIClient().generateFileForUpload(m_page, path);
611 }
612
613 bool WebChromeClient::paintCustomOverhangArea(GraphicsContext* context, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect)
614 {
615     if (!m_page->injectedBundleUIClient().shouldPaintCustomOverhangArea())
616         return false;
617
618     m_page->injectedBundleUIClient().paintCustomOverhangArea(m_page, context, horizontalOverhangArea, verticalOverhangArea, dirtyRect);
619     return true;
620 }
621
622 #if ENABLE(INPUT_TYPE_COLOR)
623 PassOwnPtr<ColorChooser> WebChromeClient::createColorChooser(ColorChooserClient* client, const Color& initialColor)
624 {
625     if (m_page->activeColorChooser())
626         return nullptr;
627
628     return adoptPtr(new WebColorChooser(m_page, client, initialColor));
629 }
630 #endif
631
632 void WebChromeClient::runOpenPanel(Frame* frame, PassRefPtr<FileChooser> prpFileChooser)
633 {
634     if (m_page->activeOpenPanelResultListener())
635         return;
636
637     RefPtr<FileChooser> fileChooser = prpFileChooser;
638
639     m_page->setActiveOpenPanelResultListener(WebOpenPanelResultListener::create(m_page, fileChooser.get()));
640     m_page->send(Messages::WebPageProxy::RunOpenPanel(static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame()->frameID(), fileChooser->settings()));
641 }
642
643 void WebChromeClient::loadIconForFiles(const Vector<String>& filenames, FileIconLoader* loader)
644 {
645     loader->notifyFinished(Icon::createIconForFiles(filenames));
646 }
647
648 void WebChromeClient::setCursor(const WebCore::Cursor& cursor)
649 {
650 #if USE(LAZY_NATIVE_CURSOR)
651     m_page->send(Messages::WebPageProxy::SetCursor(cursor));
652 #endif
653 }
654
655 void WebChromeClient::setCursorHiddenUntilMouseMoves(bool hiddenUntilMouseMoves)
656 {
657     m_page->send(Messages::WebPageProxy::SetCursorHiddenUntilMouseMoves(hiddenUntilMouseMoves));
658 }
659
660 #if ENABLE(REQUEST_ANIMATION_FRAME) && !USE(REQUEST_ANIMATION_FRAME_TIMER)
661 void WebChromeClient::scheduleAnimation()
662 {
663 #if USE(COORDINATED_GRAPHICS)
664     m_page->drawingArea()->layerTreeHost()->scheduleAnimation();
665 #endif
666 }
667 #endif
668
669 void WebChromeClient::formStateDidChange(const Node*)
670 {
671     notImplemented();
672 }
673
674 bool WebChromeClient::selectItemWritingDirectionIsNatural()
675 {
676 #if PLATFORM(EFL)
677     return true;
678 #else
679     return false;
680 #endif
681 }
682
683 bool WebChromeClient::selectItemAlignmentFollowsMenuWritingDirection()
684 {
685     return true;
686 }
687
688 bool WebChromeClient::hasOpenedPopup() const
689 {
690     notImplemented();
691     return false;
692 }
693
694 PassRefPtr<WebCore::PopupMenu> WebChromeClient::createPopupMenu(WebCore::PopupMenuClient* client) const
695 {
696     return WebPopupMenu::create(m_page, client);
697 }
698
699 PassRefPtr<WebCore::SearchPopupMenu> WebChromeClient::createSearchPopupMenu(WebCore::PopupMenuClient* client) const
700 {
701     return WebSearchPopupMenu::create(m_page, client);
702 }
703
704 #if USE(ACCELERATED_COMPOSITING)
705 GraphicsLayerFactory* WebChromeClient::graphicsLayerFactory() const
706 {
707     return m_page->drawingArea()->graphicsLayerFactory();
708 }
709
710 void WebChromeClient::attachRootGraphicsLayer(Frame*, GraphicsLayer* layer)
711 {
712     if (layer)
713         m_page->enterAcceleratedCompositingMode(layer);
714     else
715         m_page->exitAcceleratedCompositingMode();
716 }
717
718 void WebChromeClient::setNeedsOneShotDrawingSynchronization()
719 {
720     notImplemented();
721 }
722
723 void WebChromeClient::scheduleCompositingLayerFlush()
724 {
725     if (m_page->drawingArea())
726         m_page->drawingArea()->scheduleCompositingLayerFlush();
727 }
728
729 #endif
730
731 #if ENABLE(TOUCH_EVENTS)
732 void WebChromeClient::needTouchEvents(bool needTouchEvents)
733 {
734     m_page->send(Messages::WebPageProxy::NeedTouchEvents(needTouchEvents));
735 }
736 #endif
737
738 #if ENABLE(FULLSCREEN_API)
739 bool WebChromeClient::supportsFullScreenForElement(const WebCore::Element*, bool withKeyboard)
740 {
741     return m_page->fullScreenManager()->supportsFullScreen(withKeyboard);
742 }
743
744 void WebChromeClient::enterFullScreenForElement(WebCore::Element* element)
745 {
746     m_page->fullScreenManager()->enterFullScreenForElement(element);
747 }
748
749 void WebChromeClient::exitFullScreenForElement(WebCore::Element* element)
750 {
751     m_page->fullScreenManager()->exitFullScreenForElement(element);
752 }
753 #endif
754
755 void WebChromeClient::dispatchViewportPropertiesDidChange(const ViewportArguments&) const
756 {
757 #if USE(TILED_BACKING_STORE)
758     if (!m_page->useFixedLayout())
759         return;
760
761     m_page->sendViewportAttributesChanged();
762 #endif
763 }
764
765 void WebChromeClient::notifyScrollerThumbIsVisibleInRect(const IntRect& scrollerThumb)
766 {
767     m_page->send(Messages::WebPageProxy::NotifyScrollerThumbIsVisibleInRect(scrollerThumb));
768 }
769
770 void WebChromeClient::recommendedScrollbarStyleDidChange(int32_t newStyle)
771 {
772     m_page->send(Messages::WebPageProxy::RecommendedScrollbarStyleDidChange(newStyle));
773 }
774
775 bool WebChromeClient::shouldRubberBandInDirection(WebCore::ScrollDirection direction) const
776 {
777     ASSERT(direction != WebCore::ScrollUp && direction != WebCore::ScrollDown);
778     
779     if (direction == WebCore::ScrollLeft)
780         return m_page->injectedBundleUIClient().shouldRubberBandInDirection(m_page, WKScrollDirectionLeft);
781     if (direction == WebCore::ScrollRight)
782         return m_page->injectedBundleUIClient().shouldRubberBandInDirection(m_page, WKScrollDirectionRight);
783
784     ASSERT_NOT_REACHED();
785     return true;
786 }
787
788 void WebChromeClient::numWheelEventHandlersChanged(unsigned count)
789 {
790     m_page->numWheelEventHandlersChanged(count);
791 }
792
793 void WebChromeClient::logDiagnosticMessage(const String& message, const String& description, const String& success)
794 {
795     if (!m_page->corePage()->settings()->diagnosticLoggingEnabled())
796         return;
797
798     m_page->injectedBundleDiagnosticLoggingClient().logDiagnosticMessage(m_page, message, description, success);
799 }
800
801 PassRefPtr<Image> WebChromeClient::plugInStartLabelImage(RenderSnapshottedPlugIn::LabelSize size) const
802 {
803     return m_page->injectedBundleUIClient().plugInStartLabelImage(size)->bitmap()->createImage();
804 }
805
806 String WebChromeClient::plugInStartLabelTitle() const
807 {
808     return m_page->injectedBundleUIClient().plugInStartLabelTitle();
809 }
810
811 String WebChromeClient::plugInStartLabelSubtitle() const
812 {
813     return m_page->injectedBundleUIClient().plugInStartLabelSubtitle();
814 }
815
816 String WebChromeClient::plugInExtraStyleSheet() const
817 {
818     return m_page->injectedBundleUIClient().plugInExtraStyleSheet();
819 }
820
821 } // namespace WebKit