[web] Ensure Flutter adds a generator meta-tag. (flutter/engine#55714)
Adds a `meta name="generator" content="Flutter"` tag when the engine UI initializes. ## Issues Fixes https://github.com/flutter/flutter/issues/156262 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
@@ -229,6 +229,9 @@ Future<void> initializeEngineUi() async {
|
||||
RawKeyboard.initialize(onMacOs: ui_web.browser.operatingSystem == ui_web.OperatingSystem.macOs);
|
||||
KeyboardBinding.initInstance();
|
||||
|
||||
// Ensures Flutter renders a global "generator" meta-tag.
|
||||
ensureMetaTag('generator', 'Flutter');
|
||||
|
||||
if (!configuration.multiViewEnabled) {
|
||||
final EngineFlutterWindow implicitView =
|
||||
ensureImplicitViewInitialized(hostElement: configuration.hostElement);
|
||||
|
||||
@@ -722,6 +722,19 @@ void setThemeColor(ui.Color? color) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Ensure a "meta" tag with [name] and [content] is set on the page.
|
||||
void ensureMetaTag(String name, String content) {
|
||||
final DomElement? existingTag =
|
||||
domDocument.querySelector('meta[name=$name][content=$content]');
|
||||
|
||||
if (existingTag == null) {
|
||||
final DomHTMLMetaElement meta = createDomHTMLMetaElement()
|
||||
..name = name
|
||||
..content = content;
|
||||
domDocument.head!.append(meta);
|
||||
}
|
||||
}
|
||||
|
||||
bool? _ellipseFeatureDetected;
|
||||
|
||||
/// Draws CanvasElement ellipse with fallback.
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:js/js_util.dart' as js_util;
|
||||
import 'package:test/bootstrap/browser.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:ui/src/engine.dart' as engine;
|
||||
import 'package:ui/src/engine/dom.dart';
|
||||
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;
|
||||
|
||||
@JS('_flutter')
|
||||
@@ -76,6 +77,10 @@ void testMain() {
|
||||
// Check that the object we captured is actually a loader
|
||||
expect(pluginsRegistered, isTrue, reason: 'Plugins should be immediately registered in autoStart mode.');
|
||||
expect(appRan, isTrue, reason: 'App should run immediately in autoStart mode');
|
||||
|
||||
// After starting the engine, the meta-generator tag should be on the page
|
||||
final DomElement? meta = domDocument.querySelector('meta[name=generator][content=Flutter]');
|
||||
expect(meta, isNotNull, reason: 'The generator meta-tag should be added when Flutter initializes its UI.');
|
||||
});
|
||||
|
||||
// We cannot test anymore, because by now the engine has registered some stuff that can't be rewound back.
|
||||
|
||||
Reference in New Issue
Block a user