166b8b596874089025732714305e945845c18082
[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_VIEWPORT_META_TAG)
509 bool WebChromeClient::canContentsSizeChange(Frame* frame, const IntSize& size) const
510 {
511     // FIXME1: This patch should be removed AS SOON AS unexpected layout change problem is fixed.
512     // A page on naver isn't fitted when device is moved from landscape to portrait.
513     String url = frame->document()->url().string();
514     if (url.startsWith("https://nid.naver.com/user"))
515         return false;
516
517     return true;
518 }
519 #endif
520
521 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
522 bool WebChromeClient::getStandaloneStatus()
523 {
524     bool standalone = false;
525     m_page->sendSync(Messages::WebPageProxy::GetStandaloneStatus(), Messages::WebPageProxy::GetStandaloneStatus::Reply(standalone), m_page->pageID());
526     return standalone;
527 }
528 #endif
529
530 #if ENABLE(TIZEN_SEARCH_PROVIDER)
531 void WebChromeClient::addSearchProvider(const String& baseURL, const String& engineURL)
532 {
533     m_page->send(Messages::WebPageProxy::AddSearchProvider(baseURL, engineURL));
534 }
535
536 unsigned long WebChromeClient::isSearchProviderInstalled(const String& baseURL, const String& engineURL)
537 {
538     uint64_t result;
539     m_page->sendSync(Messages::WebPageProxy::IsSearchProviderInstalled(baseURL, engineURL), Messages::WebPageProxy::IsSearchProviderInstalled::Reply(result));
540     return result;
541 }
542 #endif
543
544 void WebChromeClient::contentsSizeChanged(Frame* frame, const IntSize& size) const
545 {
546     if (!m_page->corePage()->settings()->frameFlatteningEnabled()) {
547         WebFrame* largestFrame = findLargestFrameInFrameSet(m_page);
548         if (largestFrame != m_cachedFrameSetLargestFrame.get()) {
549             m_cachedFrameSetLargestFrame = largestFrame;
550             m_page->send(Messages::WebPageProxy::FrameSetLargestFrameChanged(largestFrame ? largestFrame->frameID() : 0));
551         }
552     }
553
554     if (frame->page()->mainFrame() != frame)
555         return;
556
557 #if PLATFORM(QT) || (PLATFORM(EFL) && USE(TILED_BACKING_STORE))
558     if (m_page->useFixedLayout()) {
559         // The below method updates the size().
560         m_page->resizeToContentsIfNeeded();
561         m_page->drawingArea()->layerTreeHost()->sizeDidChange(m_page->size());
562     }
563
564 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
565     // FIXME: Logic to calculate the node's position is inefficient.
566     Frame* focusedFrame = m_page->corePage()->focusController()->focusedFrame();
567     if(focusedFrame && focusedFrame->document() && focusedFrame->document()->focusedNode()) {
568         Node* node = focusedFrame->document()->focusedNode();
569         IntRect nodeRect = IntRect(0, 0, 0, 0);
570         if (node) {
571             nodeRect = WebCore::pixelSnappedIntRect(node->getRect());
572             Frame* mainFrame = m_page->corePage()->mainFrame();
573             Frame* frame = node->document()->frame();
574             Node* owner;
575             while (frame && frame != mainFrame) {
576                 owner = frame->ownerElement();
577                 if (!owner)
578                     break;
579
580                 nodeRect.setX(nodeRect.x() + owner->getRect().x());
581                 nodeRect.setY(nodeRect.y() + owner->getRect().y());
582                 frame = owner->document()->frame();
583             }
584             // we have to divide (x, y) with pageZoomFactor because pageZoomFactor was applied to them.
585             nodeRect.setX(nodeRect.x() / m_page->pageScaleFactor());
586             nodeRect.setY(nodeRect.y() / m_page->pageScaleFactor());
587         }
588         m_page->send(Messages::WebPageProxy::FocusedNodeChanged(nodeRect));
589     }
590 #endif
591
592     m_page->send(Messages::WebPageProxy::DidChangeContentsSize(m_page->size()));
593 #endif
594
595     FrameView* frameView = frame->view();
596     if (frameView && !frameView->delegatesScrolling())  {
597         bool hasHorizontalScrollbar = frameView->horizontalScrollbar();
598         bool hasVerticalScrollbar = frameView->verticalScrollbar();
599
600         if (hasHorizontalScrollbar != m_cachedMainFrameHasHorizontalScrollbar || hasVerticalScrollbar != m_cachedMainFrameHasVerticalScrollbar) {
601             m_page->send(Messages::WebPageProxy::DidChangeScrollbarsForMainFrame(hasHorizontalScrollbar, hasVerticalScrollbar));
602
603             m_cachedMainFrameHasHorizontalScrollbar = hasHorizontalScrollbar;
604             m_cachedMainFrameHasVerticalScrollbar = hasVerticalScrollbar;
605         }
606     }
607 }
608
609 void WebChromeClient::scrollRectIntoView(const IntRect&) const
610 {
611     notImplemented();
612 }
613
614 bool WebChromeClient::shouldUnavailablePluginMessageBeButton(RenderEmbeddedObject::PluginUnavailabilityReason pluginUnavailabilityReason) const
615 {
616     if (pluginUnavailabilityReason == RenderEmbeddedObject::PluginMissing || pluginUnavailabilityReason == RenderEmbeddedObject::InsecurePluginVersion) {
617         // FIXME: <rdar://problem/8794397> We should only return true when there is a
618         // missingPluginButtonClicked callback defined on the Page UI client.
619         return true;
620     }
621
622     return false;
623 }
624     
625 void WebChromeClient::unavailablePluginButtonClicked(Element* element, RenderEmbeddedObject::PluginUnavailabilityReason pluginUnavailabilityReason) const
626 {
627     ASSERT(element->hasTagName(objectTag) || element->hasTagName(embedTag) || element->hasTagName(appletTag));
628     ASSERT(pluginUnavailabilityReason == RenderEmbeddedObject::PluginMissing || pluginUnavailabilityReason == RenderEmbeddedObject::InsecurePluginVersion);
629
630     HTMLPlugInImageElement* pluginElement = static_cast<HTMLPlugInImageElement*>(element);
631
632     m_page->send(Messages::WebPageProxy::UnavailablePluginButtonClicked(pluginUnavailabilityReason, pluginElement->serviceType(), pluginElement->url(), pluginElement->getAttribute(pluginspageAttr)));
633 }
634
635 void WebChromeClient::scrollbarsModeDidChange() const
636 {
637     notImplemented();
638 }
639
640 void WebChromeClient::mouseDidMoveOverElement(const HitTestResult& hitTestResult, unsigned modifierFlags)
641 {
642     RefPtr<APIObject> userData;
643
644     // Notify the bundle client.
645     m_page->injectedBundleUIClient().mouseDidMoveOverElement(m_page, hitTestResult, static_cast<WebEvent::Modifiers>(modifierFlags), userData);
646
647     // Notify the UIProcess.
648     WebHitTestResult::Data webHitTestResultData(hitTestResult);
649     m_page->send(Messages::WebPageProxy::MouseDidMoveOverElement(webHitTestResultData, modifierFlags, InjectedBundleUserMessageEncoder(userData.get())));
650 }
651
652 void WebChromeClient::setToolTip(const String& toolTip, TextDirection)
653 {
654     // Only send a tool tip to the WebProcess if it has changed since the last time this function was called.
655
656     if (toolTip == m_cachedToolTip)
657         return;
658     m_cachedToolTip = toolTip;
659
660     m_page->send(Messages::WebPageProxy::SetToolTip(m_cachedToolTip));
661 }
662
663 void WebChromeClient::print(Frame* frame)
664 {
665     WebFrame* webFrame = static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame();
666     m_page->sendSync(Messages::WebPageProxy::PrintFrame(webFrame->frameID()), Messages::WebPageProxy::PrintFrame::Reply());
667 }
668
669 #if ENABLE(SQL_DATABASE)
670 void WebChromeClient::exceededDatabaseQuota(Frame* frame, const String& databaseName)
671 {
672     WebFrame* webFrame = static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame();
673     SecurityOrigin* origin = frame->document()->securityOrigin();
674
675     DatabaseDetails details = DatabaseTracker::tracker().detailsForNameAndOrigin(databaseName, origin);
676     uint64_t currentQuota = DatabaseTracker::tracker().quotaForOrigin(origin);
677
678 #if ENABLE(TIZEN_SQL_DATABASE)
679     uint64_t newQuota = 0;
680     const uint64_t defaultQuota = 5 * 1024 * 1024;
681     uint64_t requirement = currentQuota + details.expectedUsage();
682     if (requirement <= defaultQuota)
683         newQuota = requirement;
684     else {
685         unsigned syncSendFlags = (WebCore::AXObjectCache::accessibilityEnabled()) ? CoreIPC::SpinRunLoopWhileWaitingForReply : 0;
686         bool allowExceed = false;
687         WebProcess::shared().connection()->sendSync(
688             Messages::WebPageProxy::ExceededDatabaseQuota(webFrame->frameID(), origin->databaseIdentifier(), details.displayName(), details.expectedUsage()),
689             Messages::WebPageProxy::ExceededDatabaseQuota::Reply(allowExceed), m_page->pageID(), CoreIPC::Connection::DefaultTimeout, syncSendFlags);
690         if (allowExceed)
691             newQuota = currentQuota + details.expectedUsage();
692         else
693             newQuota = currentQuota;
694     }
695 #else
696     uint64_t currentOriginUsage = DatabaseTracker::tracker().usageForOrigin(origin);
697     uint64_t newQuota = 0;
698     WebProcess::shared().connection()->sendSync(
699         Messages::WebPageProxy::ExceededDatabaseQuota(webFrame->frameID(), origin->databaseIdentifier(), databaseName, details.displayName(), currentQuota, currentOriginUsage, details.currentUsage(), details.expectedUsage()),
700         Messages::WebPageProxy::ExceededDatabaseQuota::Reply(newQuota), m_page->pageID());
701 #endif
702
703     DatabaseTracker::tracker().setQuota(origin, newQuota);
704 }
705 #endif
706
707
708 void WebChromeClient::reachedMaxAppCacheSize(int64_t)
709 {
710     notImplemented();
711 }
712
713 void WebChromeClient::reachedApplicationCacheOriginQuota(SecurityOrigin*, int64_t)
714 {
715     notImplemented();
716 }
717
718 #if ENABLE(TIZEN_APPLICATION_CACHE)
719 bool WebChromeClient::requestApplicationCachePermission(Frame* frame)
720 {
721     WebFrame* webFrame = static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame();
722     SecurityOrigin* origin = frame->document()->securityOrigin();
723
724     unsigned syncSendFlags = WebCore::AXObjectCache::accessibilityEnabled() ? CoreIPC::SpinRunLoopWhileWaitingForReply : 0;
725     bool allow = false;
726 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
727     WebProcess::WaitForJavaScriptPopupFinished waiting;
728 #endif
729
730     if (!WebProcess::shared().connection()->sendSync(Messages::WebPageProxy::RequestApplicationCachePermission(webFrame->frameID(), origin->databaseIdentifier()), Messages::WebPageProxy::RequestApplicationCachePermission::Reply(allow), m_page->pageID(), CoreIPC::Connection::DefaultTimeout, syncSendFlags))
731         return false;
732
733     return allow;
734 }
735 #endif
736
737 #if ENABLE(DASHBOARD_SUPPORT)
738 void WebChromeClient::dashboardRegionsChanged()
739 {
740     notImplemented();
741 }
742 #endif
743
744 void WebChromeClient::populateVisitedLinks()
745 {
746 }
747
748 FloatRect WebChromeClient::customHighlightRect(Node*, const AtomicString& type, const FloatRect& lineRect)
749 {
750     notImplemented();
751     return FloatRect();
752 }
753
754 void WebChromeClient::paintCustomHighlight(Node*, const AtomicString& type, const FloatRect& boxRect, const FloatRect& lineRect,
755                                   bool behindText, bool entireLine)
756 {
757     notImplemented();
758 }
759
760 bool WebChromeClient::shouldReplaceWithGeneratedFileForUpload(const String& path, String& generatedFilename)
761 {
762     generatedFilename = m_page->injectedBundleUIClient().shouldGenerateFileForUpload(m_page, path);
763     return !generatedFilename.isNull();
764 }
765
766 String WebChromeClient::generateReplacementFile(const String& path)
767 {
768     return m_page->injectedBundleUIClient().generateFileForUpload(m_page, path);
769 }
770
771 bool WebChromeClient::paintCustomOverhangArea(GraphicsContext* context, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect)
772 {
773     if (!m_page->injectedBundleUIClient().shouldPaintCustomOverhangArea())
774         return false;
775
776     m_page->injectedBundleUIClient().paintCustomOverhangArea(m_page, context, horizontalOverhangArea, verticalOverhangArea, dirtyRect);
777     return true;
778 }
779
780 #if ENABLE(INPUT_TYPE_COLOR)
781 PassOwnPtr<ColorChooser> WebChromeClient::createColorChooser(ColorChooserClient* client, const Color& initialColor)
782 {
783     if (m_page->activeColorChooser())
784         return nullptr;
785
786     return adoptPtr(new WebColorChooser(m_page, client, initialColor));
787 }
788 #endif
789
790 void WebChromeClient::runOpenPanel(Frame* frame, PassRefPtr<FileChooser> prpFileChooser)
791 {
792 #if OS(TIZEN)
793     if (m_page->activeOpenPanelResultListener())
794         m_page->cancelForOpenPanel();
795 #else
796     if (m_page->activeOpenPanelResultListener())
797         return;
798 #endif
799
800     RefPtr<FileChooser> fileChooser = prpFileChooser;
801
802     m_page->setActiveOpenPanelResultListener(WebOpenPanelResultListener::create(m_page, fileChooser.get()));
803     m_page->send(Messages::WebPageProxy::RunOpenPanel(static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame()->frameID(), fileChooser->settings()));
804 }
805
806 void WebChromeClient::loadIconForFiles(const Vector<String>& filenames, FileIconLoader* loader)
807 {
808     loader->notifyFinished(Icon::createIconForFiles(filenames));
809 }
810
811 void WebChromeClient::setCursor(const WebCore::Cursor& cursor)
812 {
813 #if USE(LAZY_NATIVE_CURSOR)
814     m_page->send(Messages::WebPageProxy::SetCursor(cursor));
815 #endif
816 }
817
818 void WebChromeClient::setCursorHiddenUntilMouseMoves(bool hiddenUntilMouseMoves)
819 {
820     m_page->send(Messages::WebPageProxy::SetCursorHiddenUntilMouseMoves(hiddenUntilMouseMoves));
821 }
822
823 #if ENABLE(REQUEST_ANIMATION_FRAME) && !USE(REQUEST_ANIMATION_FRAME_TIMER)
824 void WebChromeClient::scheduleAnimation()
825 {
826 #if USE(UI_SIDE_COMPOSITING)
827     m_page->drawingArea()->layerTreeHost()->scheduleAnimation();
828 #endif
829 }
830 #endif
831
832 void WebChromeClient::formStateDidChange(const Node*)
833 {
834     notImplemented();
835 }
836
837 bool WebChromeClient::selectItemWritingDirectionIsNatural()
838 {
839 #if PLATFORM(WIN)
840     return true;
841 #else
842     return false;
843 #endif
844 }
845
846 bool WebChromeClient::selectItemAlignmentFollowsMenuWritingDirection()
847 {
848 #if PLATFORM(WIN)
849     return false;
850 #else
851     return true;
852 #endif
853 }
854
855 bool WebChromeClient::hasOpenedPopup() const
856 {
857     notImplemented();
858     return false;
859 }
860
861 PassRefPtr<WebCore::PopupMenu> WebChromeClient::createPopupMenu(WebCore::PopupMenuClient* client) const
862 {
863     return WebPopupMenu::create(m_page, client);
864 }
865
866 PassRefPtr<WebCore::SearchPopupMenu> WebChromeClient::createSearchPopupMenu(WebCore::PopupMenuClient* client) const
867 {
868     return WebSearchPopupMenu::create(m_page, client);
869 }
870
871 #if USE(ACCELERATED_COMPOSITING)
872 void WebChromeClient::attachRootGraphicsLayer(Frame*, GraphicsLayer* layer)
873 {
874     if (layer)
875         m_page->enterAcceleratedCompositingMode(layer);
876     else
877         m_page->exitAcceleratedCompositingMode();
878 }
879
880 void WebChromeClient::setNeedsOneShotDrawingSynchronization()
881 {
882 #if ENABLE(TIZEN_ONESHOT_DRAWING_SYNCHRONIZATION)
883     if (m_page->drawingArea())
884         m_page->drawingArea()->setNeedsOneShotDrawingSynchronization();
885 #else
886     notImplemented();
887 #endif
888 }
889
890 void WebChromeClient::scheduleCompositingLayerSync()
891 {
892     if (m_page->drawingArea())
893         m_page->drawingArea()->scheduleCompositingLayerSync();
894 }
895
896 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
897 void WebChromeClient::addOrUpdateScrollingLayer(WebCore::Node*, WebCore::GraphicsLayer* scrollingLayer, WebCore::GraphicsLayer* contentsLayer, const WebCore::IntSize& scrollSize)
898 {
899     if (!m_page->drawingArea())
900         return;
901     m_page->drawingArea()->addOrUpdateScrollingLayer(scrollingLayer, contentsLayer, scrollSize);
902 }
903
904 void WebChromeClient::removeScrollingLayer(WebCore::Node*, WebCore::GraphicsLayer* scrollingLayer, WebCore::GraphicsLayer* contentsLayer)
905 {
906     if (!m_page->drawingArea())
907         return;
908     m_page->drawingArea()->removeScrollingLayer(scrollingLayer, contentsLayer);
909 }
910 #endif // ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
911 #endif // USE(ACCELERATED_COMPOSITING)
912
913 #if PLATFORM(WIN) && USE(AVFOUNDATION)
914 WebCore::GraphicsDeviceAdapter* WebChromeClient::graphicsDeviceAdapter() const
915 {
916     if (!m_page->drawingArea())
917         return 0;
918     return m_page->drawingArea()->layerTreeHost()->graphicsDeviceAdapter();
919 }
920 #endif
921
922 #if ENABLE(TOUCH_EVENTS)
923 void WebChromeClient::needTouchEvents(bool needTouchEvents)
924 {
925     m_page->send(Messages::WebPageProxy::NeedTouchEvents(needTouchEvents));
926 }
927 #endif
928
929 #if PLATFORM(WIN)
930 void WebChromeClient::setLastSetCursorToCurrentCursor()
931 {
932 }
933 #endif
934
935 #if ENABLE(FULLSCREEN_API)
936 bool WebChromeClient::supportsFullScreenForElement(const WebCore::Element* element, bool withKeyboard)
937 {
938     return m_page->fullScreenManager()->supportsFullScreen(withKeyboard);
939 }
940
941 void WebChromeClient::enterFullScreenForElement(WebCore::Element* element)
942 {
943     m_page->fullScreenManager()->enterFullScreenForElement(element);
944 }
945
946 void WebChromeClient::exitFullScreenForElement(WebCore::Element* element)
947 {
948     m_page->fullScreenManager()->exitFullScreenForElement(element);
949 }
950 #endif
951
952 void WebChromeClient::dispatchViewportPropertiesDidChange(const ViewportArguments&) const
953 {
954 #if USE(TILED_BACKING_STORE)
955     if (!m_page->useFixedLayout())
956         return;
957
958     m_page->sendViewportAttributesChanged();
959 #endif
960 }
961
962 void WebChromeClient::notifyScrollerThumbIsVisibleInRect(const IntRect& scrollerThumb)
963 {
964     m_page->send(Messages::WebPageProxy::NotifyScrollerThumbIsVisibleInRect(scrollerThumb));
965 }
966
967 void WebChromeClient::recommendedScrollbarStyleDidChange(int32_t newStyle)
968 {
969     m_page->send(Messages::WebPageProxy::RecommendedScrollbarStyleDidChange(newStyle));
970 }
971
972 bool WebChromeClient::shouldRubberBandInDirection(WebCore::ScrollDirection direction) const
973 {
974     ASSERT(direction != WebCore::ScrollUp && direction != WebCore::ScrollDown);
975     
976     if (direction == WebCore::ScrollLeft)
977         return m_page->injectedBundleUIClient().shouldRubberBandInDirection(m_page, WKScrollDirectionLeft);
978     if (direction == WebCore::ScrollRight)
979         return m_page->injectedBundleUIClient().shouldRubberBandInDirection(m_page, WKScrollDirectionRight);
980
981     ASSERT_NOT_REACHED();
982     return true;
983 }
984
985 void WebChromeClient::numWheelEventHandlersChanged(unsigned count)
986 {
987     m_page->numWheelEventHandlersChanged(count);
988 }
989
990 #if ENABLE(SCREEN_ORIENTATION_SUPPORT) && ENABLE(TIZEN_SCREEN_ORIENTATION_SUPPORT)
991 bool WebChromeClient::lockOrientation(int willLockOrientation)
992 {
993     bool result = false;
994     m_page->sendSync(Messages::WebPageProxy::LockOrientation(willLockOrientation), Messages::WebPageProxy::LockOrientation::Reply(result));
995     return result;
996 }
997 void WebChromeClient::unlockOrientation()
998 {
999     m_page->send(Messages::WebPageProxy::UnlockOrientation());
1000 }
1001 #endif
1002
1003 void WebChromeClient::logDiagnosticMessage(const String& message, const String& description, const String& success)
1004 {
1005     if (!m_page->corePage()->settings()->diagnosticLoggingEnabled())
1006         return;
1007
1008     m_page->injectedBundleDiagnosticLoggingClient().logDiagnosticMessage(m_page, message, description, success);
1009 }
1010
1011 #if ENABLE(TIZEN_WEBKIT2_HISTORICAL_RESTORE_VISIBLE_CONTENT_RECT)
1012 void WebChromeClient::requestVisibleContentRectRestore(const IntPoint& scrollOffset, float scale)
1013 {
1014     m_page->pageDidRequestRestoreVisibleContentRect(scrollOffset, scale);
1015 }
1016
1017 float WebChromeClient::contentsScaleFactor() const
1018 {
1019     if (!m_page->drawingArea())
1020         return 0;
1021     return m_page->drawingArea()->layerTreeHost()->contentsScaleFactor();
1022 }
1023 #endif
1024
1025 #if OS(TIZEN)
1026 void WebChromeClient::rendererWillBeDestroyed(RenderObject* object)
1027 {
1028 #if ENABLE(TIZEN_SCREEN_READER)
1029     m_page->updateScreenReaderFocus(object);
1030 #endif
1031
1032 #if ENABLE(TIZEN_ISF_PORT)
1033     if (object->node() && object->node()->isRootEditableElement())
1034         m_page->send(Messages::WebPageProxy::RemoveInputMethodContext(reinterpret_cast<uintptr_t>(object->node())));
1035 #endif
1036 }
1037 #endif
1038
1039 #if ENABLE(TIZEN_INDEXED_DATABASE)
1040 bool WebChromeClient::exceededIndexedDatabaseQuota(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 allow = false;
1047 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
1048     WebProcess::WaitForJavaScriptPopupFinished waiting;
1049 #endif
1050     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))
1051         return false;
1052
1053     return allow;
1054 }
1055 #endif
1056
1057 #if ENABLE(TIZEN_FILE_SYSTEM)
1058 bool WebChromeClient::exceededLocalFileSystemQuota(Frame* frame, int64_t currentQuota)
1059 {
1060     WebFrame* webFrame = static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame();
1061     SecurityOrigin* origin = frame->document()->securityOrigin();
1062
1063     unsigned syncSendFlags = (WebCore::AXObjectCache::accessibilityEnabled()) ? CoreIPC::SpinRunLoopWhileWaitingForReply : 0;
1064     bool result = false;
1065 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
1066     WebProcess::WaitForJavaScriptPopupFinished waiting;
1067 #endif
1068     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))
1069         return false;
1070
1071     return result;
1072 }
1073 #endif
1074
1075 #if ENABLE(TIZEN_WEBKIT2_NOTIFY_SUSPEND_BY_REMOTE_WEB_INSPECTOR)
1076 void WebChromeClient::setContentSuspendedByInspector(bool isSuspended)
1077 {
1078     m_page->send(Messages::WebPageProxy::setContentSuspendedByInspector(isSuspended));
1079 }
1080 #endif
1081 } // namespace WebKit