1// Copyright 2013 The Flutter Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5part of engine; 6 7/// The HTML engine used by the current browser. 8enum BrowserEngine { 9 /// The engine that powers Chrome, Samsung Internet Browser, UC Browser, 10 /// Microsoft Edge, Opera, and others. 11 blink, 12 13 /// The engine that powers Safari. 14 webkit, 15 16 /// We were unable to detect the current browser engine. 17 unknown, 18} 19 20/// Lazily initialized current browser engine. 21BrowserEngine _browserEngine; 22 23/// Returns the [BrowserEngine] used by the current browser. 24/// 25/// This is used to implement browser-specific behavior. 26BrowserEngine get browserEngine => _browserEngine ??= _detectBrowserEngine(); 27 28BrowserEngine _detectBrowserEngine() { 29 final String vendor = html.window.navigator.vendor; 30 if (vendor == 'Google Inc.') { 31 return BrowserEngine.blink; 32 } else if (vendor == 'Apple Computer, Inc.') { 33 return BrowserEngine.webkit; 34 } 35 36 // Assume blink otherwise, but issue a warning. 37 print('WARNING: failed to detect current browser engine.'); 38 39 return BrowserEngine.unknown; 40} 41