Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1710)

Unified Diff: content/public/android/java/src/org/chromium/content/browser/NfcFactory.java

Issue 2214383002: Move registration of Java mojo interfaces to the new InterfaceRegistrar. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@java-content-interface-registry
Patch Set: fix vr_shell build Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/public/android/java/src/org/chromium/content/browser/NfcFactory.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/NfcFactory.java b/content/public/android/java/src/org/chromium/content/browser/NfcFactory.java
new file mode 100644
index 0000000000000000000000000000000000000000..7a475f18a71b6027a38f7f0227cb0987efb80f13
--- /dev/null
+++ b/content/public/android/java/src/org/chromium/content/browser/NfcFactory.java
@@ -0,0 +1,61 @@
+// Copyright 2016 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.
+
+package org.chromium.content.browser;
+
+import android.app.Activity;
+
+import org.chromium.content_public.browser.WebContents;
+import org.chromium.device.nfc.NfcImpl;
+import org.chromium.device.nfc.mojom.Nfc;
+import org.chromium.services.shell.InterfaceFactory;
+import org.chromium.ui.base.WindowAndroid;
+
+class NfcFactory implements InterfaceFactory<Nfc> {
+ private final WebContents mContents;
+
+ NfcFactory(WebContents contents) {
+ mContents = contents;
+ }
+
+ private static class ContextAwareNfcImpl
+ extends NfcImpl implements WindowAndroidChangedObserver {
+ private final ContentViewCore mContentViewCore;
+
+ ContextAwareNfcImpl(ContentViewCore contentViewCore) {
+ super(contentViewCore.getContext().getApplicationContext());
+ mContentViewCore = contentViewCore;
+ mContentViewCore.addWindowAndroidChangedObserver(this);
+ if (mContentViewCore.getWindowAndroid() != null) {
+ setActivity(mContentViewCore.getWindowAndroid().getActivity().get());
+ }
+ }
+
+ @Override
+ public void close() {
+ super.close();
+ if (mContentViewCore != null) {
+ mContentViewCore.removeWindowAndroidChangedObserver(this);
+ }
+ }
+
+ @Override
+ public void onWindowAndroidChanged(WindowAndroid newWindowAndroid) {
+ Activity activity = null;
+ if (newWindowAndroid != null) {
+ activity = newWindowAndroid.getActivity().get();
+ }
+ setActivity(activity);
+ }
+ }
+
+ @Override
+ public Nfc createImpl() {
+ ContentViewCore contentViewCore = ContentViewCore.fromWebContents(mContents);
+ if (contentViewCore == null) {
+ return null;
+ }
+ return new ContextAwareNfcImpl(contentViewCore);
+ }
+}
« no previous file with comments | « content/public/android/java/src/org/chromium/content/browser/InterfaceRegistrarImpl.java ('k') | device/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698