WebView😇😇😇

 WebView😇😇😇

Bbe9718bebdafbdc8dabbe3cadf1bc46?s=128

Keishin Yokomaku

November 28, 2017
Tweet

Transcript

  1. WebView Keishin Yokomaku (@KeithYokoma) / potatotips #45

  2. WebView Keishin Yokomaku 2 potatotips #45 Drivemode, Inc. / Principal

    Engineer @KeithYokoma: GitHub / Twitter / Qiita / Tumblr / Stack Overflow
  3. 3 WebView

  4. WebView Կ͔ͱ᠘ͷଟ͍ WebView ▸ Θ͔Δ ▸ ੲ͸SIGSEGV΋βϥͩͬͨ஍ཕݪͷΑ͏ͳ΋ͷ 4 potatotips #45

  5. WebView ChromeCustomTabs ͕͋Δ͔Β WebView ͸͍Βͳ͍ࢠ ▸ ͦΜͳ;͏ʹߟ͍͑ͯͨ࣌ظ͕Θͨ͠ʹ΋͋Γ·ͨ͠ 5 potatotips #45

  6. WebView ·ͩ WebView Ͱফ໣͍ͯ͠Δͷʁ ▸ Θͨ͠͸͍ͯ͠·͢ 6 potatotips #45

  7. WebView ࠓ೔ͷ WebView ᠘Ϩγϐ ▸ e.g. ๏త৘ใΛ WebView Ͱදࣔ͢Δ ▸

    assets ʹ html Λஔ͍ͯ WebView ʹಡ·ͤΔ ▸ ֎෦ϦϯΫ͕ͳ͚Ε͹࠷΋खܰʹࡁ·ͤΒΕΔ ▸ ಉ͡ assets ಺ͷ html ʹϦϯΫ͢Δ৔߹΋؆୯ ▸ e.g. file:///android_asset/privacy_policy.html 7 potatotips #45
  8. WebView StrictMode ▸ ThreadPolicy ͱ VmPolicy ▸ ͋Γ͕ͪͳ࣮૷ͷؒҧ͍Λݕग़ͯ͠ϩάग़ྗ΍ΫϥογϡΛൃੜͤ͞Δ ▸ ϝΠϯεϨουͰ

    I/O ▸ Ϧιʔεͷ close ๨Ε ▸ ΧελϜ͢Δͱ͖͸ඞཁͳ΋ͷ͢΂ͯΛ༗ޮʹ͢Δ ▸ ༗ޮʹͯ͠ͳ͍΋ͷ͸εϧʔ͞ΕΔ 8 potatotips #45
  9. WebView Android Nougat ͷηΩϡϦςΟ࢓༷ ▸ FileUriExposureException ▸ File εΩʔϚͷ Uri

    Λ Intent ʹ͍Εͯڞ༗Ͱ͖ͳ͘ͳͬͨ ▸ FileProvider ౳ͷ ContentProvider Ͱڞ༗͢Δ ▸ StrictMode ʹ΋Φϓγϣϯ͕͋Δ ▸ VmPolicy#penaltyDeathOnFileUriExposure() 9 potatotips #45
  10. WebView WebView#loadUrl() ͷ࢓༷ ▸ WebViewClient Λࢦఆͨ͠ͱ͖ ▸ shouldOverrideUrlLoading ͕ true:

    ΞϓϦͰಡΈࠐΈΛ؅ཧ ▸ shouldOverrideUrlLoading ͕ false: WebView ͕ಡΈࠐΈΛ؅ཧ ▸ WebViewClient Λࢦఆ͠ͳ͍ͱ͖ ▸ ActivityManager ʹ໰͍߹Θͤͯద੾ͳ΋ͷΛݺͼग़͢ 10 potatotips #45
  11. WebView WebView#loadUrl() ͷ࢓༷ ▸ WebViewClient Λࢦఆͨ͠ͱ͖ ▸ shouldOverrideUrlLoading ͕ true:

    ΞϓϦͰಡΈࠐΈΛ؅ཧ ▸ shouldOverrideUrlLoading ͕ false: WebView ͕ಡΈࠐΈΛ؅ཧ ▸ WebViewClient Λࢦఆ͠ͳ͍ͱ͖ ▸ ActivityManager ʹ໰͍߹Θͤͯద੾ͳ΋ͷΛݺͼग़͢ 11 potatotips #45
  12. WebView ActivityManager ʹ໰͍߹Θͤͯద੾ͳ΋ͷΛݺͼग़͢ ▸ Intent Λ౤͛ͯϋϯυϧͯ͘͠ΕΔΞϓϦΛ୳͢ ▸ ଘࡏ͢Ε͹ͦͪΒʹ౉͢ ▸ ଘࡏ͠ͳ͚Ε͹

    WebView ͕ϋϯυϧ͢Δ ▸ ͍ͣΕʹͯ͠΋ Intent ʹಡΈࠐΉ Uri ͕٧Ίࠐ·ΕΔ 12 potatotips #45
  13. WebView ActivityManager ʹ໰͍߹Θͤͯద੾ͳ΋ͷΛݺͼग़͢ ▸ Intent Λ౤͛ͯϋϯυϧͯ͘͠ΕΔΞϓϦΛ୳͢ ▸ ଘࡏ͢Ε͹ͦͪΒʹ౉͢ ▸ ଘࡏ͠ͳ͚Ε͹

    WebView ͕ϋϯυϧ͢Δ ▸ ͍ͣΕʹͯ͠΋ Intent ʹಡΈࠐΉ Uri ͕٧Ίࠐ·ΕΔ ▸ file:///android_asset/hogehoge.html ͳϦϯΫΛ౿Ήͱ… 13 potatotips #45
  14. 14 potatotips #45

  15. WebView WebView Λ࢖͏ͱ͖ͷڭ܇ ▸ WebViewClient Λ͖ͪΜͱ࢖͍·͠ΐ͏ ▸ ֎෦ϦϯΫ΍ JavaScript ͕ͳ͍͔ΒͱݴͬͯԿ΋͠ͳͯ͘Α͍Θ͚Ͱ͸ͳ͍

    15 potatotips #45
  16. WebView Keishin Yokomaku (@KeithYokoma) / DroidKaigi 2017

  17. Drivemode We are hiring! 17 potatotips #45

  18. Drivemode We are hiring! 18 potatotips #45

  19. DroidKaigi DroidKaigi 2018 is coming soon! ▸ Ticket: ▸ Early

    Bird: 9,800 JPY ▸ Regular: 12,000 JPY ▸ Students: 4,000 JPY 19 potatotips #45