| 1115 | } |
| 1116 | |
| 1117 | fn webkit_target( |
| 1118 | udid: &str, |
| 1119 | http_origin: &str, |
| 1120 | page: WebKitPage, |
| 1121 | app: Option<&WebKitApplication>, |
| 1122 | ) -> WebKitTarget { |
| 1123 | let id = encode_target_id(&page.app_id, page.page_id); |
| 1124 | let web_socket_url = format!("/api/simulators/{udid}/webkit/targets/{id}/socket"); |
| 1125 | let absolute_ws = websocket_url(http_origin, &web_socket_url); |
| 1126 | let inspector_url = format!( |
| 1127 | "/webkit-inspector-ui/Main.html?ws={}", |
| 1128 | absolute_ws |
| 1129 | .trim_start_matches("ws://") |
| 1130 | .trim_start_matches("wss://") |
| 1131 | ); |
| 1132 | let app_name = app.and_then(|app| app.name.clone()); |
| 1133 | let app_active = app.map(|app| app.active).unwrap_or(false); |
| 1134 | let normalized_app_id = page.app_id.to_ascii_lowercase(); |
| 1135 | let normalized_app_name = app_name.as_deref().map(str::to_ascii_lowercase); |
| 1136 | let normalized_bundle_id = app |
| 1137 | .and_then(|app| app.bundle_identifier.as_deref()) |
| 1138 | .map(str::to_ascii_lowercase); |
| 1139 | let kind = if normalized_app_id.contains("mobilesafari") |
| 1140 | || normalized_app_name.as_deref() == Some("safari") |
| 1141 | || normalized_bundle_id.as_deref() == Some("com.apple.mobilesafari") |
| 1142 | { |
| 1143 | "safari-page" |
| 1144 | } else if app.is_some_and(|app| app.is_proxy) { |
| 1145 | "web-content-proxy" |
| 1146 | } else { |
| 1147 | "app-web-content" |
| 1148 | } |
| 1149 | .to_owned(); |
| 1150 | |
| 1151 | WebKitTarget { |
| 1152 | id, |
| 1153 | app_id: page.app_id, |
| 1154 | app_name, |
| 1155 | app_active, |
| 1156 | page_active: false, |
| 1157 | page_id: page.page_id, |
| 1158 | title: page.title, |
| 1159 | url: page.url, |
| 1160 | kind, |
| 1161 | inspector_url, |
| 1162 | web_socket_url, |
| 1163 | } |
| 1164 | } |
| 1165 | |
| 1166 | fn websocket_url(http_origin: &str, path: &str) -> String { |
| 1167 | if http_origin.starts_with("https://") { |