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