bool wxWebView::Create(wxWindow* parent, int id, const wxPoint& position, const wxSize& size, long style, const wxString& name) { if ( (style & wxBORDER_MASK) == 0) style |= wxBORDER_NONE; if (!wxWindow::Create(parent, id, position, size, style, name)) return false; WTF::initializeThreading(); // This is necessary because we are using SharedTimerWin.cpp on Windows, // due to a problem with exceptions getting eaten when using the callback // approach to timers (which wx itself uses). #if __WXMSW__ WebCore::Page::setInstanceHandle(wxGetInstance()); #endif // this helps reduce flicker on platforms like MSW SetBackgroundStyle(wxBG_STYLE_CUSTOM); m_impl = new WebViewPrivate(); WebCore::InitializeLoggingChannelsIfNecessary(); WebCore::HTMLFrameOwnerElement* parentFrame = 0; WebCore::EditorClientWx* editorClient = new WebCore::EditorClientWx(); m_impl->page = new WebCore::Page(new WebCore::ChromeClientWx(this), new WebCore::ContextMenuClientWx(), editorClient, new WebCore::DragClientWx(), new WebCore::InspectorClientWx(), 0, 0); editorClient->setPage(m_impl->page); m_mainFrame = new wxWebFrame(this); // Default settings - we should have wxWebViewSettings class for this // eventually WebCore::Settings* settings = m_impl->page->settings(); settings->setLoadsImagesAutomatically(true); settings->setDefaultFixedFontSize(13); settings->setDefaultFontSize(16); settings->setSerifFontFamily("Times New Roman"); settings->setFixedFontFamily("Courier New"); settings->setSansSerifFontFamily("Arial"); settings->setStandardFontFamily("Times New Roman"); settings->setJavaScriptEnabled(true); #if ENABLE(DATABASE) settings->setDatabasesEnabled(true); #endif m_isInitialized = true; return true; }
static void Sync(JNIEnv* env, jobject obj, jint frame) { WebCore::Frame* pFrame = (WebCore::Frame*)frame; LOG_ASSERT(pFrame, "%s must take a valid frame pointer!", __FUNCTION__); WebCore::Settings* s = pFrame->settings(); if (!s) return; WebCore::DocLoader* docLoader = pFrame->document()->docLoader(); #ifdef ANDROID_LAYOUT jobject layout = env->GetObjectField(obj, gFieldIds->mLayoutAlgorithm); WebCore::Settings::LayoutAlgorithm l = (WebCore::Settings::LayoutAlgorithm) env->CallIntMethod(layout, gFieldIds->mOrdinal); if (s->layoutAlgorithm() != l) { s->setLayoutAlgorithm(l); if (pFrame->document()) { pFrame->document()->updateStyleSelector(); if (pFrame->document()->renderer()) { recursiveCleanupForFullLayout(pFrame->document()->renderer()); LOG_ASSERT(pFrame->view(), "No view for this frame when trying to relayout"); pFrame->view()->layout(); // FIXME: This call used to scroll the page to put the focus into view. // It worked on the WebViewCore, but now scrolling is done outside of the // WebViewCore, on the UI side, so there needs to be a new way to do this. //pFrame->makeFocusVisible(); } } } #endif jobject textSize = env->GetObjectField(obj, gFieldIds->mTextSize); float zoomFactor = env->GetIntField(textSize, gFieldIds->mTextSizeValue) / 100.0f; if (pFrame->zoomFactor() != zoomFactor) pFrame->setZoomFactor(zoomFactor, /*isTextOnly*/true); jstring str = (jstring)env->GetObjectField(obj, gFieldIds->mStandardFontFamily); s->setStandardFontFamily(to_string(env, str)); str = (jstring)env->GetObjectField(obj, gFieldIds->mFixedFontFamily); s->setFixedFontFamily(to_string(env, str)); str = (jstring)env->GetObjectField(obj, gFieldIds->mSansSerifFontFamily); s->setSansSerifFontFamily(to_string(env, str)); str = (jstring)env->GetObjectField(obj, gFieldIds->mSerifFontFamily); s->setSerifFontFamily(to_string(env, str)); str = (jstring)env->GetObjectField(obj, gFieldIds->mCursiveFontFamily); s->setCursiveFontFamily(to_string(env, str)); str = (jstring)env->GetObjectField(obj, gFieldIds->mFantasyFontFamily); s->setFantasyFontFamily(to_string(env, str)); str = (jstring)env->GetObjectField(obj, gFieldIds->mDefaultTextEncoding); s->setDefaultTextEncodingName(to_string(env, str)); str = (jstring)env->GetObjectField(obj, gFieldIds->mUserAgent); WebFrame::getWebFrame(pFrame)->setUserAgent(to_string(env, str)); jint size = env->GetIntField(obj, gFieldIds->mMinimumFontSize); s->setMinimumFontSize(size); size = env->GetIntField(obj, gFieldIds->mMinimumLogicalFontSize); s->setMinimumLogicalFontSize(size); size = env->GetIntField(obj, gFieldIds->mDefaultFontSize); s->setDefaultFontSize(size); size = env->GetIntField(obj, gFieldIds->mDefaultFixedFontSize); s->setDefaultFixedFontSize(size); jboolean flag = env->GetBooleanField(obj, gFieldIds->mLoadsImagesAutomatically); s->setLoadsImagesAutomatically(flag); if (flag) docLoader->setAutoLoadImages(true); #ifdef ANDROID_BLOCK_NETWORK_IMAGE flag = env->GetBooleanField(obj, gFieldIds->mBlockNetworkImage); s->setBlockNetworkImage(flag); if(!flag) docLoader->setBlockNetworkImage(false); #endif flag = env->GetBooleanField(obj, gFieldIds->mJavaScriptEnabled); s->setJavaScriptEnabled(flag); // ON = 0 // ON_DEMAND = 1 // OFF = 2 jobject pluginState = env->GetObjectField(obj, gFieldIds->mPluginState); int state = env->CallIntMethod(pluginState, gFieldIds->mOrdinal); s->setPluginsEnabled(state < 2); #ifdef ANDROID_PLUGINS s->setPluginsOnDemand(state == 1); #endif #if ENABLE(OFFLINE_WEB_APPLICATIONS) flag = env->GetBooleanField(obj, gFieldIds->mAppCacheEnabled); s->setOfflineWebApplicationCacheEnabled(flag); str = (jstring)env->GetObjectField(obj, gFieldIds->mAppCachePath); if (str) { WebCore::String path = to_string(env, str); if (path.length() && WebCore::cacheStorage().cacheDirectory().isNull()) { WebCore::cacheStorage().setCacheDirectory(path); // This database is created on the first load. If the file // doesn't exist, we create it and set its permissions. The // filename must match that in ApplicationCacheStorage.cpp. String filename = pathByAppendingComponent(path, "ApplicationCache.db"); int fd = open(filename.utf8().data(), O_CREAT | O_EXCL, permissionFlags660); if (fd >= 0) close(fd); } } jlong maxsize = env->GetIntField(obj, gFieldIds->mAppCacheMaxSize); WebCore::cacheStorage().setMaximumSize(maxsize); #endif flag = env->GetBooleanField(obj, gFieldIds->mJavaScriptCanOpenWindowsAutomatically); s->setJavaScriptCanOpenWindowsAutomatically(flag); #ifdef ANDROID_LAYOUT flag = env->GetBooleanField(obj, gFieldIds->mUseWideViewport); s->setUseWideViewport(flag); #endif #ifdef ANDROID_MULTIPLE_WINDOWS flag = env->GetBooleanField(obj, gFieldIds->mSupportMultipleWindows); s->setSupportMultipleWindows(flag); #endif flag = env->GetBooleanField(obj, gFieldIds->mShrinksStandaloneImagesToFit); s->setShrinksStandaloneImagesToFit(flag); #if ENABLE(DATABASE) flag = env->GetBooleanField(obj, gFieldIds->mDatabaseEnabled); s->setDatabasesEnabled(flag); flag = env->GetBooleanField(obj, gFieldIds->mDatabasePathHasBeenSet); if (flag) { // If the user has set the database path, sync it to the DatabaseTracker. str = (jstring)env->GetObjectField(obj, gFieldIds->mDatabasePath); if (str) { String path = to_string(env, str); WebCore::DatabaseTracker::tracker().setDatabaseDirectoryPath(path); // This database is created when the first HTML5 Database object is // instantiated. If the file doesn't exist, we create it and set its // permissions. The filename must match that in // DatabaseTracker.cpp. String filename = SQLiteFileSystem::appendDatabaseFileNameToPath(path, "Databases.db"); int fd = open(filename.utf8().data(), O_CREAT | O_EXCL, permissionFlags660); if (fd >= 0) close(fd); } } #endif #if ENABLE(DOM_STORAGE) flag = env->GetBooleanField(obj, gFieldIds->mDomStorageEnabled); s->setLocalStorageEnabled(flag); str = (jstring)env->GetObjectField(obj, gFieldIds->mDatabasePath); if (str) { WebCore::String localStorageDatabasePath = to_string(env,str); if (localStorageDatabasePath.length()) { localStorageDatabasePath = WebCore::pathByAppendingComponent( localStorageDatabasePath, "localstorage"); // We need 770 for folders mkdir(localStorageDatabasePath.utf8().data(), permissionFlags660 | S_IXUSR | S_IXGRP); s->setLocalStorageDatabasePath(localStorageDatabasePath); } } #endif flag = env->GetBooleanField(obj, gFieldIds->mGeolocationEnabled); GeolocationPermissions::setAlwaysDeny(!flag); str = (jstring)env->GetObjectField(obj, gFieldIds->mGeolocationDatabasePath); if (str) { WebCore::String path = to_string(env, str); GeolocationPermissions::setDatabasePath(path); WebCore::GeolocationPositionCache::setDatabasePath(path); // This database is created when the first Geolocation object is // instantiated. If the file doesn't exist, we create it and set its // permissions. The filename must match that in // GeolocationPositionCache.cpp. WebCore::String filename = WebCore::SQLiteFileSystem::appendDatabaseFileNameToPath( path, "CachedGeoposition.db"); int fd = open(filename.utf8().data(), O_CREAT | O_EXCL, permissionFlags660); if (fd >= 0) close(fd); } size = env->GetIntField(obj, gFieldIds->mPageCacheCapacity); if (size > 0) { s->setUsesPageCache(true); WebCore::pageCache()->setCapacity(size); } else s->setUsesPageCache(false); #if ENABLE(WEBGL) s->setWebGLEnabled(true); #endif }
void QWebSettingsPrivate::apply() { if (settings) { settings->setTextAreasAreResizable(true); QWebSettingsPrivate *global = QWebSettings::globalSettings()->d; QString family = fontFamilies.value(QWebSettings::StandardFont, global->fontFamilies.value(QWebSettings::StandardFont)); settings->setStandardFontFamily(family); family = fontFamilies.value(QWebSettings::FixedFont, global->fontFamilies.value(QWebSettings::FixedFont)); settings->setFixedFontFamily(family); family = fontFamilies.value(QWebSettings::SerifFont, global->fontFamilies.value(QWebSettings::SerifFont)); settings->setSerifFontFamily(family); family = fontFamilies.value(QWebSettings::SansSerifFont, global->fontFamilies.value(QWebSettings::SansSerifFont)); settings->setSansSerifFontFamily(family); family = fontFamilies.value(QWebSettings::CursiveFont, global->fontFamilies.value(QWebSettings::CursiveFont)); settings->setCursiveFontFamily(family); family = fontFamilies.value(QWebSettings::FantasyFont, global->fontFamilies.value(QWebSettings::FantasyFont)); settings->setFantasyFontFamily(family); int size = fontSizes.value(QWebSettings::MinimumFontSize, global->fontSizes.value(QWebSettings::MinimumFontSize)); settings->setMinimumFontSize(size); size = fontSizes.value(QWebSettings::MinimumLogicalFontSize, global->fontSizes.value(QWebSettings::MinimumLogicalFontSize)); settings->setMinimumLogicalFontSize(size); size = fontSizes.value(QWebSettings::DefaultFontSize, global->fontSizes.value(QWebSettings::DefaultFontSize)); settings->setDefaultFontSize(size); size = fontSizes.value(QWebSettings::DefaultFixedFontSize, global->fontSizes.value(QWebSettings::DefaultFixedFontSize)); settings->setDefaultFixedFontSize(size); bool value = attributes.value(QWebSettings::AutoLoadImages, global->attributes.value(QWebSettings::AutoLoadImages)); settings->setLoadsImagesAutomatically(value); value = attributes.value(QWebSettings::JavascriptEnabled, global->attributes.value(QWebSettings::JavascriptEnabled)); settings->setJavaScriptEnabled(value); value = attributes.value(QWebSettings::JavascriptCanOpenWindows, global->attributes.value(QWebSettings::JavascriptCanOpenWindows)); settings->setJavaScriptCanOpenWindowsAutomatically(value); value = attributes.value(QWebSettings::JavaEnabled, global->attributes.value(QWebSettings::JavaEnabled)); settings->setJavaEnabled(value); value = attributes.value(QWebSettings::PluginsEnabled, global->attributes.value(QWebSettings::PluginsEnabled)); settings->setPluginsEnabled(value); value = attributes.value(QWebSettings::PrivateBrowsingEnabled, global->attributes.value(QWebSettings::PrivateBrowsingEnabled)); settings->setPrivateBrowsingEnabled(value); value = attributes.value(QWebSettings::JavascriptCanAccessClipboard, global->attributes.value(QWebSettings::JavascriptCanAccessClipboard)); settings->setDOMPasteAllowed(value); value = attributes.value(QWebSettings::DeveloperExtrasEnabled, global->attributes.value(QWebSettings::DeveloperExtrasEnabled)); settings->setDeveloperExtrasEnabled(value); QUrl location = !userStyleSheetLocation.isEmpty() ? userStyleSheetLocation : global->userStyleSheetLocation; settings->setUserStyleSheetLocation(WebCore::KURL(location)); QString encoding = !defaultTextEncoding.isEmpty() ? defaultTextEncoding: global->defaultTextEncoding; settings->setDefaultTextEncodingName(encoding); QString localStoragePath = !localStorageDatabasePath.isEmpty() ? localStorageDatabasePath : global->localStorageDatabasePath; settings->setLocalStorageDatabasePath(localStoragePath); value = attributes.value(QWebSettings::ZoomTextOnly, global->attributes.value(QWebSettings::ZoomTextOnly)); settings->setZoomsTextOnly(value); value = attributes.value(QWebSettings::PrintElementBackgrounds, global->attributes.value(QWebSettings::PrintElementBackgrounds)); settings->setShouldPrintBackgrounds(value); value = attributes.value(QWebSettings::OfflineStorageDatabaseEnabled, global->attributes.value(QWebSettings::OfflineStorageDatabaseEnabled)); settings->setDatabasesEnabled(value); value = attributes.value(QWebSettings::OfflineWebApplicationCacheEnabled, global->attributes.value(QWebSettings::OfflineWebApplicationCacheEnabled)); settings->setOfflineWebApplicationCacheEnabled(value); value = attributes.value(QWebSettings::LocalStorageDatabaseEnabled, global->attributes.value(QWebSettings::LocalStorageDatabaseEnabled)); settings->setLocalStorageEnabled(value); value = attributes.value(QWebSettings::AllowUniversalAccessFromFileUrls, global->attributes.value(QWebSettings::AllowUniversalAccessFromFileUrls)); settings->setAllowUniversalAccessFromFileURLs(value); } else { QList<QWebSettingsPrivate *> settings = *::allSettings(); for (int i = 0; i < settings.count(); ++i) settings[i]->apply(); } }
static void Sync(JNIEnv* env, jobject obj, jint frame) { WebCore::Frame* pFrame = (WebCore::Frame*)frame; LOG_ASSERT(pFrame, "%s must take a valid frame pointer!", __FUNCTION__); WebCore::Settings* s = pFrame->settings(); if (!s) return; WebCore::DocLoader* docLoader = pFrame->document()->docLoader(); #ifdef ANDROID_LAYOUT jobject layout = env->GetObjectField(obj, gFieldIds->mLayoutAlgorithm); WebCore::Settings::LayoutAlgorithm l = (WebCore::Settings::LayoutAlgorithm) env->CallIntMethod(layout, gFieldIds->mOrdinal); if (s->layoutAlgorithm() != l) { s->setLayoutAlgorithm(l); if (pFrame->document()) { pFrame->document()->updateStyleSelector(); if (pFrame->document()->renderer()) { recursiveCleanupForFullLayout(pFrame->document()->renderer()); LOG_ASSERT(pFrame->view(), "No view for this frame when trying to relayout"); pFrame->view()->layout(); // FIXME: This call used to scroll the page to put the focus into view. // It worked on the WebViewCore, but now scrolling is done outside of the // WebViewCore, on the UI side, so there needs to be a new way to do this. //pFrame->makeFocusVisible(); } } } #endif jobject textSize = env->GetObjectField(obj, gFieldIds->mTextSize); float zoomFactor = env->GetIntField(textSize, gFieldIds->mTextSizeValue) / 100.0f; if (pFrame->zoomFactor() != zoomFactor) pFrame->setZoomFactor(zoomFactor, /*isTextOnly*/true); jstring str = (jstring)env->GetObjectField(obj, gFieldIds->mStandardFontFamily); s->setStandardFontFamily(to_string(env, str)); str = (jstring)env->GetObjectField(obj, gFieldIds->mFixedFontFamily); s->setFixedFontFamily(to_string(env, str)); str = (jstring)env->GetObjectField(obj, gFieldIds->mSansSerifFontFamily); s->setSansSerifFontFamily(to_string(env, str)); str = (jstring)env->GetObjectField(obj, gFieldIds->mSerifFontFamily); s->setSerifFontFamily(to_string(env, str)); str = (jstring)env->GetObjectField(obj, gFieldIds->mCursiveFontFamily); s->setCursiveFontFamily(to_string(env, str)); str = (jstring)env->GetObjectField(obj, gFieldIds->mFantasyFontFamily); s->setFantasyFontFamily(to_string(env, str)); str = (jstring)env->GetObjectField(obj, gFieldIds->mDefaultTextEncoding); s->setDefaultTextEncodingName(to_string(env, str)); str = (jstring)env->GetObjectField(obj, gFieldIds->mUserAgent); WebFrame::getWebFrame(pFrame)->setUserAgent(to_string(env, str)); jint size = env->GetIntField(obj, gFieldIds->mMinimumFontSize); s->setMinimumFontSize(size); size = env->GetIntField(obj, gFieldIds->mMinimumLogicalFontSize); s->setMinimumLogicalFontSize(size); size = env->GetIntField(obj, gFieldIds->mDefaultFontSize); s->setDefaultFontSize(size); size = env->GetIntField(obj, gFieldIds->mDefaultFixedFontSize); s->setDefaultFixedFontSize(size); jboolean flag = env->GetBooleanField(obj, gFieldIds->mLoadsImagesAutomatically); s->setLoadsImagesAutomatically(flag); if (flag) docLoader->setAutoLoadImages(true); #ifdef ANDROID_BLOCK_NETWORK_IMAGE flag = env->GetBooleanField(obj, gFieldIds->mBlockNetworkImage); s->setBlockNetworkImage(flag); if(!flag) docLoader->setBlockNetworkImage(false); #endif flag = env->GetBooleanField(obj, gFieldIds->mJavaScriptEnabled); s->setJavaScriptEnabled(flag); flag = env->GetBooleanField(obj, gFieldIds->mPluginsEnabled); s->setPluginsEnabled(flag); #if ENABLE(OFFLINE_WEB_APPLICATIONS) flag = env->GetBooleanField(obj, gFieldIds->mAppCacheEnabled); s->setOfflineWebApplicationCacheEnabled(flag); str = (jstring)env->GetObjectField(obj, gFieldIds->mAppCachePath); if (str) { WebCore::String path = to_string(env, str); if (path.length() && WebCore::cacheStorage().cacheDirectory().isNull()) { WebCore::cacheStorage().setCacheDirectory(path); } } jlong maxsize = env->GetIntField(obj, gFieldIds->mAppCacheMaxSize); WebCore::cacheStorage().setMaximumSize(maxsize); #endif flag = env->GetBooleanField(obj, gFieldIds->mJavaScriptCanOpenWindowsAutomatically); s->setJavaScriptCanOpenWindowsAutomatically(flag); #ifdef ANDROID_LAYOUT flag = env->GetBooleanField(obj, gFieldIds->mUseWideViewport); s->setUseWideViewport(flag); #endif #ifdef ANDROID_MULTIPLE_WINDOWS flag = env->GetBooleanField(obj, gFieldIds->mSupportMultipleWindows); s->setSupportMultipleWindows(flag); #endif flag = env->GetBooleanField(obj, gFieldIds->mShrinksStandaloneImagesToFit); s->setShrinksStandaloneImagesToFit(flag); #if ENABLE(DATABASE) flag = env->GetBooleanField(obj, gFieldIds->mDatabaseEnabled); s->setDatabasesEnabled(flag); str = (jstring)env->GetObjectField(obj, gFieldIds->mDatabasePath); if (str && WebCore::DatabaseTracker::tracker().databaseDirectoryPath().isNull()) WebCore::DatabaseTracker::tracker().setDatabaseDirectoryPath(to_string(env, str)); #endif #if ENABLE(DOM_STORAGE) flag = env->GetBooleanField(obj, gFieldIds->mDomStorageEnabled); s->setLocalStorageEnabled(flag); str = (jstring)env->GetObjectField(obj, gFieldIds->mDatabasePath); if (str) { WebCore::String localStorageDatabasePath = to_string(env,str); if (localStorageDatabasePath.length()) { s->setLocalStorageDatabasePath(localStorageDatabasePath); } } #endif flag = env->GetBooleanField(obj, gFieldIds->mGeolocationEnabled); GeolocationPermissions::setAlwaysDeny(!flag); str = (jstring)env->GetObjectField(obj, gFieldIds->mGeolocationDatabasePath); if (str) { GeolocationPermissions::setDatabasePath(to_string(env,str)); WebCore::Geolocation::setDatabasePath(to_string(env,str)); } size = env->GetIntField(obj, gFieldIds->mPageCacheCapacity); if (size > 0) { s->setUsesPageCache(true); WebCore::pageCache()->setCapacity(size); } else s->setUsesPageCache(false); }