summaryrefslogtreecommitdiffstats
path: root/android/autofill
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2010-08-06 12:08:59 +0100
committerBen Murdoch <benm@google.com>2010-09-13 15:04:09 +0100
commit7d214dfa174224b459660971e5b5cce2e06be02a (patch)
tree8bf36887488cddf26cb43e0394ba35972b5cfefa /android/autofill
parentf74420b3285b9fe04a7e00aa3b8c0ab07ea344bc (diff)
downloadexternal_chromium-7d214dfa174224b459660971e5b5cce2e06be02a.zip
external_chromium-7d214dfa174224b459660971e5b5cce2e06be02a.tar.gz
external_chromium-7d214dfa174224b459660971e5b5cce2e06be02a.tar.bz2
Intial set of changes to enable autofill on Android.
This is the initial checkin of AutoFill code into external/chromium. There's still lots to do, but this basically gets autofill working end to end, using a precanned profile injected from WebCore. By default, autofill is not enabled at the moment. For testing you can turn it on by setting the ENABLE_AUTOFILL environment variable to "true" and rebuilding. There is a corresponding change in external/webkit. Change-Id: I74ef1ccc3fd0625f1bb8e2f85b43a60d23c59ffc
Diffstat (limited to 'android/autofill')
-rw-r--r--android/autofill/android_url_request_context_getter.cc62
-rw-r--r--android/autofill/android_url_request_context_getter.h63
-rw-r--r--android/autofill/profile_android.cc70
-rw-r--r--android/autofill/profile_android.h217
-rw-r--r--android/autofill/url_fetcher_proxy.h152
5 files changed, 564 insertions, 0 deletions
diff --git a/android/autofill/android_url_request_context_getter.cc b/android/autofill/android_url_request_context_getter.cc
new file mode 100644
index 0000000..2ad53e9
--- /dev/null
+++ b/android/autofill/android_url_request_context_getter.cc
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2010, The Android Open Source Project
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#include "android_url_request_context_getter.h"
+
+scoped_refptr<AndroidURLRequestContextGetter> AndroidURLRequestContextGetter::instance_ = NULL;
+
+URLRequestContext* AndroidURLRequestContextGetter::GetURLRequestContext()
+{
+ return context_;
+}
+
+scoped_refptr<base::MessageLoopProxy> AndroidURLRequestContextGetter::GetIOMessageLoopProxy()
+{
+ if (!io_thread_)
+ return NULL;
+
+ if (!io_thread_->IsRunning()) {
+ base::Thread::Options options;
+ options.message_loop_type = MessageLoop::TYPE_IO;
+ if (!io_thread_->StartWithOptions(options)) {
+ io_thread_ = NULL;
+ return NULL;
+ }
+ }
+ return io_thread_->message_loop_proxy();
+}
+
+AndroidURLRequestContextGetter* AndroidURLRequestContextGetter::Get()
+{
+ if (!instance_)
+ instance_ = new AndroidURLRequestContextGetter;
+ return instance_;
+}
+
+void AndroidURLRequestContextGetter::SetURLRequestContext(URLRequestContext* c)
+{
+ context_ = c;
+}
diff --git a/android/autofill/android_url_request_context_getter.h b/android/autofill/android_url_request_context_getter.h
new file mode 100644
index 0000000..3f6f711
--- /dev/null
+++ b/android/autofill/android_url_request_context_getter.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2010, The Android Open Source Project
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ANDROID_URL_REQUEST_CONTEXT_GETTER_H
+#define ANDROID_URL_REQUEST_CONTEXT_GETTER_H
+
+#include "base/message_loop_proxy.h"
+#include "base/thread.h"
+#include "common/net/url_request_context_getter.h"
+
+class MainThreadProxy;
+
+class AndroidURLRequestContextGetter : public URLRequestContextGetter {
+public:
+ AndroidURLRequestContextGetter()
+ : context_(0), io_thread_(0) { };
+
+ virtual ~AndroidURLRequestContextGetter() { }
+
+ virtual URLRequestContext* GetURLRequestContext();
+
+ // Returns a MessageLoopProxy corresponding to the thread on which the
+ // request IO happens (the thread on which the returned URLRequestContext
+ // may be used).
+ virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy();
+
+ static AndroidURLRequestContextGetter* Get();
+
+ void SetURLRequestContext(URLRequestContext*);
+ void SetMainThread(MainThreadProxy* m) { main_thread_proxy_ = m; };
+ MainThreadProxy* GetMainThreadProxy() { return main_thread_proxy_; };
+ void SetIOThread(base::Thread* io_thread) { io_thread_ = io_thread; }
+
+private:
+ static scoped_refptr<AndroidURLRequestContextGetter> instance_;
+ URLRequestContext* context_;
+ base::Thread* io_thread_;
+ MainThreadProxy* main_thread_proxy_;
+};
+
+#endif // ANDROID_URL_REQUEST_CONTEXT_GETTER_H
diff --git a/android/autofill/profile_android.cc b/android/autofill/profile_android.cc
new file mode 100644
index 0000000..4ea1b23
--- /dev/null
+++ b/android/autofill/profile_android.cc
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2010, The Android Open Source Project
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "android/autofill/profile_android.h"
+
+#include "chrome/browser/autofill/personal_data_manager.h"
+
+ProfileImplAndroid::ProfileImplAndroid(const FilePath& path)
+ : path_(path)
+{
+}
+
+ProfileImplAndroid::~ProfileImplAndroid()
+{
+}
+
+Profile* ProfileImplAndroid::GetOriginalProfile()
+{
+ return this;
+}
+
+
+PersonalDataManager* ProfileImplAndroid::GetPersonalDataManager()
+{
+ if (!personal_data_) {
+ personal_data_ = new PersonalDataManager();
+ personal_data_->Init(this);
+ }
+
+ return personal_data_.get();
+}
+
+
+PrefService* ProfileImplAndroid::GetPrefs() {
+ if (!preferences_.get()) {
+ preferences_.reset(PrefService::CreateUserPrefService(path_));
+ }
+ return preferences_.get();
+}
+
+Profile* Profile::CreateProfile(const FilePath& path) {
+ return new ProfileImplAndroid(path);
+}
+
+URLRequestContextGetter* Profile::GetDefaultRequestContext()
+{
+ return AndroidURLRequestContextGetter::Get();
+}
diff --git a/android/autofill/profile_android.h b/android/autofill/profile_android.h
new file mode 100644
index 0000000..2af0d6f
--- /dev/null
+++ b/android/autofill/profile_android.h
@@ -0,0 +1,217 @@
+/*
+ * Copyright 2010, The Android Open Source Project
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// This class gathers state related to a single user profile.
+// On Android, we only use this for AutoFill so methods are mostly
+// just stubs.
+
+#ifndef ANDROID_AUTOFILL_PROFILE_H_
+#define ANDROID_AUTOFILL_PROFILE_H_
+
+#include "android/autofill/android_url_request_context_getter.h"
+#include "base/basictypes.h"
+#include "base/file_path.h"
+#include "base/ref_counted.h"
+#include "base/scoped_ptr.h"
+#include "base/timer.h"
+#include "chrome/browser/pref_service.h"
+#include "chrome/browser/profile.h"
+
+namespace base {
+class Time;
+}
+
+namespace history {
+class TopSites;
+}
+
+namespace net {
+class TransportSecurityState;
+class SSLConfigService;
+}
+
+namespace webkit_database {
+class DatabaseTracker;
+}
+
+class AutocompleteClassifier;
+class BackgroundContentsService;
+class BookmarkModel;
+class BrowserThemeProvider;
+class ChromeURLRequestContextGetter;
+class DesktopNotificationService;
+class DownloadManager;
+class Extension;
+class ExtensionDevToolsManager;
+class ExtensionProcessManager;
+class ExtensionMessageService;
+class ExtensionsService;
+class FaviconService;
+class FindBarState;
+class GeolocationContentSettingsMap;
+class GeolocationPermissionContext;
+class HistoryService;
+class HostContentSettingsMap;
+class HostZoomMap;
+class NavigationController;
+class NTPResourceCache;
+class PasswordStore;
+class PersonalDataManager;
+class PinnedTabService;
+class ProfileSyncService;
+class ProfileSyncFactory;
+class SessionService;
+class SpellCheckHost;
+class SSLConfigServiceManager;
+class SSLHostState;
+class TransportSecurityPersister;
+class SQLitePersistentCookieStore;
+class TabRestoreService;
+class TemplateURLFetcher;
+class TemplateURLModel;
+class ThemeProvider;
+class TokenService;
+class URLRequestContextGetter;
+class UserScriptMaster;
+class UserStyleSheetWatcher;
+class VisitedLinkMaster;
+class VisitedLinkEventListener;
+class WebDataService;
+class WebKitContext;
+class WebResourceService;
+class CloudPrintProxyService;
+
+typedef intptr_t ProfileId;
+
+// The android profile implementation.
+class ProfileImplAndroid : public Profile {
+ public:
+ virtual ~ProfileImplAndroid();
+
+ // Profile implementation.
+ virtual Profile* GetOriginalProfile();
+ virtual PersonalDataManager* GetPersonalDataManager();
+ virtual PrefService* GetPrefs();
+ virtual FilePath GetPath() { return path_; }
+
+ // Functions from Profile that we don't need on Android for AutoFill.
+ virtual ProfileId GetRuntimeId() { NOTREACHED(); return 0; }
+ virtual bool IsOffTheRecord() { NOTREACHED(); return false; }
+ virtual Profile* GetOffTheRecordProfile() { NOTREACHED(); return NULL; }
+ virtual void DestroyOffTheRecordProfile() { NOTREACHED(); }
+ virtual bool HasOffTheRecordProfile() { NOTREACHED(); return false; }
+ virtual webkit_database::DatabaseTracker* GetDatabaseTracker() { NOTREACHED(); return NULL; }
+ virtual history::TopSites* GetTopSites() { NOTREACHED(); return NULL; }
+ virtual VisitedLinkMaster* GetVisitedLinkMaster() { NOTREACHED(); return NULL; }
+ virtual UserScriptMaster* GetUserScriptMaster() { NOTREACHED(); return NULL; }
+ virtual SSLHostState* GetSSLHostState() { NOTREACHED(); return NULL; }
+ virtual net::TransportSecurityState* GetTransportSecurityState() { NOTREACHED(); return NULL; }
+ virtual ExtensionsService* GetExtensionsService() { NOTREACHED(); return NULL; }
+ virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() { NOTREACHED(); return NULL; }
+ virtual ExtensionProcessManager* GetExtensionProcessManager() { NOTREACHED(); return NULL; }
+ virtual ExtensionMessageService* GetExtensionMessageService() { NOTREACHED(); return NULL; }
+ virtual FaviconService* GetFaviconService(ServiceAccessType sat) { NOTREACHED(); return NULL; }
+ virtual HistoryService* GetHistoryService(ServiceAccessType sat) { NOTREACHED(); return NULL; }
+ virtual HistoryService* GetHistoryServiceWithoutCreating() { NOTREACHED(); return NULL; }
+ virtual AutocompleteClassifier* GetAutocompleteClassifier() { NOTREACHED(); return NULL; }
+ virtual WebDataService* GetWebDataService(ServiceAccessType sat) { NOTREACHED(); return NULL; }
+ virtual WebDataService* GetWebDataServiceWithoutCreating() { NOTREACHED(); return NULL; }
+ virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) { NOTREACHED(); return NULL; }
+ virtual TemplateURLModel* GetTemplateURLModel() { NOTREACHED(); return NULL; }
+ virtual TemplateURLFetcher* GetTemplateURLFetcher() { NOTREACHED(); return NULL; }
+ virtual DownloadManager* GetDownloadManager() { NOTREACHED(); return NULL; }
+ virtual void InitThemes() { NOTREACHED(); }
+ virtual void SetTheme(Extension* extension) { NOTREACHED(); }
+ virtual void SetNativeTheme() { NOTREACHED(); }
+ virtual void ClearTheme() { NOTREACHED(); }
+ virtual Extension* GetTheme() { NOTREACHED(); return NULL; }
+ virtual BrowserThemeProvider* GetThemeProvider() { NOTREACHED(); return NULL; }
+ virtual bool HasCreatedDownloadManager() const { NOTREACHED(); return false; }
+ virtual URLRequestContextGetter* GetRequestContext() { NOTREACHED(); return NULL; }
+ virtual URLRequestContextGetter* GetRequestContextForMedia() { NOTREACHED(); return NULL; }
+ virtual URLRequestContextGetter* GetRequestContextForExtensions() { NOTREACHED(); return NULL; }
+ virtual void RegisterExtensionWithRequestContexts(Extension* extension) { NOTREACHED(); }
+ virtual void UnregisterExtensionWithRequestContexts(Extension* extension) { NOTREACHED(); }
+ virtual net::SSLConfigService* GetSSLConfigService() { NOTREACHED(); return NULL; }
+ virtual HostContentSettingsMap* GetHostContentSettingsMap() { NOTREACHED(); return NULL; }
+ virtual HostZoomMap* GetHostZoomMap() { NOTREACHED(); return NULL; }
+ virtual GeolocationContentSettingsMap* GetGeolocationContentSettingsMap() { NOTREACHED(); return NULL; }
+ virtual GeolocationPermissionContext* GetGeolocationPermissionContext() { NOTREACHED(); return NULL; }
+ virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() { NOTREACHED(); return NULL; }
+ virtual FindBarState* GetFindBarState() { NOTREACHED(); return NULL; }
+ virtual SessionService* GetSessionService() { NOTREACHED(); return NULL; }
+ virtual void ShutdownSessionService() { NOTREACHED(); }
+ virtual bool HasSessionService() const { NOTREACHED(); return false; }
+ virtual bool DidLastSessionExitCleanly() { NOTREACHED(); return true; }
+ virtual BookmarkModel* GetBookmarkModel() { NOTREACHED(); return NULL; }
+ virtual bool IsSameProfile(Profile* profile) { NOTREACHED(); return false; }
+ virtual base::Time GetStartTime() const { NOTREACHED(); return base::Time(); }
+ virtual TabRestoreService* GetTabRestoreService() { NOTREACHED(); return NULL; }
+ virtual void ResetTabRestoreService() { NOTREACHED(); }
+ virtual SpellCheckHost* GetSpellCheckHost() { NOTREACHED(); return NULL; }
+ virtual void ReinitializeSpellCheckHost(bool force) { NOTREACHED(); }
+ virtual WebKitContext* GetWebKitContext() { NOTREACHED(); return NULL; }
+ virtual DesktopNotificationService* GetDesktopNotificationService() { NOTREACHED(); return NULL; }
+ virtual BackgroundContentsService* GetBackgroundContentsService() { NOTREACHED(); return NULL; }
+ virtual void MarkAsCleanShutdown() { NOTREACHED(); }
+ virtual void InitExtensions() { NOTREACHED(); }
+ virtual void InitWebResources() { NOTREACHED(); }
+ virtual NTPResourceCache* GetNTPResourceCache() { NOTREACHED(); return NULL; }
+ virtual FilePath last_selected_directory() { NOTREACHED(); return FilePath(""); }
+ virtual void set_last_selected_directory(const FilePath& path) { NOTREACHED(); }
+ virtual ProfileSyncService* GetProfileSyncService() { NOTREACHED(); return NULL; }
+ virtual TokenService* GetTokenService() { NOTREACHED(); return NULL; }
+ void InitSyncService() { NOTREACHED(); }
+ virtual CloudPrintProxyService* GetCloudPrintProxyService() { NOTREACHED(); return NULL; }
+ void InitCloudPrintProxyService() { NOTREACHED(); }
+
+ private:
+ friend class Profile;
+
+ explicit ProfileImplAndroid(const FilePath& path);
+
+ void CreateWebDataService() { NOTREACHED(); }
+ FilePath GetPrefFilePath() { return path_; }
+
+ void CreatePasswordStore() { NOTREACHED(); }
+
+ void StopCreateSessionServiceTimer() { NOTREACHED(); }
+
+ void EnsureRequestContextCreated() {
+ GetRequestContext();
+ }
+
+ void EnsureSessionServiceCreated() {
+ GetSessionService();
+ }
+
+ FilePath path_;
+ scoped_ptr<PrefService> preferences_;
+ scoped_refptr<PersonalDataManager> personal_data_;
+
+ DISALLOW_COPY_AND_ASSIGN(ProfileImplAndroid);
+};
+
+#endif // CHROME_BROWSER_PROFILE_H_
diff --git a/android/autofill/url_fetcher_proxy.h b/android/autofill/url_fetcher_proxy.h
new file mode 100644
index 0000000..71864f4
--- /dev/null
+++ b/android/autofill/url_fetcher_proxy.h
@@ -0,0 +1,152 @@
+/*
+ * Copyright 2010, The Android Open Source Project
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef URL_FETCHER_PROXY_H_
+#define URL_FETCHER_PROXY_H_
+
+#include "android/autofill/android_url_request_context_getter.h"
+#include "android/autofill/profile_android.h"
+#include "base/thread.h"
+#include "common/net/url_fetcher.h"
+#include "net/url_request/url_request_status.h"
+#include <WebCoreSupport/autofill/MainThreadProxy.h>
+
+#define AUTOFILL_FETCHER_ID 1
+
+class URLFetcherProxy;
+
+// The URLFetcherProxy uses RunnableMethod to call functions on it in
+// another thread, but (since it's trying to behave like a URLFetcher)
+// isn't reference counted. This specialisation makes RunnableMethod
+// work with a non-reference-counted object by not manipulating the
+// reference counts.
+// TODO: Investigate alternatives to using RunnableMethod that don't
+// expect a ref counted object so we can remove this if possible.
+template <>
+struct RunnableMethodTraits<class URLFetcherProxy> {
+ void RetainCallee(URLFetcherProxy* obj) {
+ }
+
+ void ReleaseCallee(URLFetcherProxy* obj) {
+ }
+};
+
+// A class that implements the same API as URLFetcher but instead of
+// assuming that the calling thread is a chrome thread with a message
+// loop, it assumes the calling thread is WebKit's main
+// thread. Implemented as a wrapper round URLFetcher.
+// TODO: I think this can be improved as follows, which should reduce
+// our diff here and in autofill_download.cc as we'll be able to use
+// a URLFetcher base class pointer.
+// * Have URLFetcherProxy extend URLFetcher and URLFetcherDelegate
+// * Delete the Delegate inner class here
+// * Update the URLFetcher::Create factory method to return
+// a URLFetcherProxy on Android.
+class URLFetcherProxy : public URLFetcher::Delegate {
+public:
+ class Delegate {
+ public:
+ virtual ~Delegate() { };
+ // This will be called when the URL has been fetched, successfully or not.
+ // |response_code| is the HTTP response code (200, 404, etc.) if
+ // applicable. |url|, |status| and |data| are all valid until the
+ // URLFetcherProxy instance is destroyed.
+ virtual void OnURLFetchComplete(const URLFetcherProxy* source,
+ const GURL& url,
+ const URLRequestStatus& status,
+ int response_code,
+ const ResponseCookies& cookies,
+ const std::string& data) = 0;
+ };
+
+ URLFetcherProxy(const GURL& url, Delegate* d,
+ const std::string& upload_content)
+ : url_(url), d_(d), upload_content_(upload_content)
+ {
+ URLRequestContextGetter* con = Profile::GetDefaultRequestContext();
+ scoped_refptr<base::MessageLoopProxy> mlp = con->GetIOMessageLoopProxy();
+ // TODO: See the template specialisation at the top of the file. Can we use
+ // an alternative to RunnableMethod that doesn't expect a ref counted object?
+ mlp->PostTask(FROM_HERE, NewRunnableMethod(this, &URLFetcherProxy::DoStart));
+ };
+
+
+ virtual ~URLFetcherProxy()
+ {
+ delete real_fetcher_;
+ }
+
+ virtual void OnURLFetchComplete(const URLFetcher* source,
+ const GURL& url,
+ const URLRequestStatus& status,
+ int response_code,
+ const ResponseCookies& cookies,
+ const std::string& data)
+ {
+ url_ = url;
+ status_ = status;
+ response_code_ = response_code;
+ cookies_ = cookies;
+ data_ = data;
+ MainThreadProxy::CallOnMainThread(DoComplete, this);
+ }
+
+ net::HttpResponseHeaders* response_headers() const {return real_fetcher_->response_headers();};
+
+ // Returns the back-off delay before the request will be retried,
+ // when a 5xx response was received.
+ base::TimeDelta backoff_delay() const { return real_fetcher_->backoff_delay();};
+
+private:
+ void DoStart()
+ {
+ real_fetcher_ = URLFetcher::Create(AUTOFILL_FETCHER_ID, url_, URLFetcher::POST, this);
+ real_fetcher_->set_automatcally_retry_on_5xx(false);
+ real_fetcher_->set_request_context(ProfileImplAndroid::GetDefaultRequestContext());
+ real_fetcher_->set_upload_data("text/plain", upload_content_);
+ real_fetcher_->Start();
+ };
+
+ static void DoComplete(void* context)
+ {
+ URLFetcherProxy* that = (URLFetcherProxy*)context;
+ that->d_->OnURLFetchComplete(that, that->url_, that->status_,
+ that->response_code_, that->cookies_,
+ that->data_);
+ }
+
+ URLFetcher* real_fetcher_;
+ GURL url_;
+ Delegate* d_;
+ std::string upload_content_;
+
+ URLRequestStatus status_;
+ int response_code_;
+ ResponseCookies cookies_;
+ std::string data_;
+
+ DISALLOW_EVIL_CONSTRUCTORS(URLFetcherProxy);
+};
+
+#endif // URL_FETCHER_PROXY_H_