Home | History | Annotate | Download | only in autofill
      1 /*
      2  * Copyright 2010, The Android Open Source Project
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  *  * Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  *  * Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  *
     13  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
     14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #ifndef WebAutoFill_h
     27 #define WebAutoFill_h
     28 
     29 #if ENABLE(WEB_AUTOFILL)
     30 
     31 #include "ChromiumIncludes.h"
     32 
     33 #include <map>
     34 #include <vector>
     35 #include <wtf/Noncopyable.h>
     36 #include <wtf/OwnPtr.h>
     37 #include <wtf/ThreadingPrimitives.h>
     38 
     39 class AutofillManager;
     40 class AutofillProfile;
     41 class AutoFillHost;
     42 
     43 namespace WebCore {
     44 class Frame;
     45 class HTMLFormControlElement;
     46 }
     47 
     48 namespace android
     49 {
     50 class FormManager;
     51 class WebViewCore;
     52 
     53 class FormDataAndField {
     54 public:
     55     FormDataAndField(webkit_glue::FormData* form, webkit_glue::FormField* field)
     56         : mForm(form)
     57         , mField(field)
     58     {
     59     }
     60 
     61     webkit_glue::FormData* form() { return mForm.get(); }
     62     webkit_glue::FormField* field() { return mField.get(); }
     63 
     64 private:
     65     OwnPtr<webkit_glue::FormData> mForm;
     66     OwnPtr<webkit_glue::FormField> mField;
     67 };
     68 
     69 class WebAutofill
     70 {
     71     WTF_MAKE_NONCOPYABLE(WebAutofill);
     72 public:
     73     WebAutofill();
     74     virtual ~WebAutofill();
     75     void formFieldFocused(WebCore::HTMLFormControlElement*);
     76     void fillFormFields(int queryId);
     77     void querySuccessful(const string16& value, const string16& label, int uniqueId);
     78     void fillFormInPage(int queryId, const webkit_glue::FormData& form);
     79     void setWebViewCore(WebViewCore* webViewCore) { mWebViewCore = webViewCore; }
     80     bool enabled() const;
     81 
     82     void setProfile(const string16& fullName, const string16& emailAddress, const string16& companyName,
     83                     const string16& addressLine1, const string16& addressLine2, const string16& city,
     84                     const string16& state, const string16& zipCode, const string16& country, const string16& phoneNumber);
     85     void clearProfiles();
     86 
     87     bool updateProfileLabel();
     88 
     89     void reset() { mLastSearchDomVersion = 0; }
     90 
     91 private:
     92     void init();
     93     void searchDocument(WebCore::Frame*);
     94     void setEmptyProfile();
     95     void formsSeenImpl();
     96     void cleanUpQueryMap();
     97 
     98     OwnPtr<FormManager> mFormManager;
     99     OwnPtr<AutofillManager> mAutofillManager;
    100     OwnPtr<AutoFillHost> mAutofillHost;
    101     OwnPtr<TabContents> mTabContents;
    102     OwnPtr<AutofillProfile> mAutofillProfile;
    103 
    104     typedef std::vector<webkit_glue::FormData, std::allocator<webkit_glue::FormData> > FormList;
    105     FormList mForms;
    106 
    107     typedef std::map<int, FormDataAndField*> AutofillQueryFormDataMap;
    108     AutofillQueryFormDataMap mQueryMap;
    109 
    110     typedef std::map<int, int> AutofillQueryToUniqueIdMap;
    111     AutofillQueryToUniqueIdMap mUniqueIdMap;
    112     int mQueryId;
    113 
    114     WebViewCore* mWebViewCore;
    115 
    116     unsigned mLastSearchDomVersion;
    117 
    118     WTF::Mutex mFormsSeenMutex; // Guards mFormsSeenCondition and mParsingForms.
    119     WTF::ThreadCondition mFormsSeenCondition;
    120     bool volatile mParsingForms;
    121 };
    122 
    123 }
    124 
    125 DISABLE_RUNNABLE_METHOD_REFCOUNT(android::WebAutofill);
    126 
    127 #endif // ENABLE(WEB_AUTOFILL)
    128 #endif // WebAutoFill_h
    129