[iOS WK2] Turn off position:fixed behavior when the keyboard is up
[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::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)
255 {
256     m_dynamicViewportSizeUpdateWaitingForTarget = true;
257     m_dynamicViewportSizeUpdateWaitingForLayerTreeCommit = true;
258     m_process->send(Messages::WebPage::DynamicViewportSizeUpdate(minimumLayoutSize, minimumLayoutSizeForMinimalUI, maximumUnobscuredSize, targetExposedContentRect, targetUnobscuredRect, targetUnobscuredRectInScrollViewCoordinates, targetScale, deviceOrientation), m_pageID);
259 }
260
261 void WebPageProxy::synchronizeDynamicViewportUpdate()
262 {
263     if (m_dynamicViewportSizeUpdateWaitingForTarget) {
264         // We do not want the UIProcess to finish animated resize with the old content size, scale, etc.
265         // If that happens, the UIProcess would start pushing new VisibleContentRectUpdateInfo to the WebProcess with
266         // invalid informations.
267         //
268         // Ideally, the animated resize should just be transactional, and the UIProcess would remain in the "resize" state
269         // until both DynamicViewportUpdateChangedTarget and the associated commitLayerTree are finished.
270         // The tricky part with such implementation is if a second animated resize starts before the end of the previous one.
271         // In that case, the values used for the target state needs to be computed from the output of the previous animated resize.
272         //
273         // The following is a workaround to have the UIProcess in a consistent state.
274         // Instead of handling nested resize, we block the UIProcess until the animated resize finishes.
275         double newScale;
276         FloatPoint newScrollPosition;
277         uint64_t nextValidLayerTreeTransactionID;
278         if (m_process->sendSync(Messages::WebPage::SynchronizeDynamicViewportUpdate(), Messages::WebPage::SynchronizeDynamicViewportUpdate::Reply(newScale, newScrollPosition, nextValidLayerTreeTransactionID), m_pageID, std::chrono::seconds(2))) {
279             m_dynamicViewportSizeUpdateWaitingForTarget = false;
280             m_dynamicViewportSizeUpdateLayerTreeTransactionID = nextValidLayerTreeTransactionID;
281             m_pageClient.dynamicViewportUpdateChangedTarget(newScale, newScrollPosition, nextValidLayerTreeTransactionID);
282         }
283
284     }
285
286     // If m_dynamicViewportSizeUpdateWaitingForTarget is false, we are waiting for the next valid frame with the hope it is the one for the new target.
287     // If m_dynamicViewportSizeUpdateWaitingForTarget is still true, this is a desesperate attempt to get the valid frame before finishing the animation.
288     if (m_dynamicViewportSizeUpdateWaitingForLayerTreeCommit)
289         m_process->connection()->waitForAndDispatchImmediately<Messages::RemoteLayerTreeDrawingAreaProxy::CommitLayerTree>(m_pageID, std::chrono::seconds(1), IPC::InterruptWaitingIfSyncMessageArrives);
290
291     m_dynamicViewportSizeUpdateWaitingForTarget = false;
292     m_dynamicViewportSizeUpdateWaitingForLayerTreeCommit = false;
293 }
294
295 void WebPageProxy::setViewportConfigurationMinimumLayoutSize(const WebCore::FloatSize& size)
296 {
297     m_process->send(Messages::WebPage::SetViewportConfigurationMinimumLayoutSize(size), m_pageID);
298 }
299
300 void WebPageProxy::setViewportConfigurationMinimumLayoutSizeForMinimalUI(const WebCore::FloatSize& size)
301 {
302     m_process->send(Messages::WebPage::SetViewportConfigurationMinimumLayoutSizeForMinimalUI(size), m_pageID);
303 }
304
305 void WebPageProxy::setMaximumUnobscuredSize(const WebCore::FloatSize& size)
306 {
307     m_process->send(Messages::WebPage::SetMaximumUnobscuredSize(size), m_pageID);
308 }
309
310 void WebPageProxy::setDeviceOrientation(int32_t deviceOrientation)
311 {
312     if (deviceOrientation != m_deviceOrientation) {
313         m_deviceOrientation = deviceOrientation;
314         if (isValid())
315             m_process->send(Messages::WebPage::SetDeviceOrientation(deviceOrientation), m_pageID);
316     }
317 }
318
319 void WebPageProxy::didCommitLayerTree(const WebKit::RemoteLayerTreeTransaction& layerTreeTransaction)
320 {
321     m_pageExtendedBackgroundColor = layerTreeTransaction.pageExtendedBackgroundColor();
322
323     if (!m_dynamicViewportSizeUpdateWaitingForTarget && m_dynamicViewportSizeUpdateWaitingForLayerTreeCommit) {
324         if (layerTreeTransaction.transactionID() >= m_dynamicViewportSizeUpdateLayerTreeTransactionID)
325             m_dynamicViewportSizeUpdateWaitingForLayerTreeCommit = false;
326     }
327
328     m_pageClient.didCommitLayerTree(layerTreeTransaction);
329 }
330
331 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)
332 {
333     if (!isValid()) {
334         callbackFunction(WebCore::IntPoint(), 0, 0, 0, CallbackBase::Error::Unknown);
335         return;
336     }
337
338     uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), std::make_unique<ProcessThrottler::BackgroundActivityToken>(m_process->throttler()));
339     m_process->send(Messages::WebPage::SelectWithGesture(point, (uint32_t)granularity, gestureType, gestureState, callbackID), m_pageID);
340 }
341
342 void WebPageProxy::updateSelectionWithTouches(const WebCore::IntPoint point, uint32_t touches, bool baseIsStart, std::function<void (const WebCore::IntPoint&, uint32_t, CallbackBase::Error)> callbackFunction)
343 {
344     if (!isValid()) {
345         callbackFunction(WebCore::IntPoint(), 0, CallbackBase::Error::Unknown);
346         return;
347     }
348
349     uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), std::make_unique<ProcessThrottler::BackgroundActivityToken>(m_process->throttler()));
350     m_process->send(Messages::WebPage::UpdateSelectionWithTouches(point, touches, baseIsStart, callbackID), m_pageID);
351 }
352     
353 void WebPageProxy::replaceDictatedText(const String& oldText, const String& newText)
354 {
355     m_process->send(Messages::WebPage::ReplaceDictatedText(oldText, newText), m_pageID);
356 }
357
358 void WebPageProxy::replaceSelectedText(const String& oldText, const String& newText)
359 {
360     m_process->send(Messages::WebPage::ReplaceSelectedText(oldText, newText), m_pageID);
361 }
362
363 void WebPageProxy::requestAutocorrectionData(const String& textForAutocorrection, std::function<void (const Vector<WebCore::FloatRect>&, const String&, double, uint64_t, CallbackBase::Error)> callbackFunction)
364 {
365     if (!isValid()) {
366         callbackFunction(Vector<WebCore::FloatRect>(), String(), 0, 0, CallbackBase::Error::Unknown);
367         return;
368     }
369
370     uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), std::make_unique<ProcessThrottler::BackgroundActivityToken>(m_process->throttler()));
371     m_process->send(Messages::WebPage::RequestAutocorrectionData(textForAutocorrection, callbackID), m_pageID);
372 }
373
374 void WebPageProxy::applyAutocorrection(const String& correction, const String& originalText, std::function<void (const String&, CallbackBase::Error)> callbackFunction)
375 {
376     if (!isValid()) {
377         callbackFunction(String(), CallbackBase::Error::Unknown);
378         return;
379     }
380
381     uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), std::make_unique<ProcessThrottler::BackgroundActivityToken>(m_process->throttler()));
382     m_process->send(Messages::WebPage::ApplyAutocorrection(correction, originalText, callbackID), m_pageID);
383 }
384
385 void WebPageProxy::executeEditCommand(const String& commandName, std::function<void (CallbackBase::Error)> callbackFunction)
386 {
387     if (!isValid()) {
388         callbackFunction(CallbackBase::Error::Unknown);
389         return;
390     }
391     
392     uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), std::make_unique<ProcessThrottler::BackgroundActivityToken>(m_process->throttler()));
393     m_process->send(Messages::WebPage::ExecuteEditCommandWithCallback(commandName, callbackID), m_pageID);
394 }
395
396 bool WebPageProxy::applyAutocorrection(const String& correction, const String& originalText)
397 {
398     bool autocorrectionApplied = false;
399     m_process->sendSync(Messages::WebPage::SyncApplyAutocorrection(correction, originalText), Messages::WebPage::SyncApplyAutocorrection::Reply(autocorrectionApplied), m_pageID);
400     return autocorrectionApplied;
401 }
402
403 void WebPageProxy::requestDictationContext(std::function<void (const String&, const String&, const String&, CallbackBase::Error)> callbackFunction)
404 {
405     if (!isValid()) {
406         callbackFunction(String(), String(), String(), CallbackBase::Error::Unknown);
407         return;
408     }
409
410     uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), std::make_unique<ProcessThrottler::BackgroundActivityToken>(m_process->throttler()));
411     m_process->send(Messages::WebPage::RequestDictationContext(callbackID), m_pageID);
412 }
413
414 void WebPageProxy::requestAutocorrectionContext(std::function<void (const String&, const String&, const String&, const String&, uint64_t, uint64_t, CallbackBase::Error)> callbackFunction)
415 {
416     if (!isValid()) {
417         callbackFunction(String(), String(), String(), String(), 0, 0, CallbackBase::Error::Unknown);
418         return;
419     }
420
421     uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), std::make_unique<ProcessThrottler::BackgroundActivityToken>(m_process->throttler()));
422     m_process->send(Messages::WebPage::RequestAutocorrectionContext(callbackID), m_pageID);
423 }
424
425 void WebPageProxy::getAutocorrectionContext(String& beforeContext, String& markedText, String& selectedText, String& afterContext, uint64_t& location, uint64_t& length)
426 {
427     m_process->sendSync(Messages::WebPage::GetAutocorrectionContext(), Messages::WebPage::GetAutocorrectionContext::Reply(beforeContext, markedText, selectedText, afterContext, location, length), m_pageID);
428 }
429
430 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)
431 {
432     if (!isValid()) {
433         callbackFunction(WebCore::IntPoint(), 0, 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::SelectWithTwoTouches(from, to, gestureType, gestureState, callbackID), m_pageID);
439 }
440
441 void WebPageProxy::updateBlockSelectionWithTouch(const WebCore::IntPoint point, uint32_t touch, uint32_t handlePosition)
442 {
443     m_process->send(Messages::WebPage::UpdateBlockSelectionWithTouch(point, touch, handlePosition), m_pageID);
444 }
445
446 void WebPageProxy::didReceivePositionInformation(const InteractionInformationAtPosition& info)
447 {
448     m_pageClient.positionInformationDidChange(info);
449 }
450
451 void WebPageProxy::getPositionInformation(const WebCore::IntPoint& point, InteractionInformationAtPosition& info)
452 {
453     m_process->sendSync(Messages::WebPage::GetPositionInformation(point), Messages::WebPage::GetPositionInformation::Reply(info), m_pageID);
454 }
455
456 void WebPageProxy::requestPositionInformation(const WebCore::IntPoint& point)
457 {
458     m_process->send(Messages::WebPage::RequestPositionInformation(point), m_pageID);
459 }
460
461 void WebPageProxy::startInteractionWithElementAtPosition(const WebCore::IntPoint& point)
462 {
463     m_process->send(Messages::WebPage::StartInteractionWithElementAtPosition(point), m_pageID);
464 }
465
466 void WebPageProxy::stopInteraction()
467 {
468     m_process->send(Messages::WebPage::StopInteraction(), m_pageID);
469 }
470
471 void WebPageProxy::performActionOnElement(uint32_t action)
472 {
473     m_process->send(Messages::WebPage::PerformActionOnElement(action), m_pageID);
474 }
475
476 void WebPageProxy::saveImageToLibrary(const SharedMemory::Handle& imageHandle, uint64_t imageSize)
477 {
478     RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::create(imageHandle, SharedMemory::ReadOnly);
479     RefPtr<SharedBuffer> buffer = SharedBuffer::create(static_cast<unsigned char*>(sharedMemoryBuffer->data()), imageSize);
480     m_pageClient.saveImageToLibrary(buffer);
481 }
482
483 void WebPageProxy::didUpdateBlockSelectionWithTouch(uint32_t touch, uint32_t flags, float growThreshold, float shrinkThreshold)
484 {
485     m_pageClient.didUpdateBlockSelectionWithTouch(touch, flags, growThreshold, shrinkThreshold);
486 }
487
488 void WebPageProxy::applicationWillEnterForeground()
489 {
490     m_process->send(Messages::WebPage::ApplicationWillEnterForeground(), m_pageID);
491 }
492
493 void WebPageProxy::applicationWillResignActive()
494 {
495     m_process->send(Messages::WebPage::ApplicationWillResignActive(), m_pageID);
496 }
497
498 void WebPageProxy::applicationDidBecomeActive()
499 {
500     m_process->send(Messages::WebPage::ApplicationDidBecomeActive(), m_pageID);
501 }
502
503 void WebPageProxy::notifyRevealedSelection()
504 {
505     m_pageClient.selectionDidChange();
506 }
507
508 void WebPageProxy::extendSelection(WebCore::TextGranularity granularity)
509 {
510     m_process->send(Messages::WebPage::ExtendSelection(static_cast<uint32_t>(granularity)), m_pageID);
511 }
512
513 void WebPageProxy::selectWordBackward()
514 {
515     m_process->send(Messages::WebPage::SelectWordBackward(), m_pageID);
516 }
517
518 void WebPageProxy::interpretKeyEvent(const EditorState& state, bool isCharEvent, bool& handled)
519 {
520     m_editorState = state;
521     handled = m_pageClient.interpretKeyEvent(m_keyEventQueue.first(), isCharEvent);
522 }
523
524 // Complex text input support for plug-ins.
525 void WebPageProxy::sendComplexTextInputToPlugin(uint64_t, const String&)
526 {
527     notImplemented();
528 }
529
530 void WebPageProxy::setSmartInsertDeleteEnabled(bool)
531 {
532     notImplemented();
533 }
534
535 void WebPageProxy::registerWebProcessAccessibilityToken(const IPC::DataReference& data)
536 {
537     m_pageClient.accessibilityWebProcessTokenReceived(data);
538 }    
539
540 void WebPageProxy::makeFirstResponder()
541 {
542     notImplemented();
543 }
544
545 void WebPageProxy::registerUIProcessAccessibilityTokens(const IPC::DataReference& elementToken, const IPC::DataReference& windowToken)
546 {
547     if (!isValid())
548         return;
549     
550     process().send(Messages::WebPage::RegisterUIProcessAccessibilityTokens(elementToken, windowToken), m_pageID);
551 }
552
553 void WebPageProxy::pluginFocusOrWindowFocusChanged(uint64_t, bool)
554 {
555     notImplemented();
556 }
557
558 void WebPageProxy::setPluginComplexTextInputState(uint64_t, uint64_t)
559 {
560     notImplemented();
561 }
562
563 void WebPageProxy::executeSavedCommandBySelector(const String&, bool&)
564 {
565     notImplemented();
566 }
567
568 bool WebPageProxy::shouldDelayWindowOrderingForEvent(const WebKit::WebMouseEvent&)
569 {
570     notImplemented();
571     return false;
572 }
573
574 bool WebPageProxy::acceptsFirstMouse(int, const WebKit::WebMouseEvent&)
575 {
576     notImplemented();
577     return false;
578 }
579
580 void WebPageProxy::willStartUserTriggeredZooming()
581 {
582     process().send(Messages::WebPage::WillStartUserTriggeredZooming(), m_pageID);
583 }
584
585 void WebPageProxy::potentialTapAtPosition(const WebCore::FloatPoint& position, uint64_t& requestID)
586 {
587     process().send(Messages::WebPage::PotentialTapAtPosition(requestID, position), m_pageID);
588 }
589
590 void WebPageProxy::commitPotentialTap()
591 {
592     process().send(Messages::WebPage::CommitPotentialTap(), m_pageID);
593 }
594
595 void WebPageProxy::cancelPotentialTap()
596 {
597     process().send(Messages::WebPage::CancelPotentialTap(), m_pageID);
598 }
599
600 void WebPageProxy::tapHighlightAtPosition(const WebCore::FloatPoint& position, uint64_t& requestID)
601 {
602     process().send(Messages::WebPage::TapHighlightAtPosition(requestID, position), m_pageID);
603 }
604
605 void WebPageProxy::inspectorNodeSearchMovedToPosition(const WebCore::FloatPoint& position)
606 {
607     process().send(Messages::WebPage::InspectorNodeSearchMovedToPosition(position), m_pageID);
608 }
609
610 void WebPageProxy::inspectorNodeSearchEndedAtPosition(const WebCore::FloatPoint& position)
611 {
612     process().send(Messages::WebPage::InspectorNodeSearchEndedAtPosition(position), m_pageID);
613 }
614
615 void WebPageProxy::blurAssistedNode()
616 {
617     process().send(Messages::WebPage::BlurAssistedNode(), m_pageID);
618 }
619
620 FloatSize WebPageProxy::screenSize()
621 {
622     return FloatSize(WKGetScreenSize());
623 }
624
625 FloatSize WebPageProxy::availableScreenSize()
626 {
627     return FloatSize(WKGetAvailableScreenSize());
628 }
629     
630 float WebPageProxy::textAutosizingWidth()
631 {
632     return WKGetScreenSize().width;
633 }
634
635 void WebPageProxy::dynamicViewportUpdateChangedTarget(double newScale, const WebCore::FloatPoint& newScrollPosition)
636 {
637     if (m_dynamicViewportSizeUpdateWaitingForTarget) {
638         m_dynamicViewportSizeUpdateLayerTreeTransactionID = toRemoteLayerTreeDrawingAreaProxy(drawingArea())->nextLayerTreeTransactionID();
639         m_dynamicViewportSizeUpdateWaitingForTarget = false;
640         m_pageClient.dynamicViewportUpdateChangedTarget(newScale, newScrollPosition, m_dynamicViewportSizeUpdateLayerTreeTransactionID);
641     }
642 }
643
644 void WebPageProxy::restorePageState(const WebCore::FloatRect& exposedRect, double scale)
645 {
646     m_pageClient.restorePageState(exposedRect, scale);
647 }
648
649 void WebPageProxy::restorePageCenterAndScale(const WebCore::FloatPoint& center, double scale)
650 {
651     m_pageClient.restorePageCenterAndScale(center, scale);
652 }
653
654 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)
655 {
656     m_pageClient.didGetTapHighlightGeometries(requestID, color, highlightedQuads, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius);
657 }
658
659 void WebPageProxy::startAssistingNode(const AssistedNodeInformation& information, bool userIsInteracting, bool blurPreviousNode, IPC::MessageDecoder& decoder)
660 {
661     RefPtr<API::Object> userData;
662     WebContextUserMessageDecoder messageDecoder(userData, process());
663     if (!decoder.decode(messageDecoder))
664         return;
665
666     m_pageClient.startAssistingNode(information, userIsInteracting, blurPreviousNode, userData.get());
667 }
668
669 void WebPageProxy::stopAssistingNode()
670 {
671     m_pageClient.stopAssistingNode();
672 }
673
674 #if ENABLE(INSPECTOR)
675 void WebPageProxy::showInspectorHighlight(const WebCore::Highlight& highlight)
676 {
677     m_pageClient.showInspectorHighlight(highlight);
678 }
679
680 void WebPageProxy::hideInspectorHighlight()
681 {
682     m_pageClient.hideInspectorHighlight();
683 }
684
685 void WebPageProxy::showInspectorIndication()
686 {
687     m_pageClient.showInspectorIndication();
688 }
689
690 void WebPageProxy::hideInspectorIndication()
691 {
692     m_pageClient.hideInspectorIndication();
693 }
694
695 void WebPageProxy::enableInspectorNodeSearch()
696 {
697     m_pageClient.enableInspectorNodeSearch();
698 }
699
700 void WebPageProxy::disableInspectorNodeSearch()
701 {
702     m_pageClient.disableInspectorNodeSearch();
703 }
704 #endif
705
706 void WebPageProxy::focusNextAssistedNode(bool isForward)
707 {
708     process().send(Messages::WebPage::FocusNextAssistedNode(isForward), m_pageID);
709 }
710
711 void WebPageProxy::setAssistedNodeValue(const String& value)
712 {
713     process().send(Messages::WebPage::SetAssistedNodeValue(value), m_pageID);
714 }
715
716 void WebPageProxy::setAssistedNodeValueAsNumber(double value)
717 {
718     process().send(Messages::WebPage::SetAssistedNodeValueAsNumber(value), m_pageID);
719 }
720
721 void WebPageProxy::setAssistedNodeSelectedIndex(uint32_t index, bool allowMultipleSelection)
722 {
723     process().send(Messages::WebPage::SetAssistedNodeSelectedIndex(index, allowMultipleSelection), m_pageID);
724 }
725
726 void WebPageProxy::didPerformDictionaryLookup(const AttributedString&, const DictionaryPopupInfo&)
727 {
728     notImplemented();
729 }
730
731 void WebPageProxy::savePDFToTemporaryFolderAndOpenWithNativeApplication(const String&, const String&, const IPC::DataReference&, const String&)
732 {
733     notImplemented();
734 }
735
736 void WebPageProxy::savePDFToTemporaryFolderAndOpenWithNativeApplicationRaw(const String&, const String&, const uint8_t*, unsigned long, const String&)
737 {
738     notImplemented();
739 }
740
741 void WebPageProxy::openPDFFromTemporaryFolderWithNativeApplication(const String&)
742 {
743     notImplemented();
744 }
745
746 void WebPageProxy::setAcceleratedCompositingRootLayer(LayerOrView* rootLayer)
747 {
748     m_pageClient.setAcceleratedCompositingRootLayer(rootLayer);
749 }
750
751 void WebPageProxy::showPlaybackTargetPicker(bool hasVideo, const IntRect& elementRect)
752 {
753     m_pageClient.showPlaybackTargetPicker(hasVideo, elementRect);
754 }
755
756 void WebPageProxy::zoomToRect(FloatRect rect, double minimumScale, double maximumScale)
757 {
758     m_pageClient.zoomToRect(rect, minimumScale, maximumScale);
759 }
760
761 void WebPageProxy::commitPotentialTapFailed()
762 {
763     m_pageClient.commitPotentialTapFailed();
764 }
765
766 void WebPageProxy::didNotHandleTapAsClick(const WebCore::IntPoint& point)
767 {
768     m_uiClient->didNotHandleTapAsClick(point);
769 }
770
771 void WebPageProxy::viewportMetaTagWidthDidChange(float width)
772 {
773     m_pageClient.didChangeViewportMetaTagWidth(width);
774 }
775
776 void WebPageProxy::setUsesMinimalUI(bool usesMinimalUI)
777 {
778     m_pageClient.setUsesMinimalUI(usesMinimalUI);
779 }
780
781 void WebPageProxy::didFinishDrawingPagesToPDF(const IPC::DataReference& pdfData)
782 {
783     m_pageClient.didFinishDrawingPagesToPDF(pdfData);
784 }
785
786 void WebPageProxy::contentSizeCategoryDidChange(const String& contentSizeCategory)
787 {
788     process().send(Messages::WebPage::ContentSizeCategoryDidChange(contentSizeCategory), m_pageID);
789 }
790
791 #if USE(QUICK_LOOK)
792     
793 void WebPageProxy::didStartLoadForQuickLookDocumentInMainFrame(const String& fileName, const String& uti)
794 {
795     // Ensure that fileName isn't really a path name
796     static_assert(notFound + 1 == 0, "The following line assumes WTF::notFound equals -1");
797     m_loaderClient->didStartLoadForQuickLookDocumentInMainFrame(fileName.substring(fileName.reverseFind('/') + 1), uti);
798 }
799
800 void WebPageProxy::didFinishLoadForQuickLookDocumentInMainFrame(const QuickLookDocumentData& data)
801 {
802     m_loaderClient->didFinishLoadForQuickLookDocumentInMainFrame(data);
803 }
804 #endif
805
806 } // namespace WebKit
807
808 #endif // PLATFORM(IOS)