(
env: &mut JNIEnv,
cfg: JObject,
)
| 68 | } |
| 69 | |
| 70 | fn build_inliner( |
| 71 | env: &mut JNIEnv, |
| 72 | cfg: JObject, |
| 73 | ) -> Result<CSSInliner<'static>, Error<css_inline::ParseError>> { |
| 74 | let inline_style_tags = env.get_bool_field(&cfg, "inlineStyleTags")?; |
| 75 | let keep_style_tags = env.get_bool_field(&cfg, "keepStyleTags")?; |
| 76 | let keep_link_tags = env.get_bool_field(&cfg, "keepLinkTags")?; |
| 77 | let keep_at_rules = env.get_bool_field(&cfg, "keepAtRules")?; |
| 78 | let minify_css = env.get_bool_field(&cfg, "minifyCss")?; |
| 79 | let load_remote_stylesheets = env.get_bool_field(&cfg, "loadRemoteStylesheets")?; |
| 80 | let cache_size = env.get_int_field(&cfg, "cacheSize")?; |
| 81 | let preallocate_node_capacity = env.get_int_field(&cfg, "preallocateNodeCapacity")?; |
| 82 | let remove_inlined_selectors = env.get_bool_field(&cfg, "removeInlinedSelectors")?; |
| 83 | let apply_width_attributes = env.get_bool_field(&cfg, "applyWidthAttributes")?; |
| 84 | let apply_height_attributes = env.get_bool_field(&cfg, "applyHeightAttributes")?; |
| 85 | |
| 86 | let extra_css = env.get_string_field_opt(&cfg, "extraCss")?; |
| 87 | let base_url = env.get_string_field_opt(&cfg, "baseUrl")?; |
| 88 | let mut builder = CSSInliner::options() |
| 89 | .inline_style_tags(inline_style_tags) |
| 90 | .keep_style_tags(keep_style_tags) |
| 91 | .keep_link_tags(keep_link_tags) |
| 92 | .keep_at_rules(keep_at_rules) |
| 93 | .minify_css(minify_css) |
| 94 | .load_remote_stylesheets(load_remote_stylesheets) |
| 95 | .extra_css(extra_css.map(Cow::Owned)) |
| 96 | .preallocate_node_capacity(preallocate_node_capacity as usize) |
| 97 | .remove_inlined_selectors(remove_inlined_selectors) |
| 98 | .apply_width_attributes(apply_width_attributes) |
| 99 | .apply_height_attributes(apply_height_attributes); |
| 100 | |
| 101 | if let Some(url) = base_url { |
| 102 | match css_inline::Url::parse(&url) { |
| 103 | Ok(url) => { |
| 104 | builder = builder.base_url(Some(url)); |
| 105 | } |
| 106 | Err(error) => return Err(Error::Other(error)), |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | if cache_size > 0 { |
| 111 | builder = builder.cache(StylesheetCache::new( |
| 112 | NonZeroUsize::new(cache_size as usize).expect("Cache size is not null"), |
| 113 | )); |
| 114 | } |
| 115 | |
| 116 | Ok(builder.build()) |
| 117 | } |
| 118 | |
| 119 | fn throw(mut env: JNIEnv, message: String) -> jstring { |
| 120 | let exception = env |
no test coverage detected