parseHTML function
Implementation
Future<void> parseHTML(double contextId, Uint8List codeBytes, {String? url}) async {
Completer completer = Completer();
final controller = WebFController.getControllerOfJSContextId(contextId);
if (controller == null) {
return;
}
// Pre-validate HTML content
if (codeBytes.isEmpty) {
// Empty HTML is valid, just return
completer.complete();
return completer.future;
}
// Check for excessive size (100MB limit)
if (codeBytes.length > 100 * 1024 * 1024) {
completer.completeError('HTML content exceeds maximum size limit (100MB)');
return completer.future;
}
Pointer<Uint8> codePtr = uint8ListToPointer(codeBytes);
try {
assert(_allocatedPages.containsKey(contextId));
final String effectiveUrl = (url == null || url.isEmpty) ? controller.url : url;
final Pointer<Utf8> urlPtr = effectiveUrl.isNotEmpty ? effectiveUrl.toNativeUtf8() : nullptr;
_ParseHTMLContext context = _ParseHTMLContext(completer, urlPtr);
Pointer<NativeFunction<NativeParseHTMLCallback>> resultCallback =
Pointer.fromFunction(_handleParseHTMLContextResult);
_parseHTML(_allocatedPages[contextId]!, codePtr, codeBytes.length, urlPtr, context, resultCallback);
} catch (e, stack) {
bridgeLogger.severe('Error parsing HTML', e, stack);
completer.completeError(e);
}
return completer.future;
}