summaryrefslogtreecommitdiffstats
path: root/WebKit
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2010-10-06 14:34:04 +0100
committerBen Murdoch <benm@google.com>2010-10-13 12:01:11 +0100
commit81feb0e216184fe2c8d13ef52dd678925cc4ad77 (patch)
tree412ce15f250931476a324166b1a847c47f45218a /WebKit
parent0a12879c6b8ddf8b2b27629dfd999cedd9589959 (diff)
downloadexternal_webkit-81feb0e216184fe2c8d13ef52dd678925cc4ad77.zip
external_webkit-81feb0e216184fe2c8d13ef52dd678925cc4ad77.tar.gz
external_webkit-81feb0e216184fe2c8d13ef52dd678925cc4ad77.tar.bz2
Sync autofill profile data from java.
Add the JNI bindings so that we can get the AutoFill profile data that the user entered in the Browser UI and inject that data into the WebAutoFill object. This eliminates the John Smith profile! Note that additional profile data such as addresses and phone numbers will be added very shortly. Requires a corresponding change to frameworks/base, see https://android-git.corp.google.com/g/#change,72204 Change-Id: Ie32100123ef0d868e1f7efb5604c6fac48725967
Diffstat (limited to 'WebKit')
-rw-r--r--WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp35
-rw-r--r--WebKit/android/WebCoreSupport/autofill/WebAutoFill.h4
-rw-r--r--WebKit/android/jni/WebCoreJni.cpp16
-rw-r--r--WebKit/android/jni/WebCoreJni.h5
-rw-r--r--WebKit/android/jni/WebSettings.cpp42
5 files changed, 78 insertions, 24 deletions
diff --git a/WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp b/WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp
index aff1e2f..ce0a455 100644
--- a/WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp
+++ b/WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp
@@ -57,26 +57,10 @@ WebAutoFill::WebAutoFill()
AndroidURLRequestContextGetter::Get()->SetURLRequestContextGetterFunction(&WebRequestContext::GetAndroidContext);
AndroidURLRequestContextGetter::Get()->SetIOThread(WebUrlLoaderClient::ioThread());
- TabContents* tabContents = new TabContents();
- mAutoFillManager = new AutoFillManager(tabContents);
-
- // FIXME: For testing use a precanned profile. This should come from Java land!
- mAutoFillProfile = new AutoFillProfile();
- mAutoFillProfile->SetInfo(AutoFillType(NAME_FULL), string16(ASCIIToUTF16("John Smith")));
- mAutoFillProfile->SetInfo(AutoFillType(EMAIL_ADDRESS), string16(ASCIIToUTF16("jsmith@gmail.com")));
- mAutoFillProfile->SetInfo(AutoFillType(ADDRESS_HOME_LINE1), string16(ASCIIToUTF16("123 Fake Street")));
- mAutoFillProfile->SetInfo(AutoFillType(ADDRESS_HOME_LINE2), string16(ASCIIToUTF16("Somewhere")));
- mAutoFillProfile->SetInfo(AutoFillType(ADDRESS_HOME_CITY), string16(ASCIIToUTF16("Faketown")));
- mAutoFillProfile->SetInfo(AutoFillType(ADDRESS_HOME_STATE), string16(ASCIIToUTF16("CA")));
- mAutoFillProfile->SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY), string16(ASCIIToUTF16("Germany")));
- mAutoFillProfile->SetInfo(AutoFillType(ADDRESS_HOME_ZIP), string16(ASCIIToUTF16("AB12 3DE")));
- mAutoFillProfile->SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER), string16(ASCIIToUTF16("0123456789")));
-
- std::vector<AutoFillProfile> profiles;
- profiles.push_back(*mAutoFillProfile);
- tabContents->profile()->GetPersonalDataManager()->SetProfiles(&profiles);
+ mTabContents = new TabContents();
+ mAutoFillManager = new AutoFillManager(mTabContents.get());
mAutoFillHost = new AutoFillHostAndroid(this);
- tabContents->SetAutoFillHost(mAutoFillHost.get());
+ mTabContents->SetAutoFillHost(mAutoFillHost.get());
}
WebAutoFill::~WebAutoFill()
@@ -183,6 +167,19 @@ bool WebAutoFill::enabled() const
return page ? page->settings()->autoFillEnabled() : false;
}
+void WebAutoFill::setProfile(const string16& fullName, const string16& emailAddress)
+{
+ AutoFillProfile autoFillProfile;
+
+ // Constants for AutoFill field types are found in external/chromium/chrome/browser/autofill/field_types.h.
+ autoFillProfile.SetInfo(AutoFillType(NAME_FULL), fullName);
+ autoFillProfile.SetInfo(AutoFillType(EMAIL_ADDRESS), emailAddress);
+
+ std::vector<AutoFillProfile> profiles;
+ profiles.push_back(autoFillProfile);
+ mTabContents->profile()->GetPersonalDataManager()->SetProfiles(&profiles);
+}
+
}
#endif
diff --git a/WebKit/android/WebCoreSupport/autofill/WebAutoFill.h b/WebKit/android/WebCoreSupport/autofill/WebAutoFill.h
index c1226ed..fabd3bf 100644
--- a/WebKit/android/WebCoreSupport/autofill/WebAutoFill.h
+++ b/WebKit/android/WebCoreSupport/autofill/WebAutoFill.h
@@ -63,11 +63,13 @@ public:
void setWebViewCore(WebViewCore* webViewCore) { mWebViewCore = webViewCore; }
bool enabled() const;
+ void setProfile(const string16& fullName, const string16& emailAddress);
+
private:
OwnPtr<FormManager> mFormManager;
OwnPtr<AutoFillManager> mAutoFillManager;
- OwnPtr<AutoFillProfile> mAutoFillProfile;
OwnPtr<AutoFillHost> mAutoFillHost;
+ OwnPtr<TabContents> mTabContents;
typedef std::vector<webkit_glue::FormData, std::allocator<webkit_glue::FormData> > FormList;
FormList mForms;
diff --git a/WebKit/android/jni/WebCoreJni.cpp b/WebKit/android/jni/WebCoreJni.cpp
index a785f41..dd15971 100644
--- a/WebKit/android/jni/WebCoreJni.cpp
+++ b/WebKit/android/jni/WebCoreJni.cpp
@@ -71,4 +71,20 @@ WTF::String to_string(JNIEnv* env, jstring str)
return ret;
}
+#if USE(CHROME_NETWORK_STACK)
+string16 jstringToString16(JNIEnv* env, jstring jstr)
+{
+ if (!jstr || !env)
+ return string16();
+
+ const char* s = env->GetStringUTFChars(jstr, 0);
+ if (!s)
+ return string16();
+ string16 str = UTF8ToUTF16(s);
+ env->ReleaseStringUTFChars(jstr, s);
+ checkException(env);
+ return str;
+}
+#endif
+
}
diff --git a/WebKit/android/jni/WebCoreJni.h b/WebKit/android/jni/WebCoreJni.h
index 96ee291..95bdaa0 100644
--- a/WebKit/android/jni/WebCoreJni.h
+++ b/WebKit/android/jni/WebCoreJni.h
@@ -26,6 +26,7 @@
#ifndef ANDROID_WEBKIT_WEBCOREJNI_H
#define ANDROID_WEBKIT_WEBCOREJNI_H
+#include "ChromiumIncludes.h"
#include "PlatformString.h"
#include <jni.h>
@@ -72,6 +73,10 @@ bool checkException(JNIEnv* env);
// Create a WTF::String object from a jstring object.
WTF::String to_string(JNIEnv* env, jstring str);
+#if USE(CHROME_NETWORK_STACK)
+string16 jstringToString16(JNIEnv* env, jstring jstr);
+#endif
+
}
#endif
diff --git a/WebKit/android/jni/WebSettings.cpp b/WebKit/android/jni/WebSettings.cpp
index 79c4017..f75cf9a 100644
--- a/WebKit/android/jni/WebSettings.cpp
+++ b/WebKit/android/jni/WebSettings.cpp
@@ -31,6 +31,7 @@
#include "ApplicationCacheStorage.h"
#include "BitmapAllocatorAndroid.h"
#include "CachedResourceLoader.h"
+#include "ChromiumIncludes.h"
#include "DatabaseTracker.h"
#include "Database.h"
#include "Document.h"
@@ -126,6 +127,10 @@ struct FieldIds {
mPageCacheCapacity = env->GetFieldID(clazz, "mPageCacheCapacity", "I");
#if ENABLE(WEB_AUTOFILL)
mAutoFillEnabled = env->GetFieldID(clazz, "mAutoFillEnabled", "Z");
+ mAutoFillProfile = env->GetFieldID(clazz, "mAutoFillProfile", "Landroid/webkit/WebSettings$AutoFillProfile;");
+ jclass autoFillProfileClass = env->FindClass("android/webkit/WebSettings$AutoFillProfile");
+ mAutoFillProfileFullName = env->GetFieldID(autoFillProfileClass, "mFullName", "Ljava/lang/String;");
+ mAutoFillProfileEmailAddress = env->GetFieldID(autoFillProfileClass, "mEmailAddress", "Ljava/lang/String;");
#endif
LOG_ASSERT(mLayoutAlgorithm, "Could not find field mLayoutAlgorithm");
@@ -235,6 +240,9 @@ struct FieldIds {
#endif
#if ENABLE(WEB_AUTOFILL)
jfieldID mAutoFillEnabled;
+ jfieldID mAutoFillProfile;
+ jfieldID mAutoFillProfileFullName;
+ jfieldID mAutoFillProfileEmailAddress;
#endif
};
@@ -252,6 +260,25 @@ static void recursiveCleanupForFullLayout(WebCore::RenderObject* obj)
recursiveCleanupForFullLayout(n);
}
+#if ENABLE(WEB_AUTOFILL)
+void syncAutoFillProfile(JNIEnv* env, jobject autoFillProfile, WebAutoFill* webAutoFill)
+{
+ jstring str;
+ string16 fullName;
+ string16 emailAddress;
+
+ str = static_cast<jstring>(env->GetObjectField(autoFillProfile, gFieldIds->mAutoFillProfileFullName));
+ if (str)
+ fullName = jstringToString16(env, str);
+
+ str = static_cast<jstring>(env->GetObjectField(autoFillProfile, gFieldIds->mAutoFillProfileEmailAddress));
+ if (str)
+ emailAddress = jstringToString16(env, str);
+
+ webAutoFill->setProfile(fullName, emailAddress);
+}
+#endif
+
class WebSettings {
public:
static void Sync(JNIEnv* env, jobject obj, jint frame)
@@ -454,14 +481,21 @@ public:
// for forms.
bool oldAutoFillSetting = s->autoFillEnabled();
s->setAutoFillEnabled(flag);
- if (!oldAutoFillSetting && flag) {
- EditorClientAndroid* editorC = static_cast<EditorClientAndroid*>(pFrame->page()->editorClient());
- editorC->getAutoFill()->searchDocument(pFrame->document());
- }
+
+ EditorClientAndroid* editorC = static_cast<EditorClientAndroid*>(pFrame->page()->editorClient());
+ WebAutoFill* webAutoFill = editorC->getAutoFill();
+ if (!oldAutoFillSetting && flag)
+ webAutoFill->searchDocument(pFrame->document());
+
+ // Set the active AutoFillProfile data.
+ jobject autoFillProfile = env->GetObjectField(obj, gFieldIds->mAutoFillProfile);
+ if (autoFillProfile)
+ syncAutoFillProfile(env, autoFillProfile, webAutoFill);
#endif
}
};
+
//-------------------------------------------------------------
// JNI registration
//-------------------------------------------------------------