Internal version of Binder.withSource for establishing a trusted ElementSource chain for source-restricting bindings that are re-written using Element#applyTo. Using Binder.withSource is not trustworthy because it's a public API that external users can use to spoof the original ElementSo
(
GuiceInternal guiceInternal, Binder binder, Object source)
| 134 | * @since 5.0 |
| 135 | */ |
| 136 | public static Binder withTrustedSource( |
| 137 | GuiceInternal guiceInternal, Binder binder, Object source) { |
| 138 | checkNotNull(guiceInternal); |
| 139 | if (binder instanceof RecordingBinder) { |
| 140 | return ((RecordingBinder) binder).withTrustedSource(source); |
| 141 | } |
| 142 | // Preserve existing (untrusted) behavior for non-standard Binder implementations. |
| 143 | return binder.withSource(source); |
| 144 | } |
| 145 | |
| 146 | private static class ElementsAsModule implements Module { |
| 147 | private final Iterable<? extends Element> elements; |