void InjectedBundlePage::dump() { ASSERT(InjectedBundle::shared().isTestRunning()); InjectedBundle::shared().layoutTestController()->invalidateWaitToDumpWatchdogTimer(); switch (InjectedBundle::shared().layoutTestController()->whatToDump()) { case LayoutTestController::RenderTree: { WKRetainPtr<WKStringRef> text(AdoptWK, WKBundlePageCopyRenderTreeExternalRepresentation(m_page)); InjectedBundle::shared().os() << text; break; } case LayoutTestController::MainFrameText: dumpFrameText(WKBundlePageGetMainFrame(m_page)); break; case LayoutTestController::AllFramesText: dumpAllFramesText(); break; } if (InjectedBundle::shared().layoutTestController()->shouldDumpAllFrameScrollPositions()) dumpAllFrameScrollPositions(); else if (InjectedBundle::shared().layoutTestController()->shouldDumpMainFrameScrollPosition()) dumpFrameScrollPosition(WKBundlePageGetMainFrame(m_page)); InjectedBundle::shared().done(); }
bool LayoutTestController::pauseTransitionAtTimeOnElementWithId(JSStringRef propertyName, double time, JSStringRef elementId) { // FIXME: Is it OK this works only for the main frame? // FIXME: If this is needed only for the main frame, then why is the function on WKBundleFrame instead of WKBundlePage? WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::shared().page()->page()); return WKBundleFramePauseTransitionOnElementWithId(mainFrame, toWK(propertyName).get(), toWK(elementId).get(), time); }
void TestRunner::simulateWebNotificationClick(JSValueRef notification) { WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::shared().page()->page()); JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame); uint64_t notificationID = WKBundleGetWebNotificationID(InjectedBundle::shared().bundle(), context, notification); InjectedBundle::shared().postSimulateWebNotificationClick(notificationID); }
void EventSendingController::keyDown(JSStringRef key, JSValueRef modifierArray, int location) { WKBundlePageRef page = InjectedBundle::shared().page()->page(); WKBundleFrameRef frame = WKBundlePageGetMainFrame(page); JSContextRef context = WKBundleFrameGetJavaScriptContext(frame); WKEventModifiers modifiers = parseModifierArray(context, modifierArray); WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender")); WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate()); WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage")); WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("KeyDown")); WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get()); WKRetainPtr<WKStringRef> keyKey(AdoptWK, WKStringCreateWithUTF8CString("Key")); WKDictionaryAddItem(EventSenderMessageBody.get(), keyKey.get(), toWK(key).get()); WKRetainPtr<WKStringRef> modifiersKey(AdoptWK, WKStringCreateWithUTF8CString("Modifiers")); WKRetainPtr<WKUInt64Ref> modifiersRef(AdoptWK, WKUInt64Create(modifiers)); WKDictionaryAddItem(EventSenderMessageBody.get(), modifiersKey.get(), modifiersRef.get()); WKRetainPtr<WKStringRef> locationKey(AdoptWK, WKStringCreateWithUTF8CString("Location")); WKRetainPtr<WKUInt64Ref> locationRef(AdoptWK, WKUInt64Create(location)); WKDictionaryAddItem(EventSenderMessageBody.get(), locationKey.get(), locationRef.get()); WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0); }
void EventSendingController::mouseUp(int button, JSValueRef modifierArray) { WKBundlePageRef page = InjectedBundle::shared().page()->page(); WKBundleFrameRef frame = WKBundlePageGetMainFrame(page); JSContextRef context = WKBundleFrameGetJavaScriptContext(frame); WKEventModifiers modifiers = parseModifierArray(context, modifierArray); #ifdef USE_WEBPROCESS_EVENT_SIMULATION updateClickCount(button); WKBundlePageSimulateMouseUp(page, button, m_position, m_clickCount, modifiers, m_time); #else WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender")); WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate()); WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage")); WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("MouseUp")); WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get()); WKRetainPtr<WKStringRef> buttonKey(AdoptWK, WKStringCreateWithUTF8CString("Button")); WKRetainPtr<WKUInt64Ref> buttonRef(AdoptWK, WKUInt64Create(button)); WKDictionaryAddItem(EventSenderMessageBody.get(), buttonKey.get(), buttonRef.get()); WKRetainPtr<WKStringRef> modifiersKey(AdoptWK, WKStringCreateWithUTF8CString("Modifiers")); WKRetainPtr<WKUInt64Ref> modifiersRef(AdoptWK, WKUInt64Create(modifiers)); WKDictionaryAddItem(EventSenderMessageBody.get(), modifiersKey.get(), modifiersRef.get()); WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0); #endif }
void TestRunner::setMockGeolocationPosition(double latitude, double longitude, double accuracy, JSValueRef jsAltitude, JSValueRef jsAltitudeAccuracy, JSValueRef jsHeading, JSValueRef jsSpeed) { WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::shared().page()->page()); JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame); bool providesAltitude = false; double altitude = 0.; if (!JSValueIsUndefined(context, jsAltitude)) { providesAltitude = true; altitude = JSValueToNumber(context, jsAltitude, 0); } bool providesAltitudeAccuracy = false; double altitudeAccuracy = 0.; if (!JSValueIsUndefined(context, jsAltitudeAccuracy)) { providesAltitudeAccuracy = true; altitudeAccuracy = JSValueToNumber(context, jsAltitudeAccuracy, 0); } bool providesHeading = false; double heading = 0.; if (!JSValueIsUndefined(context, jsHeading)) { providesHeading = true; heading = JSValueToNumber(context, jsHeading, 0); } bool providesSpeed = false; double speed = 0.; if (!JSValueIsUndefined(context, jsSpeed)) { providesSpeed = true; speed = JSValueToNumber(context, jsSpeed, 0); } InjectedBundle::shared().setMockGeolocationPosition(latitude, longitude, accuracy, providesAltitude, altitude, providesAltitudeAccuracy, altitudeAccuracy, providesHeading, heading, providesSpeed, speed); }
unsigned LayoutTestController::numberOfActiveAnimations() const { // FIXME: Is it OK this works only for the main frame? // FIXME: If this is needed only for the main frame, then why is the function on WKBundleFrame instead of WKBundlePage? WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::shared().page()->page()); return WKBundleFrameGetNumberOfActiveAnimations(mainFrame); }
static string toStr(WKBundlePageRef page, WKBundleScriptWorldRef world, WKBundleRangeHandleRef rangeRef) { if (!rangeRef) return "(null)"; WKBundleFrameRef frame = WKBundlePageGetMainFrame(page); JSGlobalContextRef context = WKBundleFrameGetJavaScriptContextForWorld(frame, world); JSValueRef rangeValue = WKBundleFrameGetJavaScriptWrapperForRangeForWorld(frame, rangeRef, world); ASSERT(JSValueIsObject(context, rangeValue)); JSObjectRef rangeObject = (JSObjectRef)rangeValue; JSValueRef startNodeValue = propertyValue(context, rangeObject, "startContainer"); ASSERT(JSValueIsObject(context, startNodeValue)); JSObjectRef startNodeObject = (JSObjectRef)startNodeValue; JSValueRef endNodeValue = propertyValue(context, rangeObject, "endContainer"); ASSERT(JSValueIsObject(context, endNodeValue)); JSObjectRef endNodeObject = (JSObjectRef)endNodeValue; int startOffset = propertyValueInt(context, rangeObject, "startOffset"); int endOffset = propertyValueInt(context, rangeObject, "endOffset"); ostringstream out; out << "range from " << startOffset << " of " << dumpPath(context, startNodeObject) << " to " << endOffset << " of " << dumpPath(context, endNodeObject); return out.str(); }
QtBuiltinBundlePage::~QtBuiltinBundlePage() { if (!m_navigatorQtObject) return; WKBundleFrameRef frame = WKBundlePageGetMainFrame(m_page); JSGlobalContextRef context = WKBundleFrameGetJavaScriptContext(frame); JSValueUnprotect(context, m_navigatorQtObject); }
void InjectedBundlePage::didStartProvisionalLoadForFrame(WKBundleFrameRef frame) { if (!InjectedBundle::shared().isTestRunning()) return; if (frame == WKBundlePageGetMainFrame(m_page)) m_isLoading = true; }
void TestRunner::simulateWebNotificationClick(JSValueRef notification) { auto& injectedBundle = InjectedBundle::singleton(); WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(injectedBundle.page()->page()); JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame); uint64_t notificationID = WKBundleGetWebNotificationID(injectedBundle.bundle(), context, notification); injectedBundle.postSimulateWebNotificationClick(notificationID); }
void TestRunner::queueLoad(JSStringRef url, JSStringRef target) { WKRetainPtr<WKURLRef> baseURLWK(AdoptWK, WKBundleFrameCopyURL(WKBundlePageGetMainFrame(InjectedBundle::shared().page()->page()))); WKRetainPtr<WKURLRef> urlWK(AdoptWK, WKURLCreateWithBaseURL(baseURLWK.get(), toWTFString(toWK(url)).utf8().data())); WKRetainPtr<WKStringRef> urlStringWK(AdoptWK, WKURLCopyString(urlWK.get())); InjectedBundle::shared().queueLoad(urlStringWK.get(), toWK(target).get()); }
void TestRunner::queueLoad(JSStringRef url, JSStringRef target, bool shouldOpenExternalURLs) { auto& injectedBundle = InjectedBundle::singleton(); WKRetainPtr<WKURLRef> baseURLWK(AdoptWK, WKBundleFrameCopyURL(WKBundlePageGetMainFrame(injectedBundle.page()->page()))); WKRetainPtr<WKURLRef> urlWK(AdoptWK, WKURLCreateWithBaseURL(baseURLWK.get(), toWTFString(toWK(url)).utf8().data())); WKRetainPtr<WKStringRef> urlStringWK(AdoptWK, WKURLCopyString(urlWK.get())); injectedBundle.queueLoad(urlStringWK.get(), toWK(target).get(), shouldOpenExternalURLs); }
JSValueRef TestRunner::originsWithApplicationCache() { WKRetainPtr<WKArrayRef> origins(AdoptWK, WKBundleCopyOriginsWithApplicationCache(InjectedBundle::shared().bundle())); WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::shared().page()->page()); JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame); return stringArrayToJS(context, origins.get()); }
JSRetainPtr<JSStringRef> LayoutTestController::counterValueForElementById(JSStringRef elementId) { WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::shared().page()->page()); JSObjectRef element = getElementById(mainFrame, elementId); if (!element) return 0; WKRetainPtr<WKStringRef> value(AdoptWK, WKBundleFrameCopyCounterValue(mainFrame, const_cast<JSObjectRef>(element))); return toJS(value); }
static void callLayoutTestControllerCallback(unsigned index) { if (!callbackMap().contains(index)) return; WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::shared().page()->page()); JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame); JSObjectRef callback = JSValueToObject(context, callbackMap().take(index), 0); JSObjectCallAsFunction(context, callback, JSContextGetGlobalObject(context), 0, 0, 0); JSValueUnprotect(context, callback); }
static void cacheLayoutTestControllerCallback(unsigned index, JSValueRef callback) { if (!callback) return; WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::shared().page()->page()); JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame); JSValueProtect(context, callback); callbackMap().add(index, callback); }
JSRetainPtr<JSStringRef> LayoutTestController::markerTextForListItem(JSValueRef element) { WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::shared().page()->page()); JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame); if (!element || !JSValueIsObject(context, element)) return 0; WKRetainPtr<WKStringRef> text(AdoptWK, WKBundleFrameCopyMarkerText(mainFrame, const_cast<JSObjectRef>(element))); if (WKStringIsEmpty(text.get())) return 0; return toJS(text); }
JSValueRef LayoutTestController::computedStyleIncludingVisitedInfo(JSValueRef element) { // FIXME: Is it OK this works only for the main frame? WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::shared().page()->page()); JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame); if (!JSValueIsObject(context, element)) return JSValueMakeUndefined(context); JSValueRef value = WKBundleFrameGetComputedStyleIncludingVisitedInfo(mainFrame, const_cast<JSObjectRef>(element)); if (!value) return JSValueMakeUndefined(context); return value; }
void WebArchiveTest::didReceiveMessage(WKBundleRef bundle, WKStringRef messageName, WKTypeRef body) { if (!WKStringIsEqualToUTF8CString(messageName, "GetWebArchive")) return; if (WKGetTypeID(body) != WKBundlePageGetTypeID()) return; WKBundleFrameRef frame = WKBundlePageGetMainFrame(static_cast<WKBundlePageRef>(body)); if (!frame) return; WKBundlePostMessage(bundle, Util::toWK("DidGetWebArchive").get(), adoptWK(WKBundleFrameCopyWebArchive(frame)).get()); }
static string dumpPath(WKBundlePageRef page, WKBundleScriptWorldRef world, WKBundleNodeHandleRef node) { if (!node) return "(null)"; WKBundleFrameRef frame = WKBundlePageGetMainFrame(page); JSGlobalContextRef context = WKBundleFrameGetJavaScriptContextForWorld(frame, world); JSValueRef nodeValue = WKBundleFrameGetJavaScriptWrapperForNodeForWorld(frame, node, world); ASSERT(JSValueIsObject(context, nodeValue)); JSObjectRef nodeObject = (JSObjectRef)nodeValue; return dumpPath(context, nodeObject); }
void QtBuiltinBundlePage::didReceiveMessageToNavigatorQtObject(WKStringRef contents) { static JSStringRef onmessageName = JSStringCreateWithUTF8CString("onmessage"); if (!m_navigatorQtObject) return; WKBundleFrameRef frame = WKBundlePageGetMainFrame(m_page); JSGlobalContextRef context = WKBundleFrameGetJavaScriptContext(frame); JSValueRef onmessageValue = JSObjectGetProperty(context, m_navigatorQtObject, onmessageName, 0); if (!JSValueIsObject(context, onmessageValue)) return; JSObjectRef onmessageFunction = JSValueToObject(context, onmessageValue, 0); if (!JSObjectIsFunction(context, onmessageFunction)) return; JSObjectRef wrappedMessage = createWrappedMessage(context, contents); JSObjectCallAsFunction(context, onmessageFunction, 0, 1, &wrappedMessage, 0); }
void LayoutTestController::evaluateScriptInIsolatedWorld(JSContextRef context, unsigned worldID, JSStringRef script) { // A worldID of 0 always corresponds to a new world. Any other worldID corresponds to a world // that is created once and cached forever. WKRetainPtr<WKBundleScriptWorldRef> world; if (!worldID) world.adopt(WKBundleScriptWorldCreateWorld()); else { WKRetainPtr<WKBundleScriptWorldRef>& worldSlot = worldMap().add(worldID, 0).first->second; if (!worldSlot) worldSlot.adopt(WKBundleScriptWorldCreateWorld()); world = worldSlot; } WKBundleFrameRef frame = WKBundleFrameForJavaScriptContext(context); if (!frame) frame = WKBundlePageGetMainFrame(InjectedBundle::shared().page()->page()); JSGlobalContextRef jsContext = WKBundleFrameGetJavaScriptContextForWorld(frame, world.get()); JSEvaluateScript(jsContext, script, 0, 0, 0, 0); }
static void callOnMessage(JSObjectRef object, WKStringRef contents, WKBundlePageRef page) { static JSStringRef onmessageName = JSStringCreateWithUTF8CString("onmessage"); if (!object) return; WKBundleFrameRef frame = WKBundlePageGetMainFrame(page); JSGlobalContextRef context = WKBundleFrameGetJavaScriptContext(frame); JSValueRef onmessageValue = JSObjectGetProperty(context, object, onmessageName, 0); if (!JSValueIsObject(context, onmessageValue)) return; JSObjectRef onmessageFunction = JSValueToObject(context, onmessageValue, 0); if (!JSObjectIsFunction(context, onmessageFunction)) return; JSObjectRef wrappedMessage = createWrappedMessage(context, contents); JSObjectCallAsFunction(context, onmessageFunction, 0, 1, &wrappedMessage, 0); }
QtBuiltinBundlePage::~QtBuiltinBundlePage() { if (!m_navigatorQtObject #ifdef HAVE_WEBCHANNEL && !m_navigatorQtWebChannelTransportObject #endif ) { return; } WKBundleFrameRef frame = WKBundlePageGetMainFrame(m_page); JSGlobalContextRef context = WKBundleFrameGetJavaScriptContext(frame); if (m_navigatorQtObject) JSValueUnprotect(context, m_navigatorQtObject); #ifdef HAVE_WEBCHANNEL if (m_navigatorQtWebChannelTransportObject) JSValueUnprotect(context, m_navigatorQtWebChannelTransportObject); #endif }
bool TestRunner::findString(JSStringRef target, JSValueRef optionsArrayAsValue) { WKFindOptions options = 0; auto& injectedBundle = InjectedBundle::singleton(); WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(injectedBundle.page()->page()); JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame); JSRetainPtr<JSStringRef> lengthPropertyName(Adopt, JSStringCreateWithUTF8CString("length")); JSObjectRef optionsArray = JSValueToObject(context, optionsArrayAsValue, 0); JSValueRef lengthValue = JSObjectGetProperty(context, optionsArray, lengthPropertyName.get(), 0); if (!JSValueIsNumber(context, lengthValue)) return false; size_t length = static_cast<size_t>(JSValueToNumber(context, lengthValue, 0)); for (size_t i = 0; i < length; ++i) { JSValueRef value = JSObjectGetPropertyAtIndex(context, optionsArray, i, 0); if (!JSValueIsString(context, value)) continue; JSRetainPtr<JSStringRef> optionName(Adopt, JSValueToStringCopy(context, value, 0)); if (JSStringIsEqualToUTF8CString(optionName.get(), "CaseInsensitive")) options |= kWKFindOptionsCaseInsensitive; else if (JSStringIsEqualToUTF8CString(optionName.get(), "AtWordStarts")) options |= kWKFindOptionsAtWordStarts; else if (JSStringIsEqualToUTF8CString(optionName.get(), "TreatMedialCapitalAsWordStart")) options |= kWKFindOptionsTreatMedialCapitalAsWordStart; else if (JSStringIsEqualToUTF8CString(optionName.get(), "Backwards")) options |= kWKFindOptionsBackwards; else if (JSStringIsEqualToUTF8CString(optionName.get(), "WrapAround")) options |= kWKFindOptionsWrapAround; else if (JSStringIsEqualToUTF8CString(optionName.get(), "StartInSelection")) { // FIXME: No kWKFindOptionsStartInSelection. } } return WKBundlePageFindString(injectedBundle.page()->page(), toWK(target).get(), options); }
void AccessibilityNotificationHandler::setNotificationFunctionCallback(JSValueRef notificationFunctionCallback) { if (!notificationFunctionCallback) { removeAccessibilityNotificationHandler(); disconnectAccessibilityCallbacks(); return; } m_notificationFunctionCallback = notificationFunctionCallback; #if PLATFORM(GTK) || PLATFORM(EFL) WKBundlePageRef page = InjectedBundle::singleton().page()->page(); WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(page); JSContextRef jsContext = WKBundleFrameGetJavaScriptContext(mainFrame); #else JSContextRef jsContext = nullptr; #endif if (!jsContext) return; connectAccessibilityCallbacks(); JSValueProtect(jsContext, m_notificationFunctionCallback); // Check if this notification handler is related to a specific element. if (m_platformElement) { NotificationHandlersMap::iterator currentNotificationHandler = notificationHandlers.find(m_platformElement.get()); if (currentNotificationHandler != notificationHandlers.end()) { ASSERT(currentNotificationHandler->value->platformElement()); JSValueUnprotect(jsContext, currentNotificationHandler->value->notificationFunctionCallback()); notificationHandlers.remove(currentNotificationHandler->value->platformElement().get()); } notificationHandlers.add(m_platformElement.get(), this); } else { if (globalNotificationHandler) JSValueUnprotect(jsContext, globalNotificationHandler->notificationFunctionCallback()); globalNotificationHandler = this; } }
void AccessibilityNotificationHandler::removeAccessibilityNotificationHandler() { #if PLATFORM(GTK) || PLATFORM(EFL) WKBundlePageRef page = InjectedBundle::singleton().page()->page(); WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(page); JSContextRef jsContext = WKBundleFrameGetJavaScriptContext(mainFrame); #else JSContextRef jsContext = nullptr; #endif if (!jsContext) return; if (globalNotificationHandler == this) { JSValueUnprotect(jsContext, globalNotificationHandler->notificationFunctionCallback()); globalNotificationHandler = nullptr; } else if (m_platformElement.get()) { NotificationHandlersMap::iterator removeNotificationHandler = notificationHandlers.find(m_platformElement.get()); if (removeNotificationHandler != notificationHandlers.end()) { JSValueUnprotect(jsContext, removeNotificationHandler->value->notificationFunctionCallback()); notificationHandlers.remove(removeNotificationHandler); } } }
void InjectedBundlePage::dumpAllFramesText() { WKBundleFrameRef frame = WKBundlePageGetMainFrame(m_page); dumpFrameText(frame); dumpDescendantFramesText(frame); }
void InjectedBundlePage::dumpAllFrameScrollPositions() { WKBundleFrameRef frame = WKBundlePageGetMainFrame(m_page); dumpFrameScrollPosition(frame); dumpDescendantFrameScrollPositions(frame); }