[WK2] Apply new quota policy for Web Database
[framework/web/webkit-efl.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 "WebOpenPanelParameters.h"
40 #include "WebOpenPanelResultListener.h"
41 #include "WebPage.h"
42 #include "WebPageCreationParameters.h"
43 #include "WebPageProxyMessages.h"
44 #include "WebPopupMenu.h"
45 #include "WebPreferencesStore.h"
46 #include "WebProcess.h"
47 #include "WebSearchPopupMenu.h"
48 #include <WebCore/AXObjectCache.h>
49 #include <WebCore/ColorChooser.h>
50 #include <WebCore/DatabaseTracker.h>
51 #include <WebCore/FileChooser.h>
52 #include <WebCore/FileIconLoader.h>
53 #include <WebCore/Frame.h>
54 #include <WebCore/FrameLoadRequest.h>
55 #include <WebCore/FrameLoader.h>
56 #include <WebCore/FrameView.h>
57 #include <WebCore/HTMLNames.h>
58 #include <WebCore/HTMLPlugInImageElement.h>
59 #include <WebCore/Icon.h>
60 #include <WebCore/NotImplemented.h>
61 #include <WebCore/Page.h>
62 #include <WebCore/SecurityOrigin.h>
63 #include <WebCore/Settings.h>
64
65 #if ENABLE(TIZEN_DISPLAY_MESSAGE_TO_CONSOLE)
66 #include <dlog/dlog.h>
67 #endif
68
69 using namespace WebCore;
70 using namespace HTMLNames;
71
72 namespace WebKit {
73
74 static double area(WebFrame* frame)
75 {
76     IntSize size = frame->visibleContentBoundsExcludingScrollbars().size();
77     return static_cast<double>(size.height()) * size.width();
78 }
79
80
81 static WebFrame* findLargestFrameInFrameSet(WebPage* page)
82 {
83     // Approximate what a user could consider a default target frame for application menu operations.
84
85     WebFrame* mainFrame = page->mainWebFrame();
86     if (!mainFrame->isFrameSet())
87         return 0;
88
89     WebFrame* largestSoFar = 0;
90
91     RefPtr<ImmutableArray> frameChildren = mainFrame->childFrames();
92     size_t count = frameChildren->size();
93     for (size_t i = 0; i < count; ++i) {
94         WebFrame* childFrame = frameChildren->at<WebFrame>(i);
95         if (!largestSoFar || area(childFrame) > area(largestSoFar))
96             largestSoFar = childFrame;
97     }
98
99     return largestSoFar;
100 }
101
102 void WebChromeClient::chromeDestroyed()
103 {
104     delete this;
105 }
106
107 void WebChromeClient::setWindowRect(const FloatRect& windowFrame)
108 {
109     m_page->send(Messages::WebPageProxy::SetWindowFrame(windowFrame));
110 }
111
112 FloatRect WebChromeClient::windowRect()
113 {
114     FloatRect newWindowFrame;
115
116     if (!WebProcess::shared().connection()->sendSync(Messages::WebPageProxy::GetWindowFrame(), Messages::WebPageProxy::GetWindowFrame::Reply(newWindowFrame), m_page->pageID()))
117         return FloatRect();
118
119     return newWindowFrame;
120 }
121
122 FloatRect WebChromeClient::pageRect()
123 {
124     return FloatRect(FloatPoint(), m_page->size());
125 }
126
127 void WebChromeClient::focus()
128 {
129     m_page->send(Messages::WebPageProxy::SetFocus(true));
130 }
131
132 void WebChromeClient::unfocus()
133 {
134     m_page->send(Messages::WebPageProxy::SetFocus(false));
135 }
136
137 #if PLATFORM(MAC)
138 void WebChromeClient::makeFirstResponder()
139 {
140     m_page->send(Messages::WebPageProxy::MakeFirstResponder());
141 }    
142 #endif    
143
144 bool WebChromeClient::canTakeFocus(FocusDirection)
145 {
146     notImplemented();
147     return true;
148 }
149
150 void WebChromeClient::takeFocus(FocusDirection direction)
151 {
152     m_page->send(Messages::WebPageProxy::TakeFocus(direction));
153 }
154
155 void WebChromeClient::focusedNodeChanged(Node* node)
156 {
157 #if PLATFORM(EFL)
158     IntRect nodeRect = IntRect(0, 0, 0, 0);
159     if (node) {
160         nodeRect = WebCore::pixelSnappedIntRect(node->getRect());
161         Frame* mainFrame = m_page->corePage()->mainFrame();
162         Frame* frame = node->document()->frame();
163         Node* owner;
164         while (frame && frame != mainFrame) {
165             owner = frame->ownerElement();
166             if (owner) {
167                 nodeRect.setX(nodeRect.x() + owner->getRect().x());
168                 nodeRect.setY(nodeRect.y() + owner->getRect().y());
169                 frame = owner->document()->frame();
170             } else {
171                 break;
172             }
173         }
174         // we have to divide (x, y) with pageZoomFactor because pageZoomFactor was applied to them.
175         nodeRect.setX(nodeRect.x() / m_page->pageScaleFactor());
176         nodeRect.setY(nodeRect.y() / m_page->pageScaleFactor());
177     }
178     m_page->send(Messages::WebPageProxy::FocusedNodeChanged(nodeRect));
179 #else
180     notImplemented();
181 #endif
182 }
183
184 void WebChromeClient::focusedFrameChanged(Frame* frame)
185 {
186     WebFrame* webFrame = frame ? static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame() : 0;
187
188     WebProcess::shared().connection()->send(Messages::WebPageProxy::FocusedFrameChanged(webFrame ? webFrame->frameID() : 0), m_page->pageID());
189 }
190
191 Page* WebChromeClient::createWindow(Frame*, const FrameLoadRequest& request, const WindowFeatures& windowFeatures, const NavigationAction& navigationAction)
192 {
193     uint32_t modifiers = static_cast<uint32_t>(InjectedBundleNavigationAction::modifiersForNavigationAction(navigationAction));
194     int32_t mouseButton = static_cast<int32_t>(InjectedBundleNavigationAction::mouseButtonForNavigationAction(navigationAction));
195
196     uint64_t newPageID = 0;
197     WebPageCreationParameters parameters;
198     if (!WebProcess::shared().connection()->sendSync(Messages::WebPageProxy::CreateNewPage(request.resourceRequest(), windowFeatures, modifiers, mouseButton), Messages::WebPageProxy::CreateNewPage::Reply(newPageID, parameters), m_page->pageID()))
199         return 0;
200
201     if (!newPageID)
202         return 0;
203
204     WebProcess::shared().createWebPage(newPageID, parameters);
205     return WebProcess::shared().webPage(newPageID)->corePage();
206 }
207
208 void WebChromeClient::show()
209 {
210     m_page->show();
211 }
212
213 bool WebChromeClient::canRunModal()
214 {
215     return m_page->canRunModal();
216 }
217
218 void WebChromeClient::runModal()
219 {
220     m_page->runModal();
221 }
222
223 void WebChromeClient::setToolbarsVisible(bool toolbarsAreVisible)
224 {
225     m_page->send(Messages::WebPageProxy::SetToolbarsAreVisible(toolbarsAreVisible));
226 }
227
228 bool WebChromeClient::toolbarsVisible()
229 {
230     WKBundlePageUIElementVisibility toolbarsVisibility = m_page->injectedBundleUIClient().toolbarsAreVisible(m_page);
231     if (toolbarsVisibility != WKBundlePageUIElementVisibilityUnknown)
232         return toolbarsVisibility == WKBundlePageUIElementVisible;
233     
234     bool toolbarsAreVisible = true;
235     if (!WebProcess::shared().connection()->sendSync(Messages::WebPageProxy::GetToolbarsAreVisible(), Messages::WebPageProxy::GetToolbarsAreVisible::Reply(toolbarsAreVisible), m_page->pageID()))
236         return true;
237
238     return toolbarsAreVisible;
239 }
240
241 void WebChromeClient::setStatusbarVisible(bool statusBarIsVisible)
242 {
243     m_page->send(Messages::WebPageProxy::SetStatusBarIsVisible(statusBarIsVisible));
244 }
245
246 bool WebChromeClient::statusbarVisible()
247 {
248     WKBundlePageUIElementVisibility statusbarVisibility = m_page->injectedBundleUIClient().statusBarIsVisible(m_page);
249     if (statusbarVisibility != WKBundlePageUIElementVisibilityUnknown)
250         return statusbarVisibility == WKBundlePageUIElementVisible;
251
252     bool statusBarIsVisible = true;
253     if (!WebProcess::shared().connection()->sendSync(Messages::WebPageProxy::GetStatusBarIsVisible(), Messages::WebPageProxy::GetStatusBarIsVisible::Reply(statusBarIsVisible), m_page->pageID()))
254         return true;
255
256     return statusBarIsVisible;
257 }
258
259 void WebChromeClient::setScrollbarsVisible(bool)
260 {
261     notImplemented();
262 }
263
264 bool WebChromeClient::scrollbarsVisible()
265 {
266     notImplemented();
267     return true;
268 }
269
270 void WebChromeClient::setMenubarVisible(bool menuBarVisible)
271 {
272     m_page->send(Messages::WebPageProxy::SetMenuBarIsVisible(menuBarVisible));
273 }
274
275 bool WebChromeClient::menubarVisible()
276 {
277     WKBundlePageUIElementVisibility menubarVisibility = m_page->injectedBundleUIClient().menuBarIsVisible(m_page);
278     if (menubarVisibility != WKBundlePageUIElementVisibilityUnknown)
279         return menubarVisibility == WKBundlePageUIElementVisible;
280     
281     bool menuBarIsVisible = true;
282     if (!WebProcess::shared().connection()->sendSync(Messages::WebPageProxy::GetMenuBarIsVisible(), Messages::WebPageProxy::GetMenuBarIsVisible::Reply(menuBarIsVisible), m_page->pageID()))
283         return true;
284
285     return menuBarIsVisible;
286 }
287
288 void WebChromeClient::setResizable(bool resizable)
289 {
290     m_page->send(Messages::WebPageProxy::SetIsResizable(resizable));
291 }
292
293 #if ENABLE(TIZEN_DISPLAY_MESSAGE_TO_CONSOLE)
294 void WebChromeClient::addMessageToConsole(MessageSource, MessageType, MessageLevel level, const String& message, unsigned int lineNumber, const String& sourceID)
295 #else
296 void WebChromeClient::addMessageToConsole(MessageSource, MessageType, MessageLevel, const String& message, unsigned int lineNumber, const String& sourceID)
297 #endif
298 {
299 #if ENABLE(TIZEN_DISPLAY_MESSAGE_TO_CONSOLE) // Request for WAC SDK
300     String newMessage;
301     if (lineNumber)
302         newMessage = String::format("%s:%d:%s", sourceID.utf8().data(), lineNumber, message.utf8().data());
303     else
304         newMessage = message;
305
306     switch (level) {
307     case WarningMessageLevel:
308         ALOG(LOG_WARN, "ConsoleMessage", "%s", newMessage.utf8().data());
309         break;
310     case ErrorMessageLevel:
311         ALOG(LOG_ERROR, "ConsoleMessage", "%s", newMessage.utf8().data());
312         break;
313     case LogMessageLevel:
314         ALOG(LOG_DEBUG, "ConsoleMessage", "%s", newMessage.utf8().data());
315         break;
316     default:
317         ALOG(LOG_INFO, "ConsoleMessage", "%s", newMessage.utf8().data());
318         break;
319     }
320 #endif
321     // Notify the bundle client.
322     m_page->injectedBundleUIClient().willAddMessageToConsole(m_page, message, lineNumber);
323
324     notImplemented();
325 }
326
327 bool WebChromeClient::canRunBeforeUnloadConfirmPanel()
328 {
329     return m_page->canRunBeforeUnloadConfirmPanel();
330 }
331
332 bool WebChromeClient::runBeforeUnloadConfirmPanel(const String& message, Frame* frame)
333 {
334 #if ENABLE(TIZEN_SUPPORT_BEFORE_UNLOAD_CONFIRM_PANEL)
335     WebFrame* webFrame = static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame();
336
337     unsigned syncSendFlags = (WebCore::AXObjectCache::accessibilityEnabled()) ? CoreIPC::SpinRunLoopWhileWaitingForReply : 0;
338     bool shouldClose = false;
339 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
340     WebProcess::WaitForJavaScriptPopupFinished waiting;
341 #endif
342     if (!WebProcess::shared().connection()->sendSync(Messages::WebPageProxy::RunBeforeUnloadConfirmPanel(message, webFrame->frameID()), Messages::WebPageProxy::RunBeforeUnloadConfirmPanel::Reply(shouldClose), m_page->pageID(), CoreIPC::Connection::DefaultTimeout, syncSendFlags))
343         return false;
344
345     return shouldClose;
346 #else
347     WebFrame* webFrame = static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame();
348
349     bool shouldClose = false;
350     if (!WebProcess::shared().connection()->sendSync(Messages::WebPageProxy::RunBeforeUnloadConfirmPanel(message, webFrame->frameID()), Messages::WebPageProxy::RunBeforeUnloadConfirmPanel::Reply(shouldClose), m_page->pageID()))
351         return false;
352
353     return shouldClose;
354 #endif
355 }
356
357 void WebChromeClient::closeWindowSoon()
358 {
359     // FIXME: This code assumes that the client will respond to a close page
360     // message by actually closing the page. Safari does this, but there is
361     // no guarantee that other applications will, which will leave this page
362     // half detached. This approach is an inherent limitation making parts of
363     // a close execute synchronously as part of window.close, but other parts
364     // later on.
365
366     m_page->corePage()->setGroupName(String());
367
368     if (WebFrame* frame = m_page->mainWebFrame()) {
369         if (Frame* coreFrame = frame->coreFrame())
370             coreFrame->loader()->stopForUserCancel();
371     }
372
373     m_page->sendClose();
374 }
375
376 void WebChromeClient::runJavaScriptAlert(Frame* frame, const String& alertText)
377 {
378     WebFrame* webFrame = static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame();
379
380     // Notify the bundle client.
381     m_page->injectedBundleUIClient().willRunJavaScriptAlert(m_page, alertText, webFrame);
382
383     unsigned syncSendFlags = (WebCore::AXObjectCache::accessibilityEnabled()) ? CoreIPC::SpinRunLoopWhileWaitingForReply : 0;
384 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
385     WebProcess::WaitForJavaScriptPopupFinished waiting;
386 #endif
387     WebProcess::shared().connection()->sendSync(Messages::WebPageProxy::RunJavaScriptAlert(webFrame->frameID(), alertText), Messages::WebPageProxy::RunJavaScriptAlert::Reply(), m_page->pageID(), CoreIPC::Connection::DefaultTimeout, syncSendFlags);
388 }
389
390 bool WebChromeClient::runJavaScriptConfirm(Frame* frame, const String& message)
391 {
392     WebFrame* webFrame = static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame();
393
394     // Notify the bundle client.
395     m_page->injectedBundleUIClient().willRunJavaScriptConfirm(m_page, message, webFrame);
396
397     unsigned syncSendFlags = (WebCore::AXObjectCache::accessibilityEnabled()) ? CoreIPC::SpinRunLoopWhileWaitingForReply : 0;
398     bool result = false;
399 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
400     WebProcess::WaitForJavaScriptPopupFinished waiting;
401 #endif
402     if (!WebProcess::shared().connection()->sendSync(Messages::WebPageProxy::RunJavaScriptConfirm(webFrame->frameID(), message), Messages::WebPageProxy::RunJavaScriptConfirm::Reply(result), m_page->pageID(), CoreIPC::Connection::DefaultTimeout, syncSendFlags))
403         return false;
404
405     return result;
406 }
407
408 bool WebChromeClient::runJavaScriptPrompt(Frame* frame, const String& message, const String& defaultValue, String& result)
409 {
410     WebFrame* webFrame = static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame();
411
412     // Notify the bundle client.
413     m_page->injectedBundleUIClient().willRunJavaScriptPrompt(m_page, message, defaultValue, webFrame);
414
415     unsigned syncSendFlags = (WebCore::AXObjectCache::accessibilityEnabled()) ? CoreIPC::SpinRunLoopWhileWaitingForReply : 0;
416 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
417     WebProcess::WaitForJavaScriptPopupFinished waiting;
418 #endif
419     if (!WebProcess::shared().connection()->sendSync(Messages::WebPageProxy::RunJavaScriptPrompt(webFrame->frameID(), message, defaultValue), Messages::WebPageProxy::RunJavaScriptPrompt::Reply(result), m_page->pageID(), CoreIPC::Connection::DefaultTimeout, syncSendFlags))
420         return false;
421
422     return !result.isNull();
423 }
424
425 void WebChromeClient::setStatusbarText(const String& statusbarText)
426 {
427     // Notify the bundle client.
428     m_page->injectedBundleUIClient().willSetStatusbarText(m_page, statusbarText);
429
430     m_page->send(Messages::WebPageProxy::SetStatusText(statusbarText));
431 }
432
433 bool WebChromeClient::shouldInterruptJavaScript()
434 {
435     bool shouldInterrupt = false;
436     if (!WebProcess::shared().connection()->sendSync(Messages::WebPageProxy::ShouldInterruptJavaScript(), Messages::WebPageProxy::ShouldInterruptJavaScript::Reply(shouldInterrupt), m_page->pageID()))
437         return false;
438
439     return shouldInterrupt;
440 }
441
442 KeyboardUIMode WebChromeClient::keyboardUIMode()
443 {
444     return m_page->keyboardUIMode();
445 }
446
447 IntRect WebChromeClient::windowResizerRect() const
448 {
449     return m_page->windowResizerRect();
450 }
451
452 void WebChromeClient::invalidateRootView(const IntRect&, bool)
453 {
454     // Do nothing here, there's no concept of invalidating the window in the web process.
455 }
456
457 void WebChromeClient::invalidateContentsAndRootView(const IntRect& rect, bool)
458 {
459     if (Document* document = m_page->corePage()->mainFrame()->document()) {
460         if (document->printing())
461             return;
462     }
463
464     m_page->drawingArea()->setNeedsDisplay(rect);
465 }
466
467 void WebChromeClient::invalidateContentsForSlowScroll(const IntRect& rect, bool)
468 {
469     if (Document* document = m_page->corePage()->mainFrame()->document()) {
470         if (document->printing())
471             return;
472     }
473
474     m_page->pageDidScroll();
475     m_page->drawingArea()->setNeedsDisplay(rect);
476 }
477
478 void WebChromeClient::scroll(const IntSize& scrollOffset, const IntRect& scrollRect, const IntRect& clipRect)
479 {
480     m_page->pageDidScroll();
481     m_page->drawingArea()->scroll(intersection(scrollRect, clipRect), scrollOffset);
482 }
483
484 #if USE(TILED_BACKING_STORE)
485 void WebChromeClient::delegatedScrollRequested(const IntPoint& scrollOffset)
486 {
487     m_page->pageDidRequestScroll(scrollOffset);
488 }
489 #endif
490
491 IntPoint WebChromeClient::screenToRootView(const IntPoint& point) const
492 {
493     return m_page->screenToWindow(point);
494 }
495
496 IntRect WebChromeClient::rootViewToScreen(const IntRect& rect) const
497 {
498     return m_page->windowToScreen(rect);
499 }
500
501 PlatformPageClient WebChromeClient::platformPageClient() const
502 {
503     notImplemented();
504     return 0;
505 }
506
507 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
508 bool WebChromeClient::getStandaloneStatus()
509 {
510     bool standalone = false;
511     m_page->sendSync(Messages::WebPageProxy::GetStandaloneStatus(), Messages::WebPageProxy::GetStandaloneStatus::Reply(standalone), m_page->pageID());
512     return standalone;
513 }
514 #endif
515
516 #if ENABLE(TIZEN_SEARCH_PROVIDER)
517 void WebChromeClient::addSearchProvider(const String& baseURL, const String& engineURL)
518 {
519     m_page->send(Messages::WebPageProxy::AddSearchProvider(baseURL, engineURL));
520 }
521
522 unsigned long WebChromeClient::isSearchProviderInstalled(const String& baseURL, const String& engineURL)
523 {
524     uint64_t result;
525     m_page->sendSync(Messages::WebPageProxy::IsSearchProviderInstalled(baseURL, engineURL), Messages::WebPageProxy::IsSearchProviderInstalled::Reply(result));
526     return result;
527 }
528 #endif
529
530 void WebChromeClient::contentsSizeChanged(Frame* frame, const IntSize& size) const
531 {
532     if (!m_page->corePage()->settings()->frameFlatteningEnabled()) {
533         WebFrame* largestFrame = findLargestFrameInFrameSet(m_page);
534         if (largestFrame != m_cachedFrameSetLargestFrame.get()) {
535             m_cachedFrameSetLargestFrame = largestFrame;
536             m_page->send(Messages::WebPageProxy::FrameSetLargestFrameChanged(largestFrame ? largestFrame->frameID() : 0));
537         }
538     }
539
540     if (frame->page()->mainFrame() != frame)
541         return;
542
543 #if PLATFORM(QT) || (PLATFORM(EFL) && USE(TILED_BACKING_STORE))
544     if (m_page->useFixedLayout()) {
545         // The below method updates the size().
546         m_page->resizeToContentsIfNeeded();
547         m_page->drawingArea()->layerTreeHost()->sizeDidChange(m_page->size());
548     }
549
550 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
551     // FIXME: Logic to calculate the node's position is inefficient.
552     Frame* focusedFrame = m_page->corePage()->focusController()->focusedFrame();
553     if(focusedFrame && focusedFrame->document() && focusedFrame->document()->focusedNode()) {
554         Node* node = focusedFrame->document()->focusedNode();
555         IntRect nodeRect = IntRect(0, 0, 0, 0);
556         if (node) {
557             nodeRect = WebCore::pixelSnappedIntRect(node->getRect());
558             Frame* mainFrame = m_page->corePage()->mainFrame();
559             Frame* frame = node->document()->frame();
560             Node* owner;
561             while (frame && frame != mainFrame) {
562                 owner = frame->ownerElement();
563                 if (!owner)
564                     break;
565
566                 nodeRect.setX(nodeRect.x() + owner->getRect().x());
567                 nodeRect.setY(nodeRect.y() + owner->getRect().y());
568                 frame = owner->document()->frame();
569             }
570             // we have to divide (x, y) with pageZoomFactor because pageZoomFactor was applied to them.
571             nodeRect.setX(nodeRect.x() / m_page->pageScaleFactor());
572             nodeRect.setY(nodeRect.y() / m_page->pageScaleFactor());
573         }
574         m_page->send(Messages::WebPageProxy::FocusedNodeChanged(nodeRect));
575     }
576 #endif
577
578     m_page->send(Messages::WebPageProxy::DidChangeContentsSize(m_page->size()));
579 #endif
580
581     FrameView* frameView = frame->view();
582     if (frameView && !frameView->delegatesScrolling())  {
583         bool hasHorizontalScrollbar = frameView->horizontalScrollbar();
584         bool hasVerticalScrollbar = frameView->verticalScrollbar();
585
586         if (hasHorizontalScrollbar != m_cachedMainFrameHasHorizontalScrollbar || hasVerticalScrollbar != m_cachedMainFrameHasVerticalScrollbar) {
587             m_page->send(Messages::WebPageProxy::DidChangeScrollbarsForMainFrame(hasHorizontalScrollbar, hasVerticalScrollbar));
588
589             m_cachedMainFrameHasHorizontalScrollbar = hasHorizontalScrollbar;
590             m_cachedMainFrameHasVerticalScrollbar = hasVerticalScrollbar;
591         }
592     }
593 }
594
595 void WebChromeClient::scrollRectIntoView(const IntRect&) const
596 {
597     notImplemented();
598 }
599
600 bool WebChromeClient::shouldUnavailablePluginMessageBeButton(RenderEmbeddedObject::PluginUnavailabilityReason pluginUnavailabilityReason) const
601 {
602     if (pluginUnavailabilityReason == RenderEmbeddedObject::PluginMissing || pluginUnavailabilityReason == RenderEmbeddedObject::InsecurePluginVersion) {
603         // FIXME: <rdar://problem/8794397> We should only return true when there is a
604         // missingPluginButtonClicked callback defined on the Page UI client.
605         return true;
606     }
607
608     return false;
609 }
610     
611 void WebChromeClient::unavailablePluginButtonClicked(Element* element, RenderEmbeddedObject::PluginUnavailabilityReason pluginUnavailabilityReason) const
612 {
613     ASSERT(element->hasTagName(objectTag) || element->hasTagName(embedTag) || element->hasTagName(appletTag));
614     ASSERT(pluginUnavailabilityReason == RenderEmbeddedObject::PluginMissing || pluginUnavailabilityReason == RenderEmbeddedObject::InsecurePluginVersion);
615
616     HTMLPlugInImageElement* pluginElement = static_cast<HTMLPlugInImageElement*>(element);
617
618     m_page->send(Messages::WebPageProxy::UnavailablePluginButtonClicked(pluginUnavailabilityReason, pluginElement->serviceType(), pluginElement->url(), pluginElement->getAttribute(pluginspageAttr)));
619 }
620
621 void WebChromeClient::scrollbarsModeDidChange() const
622 {
623     notImplemented();
624 }
625
626 void WebChromeClient::mouseDidMoveOverElement(const HitTestResult& hitTestResult, unsigned modifierFlags)
627 {
628     RefPtr<APIObject> userData;
629
630     // Notify the bundle client.
631     m_page->injectedBundleUIClient().mouseDidMoveOverElement(m_page, hitTestResult, static_cast<WebEvent::Modifiers>(modifierFlags), userData);
632
633     // Notify the UIProcess.
634     WebHitTestResult::Data webHitTestResultData(hitTestResult);
635     m_page->send(Messages::WebPageProxy::MouseDidMoveOverElement(webHitTestResultData, modifierFlags, InjectedBundleUserMessageEncoder(userData.get())));
636 }
637
638 void WebChromeClient::setToolTip(const String& toolTip, TextDirection)
639 {
640     // Only send a tool tip to the WebProcess if it has changed since the last time this function was called.
641
642     if (toolTip == m_cachedToolTip)
643         return;
644     m_cachedToolTip = toolTip;
645
646     m_page->send(Messages::WebPageProxy::SetToolTip(m_cachedToolTip));
647 }
648
649 void WebChromeClient::print(Frame* frame)
650 {
651     WebFrame* webFrame = static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame();
652     m_page->sendSync(Messages::WebPageProxy::PrintFrame(webFrame->frameID()), Messages::WebPageProxy::PrintFrame::Reply());
653 }
654
655 #if ENABLE(SQL_DATABASE)
656 void WebChromeClient::exceededDatabaseQuota(Frame* frame, const String& databaseName)
657 {
658     WebFrame* webFrame = static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame();
659     SecurityOrigin* origin = frame->document()->securityOrigin();
660
661     DatabaseDetails details = DatabaseTracker::tracker().detailsForNameAndOrigin(databaseName, origin);
662     uint64_t currentQuota = DatabaseTracker::tracker().quotaForOrigin(origin);
663     uint64_t currentOriginUsage = DatabaseTracker::tracker().usageForOrigin(origin);
664     uint64_t newQuota = 0;
665 #if ENABLE(TIZEN_SQL_DATABASE)
666     const uint64_t defaultQuota = 5 * 1024 * 1024;
667     uint64_t requirement = currentQuota + details.expectedUsage();
668     if (requirement <= defaultQuota)
669         newQuota = requirement;
670     else {
671         unsigned syncSendFlags = (WebCore::AXObjectCache::accessibilityEnabled()) ? CoreIPC::SpinRunLoopWhileWaitingForReply : 0;
672         bool allowExceed = false;
673         WebProcess::shared().connection()->sendSync(
674             Messages::WebPageProxy::ExceededDatabaseQuota(webFrame->frameID(), origin->databaseIdentifier(), details.displayName(), details.expectedUsage()),
675             Messages::WebPageProxy::ExceededDatabaseQuota::Reply(allowExceed), m_page->pageID(), CoreIPC::Connection::DefaultTimeout, syncSendFlags);
676         if (allowExceed)
677             newQuota = currentQuota + details.expectedUsage();
678         else
679             newQuota = currentQuota;
680     }
681 #else
682     WebProcess::shared().connection()->sendSync(
683         Messages::WebPageProxy::ExceededDatabaseQuota(webFrame->frameID(), origin->databaseIdentifier(), databaseName, details.displayName(), currentQuota, currentOriginUsage, details.currentUsage(), details.expectedUsage()),
684         Messages::WebPageProxy::ExceededDatabaseQuota::Reply(newQuota), m_page->pageID());
685 #endif
686
687     DatabaseTracker::tracker().setQuota(origin, newQuota);
688 }
689 #endif
690
691
692 void WebChromeClient::reachedMaxAppCacheSize(int64_t)
693 {
694     notImplemented();
695 }
696
697 void WebChromeClient::reachedApplicationCacheOriginQuota(SecurityOrigin*, int64_t)
698 {
699     notImplemented();
700 }
701
702 #if ENABLE(TIZEN_APPLICATION_CACHE)
703 bool WebChromeClient::requestApplicationCachePermission(Frame* frame)
704 {
705     WebFrame* webFrame = static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame();
706     SecurityOrigin* origin = frame->document()->securityOrigin();
707
708     unsigned syncSendFlags = WebCore::AXObjectCache::accessibilityEnabled() ? CoreIPC::SpinRunLoopWhileWaitingForReply : 0;
709     bool allow = false;
710 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
711     WebProcess::WaitForJavaScriptPopupFinished waiting;
712 #endif
713
714     if (!WebProcess::shared().connection()->sendSync(Messages::WebPageProxy::RequestApplicationCachePermission(webFrame->frameID(), origin->databaseIdentifier()), Messages::WebPageProxy::RequestApplicationCachePermission::Reply(allow), m_page->pageID(), CoreIPC::Connection::DefaultTimeout, syncSendFlags))
715         return false;
716
717     return allow;
718 }
719 #endif
720
721 #if ENABLE(DASHBOARD_SUPPORT)
722 void WebChromeClient::dashboardRegionsChanged()
723 {
724     notImplemented();
725 }
726 #endif
727
728 void WebChromeClient::populateVisitedLinks()
729 {
730 }
731
732 FloatRect WebChromeClient::customHighlightRect(Node*, const AtomicString& type, const FloatRect& lineRect)
733 {
734     notImplemented();
735     return FloatRect();
736 }
737
738 void WebChromeClient::paintCustomHighlight(Node*, const AtomicString& type, const FloatRect& boxRect, const FloatRect& lineRect,
739                                   bool behindText, bool entireLine)
740 {
741     notImplemented();
742 }
743
744 bool WebChromeClient::shouldReplaceWithGeneratedFileForUpload(const String& path, String& generatedFilename)
745 {
746     generatedFilename = m_page->injectedBundleUIClient().shouldGenerateFileForUpload(m_page, path);
747     return !generatedFilename.isNull();
748 }
749
750 String WebChromeClient::generateReplacementFile(const String& path)
751 {
752     return m_page->injectedBundleUIClient().generateFileForUpload(m_page, path);
753 }
754
755 bool WebChromeClient::paintCustomOverhangArea(GraphicsContext* context, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect)
756 {
757     if (!m_page->injectedBundleUIClient().shouldPaintCustomOverhangArea())
758         return false;
759
760     m_page->injectedBundleUIClient().paintCustomOverhangArea(m_page, context, horizontalOverhangArea, verticalOverhangArea, dirtyRect);
761     return true;
762 }
763
764 #if ENABLE(INPUT_TYPE_COLOR)
765 PassOwnPtr<ColorChooser> WebChromeClient::createColorChooser(ColorChooserClient* client, const Color& initialColor)
766 {
767     if (m_page->activeColorChooser())
768         return nullptr;
769
770     return adoptPtr(new WebColorChooser(m_page, client, initialColor));
771 }
772 #endif
773
774 void WebChromeClient::runOpenPanel(Frame* frame, PassRefPtr<FileChooser> prpFileChooser)
775 {
776     if (m_page->activeOpenPanelResultListener())
777         return;
778
779     RefPtr<FileChooser> fileChooser = prpFileChooser;
780
781     m_page->setActiveOpenPanelResultListener(WebOpenPanelResultListener::create(m_page, fileChooser.get()));
782     m_page->send(Messages::WebPageProxy::RunOpenPanel(static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame()->frameID(), fileChooser->settings()));
783 }
784
785 void WebChromeClient::loadIconForFiles(const Vector<String>& filenames, FileIconLoader* loader)
786 {
787     loader->notifyFinished(Icon::createIconForFiles(filenames));
788 }
789
790 void WebChromeClient::setCursor(const WebCore::Cursor& cursor)
791 {
792 #if USE(LAZY_NATIVE_CURSOR)
793     m_page->send(Messages::WebPageProxy::SetCursor(cursor));
794 #endif
795 }
796
797 void WebChromeClient::setCursorHiddenUntilMouseMoves(bool hiddenUntilMouseMoves)
798 {
799     m_page->send(Messages::WebPageProxy::SetCursorHiddenUntilMouseMoves(hiddenUntilMouseMoves));
800 }
801
802 #if ENABLE(REQUEST_ANIMATION_FRAME) && !USE(REQUEST_ANIMATION_FRAME_TIMER)
803 void WebChromeClient::scheduleAnimation()
804 {
805 #if USE(UI_SIDE_COMPOSITING)
806     m_page->drawingArea()->layerTreeHost()->scheduleAnimation();
807 #endif
808 }
809 #endif
810
811 void WebChromeClient::formStateDidChange(const Node*)
812 {
813     notImplemented();
814 }
815
816 bool WebChromeClient::selectItemWritingDirectionIsNatural()
817 {
818 #if PLATFORM(WIN)
819     return true;
820 #else
821     return false;
822 #endif
823 }
824
825 bool WebChromeClient::selectItemAlignmentFollowsMenuWritingDirection()
826 {
827 #if PLATFORM(WIN)
828     return false;
829 #else
830     return true;
831 #endif
832 }
833
834 bool WebChromeClient::hasOpenedPopup() const
835 {
836     notImplemented();
837     return false;
838 }
839
840 PassRefPtr<WebCore::PopupMenu> WebChromeClient::createPopupMenu(WebCore::PopupMenuClient* client) const
841 {
842     return WebPopupMenu::create(m_page, client);
843 }
844
845 PassRefPtr<WebCore::SearchPopupMenu> WebChromeClient::createSearchPopupMenu(WebCore::PopupMenuClient* client) const
846 {
847     return WebSearchPopupMenu::create(m_page, client);
848 }
849
850 #if USE(ACCELERATED_COMPOSITING)
851 void WebChromeClient::attachRootGraphicsLayer(Frame*, GraphicsLayer* layer)
852 {
853     if (layer)
854         m_page->enterAcceleratedCompositingMode(layer);
855     else
856         m_page->exitAcceleratedCompositingMode();
857 }
858
859 void WebChromeClient::setNeedsOneShotDrawingSynchronization()
860 {
861 #if ENABLE(TIZEN_ONESHOT_DRAWING_SYNCHRONIZATION)
862     if (m_page->drawingArea())
863         m_page->drawingArea()->setNeedsOneShotDrawingSynchronization();
864 #else
865     notImplemented();
866 #endif
867 }
868
869 void WebChromeClient::scheduleCompositingLayerSync()
870 {
871     if (m_page->drawingArea())
872         m_page->drawingArea()->scheduleCompositingLayerSync();
873 }
874
875 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
876 void WebChromeClient::addOrUpdateScrollingLayer(WebCore::Node*, WebCore::GraphicsLayer* scrollingLayer, WebCore::GraphicsLayer* contentsLayer, const WebCore::IntSize& scrollSize)
877 {
878     if (!m_page->drawingArea())
879         return;
880     m_page->drawingArea()->addOrUpdateScrollingLayer(scrollingLayer, contentsLayer, scrollSize);
881 }
882
883 void WebChromeClient::removeScrollingLayer(WebCore::Node*, WebCore::GraphicsLayer* scrollingLayer, WebCore::GraphicsLayer* contentsLayer)
884 {
885     if (!m_page->drawingArea())
886         return;
887     m_page->drawingArea()->removeScrollingLayer(scrollingLayer, contentsLayer);
888 }
889 #endif // ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
890 #endif // USE(ACCELERATED_COMPOSITING)
891
892 #if PLATFORM(WIN) && USE(AVFOUNDATION)
893 WebCore::GraphicsDeviceAdapter* WebChromeClient::graphicsDeviceAdapter() const
894 {
895     if (!m_page->drawingArea())
896         return 0;
897     return m_page->drawingArea()->layerTreeHost()->graphicsDeviceAdapter();
898 }
899 #endif
900
901 #if ENABLE(TOUCH_EVENTS)
902 void WebChromeClient::needTouchEvents(bool needTouchEvents)
903 {
904     m_page->send(Messages::WebPageProxy::NeedTouchEvents(needTouchEvents));
905 }
906 #endif
907
908 #if PLATFORM(WIN)
909 void WebChromeClient::setLastSetCursorToCurrentCursor()
910 {
911 }
912 #endif
913
914 #if ENABLE(FULLSCREEN_API)
915 bool WebChromeClient::supportsFullScreenForElement(const WebCore::Element* element, bool withKeyboard)
916 {
917     return m_page->fullScreenManager()->supportsFullScreen(withKeyboard);
918 }
919
920 void WebChromeClient::enterFullScreenForElement(WebCore::Element* element)
921 {
922     m_page->fullScreenManager()->enterFullScreenForElement(element);
923 }
924
925 void WebChromeClient::exitFullScreenForElement(WebCore::Element* element)
926 {
927     m_page->fullScreenManager()->exitFullScreenForElement(element);
928 }
929 #endif
930
931 void WebChromeClient::dispatchViewportPropertiesDidChange(const ViewportArguments&) const
932 {
933 #if USE(TILED_BACKING_STORE)
934     if (!m_page->useFixedLayout())
935         return;
936
937     m_page->sendViewportAttributesChanged();
938 #endif
939 }
940
941 void WebChromeClient::notifyScrollerThumbIsVisibleInRect(const IntRect& scrollerThumb)
942 {
943     m_page->send(Messages::WebPageProxy::NotifyScrollerThumbIsVisibleInRect(scrollerThumb));
944 }
945
946 void WebChromeClient::recommendedScrollbarStyleDidChange(int32_t newStyle)
947 {
948     m_page->send(Messages::WebPageProxy::RecommendedScrollbarStyleDidChange(newStyle));
949 }
950
951 bool WebChromeClient::shouldRubberBandInDirection(WebCore::ScrollDirection direction) const
952 {
953     ASSERT(direction != WebCore::ScrollUp && direction != WebCore::ScrollDown);
954     
955     if (direction == WebCore::ScrollLeft)
956         return m_page->injectedBundleUIClient().shouldRubberBandInDirection(m_page, WKScrollDirectionLeft);
957     if (direction == WebCore::ScrollRight)
958         return m_page->injectedBundleUIClient().shouldRubberBandInDirection(m_page, WKScrollDirectionRight);
959
960     ASSERT_NOT_REACHED();
961     return true;
962 }
963
964 void WebChromeClient::numWheelEventHandlersChanged(unsigned count)
965 {
966     m_page->numWheelEventHandlersChanged(count);
967 }
968
969 #if ENABLE(SCREEN_ORIENTATION_SUPPORT) && ENABLE(TIZEN_SCREEN_ORIENTATION_SUPPORT)
970 bool WebChromeClient::lockOrientation(int willLockOrientation)
971 {
972     bool result = false;
973     m_page->sendSync(Messages::WebPageProxy::LockOrientation(willLockOrientation), Messages::WebPageProxy::LockOrientation::Reply(result));
974     return result;
975 }
976 void WebChromeClient::unlockOrientation()
977 {
978     m_page->send(Messages::WebPageProxy::UnlockOrientation());
979 }
980 #endif
981
982 void WebChromeClient::logDiagnosticMessage(const String& message, const String& description, const String& success)
983 {
984     if (!m_page->corePage()->settings()->diagnosticLoggingEnabled())
985         return;
986
987     m_page->injectedBundleDiagnosticLoggingClient().logDiagnosticMessage(m_page, message, description, success);
988 }
989
990 #if ENABLE(TIZEN_WEBKIT2_HISTORICAL_RESTORE_VISIBLE_CONTENT_RECT)
991 void WebChromeClient::requestVisibleContentRectRestore(const IntPoint& scrollOffset, float scale)
992 {
993     m_page->pageDidRequestRestoreVisibleContentRect(scrollOffset, scale);
994 }
995
996 float WebChromeClient::contentsScaleFactor() const
997 {
998     if (!m_page->drawingArea())
999         return 0;
1000     return m_page->drawingArea()->layerTreeHost()->contentsScaleFactor();
1001 }
1002 #endif
1003
1004 #if ENABLE(TIZEN_SCREEN_READER)
1005 void WebChromeClient::rendererWillBeDestroyed(RenderObject* object)
1006 {
1007     m_page->updateScreenReaderFocus(object);
1008 }
1009 #endif
1010
1011 #if ENABLE(TIZEN_INDEXED_DATABASE)
1012 bool WebChromeClient::exceededIndexedDatabaseQuota(Frame* frame, int64_t currentQuota)
1013 {
1014     WebFrame* webFrame = static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame();
1015     SecurityOrigin* origin = frame->document()->securityOrigin();
1016
1017     unsigned syncSendFlags = (WebCore::AXObjectCache::accessibilityEnabled()) ? CoreIPC::SpinRunLoopWhileWaitingForReply : 0;
1018     bool allow = false;
1019 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
1020     WebProcess::WaitForJavaScriptPopupFinished waiting;
1021 #endif
1022     if (!WebProcess::shared().connection()->sendSync(Messages::WebPageProxy::ExceededIndexedDatabaseQuota(webFrame->frameID(), origin->databaseIdentifier(), currentQuota), Messages::WebPageProxy::ExceededIndexedDatabaseQuota::Reply(allow), m_page->pageID(), CoreIPC::Connection::DefaultTimeout, syncSendFlags))
1023         return false;
1024
1025     return allow;
1026 }
1027 #endif
1028
1029 } // namespace WebKit