summaryrefslogtreecommitdiff
path: root/chromium/weblayer/browser/password_manager_driver_factory.h
blob: b29d46960c4a9bfd187e3a28d6142a01b85bb8c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2020 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 WEBLAYER_BROWSER_PASSWORD_MANAGER_DRIVER_FACTORY_H_
#define WEBLAYER_BROWSER_PASSWORD_MANAGER_DRIVER_FACTORY_H_

#include <map>

#include "base/supports_user_data.h"
#include "components/autofill/content/common/mojom/autofill_driver.mojom.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"

namespace content {
class WebContents;
}

namespace weblayer {

// WebLayer uses the system autofill and not the autofill used by Chrome. This
// factory and the corresponding driver are only used to listen for the
// notification that a password was typed into a form, since this is used as a
// signal to start isolating that site.
// TODO(crbug.com/1088446): Find a way to easily share this with Chrome.
class PasswordManagerDriverFactory
    : public content::WebContentsObserver,
      public content::WebContentsUserData<PasswordManagerDriverFactory> {
 public:
  ~PasswordManagerDriverFactory() override;

  PasswordManagerDriverFactory(const PasswordManagerDriverFactory&) = delete;
  PasswordManagerDriverFactory& operator=(const PasswordManagerDriverFactory&) =
      delete;

  static void BindPasswordManagerDriver(
      mojo::PendingAssociatedReceiver<autofill::mojom::PasswordManagerDriver>
          pending_receiver,
      content::RenderFrameHost* render_frame_host);

 private:
  class PasswordManagerDriver;
  friend class content::WebContentsUserData<PasswordManagerDriverFactory>;

  explicit PasswordManagerDriverFactory(content::WebContents* web_contents);

  // content::WebContentsObserver:
  void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;

  PasswordManagerDriver* GetDriverForFrame(
      content::RenderFrameHost* render_frame_host);

  std::map<content::RenderFrameHost*, PasswordManagerDriver> frame_driver_map_;

  WEB_CONTENTS_USER_DATA_KEY_DECL();
};

}  // namespace weblayer

#endif  // WEBLAYER_BROWSER_PASSWORD_MANAGER_DRIVER_FACTORY_H_