refactor: Define a protocol for scheme-handling plugins #1479
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Platforms affected
iOS
Motivation and Context
Existing behaviour for plugins to opt-in to handling custom scheme resource loads was not documented and there were some unsafe assumptions around only a single plugin handling all requests.
Description
Add a
CDVPluginSchemeHandler
protocol to allow plugins to declare that they want to intercept WebKit resource loads.We don't rely on the protocol itself being implemented by the plugins (we continue to check with
-respondsToSelector:
) but this allows us to avoidobjc_msgSend
and provides a way to document some of this plugin behaviour that is not otherwise explained.Also, use a
NSMapTable
to associate plugin instances with the request being handled. Since we loop over the plugins, there's a chance that multiple plugins might want to handle different requests (which sounds like a logistical nightmare, but it's definitely possible). Now we keep a map of which plugin is handling each request so that we can make sure the right plugin gets called when the resource load is cancelled.NSMapTable
uses weak associations, so when the task is done and released, the key and value will be dropped from the table automatically.This should also resolve the unsafe plugin iteration issue that was mentioned in GH-1272 and GH-1030 by always iterating over an array of plugin objects that is a copy (due to calling
-allValues
).Testing
Existing tests pass. Tested manually in simulator with custom scheme.
Checklist