REGRESSION (WebKit2): Selection inside accelerated overflow:scroll doesn't track...
[WebKit-https.git] / Source / WebKit2 / UIProcess / ios / WebPageProxyIOS.mm
1 /*
2  * Copyright (C) 2012 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #import "config.h"
27 #import "WebPageProxy.h"
28
29 #if PLATFORM(IOS)
30
31 #import "APIUIClient.h"
32 #import "DataReference.h"
33 #import "EditingRange.h"
34 #import "NativeWebKeyboardEvent.h"
35 #import "PageClient.h"
36 #import "RemoteLayerTreeDrawingAreaProxy.h"
37 #import "RemoteLayerTreeDrawingAreaProxyMessages.h"
38 #import "RemoteLayerTreeTransaction.h"
39 #import "ViewUpdateDispatcherMessages.h"
40 #import "WKBrowsingContextControllerInternal.h"
41 #import "WebContextUserMessageCoders.h"
42 #import "WebKitSystemInterfaceIOS.h"
43 #import "WebPageMessages.h"
44 #import "WebProcessProxy.h"
45 #import "WebVideoFullscreenManagerProxy.h"
46 #import <WebCore/FrameView.h>
47 #import <WebCore/NotImplemented.h>
48 #import <WebCore/SharedBuffer.h>
49 #import <WebCore/UserAgent.h>
50
51 #if USE(QUICK_LOOK)
52 #import "APILoaderClient.h"
53 #import <wtf/text/WTFString.h>
54 #endif
55
56 using namespace WebCore;
57
58 namespace WebKit {
59
60 void WebPageProxy::platformInitialize()
61 {
62 }
63
64 static String webKitBundleVersionString()
65 {
66     return [[NSBundle bundleForClass:NSClassFromString(@"WKWebView")] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
67 }
68
69 String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
70 {
71     return standardUserAgentWithApplicationName(applicationNameForUserAgent, webKitBundleVersionString());
72 }
73
74 void WebPageProxy::getIsSpeaking(bool&)
75 {
76     notImplemented();
77 }
78
79 void WebPageProxy::speak(const String&)
80 {
81     notImplemented();
82 }
83
84 void WebPageProxy::stopSpeaking()
85 {
86     notImplemented();
87 }
88
89 void WebPageProxy::searchWithSpotlight(const String&)
90 {
91     notImplemented();
92 }
93
94 void WebPageProxy::searchTheWeb(const String&)
95 {
96     notImplemented();
97 }
98
99 void WebPageProxy::windowAndViewFramesChanged(const FloatRect&, const FloatPoint&)
100 {
101     notImplemented();
102 }
103
104 String WebPageProxy::stringSelectionForPasteboard()
105 {
106     notImplemented();
107     return String();
108 }
109
110 PassRefPtr<WebCore::SharedBuffer> WebPageProxy::dataSelectionForPasteboard(const String&)
111 {
112     notImplemented();
113     return 0;
114 }
115
116 bool WebPageProxy::readSelectionFromPasteboard(const String&)
117 {
118     notImplemented();
119     return false;
120 }
121
122 void WebPageProxy::performDictionaryLookupAtLocation(const WebCore::FloatPoint&)
123 {
124     notImplemented();
125 }
126
127 void WebPageProxy::gestureCallback(const WebCore::IntPoint& point, uint32_t gestureType, uint32_t gestureState, uint32_t flags, uint64_t callbackID)
128 {
129     auto callback = m_callbacks.take<GestureCallback>(callbackID);
130     if (!callback) {
131         ASSERT_NOT_REACHED();
132         return;
133     }
134     
135     callback->performCallbackWithReturnValue(point, gestureType, gestureState, flags);
136 }
137
138 void WebPageProxy::touchesCallback(const WebCore::IntPoint& point, uint32_t touches, uint64_t callbackID)
139 {
140     auto callback = m_callbacks.take<TouchesCallback>(callbackID);
141     if (!callback) {
142         ASSERT_NOT_REACHED();
143         return;
144     }
145
146     callback->performCallbackWithReturnValue(point, touches);
147 }
148
149 void WebPageProxy::autocorrectionDataCallback(const Vector<WebCore::FloatRect>& rects, const String& fontName, float fontSize, uint64_t fontTraits, uint64_t callbackID)
150 {
151     auto callback = m_callbacks.take<AutocorrectionDataCallback>(callbackID);
152     if (!callback) {
153         ASSERT_NOT_REACHED();
154         return;
155     }
156
157     callback->performCallbackWithReturnValue(rects, fontName, fontSize, fontTraits);
158 }
159
160 void WebPageProxy::dictationContextCallback(const String& selectedText, const String& beforeText, const String& afterText, uint64_t callbackID)
161 {
162     auto callback = m_callbacks.take<DictationContextCallback>(callbackID);
163     if (!callback) {
164         ASSERT_NOT_REACHED();
165         return;
166     }
167
168     callback->performCallbackWithReturnValue(selectedText, beforeText, afterText);
169 }
170
171 void WebPageProxy::autocorrectionContextCallback(const String& beforeText, const String& markedText, const String& selectedText, const String& afterText, uint64_t location, uint64_t length, uint64_t callbackID)
172 {
173     auto callback = m_callbacks.take<AutocorrectionContextCallback>(callbackID);
174     if (!callback) {
175         ASSERT_NOT_REACHED();
176         return;
177     }
178
179     callback->performCallbackWithReturnValue(beforeText, markedText, selectedText, afterText, location, length);
180 }
181
182 void WebPageProxy::updateVisibleContentRects(const WebCore::FloatRect& exposedRect, const WebCore::FloatRect& unobscuredRect, const WebCore::FloatRect& unobscuredRectInScrollViewCoordinates, const WebCore::FloatRect& customFixedPositionRect, double scale, bool inStableState, bool isChangingObscuredInsetsInteractively, double timestamp, double horizontalVelocity, double verticalVelocity, double scaleChangeRate)
183 {
184     if (!isValid())
185         return;
186
187     VisibleContentRectUpdateInfo visibleContentRectUpdateInfo(exposedRect, unobscuredRect, unobscuredRectInScrollViewCoordinates, customFixedPositionRect, scale, inStableState, isChangingObscuredInsetsInteractively, timestamp, horizontalVelocity, verticalVelocity, scaleChangeRate, toRemoteLayerTreeDrawingAreaProxy(drawingArea())->lastCommittedLayerTreeTransactionID());
188
189     if (visibleContentRectUpdateInfo == m_lastVisibleContentRectUpdate)
190         return;
191
192     m_lastVisibleContentRectUpdate = visibleContentRectUpdateInfo;
193     m_process->send(Messages::ViewUpdateDispatcher::VisibleContentRectUpdate(m_pageID, visibleContentRectUpdateInfo), 0);
194 }
195
196 void WebPageProxy::resendLastVisibleContentRects()
197 {
198     m_process->send(Messages::ViewUpdateDispatcher::VisibleContentRectUpdate(m_pageID, m_lastVisibleContentRectUpdate), 0);
199 }
200
201 static inline float adjustedUnexposedEdge(float documentEdge, float exposedRectEdge, float factor)
202 {
203     if (exposedRectEdge < documentEdge)
204         return documentEdge - factor * (documentEdge - exposedRectEdge);
205     
206     return exposedRectEdge;
207 }
208
209 static inline float adjustedUnexposedMaxEdge(float documentEdge, float exposedRectEdge, float factor)
210 {
211     if (exposedRectEdge > documentEdge)
212         return documentEdge + factor * (exposedRectEdge - documentEdge);
213     
214     return exposedRectEdge;
215 }
216
217 WebCore::FloatRect WebPageProxy::computeCustomFixedPositionRect(const FloatRect& unobscuredContentRect, double displayedContentScale, UnobscuredRectConstraint constraint) const
218 {
219     FloatRect constrainedUnobscuredRect = unobscuredContentRect;
220     FloatSize contentsSize = m_pageClient.contentsSize();
221     FloatRect documentRect = FloatRect(FloatPoint(), contentsSize);
222
223     if (m_pageClient.isAssistingNode())
224         return documentRect;
225
226     if (constraint == UnobscuredRectConstraint::ConstrainedToDocumentRect)
227         constrainedUnobscuredRect.intersect(documentRect);
228
229     double minimumScale = m_pageClient.minimumZoomScale();
230     
231     if (displayedContentScale < minimumScale) {
232         const CGFloat slope = 12;
233         CGFloat factor = std::max<CGFloat>(1 - slope * (minimumScale - displayedContentScale), 0);
234             
235         constrainedUnobscuredRect.setX(adjustedUnexposedEdge(documentRect.x(), constrainedUnobscuredRect.x(), factor));
236         constrainedUnobscuredRect.setY(adjustedUnexposedEdge(documentRect.y(), constrainedUnobscuredRect.y(), factor));
237         constrainedUnobscuredRect.setWidth(adjustedUnexposedMaxEdge(documentRect.maxX(), constrainedUnobscuredRect.maxX(), factor) - constrainedUnobscuredRect.x());
238         constrainedUnobscuredRect.setHeight(adjustedUnexposedMaxEdge(documentRect.maxY(), constrainedUnobscuredRect.maxY(), factor) - constrainedUnobscuredRect.y());
239     }
240     
241     return FrameView::rectForViewportConstrainedObjects(enclosingLayoutRect(constrainedUnobscuredRect), roundedLayoutSize(contentsSize), displayedContentScale, false, StickToViewportBounds);
242 }
243
244 void WebPageProxy::overflowScrollViewWillStartPanGesture()
245 {
246     m_pageClient.overflowScrollViewWillStartPanGesture();
247 }
248
249 void WebPageProxy::overflowScrollViewDidScroll()
250 {
251     m_pageClient.overflowScrollViewDidScroll();
252 }
253
254 void WebPageProxy::overflowScrollWillStartScroll()
255 {
256     m_pageClient.overflowScrollWillStartScroll();
257 }
258
259 void WebPageProxy::overflowScrollDidEndScroll()
260 {
261     m_pageClient.overflowScrollDidEndScroll();
262 }
263
264 void WebPageProxy::dynamicViewportSizeUpdate(const FloatSize& minimumLayoutSize, const WebCore::FloatSize& minimumLayoutSizeForMinimalUI, const WebCore::FloatSize& maximumUnobscuredSize, const FloatRect& targetExposedContentRect, const FloatRect& targetUnobscuredRect, const FloatRect& targetUnobscuredRectInScrollViewCoordinates,  double targetScale, int32_t deviceOrientation)
265 {
266     if (!isValid())
267         return;
268
269     m_dynamicViewportSizeUpdateWaitingForTarget = true;
270     m_dynamicViewportSizeUpdateWaitingForLayerTreeCommit = true;
271     m_process->send(Messages::WebPage::DynamicViewportSizeUpdate(minimumLayoutSize, minimumLayoutSizeForMinimalUI, maximumUnobscuredSize, targetExposedContentRect, targetUnobscuredRect, targetUnobscuredRectInScrollViewCoordinates, targetScale, deviceOrientation), m_pageID);
272 }
273
274 void WebPageProxy::synchronizeDynamicViewportUpdate()
275 {
276     if (!isValid())
277         return;
278
279     if (m_dynamicViewportSizeUpdateWaitingForTarget) {
280         // We do not want the UIProcess to finish animated resize with the old content size, scale, etc.
281         // If that happens, the UIProcess would start pushing new VisibleContentRectUpdateInfo to the WebProcess with
282         // invalid informations.
283         //
284         // Ideally, the animated resize should just be transactional, and the UIProcess would remain in the "resize" state
285         // until both DynamicViewportUpdateChangedTarget and the associated commitLayerTree are finished.
286         // The tricky part with such implementation is if a second animated resize starts before the end of the previous one.
287         // In that case, the values used for the target state needs to be computed from the output of the previous animated resize.
288         //
289         // The following is a workaround to have the UIProcess in a consistent state.
290         // Instead of handling nested resize, we block the UIProcess until the animated resize finishes.
291         double newScale;
292         FloatPoint newScrollPosition;
293         uint64_t nextValidLayerTreeTransactionID;
294         if (m_process->sendSync(Messages::WebPage::SynchronizeDynamicViewportUpdate(), Messages::WebPage::SynchronizeDynamicViewportUpdate::Reply(newScale, newScrollPosition, nextValidLayerTreeTransactionID), m_pageID, std::chrono::seconds(2))) {
295             m_dynamicViewportSizeUpdateWaitingForTarget = false;
296             m_dynamicViewportSizeUpdateLayerTreeTransactionID = nextValidLayerTreeTransactionID;
297             m_pageClient.dynamicViewportUpdateChangedTarget(newScale, newScrollPosition, nextValidLayerTreeTransactionID);
298         }
299
300     }
301
302     // If m_dynamicViewportSizeUpdateWaitingForTarget is false, we are waiting for the next valid frame with the hope it is the one for the new target.
303     // If m_dynamicViewportSizeUpdateWaitingForTarget is still true, this is a desesperate attempt to get the valid frame before finishing the animation.
304     if (m_dynamicViewportSizeUpdateWaitingForLayerTreeCommit)
305         m_process->connection()->waitForAndDispatchImmediately<Messages::RemoteLayerTreeDrawingAreaProxy::CommitLayerTree>(m_pageID, std::chrono::seconds(1), IPC::InterruptWaitingIfSyncMessageArrives);
306
307     m_dynamicViewportSizeUpdateWaitingForTarget = false;
308     m_dynamicViewportSizeUpdateWaitingForLayerTreeCommit = false;
309 }
310
311 void WebPageProxy::setViewportConfigurationMinimumLayoutSize(const WebCore::FloatSize& size)
312 {
313     m_process->send(Messages::WebPage::SetViewportConfigurationMinimumLayoutSize(size), m_pageID);
314 }
315
316 void WebPageProxy::setViewportConfigurationMinimumLayoutSizeForMinimalUI(const WebCore::FloatSize& size)
317 {
318     m_process->send(Messages::WebPage::SetViewportConfigurationMinimumLayoutSizeForMinimalUI(size), m_pageID);
319 }
320
321 void WebPageProxy::setMaximumUnobscuredSize(const WebCore::FloatSize& size)
322 {
323     m_process->send(Messages::WebPage::SetMaximumUnobscuredSize(size), m_pageID);
324 }
325
326 void WebPageProxy::setDeviceOrientation(int32_t deviceOrientation)
327 {
328     if (deviceOrientation != m_deviceOrientation) {
329         m_deviceOrientation = deviceOrientation;
330         if (isValid())
331             m_process->send(Messages::WebPage::SetDeviceOrientation(deviceOrientation), m_pageID);
332     }
333 }
334
335 void WebPageProxy::didCommitLayerTree(const WebKit::RemoteLayerTreeTransaction& layerTreeTransaction)
336 {
337     m_pageExtendedBackgroundColor = layerTreeTransaction.pageExtendedBackgroundColor();
338
339     if (!m_dynamicViewportSizeUpdateWaitingForTarget && m_dynamicViewportSizeUpdateWaitingForLayerTreeCommit) {
340         if (layerTreeTransaction.transactionID() >= m_dynamicViewportSizeUpdateLayerTreeTransactionID)
341             m_dynamicViewportSizeUpdateWaitingForLayerTreeCommit = false;
342     }
343
344     m_pageClient.didCommitLayerTree(layerTreeTransaction);
345 }
346
347 void WebPageProxy::selectWithGesture(const WebCore::IntPoint point, WebCore::TextGranularity granularity, uint32_t gestureType, uint32_t gestureState, std::function<void (const WebCore::IntPoint&, uint32_t, uint32_t, uint32_t, CallbackBase::Error)> callbackFunction)
348 {
349     if (!isValid()) {
350         callbackFunction(WebCore::IntPoint(), 0, 0, 0, CallbackBase::Error::Unknown);
351         return;
352     }
353
354     uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), std::make_unique<ProcessThrottler::BackgroundActivityToken>(m_process->throttler()));
355     m_process->send(Messages::WebPage::SelectWithGesture(point, (uint32_t)granularity, gestureType, gestureState, callbackID), m_pageID);
356 }
357
358 void WebPageProxy::updateSelectionWithTouches(const WebCore::IntPoint point, uint32_t touches, bool baseIsStart, std::function<void (const WebCore::IntPoint&, uint32_t, CallbackBase::Error)> callbackFunction)
359 {
360     if (!isValid()) {
361         callbackFunction(WebCore::IntPoint(), 0, CallbackBase::Error::Unknown);
362         return;
363     }
364
365     uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), std::make_unique<ProcessThrottler::BackgroundActivityToken>(m_process->throttler()));
366     m_process->send(Messages::WebPage::UpdateSelectionWithTouches(point, touches, baseIsStart, callbackID), m_pageID);
367 }
368     
369 void WebPageProxy::replaceDictatedText(const String& oldText, const String& newText)
370 {
371     m_process->send(Messages::WebPage::ReplaceDictatedText(oldText, newText), m_pageID);
372 }
373
374 void WebPageProxy::replaceSelectedText(const String& oldText, const String& newText)
375 {
376     m_process->send(Messages::WebPage::ReplaceSelectedText(oldText, newText), m_pageID);
377 }
378
379 void WebPageProxy::requestAutocorrectionData(const String& textForAutocorrection, std::function<void (const Vector<WebCore::FloatRect>&, const String&, double, uint64_t, CallbackBase::Error)> callbackFunction)
380 {
381     if (!isValid()) {
382         callbackFunction(Vector<WebCore::FloatRect>(), String(), 0, 0, CallbackBase::Error::Unknown);
383         return;
384     }
385
386     uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), std::make_unique<ProcessThrottler::BackgroundActivityToken>(m_process->throttler()));
387     m_process->send(Messages::WebPage::RequestAutocorrectionData(textForAutocorrection, callbackID), m_pageID);
388 }
389
390 void WebPageProxy::applyAutocorrection(const String& correction, const String& originalText, std::function<void (const String&, CallbackBase::Error)> callbackFunction)
391 {
392     if (!isValid()) {
393         callbackFunction(String(), CallbackBase::Error::Unknown);
394         return;
395     }
396
397     uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), std::make_unique<ProcessThrottler::BackgroundActivityToken>(m_process->throttler()));
398     m_process->send(Messages::WebPage::ApplyAutocorrection(correction, originalText, callbackID), m_pageID);
399 }
400
401 void WebPageProxy::executeEditCommand(const String& commandName, std::function<void (CallbackBase::Error)> callbackFunction)
402 {
403     if (!isValid()) {
404         callbackFunction(CallbackBase::Error::Unknown);
405         return;
406     }
407     
408     uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), std::make_unique<ProcessThrottler::BackgroundActivityToken>(m_process->throttler()));
409     m_process->send(Messages::WebPage::ExecuteEditCommandWithCallback(commandName, callbackID), m_pageID);
410 }
411
412 bool WebPageProxy::applyAutocorrection(const String& correction, const String& originalText)
413 {
414     bool autocorrectionApplied = false;
415     m_process->sendSync(Messages::WebPage::SyncApplyAutocorrection(correction, originalText), Messages::WebPage::SyncApplyAutocorrection::Reply(autocorrectionApplied), m_pageID);
416     return autocorrectionApplied;
417 }
418
419 void WebPageProxy::requestDictationContext(std::function<void (const String&, const String&, const String&, CallbackBase::Error)> callbackFunction)
420 {
421     if (!isValid()) {
422         callbackFunction(String(), String(), String(), CallbackBase::Error::Unknown);
423         return;
424     }
425
426     uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), std::make_unique<ProcessThrottler::BackgroundActivityToken>(m_process->throttler()));
427     m_process->send(Messages::WebPage::RequestDictationContext(callbackID), m_pageID);
428 }
429
430 void WebPageProxy::requestAutocorrectionContext(std::function<void (const String&, const String&, const String&, const String&, uint64_t, uint64_t, CallbackBase::Error)> callbackFunction)
431 {
432     if (!isValid()) {
433         callbackFunction(String(), String(), String(), String(), 0, 0, CallbackBase::Error::Unknown);
434         return;
435     }
436
437     uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), std::make_unique<ProcessThrottler::BackgroundActivityToken>(m_process->throttler()));
438     m_process->send(Messages::WebPage::RequestAutocorrectionContext(callbackID), m_pageID);
439 }
440
441 void WebPageProxy::getAutocorrectionContext(String& beforeContext, String& markedText, String& selectedText, String& afterContext, uint64_t& location, uint64_t& length)
442 {
443     m_process->sendSync(Messages::WebPage::GetAutocorrectionContext(), Messages::WebPage::GetAutocorrectionContext::Reply(beforeContext, markedText, selectedText, afterContext, location, length), m_pageID);
444 }
445
446 void WebPageProxy::selectWithTwoTouches(const WebCore::IntPoint from, const WebCore::IntPoint to, uint32_t gestureType, uint32_t gestureState, std::function<void (const WebCore::IntPoint&, uint32_t, uint32_t, uint32_t, CallbackBase::Error)> callbackFunction)
447 {
448     if (!isValid()) {
449         callbackFunction(WebCore::IntPoint(), 0, 0, 0, CallbackBase::Error::Unknown);
450         return;
451     }
452
453     uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), std::make_unique<ProcessThrottler::BackgroundActivityToken>(m_process->throttler()));
454     m_process->send(Messages::WebPage::SelectWithTwoTouches(from, to, gestureType, gestureState, callbackID), m_pageID);
455 }
456
457 void WebPageProxy::updateBlockSelectionWithTouch(const WebCore::IntPoint point, uint32_t touch, uint32_t handlePosition)
458 {
459     m_process->send(Messages::WebPage::UpdateBlockSelectionWithTouch(point, touch, handlePosition), m_pageID);
460 }
461
462 void WebPageProxy::didReceivePositionInformation(const InteractionInformationAtPosition& info)
463 {
464     m_pageClient.positionInformationDidChange(info);
465 }
466
467 void WebPageProxy::getPositionInformation(const WebCore::IntPoint& point, InteractionInformationAtPosition& info)
468 {
469     m_process->sendSync(Messages::WebPage::GetPositionInformation(point), Messages::WebPage::GetPositionInformation::Reply(info), m_pageID);
470 }
471
472 void WebPageProxy::requestPositionInformation(const WebCore::IntPoint& point)
473 {
474     m_process->send(Messages::WebPage::RequestPositionInformation(point), m_pageID);
475 }
476
477 void WebPageProxy::startInteractionWithElementAtPosition(const WebCore::IntPoint& point)
478 {
479     m_process->send(Messages::WebPage::StartInteractionWithElementAtPosition(point), m_pageID);
480 }
481
482 void WebPageProxy::stopInteraction()
483 {
484     m_process->send(Messages::WebPage::StopInteraction(), m_pageID);
485 }
486
487 void WebPageProxy::performActionOnElement(uint32_t action)
488 {
489     m_process->send(Messages::WebPage::PerformActionOnElement(action), m_pageID);
490 }
491
492 void WebPageProxy::saveImageToLibrary(const SharedMemory::Handle& imageHandle, uint64_t imageSize)
493 {
494     RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::create(imageHandle, SharedMemory::ReadOnly);
495     RefPtr<SharedBuffer> buffer = SharedBuffer::create(static_cast<unsigned char*>(sharedMemoryBuffer->data()), imageSize);
496     m_pageClient.saveImageToLibrary(buffer);
497 }
498
499 void WebPageProxy::didUpdateBlockSelectionWithTouch(uint32_t touch, uint32_t flags, float growThreshold, float shrinkThreshold)
500 {
501     m_pageClient.didUpdateBlockSelectionWithTouch(touch, flags, growThreshold, shrinkThreshold);
502 }
503
504 void WebPageProxy::applicationWillEnterForeground()
505 {
506     m_process->send(Messages::WebPage::ApplicationWillEnterForeground(), m_pageID);
507 }
508
509 void WebPageProxy::applicationWillResignActive()
510 {
511     m_process->send(Messages::WebPage::ApplicationWillResignActive(), m_pageID);
512 }
513
514 void WebPageProxy::applicationDidBecomeActive()
515 {
516     m_process->send(Messages::WebPage::ApplicationDidBecomeActive(), m_pageID);
517 }
518
519 void WebPageProxy::notifyRevealedSelection()
520 {
521     m_pageClient.selectionDidChange();
522 }
523
524 void WebPageProxy::extendSelection(WebCore::TextGranularity granularity)
525 {
526     m_process->send(Messages::WebPage::ExtendSelection(static_cast<uint32_t>(granularity)), m_pageID);
527 }
528
529 void WebPageProxy::selectWordBackward()
530 {
531     m_process->send(Messages::WebPage::SelectWordBackward(), m_pageID);
532 }
533
534 void WebPageProxy::interpretKeyEvent(const EditorState& state, bool isCharEvent, bool& handled)
535 {
536     m_editorState = state;
537     handled = m_pageClient.interpretKeyEvent(m_keyEventQueue.first(), isCharEvent);
538 }
539
540 // Complex text input support for plug-ins.
541 void WebPageProxy::sendComplexTextInputToPlugin(uint64_t, const String&)
542 {
543     notImplemented();
544 }
545
546 void WebPageProxy::setSmartInsertDeleteEnabled(bool)
547 {
548     notImplemented();
549 }
550
551 void WebPageProxy::registerWebProcessAccessibilityToken(const IPC::DataReference& data)
552 {
553     m_pageClient.accessibilityWebProcessTokenReceived(data);
554 }    
555
556 void WebPageProxy::makeFirstResponder()
557 {
558     notImplemented();
559 }
560
561 void WebPageProxy::registerUIProcessAccessibilityTokens(const IPC::DataReference& elementToken, const IPC::DataReference& windowToken)
562 {
563     if (!isValid())
564         return;
565     
566     process().send(Messages::WebPage::RegisterUIProcessAccessibilityTokens(elementToken, windowToken), m_pageID);
567 }
568
569 void WebPageProxy::pluginFocusOrWindowFocusChanged(uint64_t, bool)
570 {
571     notImplemented();
572 }
573
574 void WebPageProxy::setPluginComplexTextInputState(uint64_t, uint64_t)
575 {
576     notImplemented();
577 }
578
579 void WebPageProxy::executeSavedCommandBySelector(const String&, bool&)
580 {
581     notImplemented();
582 }
583
584 bool WebPageProxy::shouldDelayWindowOrderingForEvent(const WebKit::WebMouseEvent&)
585 {
586     notImplemented();
587     return false;
588 }
589
590 bool WebPageProxy::acceptsFirstMouse(int, const WebKit::WebMouseEvent&)
591 {
592     notImplemented();
593     return false;
594 }
595
596 void WebPageProxy::willStartUserTriggeredZooming()
597 {
598     process().send(Messages::WebPage::WillStartUserTriggeredZooming(), m_pageID);
599 }
600
601 void WebPageProxy::potentialTapAtPosition(const WebCore::FloatPoint& position, uint64_t& requestID)
602 {
603     process().send(Messages::WebPage::PotentialTapAtPosition(requestID, position), m_pageID);
604 }
605
606 void WebPageProxy::commitPotentialTap()
607 {
608     process().send(Messages::WebPage::CommitPotentialTap(), m_pageID);
609 }
610
611 void WebPageProxy::cancelPotentialTap()
612 {
613     process().send(Messages::WebPage::CancelPotentialTap(), m_pageID);
614 }
615
616 void WebPageProxy::tapHighlightAtPosition(const WebCore::FloatPoint& position, uint64_t& requestID)
617 {
618     process().send(Messages::WebPage::TapHighlightAtPosition(requestID, position), m_pageID);
619 }
620
621 void WebPageProxy::inspectorNodeSearchMovedToPosition(const WebCore::FloatPoint& position)
622 {
623     process().send(Messages::WebPage::InspectorNodeSearchMovedToPosition(position), m_pageID);
624 }
625
626 void WebPageProxy::inspectorNodeSearchEndedAtPosition(const WebCore::FloatPoint& position)
627 {
628     process().send(Messages::WebPage::InspectorNodeSearchEndedAtPosition(position), m_pageID);
629 }
630
631 void WebPageProxy::blurAssistedNode()
632 {
633     process().send(Messages::WebPage::BlurAssistedNode(), m_pageID);
634 }
635
636 FloatSize WebPageProxy::screenSize()
637 {
638     return FloatSize(WKGetScreenSize());
639 }
640
641 FloatSize WebPageProxy::availableScreenSize()
642 {
643     return FloatSize(WKGetAvailableScreenSize());
644 }
645     
646 float WebPageProxy::textAutosizingWidth()
647 {
648     return WKGetScreenSize().width;
649 }
650
651 void WebPageProxy::dynamicViewportUpdateChangedTarget(double newScale, const WebCore::FloatPoint& newScrollPosition)
652 {
653     if (m_dynamicViewportSizeUpdateWaitingForTarget) {
654         m_dynamicViewportSizeUpdateLayerTreeTransactionID = toRemoteLayerTreeDrawingAreaProxy(drawingArea())->nextLayerTreeTransactionID();
655         m_dynamicViewportSizeUpdateWaitingForTarget = false;
656         m_pageClient.dynamicViewportUpdateChangedTarget(newScale, newScrollPosition, m_dynamicViewportSizeUpdateLayerTreeTransactionID);
657     }
658 }
659
660 void WebPageProxy::restorePageState(const WebCore::FloatRect& exposedRect, double scale)
661 {
662     m_pageClient.restorePageState(exposedRect, scale);
663 }
664
665 void WebPageProxy::restorePageCenterAndScale(const WebCore::FloatPoint& center, double scale)
666 {
667     m_pageClient.restorePageCenterAndScale(center, scale);
668 }
669
670 void WebPageProxy::didGetTapHighlightGeometries(uint64_t requestID, const WebCore::Color& color, const Vector<WebCore::FloatQuad>& highlightedQuads, const WebCore::IntSize& topLeftRadius, const WebCore::IntSize& topRightRadius, const WebCore::IntSize& bottomLeftRadius, const WebCore::IntSize& bottomRightRadius)
671 {
672     m_pageClient.didGetTapHighlightGeometries(requestID, color, highlightedQuads, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius);
673 }
674
675 void WebPageProxy::startAssistingNode(const AssistedNodeInformation& information, bool userIsInteracting, bool blurPreviousNode, IPC::MessageDecoder& decoder)
676 {
677     RefPtr<API::Object> userData;
678     WebContextUserMessageDecoder messageDecoder(userData, process());
679     if (!decoder.decode(messageDecoder))
680         return;
681
682     m_pageClient.startAssistingNode(information, userIsInteracting, blurPreviousNode, userData.get());
683 }
684
685 void WebPageProxy::stopAssistingNode()
686 {
687     m_pageClient.stopAssistingNode();
688 }
689
690 #if ENABLE(INSPECTOR)
691 void WebPageProxy::showInspectorHighlight(const WebCore::Highlight& highlight)
692 {
693     m_pageClient.showInspectorHighlight(highlight);
694 }
695
696 void WebPageProxy::hideInspectorHighlight()
697 {
698     m_pageClient.hideInspectorHighlight();
699 }
700
701 void WebPageProxy::showInspectorIndication()
702 {
703     m_pageClient.showInspectorIndication();
704 }
705
706 void WebPageProxy::hideInspectorIndication()
707 {
708     m_pageClient.hideInspectorIndication();
709 }
710
711 void WebPageProxy::enableInspectorNodeSearch()
712 {
713     m_pageClient.enableInspectorNodeSearch();
714 }
715
716 void WebPageProxy::disableInspectorNodeSearch()
717 {
718     m_pageClient.disableInspectorNodeSearch();
719 }
720 #endif
721
722 void WebPageProxy::focusNextAssistedNode(bool isForward)
723 {
724     process().send(Messages::WebPage::FocusNextAssistedNode(isForward), m_pageID);
725 }
726
727 void WebPageProxy::setAssistedNodeValue(const String& value)
728 {
729     process().send(Messages::WebPage::SetAssistedNodeValue(value), m_pageID);
730 }
731
732 void WebPageProxy::setAssistedNodeValueAsNumber(double value)
733 {
734     process().send(Messages::WebPage::SetAssistedNodeValueAsNumber(value), m_pageID);
735 }
736
737 void WebPageProxy::setAssistedNodeSelectedIndex(uint32_t index, bool allowMultipleSelection)
738 {
739     process().send(Messages::WebPage::SetAssistedNodeSelectedIndex(index, allowMultipleSelection), m_pageID);
740 }
741
742 void WebPageProxy::didPerformDictionaryLookup(const AttributedString&, const DictionaryPopupInfo&)
743 {
744     notImplemented();
745 }
746
747 void WebPageProxy::savePDFToTemporaryFolderAndOpenWithNativeApplication(const String&, const String&, const IPC::DataReference&, const String&)
748 {
749     notImplemented();
750 }
751
752 void WebPageProxy::savePDFToTemporaryFolderAndOpenWithNativeApplicationRaw(const String&, const String&, const uint8_t*, unsigned long, const String&)
753 {
754     notImplemented();
755 }
756
757 void WebPageProxy::openPDFFromTemporaryFolderWithNativeApplication(const String&)
758 {
759     notImplemented();
760 }
761
762 void WebPageProxy::setAcceleratedCompositingRootLayer(LayerOrView* rootLayer)
763 {
764     m_pageClient.setAcceleratedCompositingRootLayer(rootLayer);
765 }
766
767 void WebPageProxy::showPlaybackTargetPicker(bool hasVideo, const IntRect& elementRect)
768 {
769     m_pageClient.showPlaybackTargetPicker(hasVideo, elementRect);
770 }
771
772 void WebPageProxy::zoomToRect(FloatRect rect, double minimumScale, double maximumScale)
773 {
774     m_pageClient.zoomToRect(rect, minimumScale, maximumScale);
775 }
776
777 void WebPageProxy::commitPotentialTapFailed()
778 {
779     m_pageClient.commitPotentialTapFailed();
780 }
781
782 void WebPageProxy::didNotHandleTapAsClick(const WebCore::IntPoint& point)
783 {
784     m_uiClient->didNotHandleTapAsClick(point);
785 }
786
787 void WebPageProxy::viewportMetaTagWidthDidChange(float width)
788 {
789     m_pageClient.didChangeViewportMetaTagWidth(width);
790 }
791
792 void WebPageProxy::setUsesMinimalUI(bool usesMinimalUI)
793 {
794     m_pageClient.setUsesMinimalUI(usesMinimalUI);
795 }
796
797 void WebPageProxy::didFinishDrawingPagesToPDF(const IPC::DataReference& pdfData)
798 {
799     m_pageClient.didFinishDrawingPagesToPDF(pdfData);
800 }
801
802 void WebPageProxy::contentSizeCategoryDidChange(const String& contentSizeCategory)
803 {
804     process().send(Messages::WebPage::ContentSizeCategoryDidChange(contentSizeCategory), m_pageID);
805 }
806
807 #if USE(QUICK_LOOK)
808     
809 void WebPageProxy::didStartLoadForQuickLookDocumentInMainFrame(const String& fileName, const String& uti)
810 {
811     // Ensure that fileName isn't really a path name
812     static_assert(notFound + 1 == 0, "The following line assumes WTF::notFound equals -1");
813     m_loaderClient->didStartLoadForQuickLookDocumentInMainFrame(fileName.substring(fileName.reverseFind('/') + 1), uti);
814 }
815
816 void WebPageProxy::didFinishLoadForQuickLookDocumentInMainFrame(const QuickLookDocumentData& data)
817 {
818     m_loaderClient->didFinishLoadForQuickLookDocumentInMainFrame(data);
819 }
820 #endif
821
822 } // namespace WebKit
823
824 #endif // PLATFORM(IOS)