Chromium Code Reviews
Description[Device Service] Decouple NFC implementation from //content
This CL ports the NFC implementation from being hosted by //content
to being hosted by the Device Service. This task is challenging because
the NFC implementation needs access to the Activity of the WebContents
that is associated with the requesting render frame. Moreore, that
Activity can change if the WebContents is reparented (e.g., moved from
being in a custom tab to being in Chrome by the user).
To handle these challenges, this CL takes a similar approach to that
taken for WakeLock: information is passed to the Device Service that
allows the NFC implementation to map a host ID to the Activity associated
with that ID. Specifically:
- The NFCProvider Mojo interface is introduced. It supports connecting to
an NFC instance associated with a given host ID.
- The NFCDelegate.java interface is introduced. This interface supports
mapping from host IDs to Activity, including tracking when the Activity
associated with a host ID changes. This interface is passed into the
Device Service by its embedder.
- NfcImpl.java uses the NFCDelegate to access the Activity that it needs.
- //content provides a ContentNFCDelegate implementation. This implementation
maps host IDs to WebContents instances via an NfcHost internal helper
class.
- //content/browser now handles requests to connect to NFC by forwarding
them on to the Device Service (i.e., NFCProvider), passing the host
ID associated with the WebContents in question in order to allow the
NFC implementation to map back to that WebContents via NFCDelegate.
The net sum of the above is that //content's dependence on the NFC
implementation is removed.
Note that in addition to the below-described test, I also tested reparenting as
follows:
- Close Chromium on the device
- On the host, execute:
adb shell "am start -a 'android.intent.action.VIEW' -n org.chromium.chrome/com.google.android.apps.chrome.Main -d https://colinblundell.github.io/nfc.html --es \"android.support.customtabs.extra.SESSION\" \"bla\""
- On the phone, you should see a custom tab pop up. Push a message.
- Reparent the tab by tapping "Open in Chromium." Verify that the tab was
reparented, i.e., there was no reload operation.
- Bring the device close to the NFC tag and verify that you see "Message
pushed" on the webpage.
BUG=680924
TEST=On Chrome on Android, go to about://flags and turn on "Experimental Web
Platform features" and "WebNFC Android". Restart Chrome. Obtain a physical
NFC tag. Go to https://colinblundell.github.io/nfc.html and verify that the
page says "NFC API found". Enter a message on the webpage and press "Push
message to tag". Bring the phone near the tag and verifiy that the page outputs
"Message pushed." Press "Read data from tag", bring the phone near the tag,
and verify that the webpage outputs the message that you just pushed to the
tag.
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_site_isolation
Review-Url: https://codereview.chromium.org/2865653002
Cr-Commit-Position: refs/heads/master@{#471727}
Committed: https://chromium.googlesource.com/chromium/src/+/f5316fccc7bac30a357a1254aef8dc4a605bc045
Patch Set 1 #Patch Set 2 : Self-review #Patch Set 3 : More self-review #Patch Set 4 : Move code to NfcHost.java constructor now that it's possible #Patch Set 5 : Stab at fixing NFCTest #Patch Set 6 : extra fix #
Total comments: 6
Patch Set 7 : Rebase #Patch Set 8 : Response to review + fix for tests that don't actually run on bots #
Total comments: 4
Patch Set 9 : Response to reviews #
Total comments: 25
Patch Set 10 : Rebase #Patch Set 11 : Response to review #
Total comments: 6
Patch Set 12 : Response to review #Patch Set 13 : Rebase #Depends on Patchset: Messages
Total messages: 51 (39 generated)
|