HRESULT STDMETHODCALLTYPE DOMHTMLTextAreaElement::value( /* [retval][out] */ BSTR* result) { ASSERT(m_element && m_element->hasTagName(textareaTag)); HTMLTextAreaElement* textareaElement = static_cast<HTMLTextAreaElement*>(m_element); WebCore::String valueString = textareaElement->value(); *result = BString(valueString.characters(), valueString.length()).release(); if (valueString.length() && !*result) return E_OUTOFMEMORY; return S_OK; }
HRESULT STDMETHODCALLTYPE DOMCSSStyleDeclaration::getPropertyValue( /* [in] */ BSTR propertyName, /* [retval][out] */ BSTR* result) { WebCore::String propertyNameString(propertyName); WebCore::String value = m_style->getPropertyValue(propertyNameString); *result = SysAllocStringLen(value.characters(), value.length()); if (value.length() && !*result) return E_OUTOFMEMORY; return S_OK; }
static void write_string(WTF::Vector<char>& v, const WebCore::String& str) { unsigned strLen = str.length(); // Only do work if the string has data. if (strLen) { // Determine how much to grow the vector. Use the worst case for utf8 to // avoid reading the string twice. Add sizeof(unsigned) to hold the // string length in utf8. unsigned vectorLen = v.size() + sizeof(unsigned); unsigned length = (strLen << 2) + vectorLen; // Grow the vector. This will change the value of v.size() but we // remember the original size above. v.grow(length); // Grab the position to write to. char* data = v.begin() + vectorLen; // Write the actual string int l = SkUTF16_ToUTF8(str.characters(), strLen, data); LOGV("Writing string %d %.*s", l, l, data); // Go back and write the utf8 length. Subtract sizeof(unsigned) from // data to get the position to write the length. memcpy(data - sizeof(unsigned), (char*)&l, sizeof(unsigned)); // Shrink the internal state of the vector so we match what was // actually written. v.shrink(vectorLen + l); } else v.append((char*)&strLen, sizeof(unsigned)); }
static const char* anp_getApplicationDataDirectory() { if (NULL == gApplicationDataDir) { PluginClient* client = JavaSharedClient::GetPluginClient(); if (!client) return NULL; WebCore::String path = client->getPluginSharedDataDirectory(); int length = path.length(); if (length == 0) return NULL; char* storage = (char*) malloc(length + 1); if (NULL == storage) return NULL; memcpy(storage, path.utf8().data(), length); storage[length] = '\0'; // save this assignment for last, so that if multiple threads call us // (which should never happen), we never return an incomplete global. // At worst, we would allocate storage for the path twice. gApplicationDataDir = storage; } return gApplicationDataDir; }
jstring WebCoreResourceLoader::RedirectedToUrl(JNIEnv* env, jobject obj, jstring baseUrl, jstring redirectTo, jint nativeResponse) { #ifdef ANDROID_INSTRUMENT TimeCounterAuto counter(TimeCounter::ResourceTimeCounter); #endif LOGV("webcore_resourceloader redirectedToUrl"); WebCore::ResourceHandle* handle = GET_NATIVE_HANDLE(env, obj); LOG_ASSERT(handle, "nativeRedirectedToUrl must take a valid handle!"); // ResourceLoader::didFail() can set handle to be NULL, we need to check if (!handle) return NULL; LOG_ASSERT(handle->client(), "Why do we not have a client?"); WebCore::ResourceRequest r = handle->request(); WebCore::KURL url(WebCore::KURL(WebCore::ParsedURLString, to_string(env, baseUrl)), to_string(env, redirectTo)); r.setURL(url); if (r.httpMethod() == "POST") { r.setHTTPMethod("GET"); r.clearHTTPReferrer(); r.setHTTPBody(0); r.setHTTPContentType(""); } WebCore::ResourceResponse* response = (WebCore::ResourceResponse*)nativeResponse; // If the url fails to resolve the relative path, return null. if (url.protocol().isEmpty()) { delete response; return NULL; } handle->client()->willSendRequest(handle, r, *response); delete response; WebCore::String s = url.string(); return env->NewString((unsigned short*)s.characters(), s.length()); }
static jobject GetOrigins(JNIEnv* env, jobject obj) { Vector<RefPtr<WebCore::SecurityOrigin> > coreOrigins; WebCore::DatabaseTracker::tracker().origins(coreOrigins); Vector<WebCore::KURL> manifestUrls; if (WebCore::cacheStorage().manifestURLs(&manifestUrls)) { int size = manifestUrls.size(); for (int i = 0; i < size; ++i) { RefPtr<WebCore::SecurityOrigin> manifestOrigin = WebCore::SecurityOrigin::create(manifestUrls[i]); if (manifestOrigin.get() == 0) continue; coreOrigins.append(manifestOrigin); } } jclass setClass = env->FindClass("java/util/HashSet"); jmethodID cid = env->GetMethodID(setClass, "<init>", "()V"); jmethodID mid = env->GetMethodID(setClass, "add", "(Ljava/lang/Object;)Z"); jobject set = env->NewObject(setClass, cid); for (unsigned i = 0; i < coreOrigins.size(); ++i) { WebCore::SecurityOrigin* origin = coreOrigins[i].get(); WebCore::String url = origin->toString(); jstring jUrl = env->NewString(url.characters(), url.length()); env->CallBooleanMethod(set, mid, jUrl); env->DeleteLocalRef(jUrl); } return set; }
HRESULT STDMETHODCALLTYPE DOMHTMLFormElement::method( /* [retval][out] */ BSTR* result) { ASSERT(m_element && m_element->hasTagName(formTag)); WebCore::String methodString = static_cast<HTMLFormElement*>(m_element)->method(); *result = BString(methodString.characters(), methodString.length()).release(); return S_OK; }
HRESULT STDMETHODCALLTYPE DOMHTMLElement::innerText( /* [retval][out] */ BSTR* result) { ASSERT(m_element && m_element->isHTMLElement()); WebCore::String innerTextString = static_cast<HTMLElement*>(m_element)->innerText(); *result = BString(innerTextString.characters(), innerTextString.length()).release(); return S_OK; }
void JavaBridge::setCookies(WebCore::KURL const& url, WebCore::String const& value) { JNIEnv* env = JSC::Bindings::getJNIEnv(); const WebCore::String& urlStr = url.string(); jstring jUrlStr = env->NewString(urlStr.characters(), urlStr.length()); jstring jValueStr = env->NewString(value.characters(), value.length()); AutoJObject obj = getRealObject(env, mJavaObject); env->CallVoidMethod(obj.get(), mSetCookies, jUrlStr, jValueStr); env->DeleteLocalRef(jUrlStr); env->DeleteLocalRef(jValueStr); }
/* * This static method is called to check to see if a POST response is in * the cache. This may be slow, but is only used during a navigation to * a POST response. */ bool WebCoreResourceLoader::willLoadFromCache(const WebCore::KURL& url, int64_t identifier) { JNIEnv* env = JSC::Bindings::getJNIEnv(); WebCore::String urlStr = url.string(); jstring jUrlStr = env->NewString(urlStr.characters(), urlStr.length()); jclass resourceLoader = env->FindClass("android/webkit/LoadListener"); bool val = env->CallStaticBooleanMethod(resourceLoader, gResourceLoader.mWillLoadFromCacheMethodID, jUrlStr, identifier); checkException(env); env->DeleteLocalRef(jUrlStr); return val; }
static bool isValidProtocolString(const WebCore::String& protocol) { if (protocol.isNull()) return true; if (protocol.isEmpty()) return false; const UChar* characters = protocol.characters(); for (size_t i = 0; i < protocol.length(); i++) { if (characters[i] < 0x21 || characters[i] > 0x7E) return false; } return true; }
WebCore::String JavaBridge::getSignedPublicKeyAndChallengeString(unsigned index, const WebCore::String& challenge, const WebCore::KURL& url) { JNIEnv* env = JSC::Bindings::getJNIEnv(); jstring jChallenge = env->NewString(challenge.characters(), challenge.length()); const WebCore::String& urlStr = url.string(); jstring jUrl = env->NewString(urlStr.characters(), urlStr.length()); AutoJObject obj = getRealObject(env, mJavaObject); jstring key = (jstring) env->CallObjectMethod(obj.get(), mGetSignedPublicKey, index, jChallenge, jUrl); WebCore::String ret = to_string(env, key); env->DeleteLocalRef(jChallenge); env->DeleteLocalRef(jUrl); env->DeleteLocalRef(key); return ret; }
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 }
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); }