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