diff options
Diffstat (limited to 'android_webview/browser')
-rw-r--r-- | android_webview/browser/DEPS | 1 | ||||
-rw-r--r-- | android_webview/browser/aw_autofill_manager_delegate.cc | 122 | ||||
-rw-r--r-- | android_webview/browser/aw_autofill_manager_delegate.h | 84 | ||||
-rw-r--r-- | android_webview/browser/aw_browser_context.cc | 15 | ||||
-rw-r--r-- | android_webview/browser/aw_browser_context.h | 4 | ||||
-rw-r--r-- | android_webview/browser/aw_pref_store.cc | 75 | ||||
-rw-r--r-- | android_webview/browser/aw_pref_store.h | 59 |
7 files changed, 358 insertions, 2 deletions
diff --git a/android_webview/browser/DEPS b/android_webview/browser/DEPS index 555efd1..c32e861 100644 --- a/android_webview/browser/DEPS +++ b/android_webview/browser/DEPS @@ -10,6 +10,7 @@ include_rules = [ "+components/autofill/browser", "+components/autofill/common", "+components/navigation_interception", + "+components/user_prefs", "+components/visitedlink/browser", "+components/webdata/common", diff --git a/android_webview/browser/aw_autofill_manager_delegate.cc b/android_webview/browser/aw_autofill_manager_delegate.cc new file mode 100644 index 0000000..30c5981 --- /dev/null +++ b/android_webview/browser/aw_autofill_manager_delegate.cc @@ -0,0 +1,122 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "android_webview/browser/aw_autofill_manager_delegate.h" +#include "android_webview/browser/aw_browser_context.h" +#include "android_webview/browser/aw_content_browser_client.h" +#include "android_webview/browser/aw_pref_store.h" +#include "base/logging.h" +#include "base/prefs/pref_registry_simple.h" +#include "base/prefs/pref_service.h" +#include "base/prefs/pref_service_builder.h" +#include "components/autofill/browser/autocheckout/whitelist_manager.h" +#include "components/autofill/browser/webdata/autofill_webdata_service.h" +#include "components/autofill/common/autofill_pref_names.h" +#include "components/user_prefs/user_prefs.h" + +namespace { + +// Shows notifications which correspond to PersistentPrefStore's reading errors. +void HandleReadError(PersistentPrefStore::PrefReadError error) { +} + +} + +namespace android_webview { + +AwAutofillManagerDelegate::AwAutofillManagerDelegate(bool enabled) { + PrefRegistrySimple* pref_registry = new PrefRegistrySimple(); + pref_registry->RegisterBooleanPref( + autofill::prefs::kAutofillEnabled, enabled); + pref_registry->RegisterDoublePref( + autofill::prefs::kAutofillPositiveUploadRate, 0.0); + pref_registry->RegisterDoublePref( + autofill::prefs::kAutofillNegativeUploadRate, 0.0); + + PrefServiceBuilder pref_service_builder; + pref_service_builder.WithUserPrefs(new AwPrefStore()); + pref_service_builder.WithReadErrorCallback(base::Bind(&HandleReadError)); + + AwBrowserContext* context = AwContentBrowserClient::GetAwBrowserContext(); + components::UserPrefs::Set(context, + pref_service_builder.Create(pref_registry)); +} + +AwAutofillManagerDelegate::~AwAutofillManagerDelegate() { } + +void AwAutofillManagerDelegate::SetSaveFormData(bool enabled) { + PrefService* service = GetPrefs(); + DCHECK(service); + service->SetBoolean(autofill::prefs::kAutofillEnabled, enabled); +} + +bool AwAutofillManagerDelegate::GetSaveFormData() { + PrefService* service = GetPrefs(); + DCHECK(service); + return service->GetBoolean(autofill::prefs::kAutofillEnabled); +} + +PrefService* AwAutofillManagerDelegate::GetPrefs() { + return components::UserPrefs::Get( + AwContentBrowserClient::GetAwBrowserContext()); +} + +autofill::PersonalDataManager* +AwAutofillManagerDelegate::GetPersonalDataManager() { + return NULL; +} + +autofill::autocheckout::WhitelistManager* +AwAutofillManagerDelegate::GetAutocheckoutWhitelistManager() const { + return NULL; +} + +void AwAutofillManagerDelegate::HideRequestAutocompleteDialog() { +} + +void AwAutofillManagerDelegate::OnAutocheckoutError() { +} + +void AwAutofillManagerDelegate::ShowAutofillSettings() { +} + +void AwAutofillManagerDelegate::ConfirmSaveCreditCard( + const autofill::AutofillMetrics& metric_logger, + const autofill::CreditCard& credit_card, + const base::Closure& save_card_callback) { +} + +void AwAutofillManagerDelegate::ShowAutocheckoutBubble( + const gfx::RectF& bounding_box, + bool is_google_user, + const base::Callback<void(bool)>& callback) { +} + +void AwAutofillManagerDelegate::HideAutocheckoutBubble() { +} + +void AwAutofillManagerDelegate::ShowRequestAutocompleteDialog( + const autofill::FormData& form, + const GURL& source_url, + autofill::DialogType dialog_type, + const base::Callback<void(const autofill::FormStructure*, + const std::string&)>& callback) { +} + +void AwAutofillManagerDelegate::ShowAutofillPopup( + const gfx::RectF& element_bounds, + const std::vector<string16>& values, + const std::vector<string16>& labels, + const std::vector<string16>& icons, + const std::vector<int>& identifiers, + base::WeakPtr<autofill::AutofillPopupDelegate> delegate) { +} + +void AwAutofillManagerDelegate::HideAutofillPopup() { +} + +void AwAutofillManagerDelegate::UpdateProgressBar(double value) { +} + +} // namespace android_webview diff --git a/android_webview/browser/aw_autofill_manager_delegate.h b/android_webview/browser/aw_autofill_manager_delegate.h new file mode 100644 index 0000000..80cc43a --- /dev/null +++ b/android_webview/browser/aw_autofill_manager_delegate.h @@ -0,0 +1,84 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ANDROID_WEBVIEW_BROWSER_AW_AUTOFILL_MANAGER_DELEGATE_H_ +#define ANDROID_WEBVIEW_BROWSER_AW_AUTOFILL_MANAGER_DELEGATE_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "base/prefs/pref_registry_simple.h" +#include "base/prefs/pref_service_builder.h" +#include "components/autofill/browser/autofill_manager_delegate.h" + +namespace autofill { +class AutofillMetrics; +class AutofillPopupDelegate; +class CreditCard; +class FormStructure; +class PasswordGenerator; +class PersonalDataManager; +struct FormData; +namespace autocheckout { +class WhitelistManager; +} +} + +namespace content { +class WebContents; +} + +class PersonalDataManager; +class PrefService; + +namespace android_webview { + +class AwAutofillManagerDelegate : + public autofill::AutofillManagerDelegate { + public: + AwAutofillManagerDelegate(bool enabled); + virtual ~AwAutofillManagerDelegate(); + + void SetSaveFormData(bool enabled); + bool GetSaveFormData(); + + // AutofillManagerDelegate implementation. + virtual autofill::PersonalDataManager* GetPersonalDataManager() OVERRIDE; + virtual PrefService* GetPrefs() OVERRIDE; + virtual autofill::autocheckout::WhitelistManager* + GetAutocheckoutWhitelistManager() const OVERRIDE; + virtual void HideRequestAutocompleteDialog() OVERRIDE; + virtual void OnAutocheckoutError() OVERRIDE; + virtual void ShowAutofillSettings() OVERRIDE; + virtual void ConfirmSaveCreditCard( + const autofill::AutofillMetrics& metric_logger, + const autofill::CreditCard& credit_card, + const base::Closure& save_card_callback) OVERRIDE; + virtual void ShowAutocheckoutBubble( + const gfx::RectF& bounds, + bool is_google_user, + const base::Callback<void(bool)>& callback) OVERRIDE; + virtual void HideAutocheckoutBubble() OVERRIDE; + virtual void ShowRequestAutocompleteDialog( + const autofill::FormData& form, + const GURL& source_url, + autofill::DialogType dialog_type, + const base::Callback<void(const autofill::FormStructure*, + const std::string&)>& callback) OVERRIDE; + virtual void ShowAutofillPopup( + const gfx::RectF& element_bounds, + const std::vector<string16>& values, + const std::vector<string16>& labels, + const std::vector<string16>& icons, + const std::vector<int>& identifiers, + base::WeakPtr<autofill::AutofillPopupDelegate> delegate) OVERRIDE; + virtual void HideAutofillPopup() OVERRIDE; + virtual void UpdateProgressBar(double value) OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(AwAutofillManagerDelegate); +}; + +} // namespace android_webview + +#endif // ANDROID_WEBVIEW_BROWSER_AW_AUTOFILL_MANAGER_DELEGATE_H_ diff --git a/android_webview/browser/aw_browser_context.cc b/android_webview/browser/aw_browser_context.cc index 1ecf9ec..9a4881d 100644 --- a/android_webview/browser/aw_browser_context.cc +++ b/android_webview/browser/aw_browser_context.cc @@ -100,8 +100,6 @@ AwQuotaManagerBridge* AwBrowserContext::GetQuotaManagerBridge() { return quota_manager_bridge_.get(); } -// TODO(sgurun) we may need to do this at the constructor, depending on -// how the rest of the implementation to enable autocomplete unwraps itself. AwFormDatabaseService* AwBrowserContext::GetFormDatabaseService() { if (!form_database_service_) { form_database_service_.reset( @@ -110,6 +108,19 @@ AwFormDatabaseService* AwBrowserContext::GetFormDatabaseService() { return form_database_service_.get(); } +AwAutofillManagerDelegate* AwBrowserContext::AutofillManagerDelegate() { + return autofill_manager_delegate_.get(); +} + +AwAutofillManagerDelegate* AwBrowserContext::CreateAutofillManagerDelegate( + bool enabled) { + if (!autofill_manager_delegate_) { + autofill_manager_delegate_.reset( + new AwAutofillManagerDelegate(enabled)); + } + return autofill_manager_delegate_.get(); +} + base::FilePath AwBrowserContext::GetPath() { return context_storage_path_; } diff --git a/android_webview/browser/aw_browser_context.h b/android_webview/browser/aw_browser_context.h index 177c612..98476a4 100644 --- a/android_webview/browser/aw_browser_context.h +++ b/android_webview/browser/aw_browser_context.h @@ -7,6 +7,7 @@ #include <vector> +#include "android_webview/browser/aw_autofill_manager_delegate.h" #include "android_webview/browser/aw_download_manager_delegate.h" #include "base/basictypes.h" #include "base/compiler_specific.h" @@ -69,6 +70,8 @@ class AwBrowserContext : public content::BrowserContext, AwQuotaManagerBridge* GetQuotaManagerBridge(); AwFormDatabaseService* GetFormDatabaseService(); + AwAutofillManagerDelegate* AutofillManagerDelegate(); + AwAutofillManagerDelegate* CreateAutofillManagerDelegate(bool enabled); // content::BrowserContext implementation. virtual base::FilePath GetPath() OVERRIDE; @@ -105,6 +108,7 @@ class AwBrowserContext : public content::BrowserContext, geolocation_permission_context_; scoped_ptr<AwQuotaManagerBridge> quota_manager_bridge_; scoped_ptr<AwFormDatabaseService> form_database_service_; + scoped_ptr<AwAutofillManagerDelegate> autofill_manager_delegate_; AwDownloadManagerDelegate download_manager_delegate_; diff --git a/android_webview/browser/aw_pref_store.cc b/android_webview/browser/aw_pref_store.cc new file mode 100644 index 0000000..613a847 --- /dev/null +++ b/android_webview/browser/aw_pref_store.cc @@ -0,0 +1,75 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "android_webview/browser/aw_pref_store.h" + +#include "base/memory/scoped_ptr.h" +#include "base/values.h" + +AwPrefStore::AwPrefStore() {} + +AwPrefStore::~AwPrefStore() {} + +bool AwPrefStore::GetValue(const std::string& key, + const Value** value) const { + return prefs_.GetValue(key, value); +} + +bool AwPrefStore::GetMutableValue(const std::string& key, + Value** value) { + return prefs_.GetValue(key, value); +} + +void AwPrefStore::AddObserver(PrefStore::Observer* observer) { + observers_.AddObserver(observer); +} + +void AwPrefStore::RemoveObserver(PrefStore::Observer* observer) { + observers_.RemoveObserver(observer); +} + +size_t AwPrefStore::NumberOfObservers() const { + return observers_.size(); +} + +bool AwPrefStore::IsInitializationComplete() const { + return true; +} + +void AwPrefStore::SetValue(const std::string& key, Value* value) { + DCHECK(value); + if (prefs_.SetValue(key, value)) + ReportValueChanged(key); +} + +void AwPrefStore::SetValueSilently(const std::string& key, Value* value) { + prefs_.SetValue(key, value); +} + +void AwPrefStore::RemoveValue(const std::string& key) { + if (prefs_.RemoveValue(key)) + ReportValueChanged(key); +} + +void AwPrefStore::MarkNeedsEmptyValue(const std::string& key) { +} + +bool AwPrefStore::ReadOnly() const { + return false; +} + +PersistentPrefStore::PrefReadError AwPrefStore::GetReadError() const { + return PersistentPrefStore::PREF_READ_ERROR_NONE; +} + +PersistentPrefStore::PrefReadError AwPrefStore::ReadPrefs() { + return PersistentPrefStore::PREF_READ_ERROR_NONE; +} + +void AwPrefStore::ReadPrefsAsync(ReadErrorDelegate* error_delegate_raw) { +} + +void AwPrefStore::ReportValueChanged(const std::string& key) { + FOR_EACH_OBSERVER(Observer, observers_, OnPrefValueChanged(key)); +} diff --git a/android_webview/browser/aw_pref_store.h b/android_webview/browser/aw_pref_store.h new file mode 100644 index 0000000..e636e1b --- /dev/null +++ b/android_webview/browser/aw_pref_store.h @@ -0,0 +1,59 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ANDROID_WEBVIEW_BROWSER_AW_PREF_STORE_H_ +#define ANDROID_WEBVIEW_BROWSER_AW_PREF_STORE_H_ + +#include <string> + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "base/observer_list.h" +#include "base/prefs/persistent_pref_store.h" +#include "base/prefs/pref_value_map.h" + +// A light-weight prefstore implementation that keeps preferences +// in a memory backed store. This is not a persistent prefstore -- we +// subclass the PersistentPrefStore here since it is needed by the +// PrefService, which in turn is needed by the Autofill component. +class AwPrefStore : public PersistentPrefStore { + public: + AwPrefStore(); + + // Overriden from PrefStore. + virtual bool GetValue(const std::string& key, + const base::Value** result) const OVERRIDE; + virtual void AddObserver(PrefStore::Observer* observer) OVERRIDE; + virtual void RemoveObserver(PrefStore::Observer* observer) OVERRIDE; + virtual size_t NumberOfObservers() const OVERRIDE; + virtual bool IsInitializationComplete() const OVERRIDE; + + // PersistentPrefStore overrides: + virtual bool GetMutableValue(const std::string& key, + base::Value** result) OVERRIDE; + virtual void ReportValueChanged(const std::string& key) OVERRIDE; + virtual void SetValue(const std::string& key, base::Value* value) OVERRIDE; + virtual void SetValueSilently(const std::string& key, + base::Value* value) OVERRIDE; + virtual void RemoveValue(const std::string& key) OVERRIDE; + virtual void MarkNeedsEmptyValue(const std::string& key) OVERRIDE; + virtual bool ReadOnly() const OVERRIDE; + virtual PrefReadError GetReadError() const OVERRIDE; + virtual PersistentPrefStore::PrefReadError ReadPrefs() OVERRIDE; + virtual void ReadPrefsAsync(ReadErrorDelegate* error_delegate) OVERRIDE; + virtual void CommitPendingWrite() OVERRIDE {} + + protected: + virtual ~AwPrefStore(); + + private: + // Stores the preference values. + PrefValueMap prefs_; + + ObserverList<PrefStore::Observer, true> observers_; + + DISALLOW_COPY_AND_ASSIGN(AwPrefStore); +}; + +#endif // ANDROID_WEBVIEW_BROWSER_AW_PREF_STORE_H_ |