summaryrefslogtreecommitdiffstats
path: root/Source/WebKit
diff options
context:
space:
mode:
authorKristian Monsen <kristianm@google.com>2011-11-09 11:39:07 +0000
committerKristian Monsen <kristianm@google.com>2011-11-09 15:26:47 +0000
commitdd14b5fc24b7b5dc7542e8af7249d239efb87516 (patch)
tree14df4cf1eea0f167e197cd6ec24fa58b56b87523 /Source/WebKit
parentfa37b19364efa4d2d48a77ab7d39ef6adcf7ff62 (diff)
downloadexternal_webkit-dd14b5fc24b7b5dc7542e8af7249d239efb87516.zip
external_webkit-dd14b5fc24b7b5dc7542e8af7249d239efb87516.tar.gz
external_webkit-dd14b5fc24b7b5dc7542e8af7249d239efb87516.tar.bz2
Part of fix for bug 5584571 Add HTTP request header with app name
Getting the app package name from JNI. Cache the string after the first call. Add a header to every request with: X-Requested-With: com.package.name Change-Id: If9d8c131f6c4203036678516ccae6a7ec9131df9
Diffstat (limited to 'Source/WebKit')
-rw-r--r--Source/WebKit/android/WebCoreSupport/ChromiumIncludes.h1
-rw-r--r--Source/WebKit/android/WebCoreSupport/WebRequest.cpp21
2 files changed, 21 insertions, 1 deletions
diff --git a/Source/WebKit/android/WebCoreSupport/ChromiumIncludes.h b/Source/WebKit/android/WebCoreSupport/ChromiumIncludes.h
index 5dd1cac..e59fe09 100644
--- a/Source/WebKit/android/WebCoreSupport/ChromiumIncludes.h
+++ b/Source/WebKit/android/WebCoreSupport/ChromiumIncludes.h
@@ -58,6 +58,7 @@
#include <android/net/android_network_library_impl.h>
#include <android/jni/jni_utils.h>
#include <base/callback.h>
+#include <base/lazy_instance.h>
#include <base/memory/ref_counted.h>
#include <base/message_loop_proxy.h>
#include <base/openssl_util.h>
diff --git a/Source/WebKit/android/WebCoreSupport/WebRequest.cpp b/Source/WebKit/android/WebCoreSupport/WebRequest.cpp
index 90b0939..c239b80 100644
--- a/Source/WebKit/android/WebCoreSupport/WebRequest.cpp
+++ b/Source/WebKit/android/WebCoreSupport/WebRequest.cpp
@@ -30,6 +30,7 @@
#include "MainThread.h"
#include "UrlInterceptResponse.h"
#include "WebCoreFrameBridge.h"
+#include "WebCoreJni.h"
#include "WebRequestContext.h"
#include "WebResourceRequest.h"
#include "WebUrlLoaderClient.h"
@@ -58,7 +59,24 @@ while (0)
namespace android {
namespace {
- const int kInitialReadBufSize = 32768;
+const int kInitialReadBufSize = 32768;
+const char* kXRequestedWithHeader = "X-Requested-With";
+
+struct RequestPackageName {
+ std::string value;
+ RequestPackageName();
+};
+
+RequestPackageName::RequestPackageName() {
+ JNIEnv* env = JSC::Bindings::getJNIEnv();
+ jclass bridgeClass = env->FindClass("android/webkit/JniUtil");
+ jmethodID method = env->GetStaticMethodID(bridgeClass, "getPackageName", "()Ljava/lang/String;");
+ value = jstringToStdString(env, static_cast<jstring>(env->CallStaticObjectMethod(bridgeClass, method)));
+ env->DeleteLocalRef(bridgeClass);
+}
+
+base::LazyInstance<RequestPackageName> s_packageName(base::LINKER_INITIALIZED);
+
}
WebRequest::WebRequest(WebUrlLoaderClient* loader, const WebResourceRequest& webResourceRequest)
@@ -79,6 +97,7 @@ WebRequest::WebRequest(WebUrlLoaderClient* loader, const WebResourceRequest& web
m_request = new net::URLRequest(gurl, this);
m_request->SetExtraRequestHeaders(webResourceRequest.requestHeaders());
+ m_request->SetExtraRequestHeaderByName(kXRequestedWithHeader, s_packageName.Get().value, true);
m_request->set_referrer(webResourceRequest.referrer());
m_request->set_method(webResourceRequest.method());
m_request->set_load_flags(webResourceRequest.loadFlags());