WebView Keishin Yokomaku (@KeithYokoma) / potatotips #45
View Slide
WebView Keishin Yokomaku2potatotips #45Drivemode, Inc. / Principal Engineer@KeithYokoma: GitHub / Twitter / Qiita / Tumblr / Stack Overflow
3WebView
WebView Կ͔ͱ᠘ͷଟ͍ WebView▸ Θ͔Δ▸ ੲSIGSEGVβϥͩͬͨཕݪͷΑ͏ͳͷ4potatotips #45
WebView ChromeCustomTabs ͕͋Δ͔Β WebView ͍Βͳ͍ࢠ▸ ͦΜͳ;͏ʹߟ͍͑ͯͨ࣌ظ͕Θͨ͠ʹ͋Γ·ͨ͠5potatotips #45
WebView ·ͩ WebView Ͱফ͍ͯ͠Δͷʁ▸ Θ͍ͨͯ͠͠·͢6potatotips #45
WebView ࠓͷ WebView ᠘Ϩγϐ▸ e.g. ๏తใΛ WebView Ͱදࣔ͢Δ▸ assets ʹ html Λஔ͍ͯ WebView ʹಡ·ͤΔ▸ ֎෦ϦϯΫ͕ͳ͚Ε࠷खܰʹࡁ·ͤΒΕΔ▸ ಉ͡ assets ͷ html ʹϦϯΫ͢Δ߹؆୯▸ e.g. file:///android_asset/privacy_policy.html7potatotips #45
WebView StrictMode▸ ThreadPolicy ͱ VmPolicy▸ ͋Γ͕ͪͳ࣮ͷؒҧ͍Λݕग़ͯ͠ϩάग़ྗΫϥογϡΛൃੜͤ͞Δ▸ ϝΠϯεϨουͰ I/O▸ Ϧιʔεͷ close Ε▸ ΧελϜ͢Δͱ͖ඞཁͳͷͯ͢Λ༗ޮʹ͢Δ▸ ༗ޮʹͯ͠ͳ͍ͷεϧʔ͞ΕΔ8potatotips #45
WebView Android Nougat ͷηΩϡϦςΟ༷▸ FileUriExposureException▸ File εΩʔϚͷ Uri Λ Intent ʹ͍Εͯڞ༗Ͱ͖ͳ͘ͳͬͨ▸ FileProvider ͷ ContentProvider Ͱڞ༗͢Δ▸ StrictMode ʹΦϓγϣϯ͕͋Δ▸ VmPolicy#penaltyDeathOnFileUriExposure()9potatotips #45
WebView WebView#loadUrl() ͷ༷▸ WebViewClient Λࢦఆͨ͠ͱ͖▸ shouldOverrideUrlLoading ͕ true: ΞϓϦͰಡΈࠐΈΛཧ▸ shouldOverrideUrlLoading ͕ false: WebView ͕ಡΈࠐΈΛཧ▸ WebViewClient Λࢦఆ͠ͳ͍ͱ͖▸ ActivityManager ʹ͍߹ΘͤͯదͳͷΛݺͼग़͢10potatotips #45
WebView WebView#loadUrl() ͷ༷▸ WebViewClient Λࢦఆͨ͠ͱ͖▸ shouldOverrideUrlLoading ͕ true: ΞϓϦͰಡΈࠐΈΛཧ▸ shouldOverrideUrlLoading ͕ false: WebView ͕ಡΈࠐΈΛཧ▸ WebViewClient Λࢦఆ͠ͳ͍ͱ͖▸ ActivityManager ʹ͍߹ΘͤͯదͳͷΛݺͼग़͢11potatotips #45
WebView ActivityManager ʹ͍߹ΘͤͯదͳͷΛݺͼग़͢▸ Intent Λ͛ͯϋϯυϧͯ͘͠ΕΔΞϓϦΛ୳͢▸ ଘࡏ͢ΕͦͪΒʹ͢▸ ଘࡏ͠ͳ͚Ε WebView ͕ϋϯυϧ͢Δ▸ ͍ͣΕʹͯ͠ Intent ʹಡΈࠐΉ Uri ͕٧Ίࠐ·ΕΔ12potatotips #45
WebView ActivityManager ʹ͍߹ΘͤͯదͳͷΛݺͼग़͢▸ Intent Λ͛ͯϋϯυϧͯ͘͠ΕΔΞϓϦΛ୳͢▸ ଘࡏ͢ΕͦͪΒʹ͢▸ ଘࡏ͠ͳ͚Ε WebView ͕ϋϯυϧ͢Δ▸ ͍ͣΕʹͯ͠ Intent ʹಡΈࠐΉ Uri ͕٧Ίࠐ·ΕΔ▸ file:///android_asset/hogehoge.html ͳϦϯΫΛ౿Ήͱ…13potatotips #45
14potatotips #45
WebView WebView Λ͏ͱ͖ͷڭ܇▸ WebViewClient Λ͖ͪΜͱ͍·͠ΐ͏▸ ֎෦ϦϯΫ JavaScript ͕ͳ͍͔ΒͱݴͬͯԿ͠ͳͯ͘Α͍Θ͚Ͱͳ͍15potatotips #45
WebView Keishin Yokomaku (@KeithYokoma) / DroidKaigi 2017
DrivemodeWe are hiring!17potatotips #45
DrivemodeWe are hiring!18potatotips #45
DroidKaigiDroidKaigi 2018 is coming soon!▸ Ticket:▸ Early Bird: 9,800 JPY▸ Regular: 12,000 JPY▸ Students: 4,000 JPY19potatotips #45