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 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 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; }
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; }
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; }
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; }