void LayoutTestController::addUserStyleSheet(JSStringRef source, bool allFrames) { WKRetainPtr<WKStringRef> sourceWK = toWK(source); WKRetainPtr<WKBundleScriptWorldRef> scriptWorld(AdoptWK, WKBundleScriptWorldCreateWorld()); WKBundleAddUserStyleSheet(InjectedBundle::shared().bundle(), InjectedBundle::shared().pageGroup(), scriptWorld.get(), sourceWK.get(), 0, 0, 0, (allFrames ? kWKInjectInAllFrames : kWKInjectInTopFrameOnly)); }
void DOMWindowExtensionBasic::initialize(WKBundleRef bundle, WKTypeRef userData) { assert(WKGetTypeID(userData) == WKBundlePageGroupGetTypeID()); WKBundlePageGroupRef pageGroup = static_cast<WKBundlePageGroupRef>(userData); WKRetainPtr<WKStringRef> source(AdoptWK, WKStringCreateWithUTF8CString("alert('Unimportant alert');")); WKBundleAddUserScript(bundle, pageGroup, WKBundleScriptWorldCreateWorld(), source.get(), 0, 0, 0, kWKInjectAtDocumentStart, kWKInjectInAllFrames); }
InjectedBundlePage::InjectedBundlePage(WKBundlePageRef page) : m_page(page) , m_world(AdoptWK, WKBundleScriptWorldCreateWorld()) , m_isLoading(false) { WKBundlePageLoaderClient loaderClient = { 0, this, didStartProvisionalLoadForFrame, didReceiveServerRedirectForProvisionalLoadForFrame, didFailProvisionalLoadWithErrorForFrame, didCommitLoadForFrame, didFinishDocumentLoadForFrame, didFinishLoadForFrame, didFailLoadWithErrorForFrame, didReceiveTitleForFrame, 0, 0, 0, didClearWindowForFrame, didCancelClientRedirectForFrame, willPerformClientRedirectForFrame, didChangeLocationWithinPageForFrame, didHandleOnloadEventsForFrame, didDisplayInsecureContentForFrame, didRunInsecureContentForFrame }; WKBundlePageSetLoaderClient(m_page, &loaderClient); WKBundlePageUIClient uiClient = { 0, this, willAddMessageToConsole, willSetStatusbarText, willRunJavaScriptAlert, willRunJavaScriptConfirm, willRunJavaScriptPrompt, 0 /*mouseDidMoveOverElement*/ }; WKBundlePageSetUIClient(m_page, &uiClient); WKBundlePageEditorClient editorClient = { 0, this, shouldBeginEditing, shouldEndEditing, shouldInsertNode, shouldInsertText, shouldDeleteRange, shouldChangeSelectedRange, shouldApplyStyle, didBeginEditing, didEndEditing, didChange, didChangeSelection }; WKBundlePageSetEditorClient(m_page, &editorClient); }
void LayoutTestController::addUserScript(JSStringRef source, bool runAtStart, bool allFrames) { WKRetainPtr<WKStringRef> sourceWK = toWK(source); WKRetainPtr<WKBundleScriptWorldRef> scriptWorld(AdoptWK, WKBundleScriptWorldCreateWorld()); WKBundleAddUserScript(InjectedBundle::shared().bundle(), scriptWorld.get(), sourceWK.get(), 0, 0, 0, (runAtStart ? kWKInjectAtDocumentStart : kWKInjectAtDocumentEnd), (allFrames ? kWKInjectInAllFrames : kWKInjectInTopFrameOnly)); }
void TestRunner::addUserStyleSheet(JSStringRef source, bool allFrames) { WKRetainPtr<WKStringRef> sourceWK = toWK(source); WKRetainPtr<WKBundleScriptWorldRef> scriptWorld(AdoptWK, WKBundleScriptWorldCreateWorld()); auto& injectedBundle = InjectedBundle::singleton(); WKBundleAddUserStyleSheet(injectedBundle.bundle(), injectedBundle.pageGroup(), scriptWorld.get(), sourceWK.get(), 0, 0, 0, (allFrames ? kWKInjectInAllFrames : kWKInjectInTopFrameOnly)); }
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); }