void LayoutTestController::overridePreference(JSStringRef key, JSStringRef value) { GOwnPtr<gchar> originalName(JSStringCopyUTF8CString(key)); GOwnPtr<gchar> valueAsString(JSStringCopyUTF8CString(value)); WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); ASSERT(view); // This transformation could be handled by a hash table (and it once was), but // having it prominent, makes it easier for people from other ports to keep the // list up to date. const gchar* propertyName = 0; if (g_str_equal(originalName.get(), "WebKitJavaScriptEnabled")) propertyName = "enable-scripts"; else if (g_str_equal(originalName.get(), "WebKitDefaultFontSize")) propertyName = "default-font-size"; else if (g_str_equal(originalName.get(), "WebKitEnableCaretBrowsing")) propertyName = "enable-caret-browsing"; else if (g_str_equal(originalName.get(), "WebKitUsesPageCachePreferenceKey")) propertyName = "enable-page-cache"; else if (g_str_equal(originalName.get(), "WebKitPluginsEnabled")) propertyName = "enable-plugins"; else if (g_str_equal(originalName.get(), "WebKitHyperlinkAuditingEnabled")) propertyName = "enable-hyperlink-auditing"; else if (g_str_equal(originalName.get(), "WebKitTabToLinksPreferenceKey")) { DumpRenderTreeSupportGtk::setLinksIncludedInFocusChain(!g_ascii_strcasecmp(valueAsString.get(), "true") || !g_ascii_strcasecmp(valueAsString.get(), "1")); return; } else { fprintf(stderr, "LayoutTestController::overridePreference tried to override " "unknown preference '%s'.\n", originalName.get()); return; } WebKitWebSettings* settings = webkit_web_view_get_settings(view); GParamSpec* pspec = g_object_class_find_property(G_OBJECT_CLASS( WEBKIT_WEB_SETTINGS_GET_CLASS(settings)), propertyName); GValue currentPropertyValue = { 0, { { 0 } } }; g_value_init(¤tPropertyValue, pspec->value_type); if (G_VALUE_HOLDS_STRING(¤tPropertyValue)) g_object_set(settings, propertyName, valueAsString.get(), NULL); else if (G_VALUE_HOLDS_BOOLEAN(¤tPropertyValue)) g_object_set(G_OBJECT(settings), propertyName, !g_ascii_strcasecmp(valueAsString.get(), "true") || !g_ascii_strcasecmp(valueAsString.get(), "1"), NULL); else if (G_VALUE_HOLDS_INT(¤tPropertyValue)) g_object_set(G_OBJECT(settings), propertyName, atoi(valueAsString.get()), NULL); else if (G_VALUE_HOLDS_FLOAT(¤tPropertyValue)) { gfloat newValue = g_ascii_strtod(valueAsString.get(), 0); g_object_set(G_OBJECT(settings), propertyName, newValue, NULL); } else fprintf(stderr, "LayoutTestController::overridePreference failed to override " "preference '%s'.\n", originalName.get()); }
bool LoadHTMLStringItem::invoke() const { GUniquePtr<gchar> content(JSStringCopyUTF8CString(m_content.get())); GUniquePtr<gchar> baseURL(JSStringCopyUTF8CString(m_baseURL.get())); if (m_unreachableURL) { GUniquePtr<gchar> unreachableURL(JSStringCopyUTF8CString(m_unreachableURL.get())); webkit_web_frame_load_alternate_string(mainFrame, content.get(), baseURL.get(), unreachableURL.get()); return true; } webkit_web_frame_load_string(mainFrame, content.get(), 0, 0, baseURL.get()); return true; }
void LayoutTestController::setUserStyleSheetLocation(JSStringRef path) { g_free(userStyleSheet); userStyleSheet = JSStringCopyUTF8CString(path); if (userStyleSheetEnabled) setUserStyleSheetEnabled(true); }
void LayoutTestController::addUserStyleSheet(JSStringRef source, bool allFrames) { GOwnPtr<gchar> sourceCode(JSStringCopyUTF8CString(source)); DumpRenderTreeSupportGtk::addUserStyleSheet(mainFrame, sourceCode.get(), allFrames); // FIXME: needs more investigation why userscripts/user-style-top-frame-only.html fails when allFrames is false. }
// Application controller static callback. static JSValueRef fillConfigurationFromFile(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception, ConfigFileType type) { if (argumentCount < 1) return JSValueMakeUndefined(context); JSRetainPtr<JSStringRef> fileNameJSString(Adopt, JSValueToStringCopy(context, arguments[0], exception)); //ASSERT(!*exception); ApplicationTestController* controller = static_cast<ApplicationTestController*>(JSObjectGetPrivate(thisObject)); char* relativeURL = JSStringCopyUTF8CString(fileNameJSString.get()); if (strncmp("http://", relativeURL, 7) != 0 && strncmp("https://", relativeURL, 8) != 0 && strncmp("data:", relativeURL, 5) != 0 && strncmp("file://", relativeURL, 7) != 0) { WebView* webView = getWebView(); string mainFrameURL = webView->mainFrameURL(); size_t pos = mainFrameURL.find_last_of("/"); string absoluteURL = mainFrameURL.substr(0, pos + 1); absoluteURL += relativeURL; size_t pos2 = absoluteURL.find_last_of("?"); if (pos2 == absoluteURL.size() - 1) absoluteURL = absoluteURL.substr(0, pos2); controller->fillConfigurationFromFile((char*)absoluteURL.c_str(), type); return JSValueMakeUndefined(context); } controller->fillConfigurationFromFile(relativeURL, type); return JSValueMakeUndefined(context); }
bool ScriptItem::invoke() const { char* scriptString = JSStringCopyUTF8CString(m_script.get()); getWebView()->executeScript(scriptString); free(scriptString); return true; }
void TestRunner::setUserStyleSheetLocation(JSStringRef path) { g_free(userStyleSheet); userStyleSheet = JSStringCopyUTF8CString(path); if (userStyleSheetEnabled) setUserStyleSheetEnabled(true); }
int LayoutTestController::pageNumberForElementById(JSStringRef id, float pageWidth, float pageHeight) { gchar* idGChar = JSStringCopyUTF8CString(id); int pageNumber = DumpRenderTreeSupportGtk::pageNumberForElementById(mainFrame, idGChar, pageWidth, pageHeight); g_free(idGChar); return pageNumber; }
bool ScriptItem::invoke() const { WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame); gchar* scriptString = JSStringCopyUTF8CString(m_script.get()); webkit_web_view_execute_script(webView, scriptString); g_free(scriptString); return true; }
void TestRunner::evaluateInWebInspector(JSStringRef script) { WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame); WebKitWebInspector* inspector = webkit_web_view_get_inspector(webView); char* scriptString = JSStringCopyUTF8CString(script); webkit_web_inspector_execute_script(inspector, scriptString); g_free(scriptString); }
void LayoutTestController::evaluateInWebInspector(long callId, JSStringRef script) { WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame); WebKitWebInspector* inspector = webkit_web_view_get_inspector(webView); char* scriptString = JSStringCopyUTF8CString(script); webkit_web_inspector_execute_script(inspector, callId, scriptString); g_free(scriptString); }
void LayoutTestController::setMockGeolocationError(int code, JSStringRef message) { WebKitWebView* view = WEBKIT_WEB_VIEW(g_slist_nth_data(webViewList, 0)); if (!view) view = webkit_web_frame_get_web_view(mainFrame); ASSERT(view); GOwnPtr<gchar> cMessage(JSStringCopyUTF8CString(message)); DumpRenderTreeSupportGtk::setMockGeolocationError(view, code, cMessage.get()); }
bool LayoutTestController::isCommandEnabled(JSStringRef name) { WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); ASSERT(view); gchar* cName = JSStringCopyUTF8CString(name); bool result = DumpRenderTreeSupportGtk::isCommandEnabled(view, cName); g_free(cName); return result; }
bool LoadItem::invoke() const { char* targetString = JSStringCopyUTF8CString(m_target.get()); WebFrame* targetFrame; if (!strlen(targetString)) targetFrame = getWebView()->mainFrame(); else targetFrame = getWebView()->mainFrame()->findFrameNamed(targetString); free(targetString); char* urlString = JSStringCopyUTF8CString(m_url.get()); targetFrame->loadURL(urlString); // WebKitNetworkRequest* request = webkit_network_request_new(urlString); free(urlString); // webkit_web_frame_load_request(targetFrame, request); // g_object_unref(request); return true; }
bool LoadItem::invoke() const { gchar* targetString = JSStringCopyUTF8CString(m_target.get()); WebKitWebFrame* targetFrame; if (!strlen(targetString)) targetFrame = mainFrame; else targetFrame = webkit_web_frame_find_frame(mainFrame, targetString); g_free(targetString); gchar* urlString = JSStringCopyUTF8CString(m_url.get()); WebKitNetworkRequest* request = webkit_network_request_new(urlString); g_free(urlString); webkit_web_frame_load_request(targetFrame, request); g_object_unref(request); return true; }
JSRetainPtr<JSStringRef> LayoutTestController::counterValueForElementById(JSStringRef id) { gchar* idGChar = JSStringCopyUTF8CString(id); CString counterValueGChar = DumpRenderTreeSupportGtk::counterValueForElementById(mainFrame, idGChar); g_free(idGChar); if (counterValueGChar.isNull()) return 0; JSRetainPtr<JSStringRef> counterValue(Adopt, JSStringCreateWithUTF8CString(counterValueGChar.data())); return counterValue; }
void TestRunner::setMockGeolocationPositionUnavailableError(JSStringRef message) { WebKitWebView* view = WEBKIT_WEB_VIEW(g_slist_nth_data(webViewList, 0)); if (!view) view = webkit_web_frame_get_web_view(mainFrame); ASSERT(view); GOwnPtr<gchar> cMessage(JSStringCopyUTF8CString(message)); DumpRenderTreeSupportGtk::setMockGeolocationPositionUnavailableError(view, cMessage.get()); }
JSStringRef LayoutTestController::pathToLocalResource(JSContextRef context, JSStringRef url) { GOwnPtr<char> urlCString(JSStringCopyUTF8CString(url)); if (!g_str_has_prefix(urlCString.get(), "file:///tmp/LayoutTests/")) return JSStringRetain(url); const char* layoutTestsSuffix = urlCString.get() + strlen("file:///tmp/"); GOwnPtr<char> testPath(g_build_filename(getTopLevelPath().data(), layoutTestsSuffix, NULL)); GOwnPtr<char> testURI(g_filename_to_uri(testPath.get(), 0, 0)); return JSStringCreateWithUTF8CString(testURI.get()); }
void LayoutTestController::queueLoad(JSStringRef url, JSStringRef target) { gchar* relativeURL = JSStringCopyUTF8CString(url); SoupURI* baseURI = soup_uri_new(webkit_web_frame_get_uri(mainFrame)); SoupURI* absoluteURI = soup_uri_new_with_base(baseURI, relativeURL); soup_uri_free(baseURI); g_free(relativeURL); gchar* absoluteCString; if (absoluteURI) { absoluteCString = soup_uri_to_string(absoluteURI, FALSE); soup_uri_free(absoluteURI); } else absoluteCString = JSStringCopyUTF8CString(url); JSRetainPtr<JSStringRef> absoluteURL(Adopt, JSStringCreateWithUTF8CString(absoluteCString)); g_free(absoluteCString); WorkQueue::shared()->queue(new LoadItem(absoluteURL.get(), target)); }
void TestRunner::setTextDirection(JSStringRef direction) { GUniquePtr<gchar> writingDirection(JSStringCopyUTF8CString(direction)); WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); ASSERT(view); if (g_str_equal(writingDirection.get(), "auto")) gtk_widget_set_direction(GTK_WIDGET(view), GTK_TEXT_DIR_NONE); else if (g_str_equal(writingDirection.get(), "ltr")) gtk_widget_set_direction(GTK_WIDGET(view), GTK_TEXT_DIR_LTR); else if (g_str_equal(writingDirection.get(), "rtl")) gtk_widget_set_direction(GTK_WIDGET(view), GTK_TEXT_DIR_RTL); else fprintf(stderr, "TestRunner::setTextDirection called with unknown direction: '%s'.\n", writingDirection.get()); }
void TestRunner::queueLoad(JSStringRef url, JSStringRef target) { GUniquePtr<gchar> relativeURL(JSStringCopyUTF8CString(url)); SoupURI* baseURI = soup_uri_new(webkit_web_frame_get_uri(mainFrame)); SoupURI* absoluteURI = soup_uri_new_with_base(baseURI, relativeURL.get()); soup_uri_free(baseURI); if (!absoluteURI) { WorkQueue::shared()->queue(new LoadItem(url, target)); return; } CString absoluteURIString = soupURIToStringPreservingPassword(absoluteURI); JSRetainPtr<JSStringRef> absoluteURL(Adopt, JSStringCreateWithUTF8CString(absoluteURIString.data())); WorkQueue::shared()->queue(new LoadItem(absoluteURL.get(), target)); soup_uri_free(absoluteURI); }
void LayoutTestController::setViewModeMediaFeature(JSStringRef mode) { WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); ASSERT(view); char* viewMode = JSStringCopyUTF8CString(mode); if (!g_strcmp0(viewMode, "windowed")) webkit_web_view_set_view_mode(view, WEBKIT_WEB_VIEW_VIEW_MODE_WINDOWED); else if (!g_strcmp0(viewMode, "floating")) webkit_web_view_set_view_mode(view, WEBKIT_WEB_VIEW_VIEW_MODE_FLOATING); else if (!g_strcmp0(viewMode, "fullscreen")) webkit_web_view_set_view_mode(view, WEBKIT_WEB_VIEW_VIEW_MODE_FULLSCREEN); else if (!g_strcmp0(viewMode, "maximized")) webkit_web_view_set_view_mode(view, WEBKIT_WEB_VIEW_VIEW_MODE_MAXIMIZED); else if (!g_strcmp0(viewMode, "minimized")) webkit_web_view_set_view_mode(view, WEBKIT_WEB_VIEW_VIEW_MODE_MINIMIZED); g_free(viewMode); }
static JSValueRef setPermissionsForMainApplication(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { #if ENABLE(DAE_APPLICATION) if (argumentCount < 1) return JSValueMakeUndefined(context); JSRetainPtr<JSStringRef> permissions(Adopt, JSValueToStringCopy(context, arguments[0], exception)); //ASSERT(!*exception); #if ENABLE(DAE_PERMISSION) // Clear permissions. SharedPtr<WebApplication> webApp = webAppMgr().application(getWebView()); if (webApp) { webApp->setPermissions(0); webApp->setPermissions(JSStringCopyUTF8CString(permissions.get())); } #endif #endif return JSValueMakeUndefined(context); }
bool LayoutTestController::findString(JSContextRef context, JSStringRef target, JSObjectRef optionsArray) { WebKitFindOptions findOptions = 0; WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame); ASSERT(webView); JSRetainPtr<JSStringRef> lengthPropertyName(Adopt, JSStringCreateWithUTF8CString("length")); JSValueRef lengthValue = JSObjectGetProperty(context, optionsArray, lengthPropertyName.get(), 0); if (!JSValueIsNumber(context, lengthValue)) return false; GOwnPtr<gchar> targetString(JSStringCopyUTF8CString(target)); 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")) findOptions |= WebKit::WebFindOptionsCaseInsensitive; else if (JSStringIsEqualToUTF8CString(optionName.get(), "AtWordStarts")) findOptions |= WebKit::WebFindOptionsAtWordStarts; else if (JSStringIsEqualToUTF8CString(optionName.get(), "TreatMedialCapitalAsWordStart")) findOptions |= WebKit::WebFindOptionsTreatMedialCapitalAsWordStart; else if (JSStringIsEqualToUTF8CString(optionName.get(), "Backwards")) findOptions |= WebKit::WebFindOptionsBackwards; else if (JSStringIsEqualToUTF8CString(optionName.get(), "WrapAround")) findOptions |= WebKit::WebFindOptionsWrapAround; else if (JSStringIsEqualToUTF8CString(optionName.get(), "StartInSelection")) findOptions |= WebKit::WebFindOptionsStartInSelection; } return DumpRenderTreeSupportGtk::findString(webView, targetString.get(), findOptions); }
void LayoutTestController::setDomainRelaxationForbiddenForURLScheme(bool forbidden, JSStringRef scheme) { GOwnPtr<gchar> urlScheme(JSStringCopyUTF8CString(scheme)); DumpRenderTreeSupportGtk::setDomainRelaxationForbiddenForURLScheme(forbidden, urlScheme.get()); }
void TestRunner::addUserScript(JSStringRef source, bool runAtStart, bool allFrames) { GUniquePtr<gchar> sourceCode(JSStringCopyUTF8CString(source)); DumpRenderTreeSupportGtk::addUserScript(mainFrame, sourceCode.get(), runAtStart, allFrames); }
bool LayoutTestController::pauseTransitionAtTimeOnElementWithId(JSStringRef propertyName, double time, JSStringRef elementId) { char* name = JSStringCopyUTF8CString(propertyName); char* element = JSStringCopyUTF8CString(elementId); return getWebView()->mainFrame()->pauseTransition(name, time, element); }
void TestRunner::setDomainRelaxationForbiddenForURLScheme(bool forbidden, JSStringRef scheme) { GUniquePtr<gchar> urlScheme(JSStringCopyUTF8CString(scheme)); DumpRenderTreeSupportGtk::setDomainRelaxationForbiddenForURLScheme(forbidden, urlScheme.get()); }