| /* |
| * Copyright (C) 2015 Apple Inc. All rights reserved. |
| * |
| * Redistribution and use in source and binary forms, with or without |
| * modification, are permitted provided that the following conditions |
| * are met: |
| * 1. Redistributions of source code must retain the above copyright |
| * notice, this list of conditions and the following disclaimer. |
| * 2. Redistributions in binary form must reproduce the above copyright |
| * notice, this list of conditions and the following disclaimer in the |
| * documentation and/or other materials provided with the distribution. |
| * |
| * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| * THE POSSIBILITY OF SUCH DAMAGE. |
| */ |
| |
| #include "config.h" |
| #include "UIScriptController.h" |
| |
| #include "JSUIScriptController.h" |
| #include "UIScriptContext.h" |
| #include <JavaScriptCore/JSValueRef.h> |
| #include <JavaScriptCore/OpaqueJSString.h> |
| |
| namespace WTR { |
| |
| DeviceOrientation* toDeviceOrientation(JSContextRef context, JSValueRef value) |
| { |
| static DeviceOrientation values[] = { |
| DeviceOrientation::Portrait, |
| DeviceOrientation::PortraitUpsideDown, |
| DeviceOrientation::LandscapeLeft, |
| DeviceOrientation::LandscapeRight |
| }; |
| |
| auto option = adopt(JSValueToStringCopy(context, value, nullptr)); |
| if (option.get()->string() == "portrait") |
| return &values[0]; |
| |
| if (option.get()->string() == "portrait-upsidedown") |
| return &values[1]; |
| |
| if (option.get()->string() == "landscape-left") |
| return &values[2]; |
| |
| if (option.get()->string() == "landscape-right") |
| return &values[3]; |
| |
| return nullptr; |
| } |
| |
| UIScriptController::UIScriptController(UIScriptContext& context) |
| : m_context(&context) |
| { |
| } |
| |
| #if !PLATFORM(IOS_FAMILY) |
| void UIScriptController::checkForOutstandingCallbacks() |
| { |
| } |
| #endif |
| |
| void UIScriptController::contextDestroyed() |
| { |
| m_context = nullptr; |
| } |
| |
| void UIScriptController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception) |
| { |
| setProperty(context, windowObject, "uiController", this, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception); |
| } |
| |
| JSClassRef UIScriptController::wrapperClass() |
| { |
| return JSUIScriptController::uIScriptControllerClass(); |
| } |
| |
| #if !PLATFORM(COCOA) |
| void UIScriptController::doAsyncTask(JSValueRef) |
| { |
| } |
| |
| void simulateAccessibilitySettingsChangeNotification(JSValueRef) |
| { |
| } |
| |
| void UIScriptController::doAfterPresentationUpdate(JSValueRef) |
| { |
| } |
| |
| void UIScriptController::doAfterNextStablePresentationUpdate(JSValueRef) |
| { |
| } |
| |
| void UIScriptController::doAfterVisibleContentRectUpdate(JSValueRef) |
| { |
| } |
| #endif |
| |
| void UIScriptController::setDidStartFormControlInteractionCallback(JSValueRef callback) |
| { |
| m_context->registerCallback(callback, CallbackTypeDidStartFormControlInteraction); |
| platformSetDidStartFormControlInteractionCallback(); |
| } |
| |
| JSValueRef UIScriptController::didStartFormControlInteractionCallback() const |
| { |
| return m_context->callbackWithID(CallbackTypeDidStartFormControlInteraction); |
| } |
| |
| void UIScriptController::setDidEndFormControlInteractionCallback(JSValueRef callback) |
| { |
| m_context->registerCallback(callback, CallbackTypeDidEndFormControlInteraction); |
| platformSetDidEndFormControlInteractionCallback(); |
| } |
| |
| JSValueRef UIScriptController::didEndFormControlInteractionCallback() const |
| { |
| return m_context->callbackWithID(CallbackTypeDidEndFormControlInteraction); |
| } |
| |
| void UIScriptController::setDidShowForcePressPreviewCallback(JSValueRef callback) |
| { |
| m_context->registerCallback(callback, CallbackTypeDidShowForcePressPreview); |
| platformSetDidShowForcePressPreviewCallback(); |
| } |
| |
| JSValueRef UIScriptController::didShowForcePressPreviewCallback() const |
| { |
| return m_context->callbackWithID(CallbackTypeDidShowForcePressPreview); |
| } |
| |
| void UIScriptController::setDidDismissForcePressPreviewCallback(JSValueRef callback) |
| { |
| m_context->registerCallback(callback, CallbackTypeDidDismissForcePressPreview); |
| platformSetDidDismissForcePressPreviewCallback(); |
| } |
| |
| JSValueRef UIScriptController::didDismissForcePressPreviewCallback() const |
| { |
| return m_context->callbackWithID(CallbackTypeDidDismissForcePressPreview); |
| } |
| |
| void UIScriptController::setWillBeginZoomingCallback(JSValueRef callback) |
| { |
| m_context->registerCallback(callback, CallbackTypeWillBeginZooming); |
| platformSetWillBeginZoomingCallback(); |
| } |
| |
| JSValueRef UIScriptController::willBeginZoomingCallback() const |
| { |
| return m_context->callbackWithID(CallbackTypeWillBeginZooming); |
| } |
| |
| void UIScriptController::setDidEndZoomingCallback(JSValueRef callback) |
| { |
| m_context->registerCallback(callback, CallbackTypeDidEndZooming); |
| platformSetDidEndZoomingCallback(); |
| } |
| |
| JSValueRef UIScriptController::didEndZoomingCallback() const |
| { |
| return m_context->callbackWithID(CallbackTypeDidEndZooming); |
| } |
| |
| void UIScriptController::setDidEndScrollingCallback(JSValueRef callback) |
| { |
| m_context->registerCallback(callback, CallbackTypeDidEndScrolling); |
| platformSetDidEndScrollingCallback(); |
| } |
| |
| JSValueRef UIScriptController::didEndScrollingCallback() const |
| { |
| return m_context->callbackWithID(CallbackTypeDidEndScrolling); |
| } |
| |
| void UIScriptController::setDidShowKeyboardCallback(JSValueRef callback) |
| { |
| m_context->registerCallback(callback, CallbackTypeDidShowKeyboard); |
| platformSetDidShowKeyboardCallback(); |
| } |
| |
| JSValueRef UIScriptController::didShowKeyboardCallback() const |
| { |
| return m_context->callbackWithID(CallbackTypeDidShowKeyboard); |
| } |
| |
| void UIScriptController::setDidHideKeyboardCallback(JSValueRef callback) |
| { |
| m_context->registerCallback(callback, CallbackTypeDidHideKeyboard); |
| platformSetDidHideKeyboardCallback(); |
| } |
| |
| JSValueRef UIScriptController::didHideKeyboardCallback() const |
| { |
| return m_context->callbackWithID(CallbackTypeDidHideKeyboard); |
| } |
| |
| void UIScriptController::setDidShowMenuCallback(JSValueRef callback) |
| { |
| m_context->registerCallback(callback, CallbackTypeDidShowMenu); |
| platformSetDidShowMenuCallback(); |
| } |
| |
| JSValueRef UIScriptController::didShowMenuCallback() const |
| { |
| return m_context->callbackWithID(CallbackTypeDidShowMenu); |
| } |
| |
| void UIScriptController::setDidHideMenuCallback(JSValueRef callback) |
| { |
| m_context->registerCallback(callback, CallbackTypeDidHideMenu); |
| platformSetDidHideMenuCallback(); |
| } |
| |
| JSValueRef UIScriptController::didHideMenuCallback() const |
| { |
| return m_context->callbackWithID(CallbackTypeDidHideMenu); |
| } |
| |
| void UIScriptController::setWillPresentPopoverCallback(JSValueRef callback) |
| { |
| m_context->registerCallback(callback, CallbackTypeWillPresentPopover); |
| platformSetWillPresentPopoverCallback(); |
| } |
| |
| JSValueRef UIScriptController::willPresentPopoverCallback() const |
| { |
| return m_context->callbackWithID(CallbackTypeWillPresentPopover); |
| } |
| |
| void UIScriptController::setDidDismissPopoverCallback(JSValueRef callback) |
| { |
| m_context->registerCallback(callback, CallbackTypeDidDismissPopover); |
| platformSetDidDismissPopoverCallback(); |
| } |
| |
| JSValueRef UIScriptController::didDismissPopoverCallback() const |
| { |
| return m_context->callbackWithID(CallbackTypeDidDismissPopover); |
| } |
| |
| #if !PLATFORM(COCOA) |
| |
| void UIScriptController::zoomToScale(double, JSValueRef) |
| { |
| } |
| |
| void UIScriptController::setViewScale(double) |
| { |
| } |
| |
| void UIScriptController::setMinimumEffectiveWidth(double) |
| { |
| } |
| |
| void UIScriptController::setAllowsViewportShrinkToFit(bool) |
| { |
| } |
| |
| void UIScriptController::resignFirstResponder() |
| { |
| } |
| |
| void UIScriptController::simulateAccessibilitySettingsChangeNotification(JSValueRef) |
| { |
| } |
| |
| JSObjectRef UIScriptController::contentsOfUserInterfaceItem(JSStringRef interfaceItem) const |
| { |
| return nullptr; |
| } |
| |
| void UIScriptController::setDefaultCalendarType(JSStringRef calendarIdentifier) |
| { |
| } |
| |
| JSObjectRef UIScriptController::calendarType() const |
| { |
| return nullptr; |
| } |
| |
| void UIScriptController::toggleCapsLock(JSValueRef) |
| { |
| } |
| |
| #endif // !PLATFORM(COCOA) |
| |
| void UIScriptController::playBackEventStream(JSStringRef stream, JSValueRef callback) |
| { |
| platformPlayBackEventStream(stream, callback); |
| } |
| |
| #if !PLATFORM(IOS_FAMILY) |
| void UIScriptController::touchDownAtPoint(long x, long y, long touchCount, JSValueRef) |
| { |
| } |
| |
| void UIScriptController::liftUpAtPoint(long x, long y, long touchCount, JSValueRef) |
| { |
| } |
| |
| void UIScriptController::singleTapAtPoint(long x, long y, JSValueRef) |
| { |
| } |
| |
| void UIScriptController::singleTapAtPointWithModifiers(long x, long y, JSValueRef modifierArray, JSValueRef callback) |
| { |
| } |
| |
| void UIScriptController::doubleTapAtPoint(long x, long y, JSValueRef) |
| { |
| } |
| |
| void UIScriptController::dragFromPointToPoint(long startX, long startY, long endX, long endY, double durationSeconds, JSValueRef callback) |
| { |
| } |
| |
| void UIScriptController::longPressAtPoint(long x, long y, JSValueRef) |
| { |
| } |
| |
| void UIScriptController::stylusDownAtPoint(long x, long y, float azimuthAngle, float altitudeAngle, float pressure, JSValueRef callback) |
| { |
| } |
| |
| void UIScriptController::stylusMoveToPoint(long x, long y, float azimuthAngle, float altitudeAngle, float pressure, JSValueRef callback) |
| { |
| } |
| |
| void UIScriptController::stylusUpAtPoint(long x, long y, JSValueRef callback) |
| { |
| } |
| |
| void UIScriptController::stylusTapAtPoint(long x, long y, float azimuthAngle, float altitudeAngle, float pressure, JSValueRef callback) |
| { |
| } |
| |
| void UIScriptController::stylusTapAtPointWithModifiers(long x, long y, float azimuthAngle, float altitudeAngle, float pressure, JSValueRef modifierArray, JSValueRef callback) |
| { |
| } |
| |
| void UIScriptController::sendEventStream(JSStringRef eventsJSON, JSValueRef callback) |
| { |
| } |
| |
| void UIScriptController::enterText(JSStringRef) |
| { |
| } |
| |
| void UIScriptController::typeCharacterUsingHardwareKeyboard(JSStringRef, JSValueRef) |
| { |
| } |
| |
| void UIScriptController::keyDown(JSStringRef, JSValueRef) |
| { |
| } |
| |
| void UIScriptController::dismissFormAccessoryView() |
| { |
| } |
| |
| void UIScriptController::dismissFilePicker(JSValueRef) |
| { |
| } |
| |
| void UIScriptController::setTimePickerValue(long, long) |
| { |
| } |
| |
| void UIScriptController::selectFormAccessoryPickerRow(long) |
| { |
| } |
| |
| JSRetainPtr<JSStringRef> UIScriptController::textContentType() const |
| { |
| return nullptr; |
| } |
| |
| JSRetainPtr<JSStringRef> UIScriptController::selectFormPopoverTitle() const |
| { |
| return nullptr; |
| } |
| |
| JSRetainPtr<JSStringRef> UIScriptController::formInputLabel() const |
| { |
| return nullptr; |
| } |
| |
| bool UIScriptController::isPresentingModally() const |
| { |
| return false; |
| } |
| |
| double UIScriptController::contentOffsetX() const |
| { |
| return 0; |
| } |
| |
| double UIScriptController::contentOffsetY() const |
| { |
| return 0; |
| } |
| |
| bool UIScriptController::scrollUpdatesDisabled() const |
| { |
| return false; |
| } |
| |
| void UIScriptController::setScrollUpdatesDisabled(bool) |
| { |
| } |
| |
| void UIScriptController::scrollToOffset(long x, long y) |
| { |
| } |
| |
| void UIScriptController::immediateScrollToOffset(long x, long y) |
| { |
| } |
| |
| void UIScriptController::immediateScrollElementAtContentPointToOffset(long x, long y, long xScrollOffset, long yScrollOffset) |
| { |
| } |
| |
| void UIScriptController::immediateZoomToScale(double scale) |
| { |
| } |
| |
| void UIScriptController::keyboardAccessoryBarNext() |
| { |
| } |
| |
| void UIScriptController::keyboardAccessoryBarPrevious() |
| { |
| } |
| |
| void UIScriptController::applyAutocorrection(JSStringRef, JSStringRef, JSValueRef) |
| { |
| } |
| |
| bool UIScriptController::isShowingKeyboard() const |
| { |
| return false; |
| } |
| |
| double UIScriptController::zoomScale() const |
| { |
| return 1; |
| } |
| |
| double UIScriptController::minimumZoomScale() const |
| { |
| return 1; |
| } |
| |
| double UIScriptController::maximumZoomScale() const |
| { |
| return 1; |
| } |
| |
| Optional<bool> UIScriptController::stableStateOverride() const |
| { |
| return WTF::nullopt; |
| } |
| |
| void UIScriptController::setStableStateOverride(Optional<bool>) |
| { |
| } |
| |
| JSObjectRef UIScriptController::contentVisibleRect() const |
| { |
| return nullptr; |
| } |
| |
| JSObjectRef UIScriptController::textSelectionRangeRects() const |
| { |
| return nullptr; |
| } |
| |
| JSObjectRef UIScriptController::textSelectionCaretRect() const |
| { |
| return nullptr; |
| } |
| |
| JSObjectRef UIScriptController::selectionStartGrabberViewRect() const |
| { |
| return nullptr; |
| } |
| |
| JSObjectRef UIScriptController::selectionCaretViewRect() const |
| { |
| return nullptr; |
| } |
| |
| JSObjectRef UIScriptController::selectionRangeViewRects() const |
| { |
| return nullptr; |
| } |
| |
| JSObjectRef UIScriptController::selectionEndGrabberViewRect() const |
| { |
| return nullptr; |
| } |
| |
| JSObjectRef UIScriptController::inputViewBounds() const |
| { |
| return nullptr; |
| } |
| |
| void UIScriptController::removeAllDynamicDictionaries() |
| { |
| } |
| |
| JSRetainPtr<JSStringRef> UIScriptController::scrollingTreeAsText() const |
| { |
| return nullptr; |
| } |
| |
| JSObjectRef UIScriptController::propertiesOfLayerWithID(uint64_t layerID) const |
| { |
| return nullptr; |
| } |
| |
| void UIScriptController::platformSetDidStartFormControlInteractionCallback() |
| { |
| } |
| |
| void UIScriptController::platformSetDidEndFormControlInteractionCallback() |
| { |
| } |
| |
| void UIScriptController::platformSetDidShowForcePressPreviewCallback() |
| { |
| } |
| |
| void UIScriptController::platformSetDidDismissForcePressPreviewCallback() |
| { |
| } |
| |
| void UIScriptController::platformSetWillBeginZoomingCallback() |
| { |
| } |
| |
| void UIScriptController::platformSetDidEndZoomingCallback() |
| { |
| } |
| |
| void UIScriptController::platformSetDidEndScrollingCallback() |
| { |
| } |
| |
| void UIScriptController::platformSetDidShowKeyboardCallback() |
| { |
| } |
| |
| void UIScriptController::platformSetDidHideKeyboardCallback() |
| { |
| } |
| |
| void UIScriptController::platformSetDidShowMenuCallback() |
| { |
| } |
| |
| void UIScriptController::platformSetDidHideMenuCallback() |
| { |
| } |
| |
| bool UIScriptController::isShowingPopover() const |
| { |
| return false; |
| } |
| |
| void UIScriptController::platformSetWillPresentPopoverCallback() |
| { |
| } |
| |
| void UIScriptController::platformSetDidDismissPopoverCallback() |
| { |
| } |
| |
| JSObjectRef UIScriptController::menuRect() const |
| { |
| return nullptr; |
| } |
| |
| JSObjectRef UIScriptController::rectForMenuAction(JSStringRef) const |
| { |
| return nullptr; |
| } |
| |
| bool UIScriptController::isDismissingMenu() const |
| { |
| return false; |
| } |
| |
| bool UIScriptController::isShowingMenu() const |
| { |
| return false; |
| } |
| |
| void UIScriptController::platformClearAllCallbacks() |
| { |
| } |
| |
| void UIScriptController::retrieveSpeakSelectionContent(JSValueRef) |
| { |
| } |
| |
| JSRetainPtr<JSStringRef> UIScriptController::accessibilitySpeakSelectionContent() const |
| { |
| return nullptr; |
| } |
| |
| void UIScriptController::setSafeAreaInsets(double top, double right, double bottom, double left) |
| { |
| } |
| |
| void UIScriptController::drawSquareInEditableImage() |
| { |
| } |
| |
| long UIScriptController::numberOfStrokesInEditableImage() |
| { |
| return 0; |
| } |
| |
| JSObjectRef UIScriptController::attachmentInfo(JSStringRef) |
| { |
| return nullptr; |
| } |
| |
| void UIScriptController::setKeyboardInputModeIdentifier(JSStringRef) |
| { |
| } |
| |
| void UIScriptController::setHardwareKeyboardAttached(bool) |
| { |
| } |
| |
| #endif |
| |
| #if !PLATFORM(COCOA) |
| |
| void UIScriptController::simulateRotation(DeviceOrientation*, JSValueRef callback) |
| { |
| } |
| |
| void UIScriptController::simulateRotationLikeSafari(DeviceOrientation*, JSValueRef callback) |
| { |
| } |
| |
| void UIScriptController::findString(JSStringRef, unsigned long options, unsigned long maxCount) |
| { |
| } |
| |
| void UIScriptController::removeViewFromWindow(JSValueRef) |
| { |
| } |
| |
| void UIScriptController::addViewToWindow(JSValueRef) |
| { |
| } |
| |
| void UIScriptController::beginBackSwipe(JSValueRef callback) |
| { |
| } |
| |
| void UIScriptController::completeBackSwipe(JSValueRef callback) |
| { |
| } |
| |
| void UIScriptController::setShareSheetCompletesImmediatelyWithResolution(bool) |
| { |
| } |
| |
| bool UIScriptController::isShowingDataListSuggestions() const |
| { |
| return false; |
| } |
| |
| void UIScriptController::overridePreference(JSStringRef, JSStringRef) |
| { |
| } |
| |
| JSRetainPtr<JSStringRef> UIScriptController::lastUndoLabel() const |
| { |
| return nullptr; |
| } |
| |
| JSRetainPtr<JSStringRef> UIScriptController::firstRedoLabel() const |
| { |
| return nullptr; |
| } |
| |
| #endif // !PLATFORM(COCOA) |
| |
| #if !PLATFORM(MAC) |
| |
| void UIScriptController::replaceTextAtRange(JSStringRef, int, int) |
| { |
| } |
| |
| void UIScriptController::platformPlayBackEventStream(JSStringRef, JSValueRef) |
| { |
| } |
| |
| void UIScriptController::firstResponderSuppressionForWebView(bool) |
| { |
| } |
| |
| void UIScriptController::makeWindowContentViewFirstResponder() |
| { |
| } |
| |
| bool UIScriptController::isWindowContentViewFirstResponder() const |
| { |
| return false; |
| } |
| |
| #endif |
| |
| void UIScriptController::uiScriptComplete(JSStringRef result) |
| { |
| m_context->requestUIScriptCompletion(result); |
| platformClearAllCallbacks(); |
| } |
| |
| } |