• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_GENERATION_AGENT_H_
6 #define COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_GENERATION_AGENT_H_
7 
8 #include <map>
9 #include <utility>
10 #include <vector>
11 
12 #include "base/memory/scoped_ptr.h"
13 #include "content/public/renderer/render_view_observer.h"
14 #include "third_party/WebKit/public/web/WebInputElement.h"
15 #include "third_party/WebKit/public/web/WebPasswordGeneratorClient.h"
16 #include "url/gurl.h"
17 
18 namespace blink {
19 class WebCString;
20 class WebDocument;
21 }
22 
23 namespace autofill {
24 
25 struct FormData;
26 struct PasswordForm;
27 
28 // This class is responsible for controlling communication for password
29 // generation between the browser (which shows the popup and generates
30 // passwords) and WebKit (shows the generation icon in the password field).
31 class PasswordGenerationAgent : public content::RenderViewObserver,
32                                 public blink::WebPasswordGeneratorClient {
33  public:
34   explicit PasswordGenerationAgent(content::RenderView* render_view);
35   virtual ~PasswordGenerationAgent();
36 
37  protected:
38   // Returns true if this document is one that we should consider analyzing.
39   // Virtual so that it can be overriden during testing.
40   virtual bool ShouldAnalyzeDocument(const blink::WebDocument& document) const;
41 
42   // RenderViewObserver:
43   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
44 
45  private:
46   // RenderViewObserver:
47   virtual void DidFinishDocumentLoad(blink::WebFrame* frame) OVERRIDE;
48   virtual void DidFinishLoad(blink::WebFrame* frame) OVERRIDE;
49 
50   // WebPasswordGeneratorClient:
51   virtual void openPasswordGenerator(blink::WebInputElement& element) OVERRIDE;
52 
53   // Message handlers.
54   void OnFormNotBlacklisted(const PasswordForm& form);
55   void OnPasswordAccepted(const base::string16& password);
56   void OnAccountCreationFormsDetected(
57       const std::vector<autofill::FormData>& forms);
58 
59   // Helper function to decide whether we should show password generation icon.
60   void MaybeShowIcon();
61 
62   content::RenderView* render_view_;
63 
64   // Stores the origin of the account creation form we detected.
65   scoped_ptr<PasswordForm> possible_account_creation_form_;
66 
67   // Stores the origins of the password forms confirmed not to be blacklisted
68   // by the browser. A form can be blacklisted if a user chooses "never save
69   // passwords for this site".
70   std::vector<GURL> not_blacklisted_password_form_origins_;
71 
72   // Stores each password form for which the Autofill server classifies one of
73   // the form's fields as an ACCOUNT_CREATION_PASSWORD. These forms will
74   // not be sent if the feature is disabled.
75   std::vector<autofill::FormData> generation_enabled_forms_;
76 
77   std::vector<blink::WebInputElement> passwords_;
78 
79   DISALLOW_COPY_AND_ASSIGN(PasswordGenerationAgent);
80 };
81 
82 }  // namespace autofill
83 
84 #endif  // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_GENERATION_AGENT_H_
85