[iOS] Synchronize the WKContentView and UIScrollView updates with the tiles being...
[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 "PageBanner.h"
35 #include "WebColorChooser.h"
36 #include "WebCoreArgumentCoders.h"
37 #include "WebFrame.h"
38 #include "WebFrameLoaderClient.h"
39 #include "WebFullScreenManager.h"
40 #include "WebImage.h"
41 #include "WebOpenPanelParameters.h"
42 #include "WebOpenPanelResultListener.h"
43 #include "WebPage.h"
44 #include "WebPageCreationParameters.h"
45 #include "WebPageProxyMessages.h"
46 #include "WebPopupMenu.h"
47 #include "WebPreferencesStore.h"
48 #include "WebProcess.h"
49 #include "WebProcessProxyMessages.h"
50 #include "WebSearchPopupMenu.h"
51 #include "WebSecurityOrigin.h"
52 #include <WebCore/AXObjectCache.h>
53 #include <WebCore/ColorChooser.h>
54 #include <WebCore/DatabaseManager.h>
55 #include <WebCore/DocumentLoader.h>
56 #include <WebCore/FileChooser.h>
57 #include <WebCore/FileIconLoader.h>
58 #include <WebCore/FrameLoadRequest.h>
59 #include <WebCore/FrameLoader.h>
60 #include <WebCore/FrameView.h>
61 #include <WebCore/HTMLInputElement.h>
62 #include <WebCore/HTMLNames.h>
63 #include <WebCore/HTMLParserIdioms.h>
64 #include <WebCore/HTMLPlugInImageElement.h>
65 #include <WebCore/Icon.h>
66 #include <WebCore/MainFrame.h>
67 #include <WebCore/NotImplemented.h>
68 #include <WebCore/Page.h>
69 #include <WebCore/SecurityOrigin.h>
70 #include <WebCore/Settings.h>
71
72 #if ENABLE(ASYNC_SCROLLING)
73 #include "RemoteScrollingCoordinator.h"
74 #endif
75
76 #if PLATFORM(GTK)
77 #include "PrinterListGtk.h"
78 #endif
79
80 using namespace WebCore;
81 using namespace HTMLNames;
82
83 namespace WebKit {
84
85 static double area(WebFrame* frame)
86 {
87     IntSize size = frame->visibleContentBoundsExcludingScrollbars().size();
88     return static_cast<double>(size.height()) * size.width();
89 }
90
91
92 static WebFrame* findLargestFrameInFrameSet(WebPage* page)
93 {
94     // Approximate what a user could consider a default target frame for application menu operations.
95
96     WebFrame* mainFrame = page->mainWebFrame();
97     if (!mainFrame || !mainFrame->isFrameSet())
98         return 0;
99
100     WebFrame* largestSoFar = 0;
101
102     RefPtr<API::Array> frameChildren = mainFrame->childFrames();
103     size_t count = frameChildren->size();
104     for (size_t i = 0; i < count; ++i) {
105         WebFrame* childFrame = frameChildren->at<WebFrame>(i);
106         if (!largestSoFar || area(childFrame) > area(largestSoFar))
107             largestSoFar = childFrame;
108     }
109
110     return largestSoFar;
111 }
112
113 void WebChromeClient::chromeDestroyed()
114 {
115     delete this;
116 }
117
118 void WebChromeClient::setWindowRect(const FloatRect& windowFrame)
119 {
120     m_page->sendSetWindowFrame(windowFrame);
121 }
122
123 FloatRect WebChromeClient::windowRect()
124 {
125 #if PLATFORM(MAC)
126     if (m_page->hasCachedWindowFrame())
127         return m_page->windowFrameInUnflippedScreenCoordinates();
128 #endif
129
130     FloatRect newWindowFrame;
131
132     if (!WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebPageProxy::GetWindowFrame(), Messages::WebPageProxy::GetWindowFrame::Reply(newWindowFrame), m_page->pageID()))
133         return FloatRect();
134
135     return newWindowFrame;
136 }
137
138 FloatRect WebChromeClient::pageRect()
139 {
140     return FloatRect(FloatPoint(), m_page->size());
141 }
142
143 void WebChromeClient::focus()
144 {
145     m_page->send(Messages::WebPageProxy::SetFocus(true));
146 }
147
148 void WebChromeClient::unfocus()
149 {
150     m_page->send(Messages::WebPageProxy::SetFocus(false));
151 }
152
153 #if PLATFORM(MAC)
154 void WebChromeClient::makeFirstResponder()
155 {
156     m_page->send(Messages::WebPageProxy::MakeFirstResponder());
157 }    
158 #endif    
159
160 bool WebChromeClient::canTakeFocus(FocusDirection)
161 {
162     notImplemented();
163     return true;
164 }
165
166 void WebChromeClient::takeFocus(FocusDirection direction)
167 {
168     m_page->send(Messages::WebPageProxy::TakeFocus(direction));
169 }
170
171 void WebChromeClient::focusedElementChanged(Element* element)
172 {
173     if (!element)
174         return;
175     if (!isHTMLInputElement(element))
176         return;
177
178     HTMLInputElement* inputElement = toHTMLInputElement(element);
179     if (!inputElement->isText())
180         return;
181
182     WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(element->document().frame()->loader().client());
183     WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0;
184     ASSERT(webFrame);
185     m_page->injectedBundleFormClient().didFocusTextField(m_page, inputElement, webFrame);
186 }
187
188 void WebChromeClient::focusedFrameChanged(Frame* frame)
189 {
190     WebFrameLoaderClient* webFrameLoaderClient = frame ? toWebFrameLoaderClient(frame->loader().client()) : 0;
191     WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0;
192
193     WebProcess::shared().parentProcessConnection()->send(Messages::WebPageProxy::FocusedFrameChanged(webFrame ? webFrame->frameID() : 0), m_page->pageID());
194 }
195
196 Page* WebChromeClient::createWindow(Frame* frame, const FrameLoadRequest& request, const WindowFeatures& windowFeatures, const NavigationAction& navigationAction)
197 {
198     uint32_t modifiers = static_cast<uint32_t>(InjectedBundleNavigationAction::modifiersForNavigationAction(navigationAction));
199     int32_t mouseButton = static_cast<int32_t>(InjectedBundleNavigationAction::mouseButtonForNavigationAction(navigationAction));
200
201 #if ENABLE(FULLSCREEN_API)
202     if (frame->document() && frame->document()->webkitCurrentFullScreenElement())
203         frame->document()->webkitCancelFullScreen();
204 #else
205     UNUSED_PARAM(frame);
206 #endif
207
208     uint64_t newPageID = 0;
209     WebPageCreationParameters parameters;
210     if (!WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebPageProxy::CreateNewPage(request.resourceRequest(), windowFeatures, modifiers, mouseButton), Messages::WebPageProxy::CreateNewPage::Reply(newPageID, parameters), m_page->pageID()))
211         return 0;
212
213     if (!newPageID)
214         return 0;
215
216     WebProcess::shared().createWebPage(newPageID, parameters);
217     return WebProcess::shared().webPage(newPageID)->corePage();
218 }
219
220 void WebChromeClient::show()
221 {
222     m_page->show();
223 }
224
225 bool WebChromeClient::canRunModal()
226 {
227     return m_page->canRunModal();
228 }
229
230 void WebChromeClient::runModal()
231 {
232     m_page->runModal();
233 }
234
235 void WebChromeClient::setToolbarsVisible(bool toolbarsAreVisible)
236 {
237     m_page->send(Messages::WebPageProxy::SetToolbarsAreVisible(toolbarsAreVisible));
238 }
239
240 bool WebChromeClient::toolbarsVisible()
241 {
242     WKBundlePageUIElementVisibility toolbarsVisibility = m_page->injectedBundleUIClient().toolbarsAreVisible(m_page);
243     if (toolbarsVisibility != WKBundlePageUIElementVisibilityUnknown)
244         return toolbarsVisibility == WKBundlePageUIElementVisible;
245     
246     bool toolbarsAreVisible = true;
247     if (!WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebPageProxy::GetToolbarsAreVisible(), Messages::WebPageProxy::GetToolbarsAreVisible::Reply(toolbarsAreVisible), m_page->pageID()))
248         return true;
249
250     return toolbarsAreVisible;
251 }
252
253 void WebChromeClient::setStatusbarVisible(bool statusBarIsVisible)
254 {
255     m_page->send(Messages::WebPageProxy::SetStatusBarIsVisible(statusBarIsVisible));
256 }
257
258 bool WebChromeClient::statusbarVisible()
259 {
260     WKBundlePageUIElementVisibility statusbarVisibility = m_page->injectedBundleUIClient().statusBarIsVisible(m_page);
261     if (statusbarVisibility != WKBundlePageUIElementVisibilityUnknown)
262         return statusbarVisibility == WKBundlePageUIElementVisible;
263
264     bool statusBarIsVisible = true;
265     if (!WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebPageProxy::GetStatusBarIsVisible(), Messages::WebPageProxy::GetStatusBarIsVisible::Reply(statusBarIsVisible), m_page->pageID()))
266         return true;
267
268     return statusBarIsVisible;
269 }
270
271 void WebChromeClient::setScrollbarsVisible(bool)
272 {
273     notImplemented();
274 }
275
276 bool WebChromeClient::scrollbarsVisible()
277 {
278     notImplemented();
279     return true;
280 }
281
282 void WebChromeClient::setMenubarVisible(bool menuBarVisible)
283 {
284     m_page->send(Messages::WebPageProxy::SetMenuBarIsVisible(menuBarVisible));
285 }
286
287 bool WebChromeClient::menubarVisible()
288 {
289     WKBundlePageUIElementVisibility menubarVisibility = m_page->injectedBundleUIClient().menuBarIsVisible(m_page);
290     if (menubarVisibility != WKBundlePageUIElementVisibilityUnknown)
291         return menubarVisibility == WKBundlePageUIElementVisible;
292     
293     bool menuBarIsVisible = true;
294     if (!WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebPageProxy::GetMenuBarIsVisible(), Messages::WebPageProxy::GetMenuBarIsVisible::Reply(menuBarIsVisible), m_page->pageID()))
295         return true;
296
297     return menuBarIsVisible;
298 }
299
300 void WebChromeClient::setResizable(bool resizable)
301 {
302     m_page->send(Messages::WebPageProxy::SetIsResizable(resizable));
303 }
304
305 void WebChromeClient::addMessageToConsole(MessageSource, MessageLevel, const String& message, unsigned lineNumber, unsigned /*columnNumber*/, const String& /*sourceID*/)
306 {
307     // Notify the bundle client.
308     m_page->injectedBundleUIClient().willAddMessageToConsole(m_page, message, lineNumber);
309
310     notImplemented();
311 }
312
313 bool WebChromeClient::canRunBeforeUnloadConfirmPanel()
314 {
315     return m_page->canRunBeforeUnloadConfirmPanel();
316 }
317
318 bool WebChromeClient::runBeforeUnloadConfirmPanel(const String& message, Frame* frame)
319 {
320     WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(frame->loader().client());
321     WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0;
322     ASSERT(webFrame);
323
324     bool shouldClose = false;
325     if (!WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebPageProxy::RunBeforeUnloadConfirmPanel(message, webFrame->frameID()), Messages::WebPageProxy::RunBeforeUnloadConfirmPanel::Reply(shouldClose), m_page->pageID()))
326         return false;
327
328     return shouldClose;
329 }
330
331 void WebChromeClient::closeWindowSoon()
332 {
333     // FIXME: This code assumes that the client will respond to a close page
334     // message by actually closing the page. Safari does this, but there is
335     // no guarantee that other applications will, which will leave this page
336     // half detached. This approach is an inherent limitation making parts of
337     // a close execute synchronously as part of window.close, but other parts
338     // later on.
339
340     m_page->corePage()->setGroupName(String());
341
342     if (WebFrame* frame = m_page->mainWebFrame()) {
343         if (Frame* coreFrame = frame->coreFrame())
344             coreFrame->loader().stopForUserCancel();
345     }
346
347     m_page->sendClose();
348 }
349
350 void WebChromeClient::runJavaScriptAlert(Frame* frame, const String& alertText)
351 {
352     WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(frame->loader().client());
353     WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0;
354     ASSERT(webFrame);
355
356     // Notify the bundle client.
357     m_page->injectedBundleUIClient().willRunJavaScriptAlert(m_page, alertText, webFrame);
358
359     // FIXME (126021): It is not good to change IPC behavior conditionally, and SpinRunLoopWhileWaitingForReply was known to cause trouble in other similar cases.
360     unsigned syncSendFlags = (WebCore::AXObjectCache::accessibilityEnabled()) ? IPC::SpinRunLoopWhileWaitingForReply : 0;
361     WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebPageProxy::RunJavaScriptAlert(webFrame->frameID(), alertText), Messages::WebPageProxy::RunJavaScriptAlert::Reply(), m_page->pageID(), std::chrono::milliseconds::max(), syncSendFlags);
362 }
363
364 bool WebChromeClient::runJavaScriptConfirm(Frame* frame, const String& message)
365 {
366     WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(frame->loader().client());
367     WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0;
368     ASSERT(webFrame);
369
370     // Notify the bundle client.
371     m_page->injectedBundleUIClient().willRunJavaScriptConfirm(m_page, message, webFrame);
372
373     // FIXME (126021): It is not good to change IPC behavior conditionally, and SpinRunLoopWhileWaitingForReply was known to cause trouble in other similar cases.
374     unsigned syncSendFlags = (WebCore::AXObjectCache::accessibilityEnabled()) ? IPC::SpinRunLoopWhileWaitingForReply : 0;
375     bool result = false;
376     if (!WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebPageProxy::RunJavaScriptConfirm(webFrame->frameID(), message), Messages::WebPageProxy::RunJavaScriptConfirm::Reply(result), m_page->pageID(), std::chrono::milliseconds::max(), syncSendFlags))
377         return false;
378
379     return result;
380 }
381
382 bool WebChromeClient::runJavaScriptPrompt(Frame* frame, const String& message, const String& defaultValue, String& result)
383 {
384     WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(frame->loader().client());
385     WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0;
386     ASSERT(webFrame);
387
388     // Notify the bundle client.
389     m_page->injectedBundleUIClient().willRunJavaScriptPrompt(m_page, message, defaultValue, webFrame);
390
391     // FIXME (126021): It is not good to change IPC behavior conditionally, and SpinRunLoopWhileWaitingForReply was known to cause trouble in other similar cases.
392     unsigned syncSendFlags = (WebCore::AXObjectCache::accessibilityEnabled()) ? IPC::SpinRunLoopWhileWaitingForReply : 0;
393     if (!WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebPageProxy::RunJavaScriptPrompt(webFrame->frameID(), message, defaultValue), Messages::WebPageProxy::RunJavaScriptPrompt::Reply(result), m_page->pageID(), std::chrono::milliseconds::max(), syncSendFlags))
394         return false;
395
396     return !result.isNull();
397 }
398
399 void WebChromeClient::setStatusbarText(const String& statusbarText)
400 {
401     // Notify the bundle client.
402     m_page->injectedBundleUIClient().willSetStatusbarText(m_page, statusbarText);
403
404     m_page->send(Messages::WebPageProxy::SetStatusText(statusbarText));
405 }
406
407 bool WebChromeClient::shouldInterruptJavaScript()
408 {
409     bool shouldInterrupt = false;
410     if (!WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebPageProxy::ShouldInterruptJavaScript(), Messages::WebPageProxy::ShouldInterruptJavaScript::Reply(shouldInterrupt), m_page->pageID()))
411         return false;
412
413     return shouldInterrupt;
414 }
415
416 KeyboardUIMode WebChromeClient::keyboardUIMode()
417 {
418     return m_page->keyboardUIMode();
419 }
420
421 IntRect WebChromeClient::windowResizerRect() const
422 {
423     return m_page->windowResizerRect();
424 }
425
426 void WebChromeClient::invalidateRootView(const IntRect&, bool)
427 {
428     // Do nothing here, there's no concept of invalidating the window in the web process.
429 }
430
431 void WebChromeClient::invalidateContentsAndRootView(const IntRect& rect, bool)
432 {
433     if (Document* document = m_page->corePage()->mainFrame().document()) {
434         if (document->printing())
435             return;
436     }
437
438     m_page->drawingArea()->setNeedsDisplayInRect(rect);
439 }
440
441 void WebChromeClient::invalidateContentsForSlowScroll(const IntRect& rect, bool)
442 {
443     if (Document* document = m_page->corePage()->mainFrame().document()) {
444         if (document->printing())
445             return;
446     }
447
448     m_page->pageDidScroll();
449 #if USE(COORDINATED_GRAPHICS)
450     m_page->drawingArea()->scroll(rect, IntSize());
451 #else
452     m_page->drawingArea()->setNeedsDisplayInRect(rect);
453 #endif
454 }
455
456 void WebChromeClient::scroll(const IntSize& scrollDelta, const IntRect& scrollRect, const IntRect& clipRect)
457 {
458     m_page->pageDidScroll();
459     m_page->drawingArea()->scroll(intersection(scrollRect, clipRect), scrollDelta);
460 }
461
462 #if USE(TILED_BACKING_STORE)
463 void WebChromeClient::delegatedScrollRequested(const IntPoint& scrollOffset)
464 {
465     m_page->pageDidRequestScroll(scrollOffset);
466 }
467 #endif
468
469 IntPoint WebChromeClient::screenToRootView(const IntPoint& point) const
470 {
471     return m_page->screenToWindow(point);
472 }
473
474 IntRect WebChromeClient::rootViewToScreen(const IntRect& rect) const
475 {
476     return m_page->windowToScreen(rect);
477 }
478
479 PlatformPageClient WebChromeClient::platformPageClient() const
480 {
481     notImplemented();
482     return 0;
483 }
484
485 void WebChromeClient::contentsSizeChanged(Frame* frame, const IntSize& size) const
486 {
487     if (!m_page->corePage()->settings().frameFlatteningEnabled()) {
488         WebFrame* largestFrame = findLargestFrameInFrameSet(m_page);
489         if (largestFrame != m_cachedFrameSetLargestFrame.get()) {
490             m_cachedFrameSetLargestFrame = largestFrame;
491             m_page->send(Messages::WebPageProxy::FrameSetLargestFrameChanged(largestFrame ? largestFrame->frameID() : 0));
492         }
493     }
494
495     if (&frame->page()->mainFrame() != frame)
496         return;
497
498 #if USE(COORDINATED_GRAPHICS)
499     if (m_page->useFixedLayout())
500         m_page->drawingArea()->layerTreeHost()->sizeDidChange(size);
501
502     m_page->send(Messages::WebPageProxy::DidChangeContentSize(size));
503 #endif
504
505
506     m_page->drawingArea()->mainFrameContentSizeChanged(size);
507
508     FrameView* frameView = frame->view();
509     if (frameView && !frameView->delegatesScrolling())  {
510         bool hasHorizontalScrollbar = frameView->horizontalScrollbar();
511         bool hasVerticalScrollbar = frameView->verticalScrollbar();
512
513         if (hasHorizontalScrollbar != m_cachedMainFrameHasHorizontalScrollbar || hasVerticalScrollbar != m_cachedMainFrameHasVerticalScrollbar) {
514             m_page->send(Messages::WebPageProxy::DidChangeScrollbarsForMainFrame(hasHorizontalScrollbar, hasVerticalScrollbar));
515
516             m_cachedMainFrameHasHorizontalScrollbar = hasHorizontalScrollbar;
517             m_cachedMainFrameHasVerticalScrollbar = hasVerticalScrollbar;
518         }
519     }
520 }
521
522 void WebChromeClient::scrollRectIntoView(const IntRect&) const
523 {
524     notImplemented();
525 }
526
527 bool WebChromeClient::shouldUnavailablePluginMessageBeButton(RenderEmbeddedObject::PluginUnavailabilityReason pluginUnavailabilityReason) const
528 {
529     switch (pluginUnavailabilityReason) {
530     case RenderEmbeddedObject::PluginMissing:
531         // FIXME: <rdar://problem/8794397> We should only return true when there is a
532         // missingPluginButtonClicked callback defined on the Page UI client.
533     case RenderEmbeddedObject::InsecurePluginVersion:
534         return true;
535
536
537     case RenderEmbeddedObject::PluginCrashed:
538     case RenderEmbeddedObject::PluginBlockedByContentSecurityPolicy:
539         return false;
540     }
541
542     ASSERT_NOT_REACHED();
543     return false;
544 }
545     
546 void WebChromeClient::unavailablePluginButtonClicked(Element* element, RenderEmbeddedObject::PluginUnavailabilityReason pluginUnavailabilityReason) const
547 {
548 #if ENABLE(NETSCAPE_PLUGIN_API)
549     ASSERT(element->hasTagName(objectTag) || element->hasTagName(embedTag) || element->hasTagName(appletTag));
550     ASSERT(pluginUnavailabilityReason == RenderEmbeddedObject::PluginMissing || pluginUnavailabilityReason == RenderEmbeddedObject::InsecurePluginVersion || pluginUnavailabilityReason);
551
552     HTMLPlugInImageElement* pluginElement = static_cast<HTMLPlugInImageElement*>(element);
553
554     String frameURLString = pluginElement->document().frame()->loader().documentLoader()->responseURL().string();
555     String pageURLString = m_page->mainFrame()->loader().documentLoader()->responseURL().string();
556     String pluginURLString = pluginElement->document().completeURL(pluginElement->url()).string();
557     URL pluginspageAttributeURL = element->document().completeURL(stripLeadingAndTrailingHTMLSpaces(pluginElement->getAttribute(pluginspageAttr)));
558     if (!pluginspageAttributeURL.protocolIsInHTTPFamily())
559         pluginspageAttributeURL = URL();
560     m_page->send(Messages::WebPageProxy::UnavailablePluginButtonClicked(pluginUnavailabilityReason, pluginElement->serviceType(), pluginURLString, pluginspageAttributeURL.string(), frameURLString, pageURLString));
561 #else
562     UNUSED_PARAM(element);
563     UNUSED_PARAM(pluginUnavailabilityReason);
564 #endif // ENABLE(NETSCAPE_PLUGIN_API)
565 }
566
567 void WebChromeClient::scrollbarsModeDidChange() const
568 {
569     notImplemented();
570 }
571
572 void WebChromeClient::mouseDidMoveOverElement(const HitTestResult& hitTestResult, unsigned modifierFlags)
573 {
574     RefPtr<API::Object> userData;
575
576     // Notify the bundle client.
577     m_page->injectedBundleUIClient().mouseDidMoveOverElement(m_page, hitTestResult, static_cast<WebEvent::Modifiers>(modifierFlags), userData);
578
579     // Notify the UIProcess.
580     WebHitTestResult::Data webHitTestResultData(hitTestResult);
581     m_page->send(Messages::WebPageProxy::MouseDidMoveOverElement(webHitTestResultData, modifierFlags, InjectedBundleUserMessageEncoder(userData.get())));
582 }
583
584 void WebChromeClient::setToolTip(const String& toolTip, TextDirection)
585 {
586     // Only send a tool tip to the WebProcess if it has changed since the last time this function was called.
587
588     if (toolTip == m_cachedToolTip)
589         return;
590     m_cachedToolTip = toolTip;
591
592     m_page->send(Messages::WebPageProxy::SetToolTip(m_cachedToolTip));
593 }
594
595 void WebChromeClient::print(Frame* frame)
596 {
597     WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(frame->loader().client());
598     WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0;
599     ASSERT(webFrame);
600
601 #if PLATFORM(GTK) && defined(HAVE_GTK_UNIX_PRINTING)
602     // When printing synchronously in GTK+ we need to make sure that we have a list of Printers before starting the print operation.
603     // Getting the list of printers is done synchronously by GTK+, but using a nested main loop that might process IPC messages
604     // comming from the UI process like EndPrinting. When the EndPriting message is received while the printer list is being populated,
605     // the print operation is finished unexpectely and the web process crashes, see https://bugs.webkit.org/show_bug.cgi?id=126979.
606     // The PrinterListGtk class gets the list of printers in the constructor so we just need to ensure there's an instance alive
607     // during the synchronous print operation.
608     RefPtr<PrinterListGtk> printerList = PrinterListGtk::shared();
609 #endif
610
611     m_page->sendSync(Messages::WebPageProxy::PrintFrame(webFrame->frameID()), Messages::WebPageProxy::PrintFrame::Reply());
612 }
613
614 #if ENABLE(SQL_DATABASE)
615 void WebChromeClient::exceededDatabaseQuota(Frame* frame, const String& databaseName, DatabaseDetails details)
616 {
617     WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(frame->loader().client());
618     WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0;
619     ASSERT(webFrame);
620     
621     SecurityOrigin* origin = frame->document()->securityOrigin();
622
623     DatabaseManager& dbManager = DatabaseManager::manager();
624     uint64_t currentQuota = dbManager.quotaForOrigin(origin);
625     uint64_t currentOriginUsage = dbManager.usageForOrigin(origin);
626     uint64_t newQuota = 0;
627     RefPtr<WebSecurityOrigin> webSecurityOrigin = WebSecurityOrigin::createFromDatabaseIdentifier(origin->databaseIdentifier());
628     newQuota = m_page->injectedBundleUIClient().didExceedDatabaseQuota(m_page, webSecurityOrigin.get(), databaseName, details.displayName(), currentQuota, currentOriginUsage, details.currentUsage(), details.expectedUsage());
629
630     if (!newQuota) {
631         WebProcess::shared().parentProcessConnection()->sendSync(
632             Messages::WebPageProxy::ExceededDatabaseQuota(webFrame->frameID(), origin->databaseIdentifier(), databaseName, details.displayName(), currentQuota, currentOriginUsage, details.currentUsage(), details.expectedUsage()),
633             Messages::WebPageProxy::ExceededDatabaseQuota::Reply(newQuota), m_page->pageID());
634     }
635
636     dbManager.setQuota(origin, newQuota);
637 }
638 #endif
639
640
641 void WebChromeClient::reachedMaxAppCacheSize(int64_t)
642 {
643     notImplemented();
644 }
645
646 void WebChromeClient::reachedApplicationCacheOriginQuota(SecurityOrigin* origin, int64_t totalBytesNeeded)
647 {
648     RefPtr<WebSecurityOrigin> webSecurityOrigin = WebSecurityOrigin::createFromString(origin->toString());
649     m_page->injectedBundleUIClient().didReachApplicationCacheOriginQuota(m_page, webSecurityOrigin.get(), totalBytesNeeded);
650 }
651
652 #if ENABLE(DASHBOARD_SUPPORT)
653 void WebChromeClient::annotatedRegionsChanged()
654 {
655     notImplemented();
656 }
657 #endif
658
659 void WebChromeClient::populateVisitedLinks()
660 {
661 }
662
663 FloatRect WebChromeClient::customHighlightRect(Node*, const AtomicString& /*type*/, const FloatRect& /*lineRect*/)
664 {
665     notImplemented();
666     return FloatRect();
667 }
668
669 void WebChromeClient::paintCustomHighlight(Node*, const AtomicString& /*type*/, const FloatRect& /*boxRect*/, const FloatRect& /*lineRect*/, 
670                                            bool /*behindText*/, bool /*entireLine*/)
671 {
672     notImplemented();
673 }
674
675 bool WebChromeClient::shouldReplaceWithGeneratedFileForUpload(const String& path, String& generatedFilename)
676 {
677     generatedFilename = m_page->injectedBundleUIClient().shouldGenerateFileForUpload(m_page, path);
678     return !generatedFilename.isNull();
679 }
680
681 String WebChromeClient::generateReplacementFile(const String& path)
682 {
683     return m_page->injectedBundleUIClient().generateFileForUpload(m_page, path);
684 }
685
686 #if ENABLE(INPUT_TYPE_COLOR)
687 PassOwnPtr<ColorChooser> WebChromeClient::createColorChooser(ColorChooserClient* client, const Color& initialColor)
688 {
689     return adoptPtr(new WebColorChooser(m_page, client, initialColor));
690 }
691 #endif
692
693 void WebChromeClient::runOpenPanel(Frame* frame, PassRefPtr<FileChooser> prpFileChooser)
694 {
695     if (m_page->activeOpenPanelResultListener())
696         return;
697
698     RefPtr<FileChooser> fileChooser = prpFileChooser;
699
700     m_page->setActiveOpenPanelResultListener(WebOpenPanelResultListener::create(m_page, fileChooser.get()));
701
702     WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(frame->loader().client());
703     WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0;
704     ASSERT(webFrame);
705
706     m_page->send(Messages::WebPageProxy::RunOpenPanel(webFrame->frameID(), fileChooser->settings()));
707 }
708
709 void WebChromeClient::loadIconForFiles(const Vector<String>& filenames, FileIconLoader* loader)
710 {
711     loader->notifyFinished(Icon::createIconForFiles(filenames));
712 }
713
714 #if !PLATFORM(IOS)
715 void WebChromeClient::setCursor(const WebCore::Cursor& cursor)
716 {
717     m_page->send(Messages::WebPageProxy::SetCursor(cursor));
718 }
719
720 void WebChromeClient::setCursorHiddenUntilMouseMoves(bool hiddenUntilMouseMoves)
721 {
722     m_page->send(Messages::WebPageProxy::SetCursorHiddenUntilMouseMoves(hiddenUntilMouseMoves));
723 }
724 #endif
725
726 #if ENABLE(REQUEST_ANIMATION_FRAME) && !USE(REQUEST_ANIMATION_FRAME_TIMER)
727 void WebChromeClient::scheduleAnimation()
728 {
729 #if USE(COORDINATED_GRAPHICS)
730     m_page->drawingArea()->layerTreeHost()->scheduleAnimation();
731 #endif
732 }
733 #endif
734
735 void WebChromeClient::formStateDidChange(const Node*)
736 {
737     notImplemented();
738 }
739
740 void WebChromeClient::didAssociateFormControls(const Vector<RefPtr<WebCore::Element>>& elements)
741 {
742     return m_page->injectedBundleFormClient().didAssociateFormControls(m_page, elements);
743 }
744
745 bool WebChromeClient::shouldNotifyOnFormChanges()
746 {
747     return m_page->injectedBundleFormClient().shouldNotifyOnFormChanges(m_page);
748 }
749
750 bool WebChromeClient::selectItemWritingDirectionIsNatural()
751 {
752 #if PLATFORM(EFL)
753     return true;
754 #else
755     return false;
756 #endif
757 }
758
759 bool WebChromeClient::selectItemAlignmentFollowsMenuWritingDirection()
760 {
761     return true;
762 }
763
764 bool WebChromeClient::hasOpenedPopup() const
765 {
766     notImplemented();
767     return false;
768 }
769
770 PassRefPtr<WebCore::PopupMenu> WebChromeClient::createPopupMenu(WebCore::PopupMenuClient* client) const
771 {
772     return WebPopupMenu::create(m_page, client);
773 }
774
775 PassRefPtr<WebCore::SearchPopupMenu> WebChromeClient::createSearchPopupMenu(WebCore::PopupMenuClient* client) const
776 {
777     return WebSearchPopupMenu::create(m_page, client);
778 }
779
780 GraphicsLayerFactory* WebChromeClient::graphicsLayerFactory() const
781 {
782     return m_page->drawingArea()->graphicsLayerFactory();
783 }
784
785 void WebChromeClient::attachRootGraphicsLayer(Frame*, GraphicsLayer* layer)
786 {
787     if (layer)
788         m_page->enterAcceleratedCompositingMode(layer);
789     else
790         m_page->exitAcceleratedCompositingMode();
791 }
792
793 void WebChromeClient::setNeedsOneShotDrawingSynchronization()
794 {
795     notImplemented();
796 }
797
798 void WebChromeClient::scheduleCompositingLayerFlush()
799 {
800     if (m_page->drawingArea())
801         m_page->drawingArea()->scheduleCompositingLayerFlush();
802 }
803
804
805 bool WebChromeClient::layerTreeStateIsFrozen() const
806 {
807     if (m_page->drawingArea())
808         return m_page->drawingArea()->layerTreeStateIsFrozen();
809
810     return false;
811 }
812
813 #if ENABLE(ASYNC_SCROLLING)
814 PassRefPtr<ScrollingCoordinator> WebChromeClient::createScrollingCoordinator(Page* page) const
815 {
816     ASSERT(m_page->corePage() == page);
817     if (m_page->drawingArea()->type() == DrawingAreaTypeRemoteLayerTree)
818         return RemoteScrollingCoordinator::create(m_page);
819
820     return 0;
821 }
822 #endif
823
824 #if ENABLE(TOUCH_EVENTS)
825 void WebChromeClient::needTouchEvents(bool needTouchEvents)
826 {
827     m_page->send(Messages::WebPageProxy::NeedTouchEvents(needTouchEvents));
828 }
829 #endif
830
831 #if ENABLE(FULLSCREEN_API)
832 bool WebChromeClient::supportsFullScreenForElement(const WebCore::Element*, bool withKeyboard)
833 {
834     return m_page->fullScreenManager()->supportsFullScreen(withKeyboard);
835 }
836
837 void WebChromeClient::enterFullScreenForElement(WebCore::Element* element)
838 {
839     m_page->fullScreenManager()->enterFullScreenForElement(element);
840 }
841
842 void WebChromeClient::exitFullScreenForElement(WebCore::Element* element)
843 {
844     m_page->fullScreenManager()->exitFullScreenForElement(element);
845 }
846 #endif
847
848 void WebChromeClient::dispatchViewportPropertiesDidChange(const ViewportArguments& viewportArguments) const
849 {
850     UNUSED_PARAM(viewportArguments);
851 #if PLATFORM(IOS)
852     m_page->viewportPropertiesDidChange(viewportArguments);
853 #endif
854 #if USE(TILED_BACKING_STORE)
855     if (!m_page->useFixedLayout())
856         return;
857
858     m_page->sendViewportAttributesChanged();
859 #endif
860 }
861
862 void WebChromeClient::notifyScrollerThumbIsVisibleInRect(const IntRect& scrollerThumb)
863 {
864     m_page->send(Messages::WebPageProxy::NotifyScrollerThumbIsVisibleInRect(scrollerThumb));
865 }
866
867 void WebChromeClient::recommendedScrollbarStyleDidChange(int32_t newStyle)
868 {
869     m_page->send(Messages::WebPageProxy::RecommendedScrollbarStyleDidChange(newStyle));
870 }
871
872 Color WebChromeClient::underlayColor() const
873 {
874     return m_page->underlayColor();
875 }
876
877 void WebChromeClient::numWheelEventHandlersChanged(unsigned count)
878 {
879     m_page->numWheelEventHandlersChanged(count);
880 }
881
882 void WebChromeClient::logDiagnosticMessage(const String& message, const String& description, const String& success)
883 {
884     if (!m_page->corePage()->settings().diagnosticLoggingEnabled())
885         return;
886
887     m_page->injectedBundleDiagnosticLoggingClient().logDiagnosticMessage(m_page, message, description, success);
888 }
889
890 String WebChromeClient::plugInStartLabelTitle(const String& mimeType) const
891 {
892     return m_page->injectedBundleUIClient().plugInStartLabelTitle(mimeType);
893 }
894
895 String WebChromeClient::plugInStartLabelSubtitle(const String& mimeType) const
896 {
897     return m_page->injectedBundleUIClient().plugInStartLabelSubtitle(mimeType);
898 }
899
900 String WebChromeClient::plugInExtraStyleSheet() const
901 {
902     return m_page->injectedBundleUIClient().plugInExtraStyleSheet();
903 }
904
905 String WebChromeClient::plugInExtraScript() const
906 {
907     return m_page->injectedBundleUIClient().plugInExtraScript();
908 }
909
910 void WebChromeClient::enableSuddenTermination()
911 {
912     m_page->send(Messages::WebProcessProxy::EnableSuddenTermination());
913 }
914
915 void WebChromeClient::disableSuddenTermination()
916 {
917     m_page->send(Messages::WebProcessProxy::DisableSuddenTermination());
918 }
919
920 void WebChromeClient::didAddHeaderLayer(GraphicsLayer* headerParent)
921 {
922 #if ENABLE(RUBBER_BANDING)
923     if (PageBanner* banner = m_page->headerPageBanner())
924         banner->didAddParentLayer(headerParent);
925 #else
926     UNUSED_PARAM(headerParent);
927 #endif
928 }
929
930 void WebChromeClient::didAddFooterLayer(GraphicsLayer* footerParent)
931 {
932 #if ENABLE(RUBBER_BANDING)
933     if (PageBanner* banner = m_page->footerPageBanner())
934         banner->didAddParentLayer(footerParent);
935 #else
936     UNUSED_PARAM(footerParent);
937 #endif
938 }
939
940 bool WebChromeClient::shouldUseTiledBackingForFrameView(const FrameView* frameView) const
941 {
942     return m_page->drawingArea()->shouldUseTiledBackingForFrameView(frameView);
943 }
944
945 void WebChromeClient::incrementActivePageCount()
946 {
947     WebProcess::shared().incrementActiveTaskCount();
948 }
949
950 void WebChromeClient::decrementActivePageCount()
951 {
952     WebProcess::shared().decrementActiveTaskCount();
953 }
954
955 } // namespace WebKit