summaryrefslogtreecommitdiff
path: root/chromium/content/browser/android/nfc_host.h
blob: 1d203274b6f7d4131152fc7353de0b236f6fd541 (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
// Copyright 2017 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 CONTENT_BROWSER_ANDROID_NFC_HOST_H_
#define CONTENT_BROWSER_ANDROID_NFC_HOST_H_

#include "base/android/jni_android.h"
#include "content/public/browser/permission_controller.h"
#include "content/public/browser/web_contents_observer.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/device/public/mojom/nfc_provider.mojom.h"
#include "third_party/blink/public/mojom/permissions/permission_status.mojom-forward.h"

namespace content {

class PermissionControllerImpl;

// On Android, NFC requires the Activity associated with the context in order to
// access the NFC system APIs. NFCHost provides this functionality by mapping
// NFC context IDs to the WebContents associated with those IDs.
class NFCHost : public WebContentsObserver {
 public:
  explicit NFCHost(WebContents* web_contents);
  ~NFCHost() override;

  void GetNFC(RenderFrameHost* render_frame_host,
              mojo::PendingReceiver<device::mojom::NFC> receiver);

  // WebContentsObserver implementation.
  void RenderFrameHostChanged(RenderFrameHost* old_host,
                              RenderFrameHost* new_host) override;

  // WebContentsObserver implementation.
  void OnVisibilityChanged(Visibility visibility) override;

 private:
  void OnPermissionStatusChange(blink::mojom::PermissionStatus status);
  void Close();

  // The permission controller for this browser context.
  PermissionControllerImpl* permission_controller_;

  mojo::Remote<device::mojom::NFCProvider> nfc_provider_;

  // Permission change subscription ID provided by |permission_controller_|.
  int subscription_id_ = PermissionController::kNoPendingOperation;

  DISALLOW_COPY_AND_ASSIGN(NFCHost);
};

}  // namespace content

#endif  // CONTENT_BROWSER_ANDROID_NFC_HOST_H_