web_validator.dart 2.54 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
// @dart = 2.8

7 8
import 'package:meta/meta.dart';

9
import '../base/platform.dart';
10 11 12
import '../doctor.dart';
import 'chrome.dart';

13
/// A validator for Chromium-based browsers.
14 15
abstract class ChromiumValidator extends DoctorValidator {
  const ChromiumValidator(String title) : super(title);
16

17 18 19
  Platform get _platform;
  ChromiumLauncher get _chromiumLauncher;
  String get _name;
20 21 22

  @override
  Future<ValidationResult> validate() async {
23
    final bool canRunChromium = _chromiumLauncher.canFindExecutable();
24
    final String chromiumSearchLocation = _chromiumLauncher.findExecutable();
25
    final List<ValidationMessage> messages = <ValidationMessage>[
26
      if (_platform.environment.containsKey(kChromeEnvironment))
27
        if (!canRunChromium)
28
          ValidationMessage.hint('$chromiumSearchLocation is not executable.')
29
        else
30
          ValidationMessage('$kChromeEnvironment = $chromiumSearchLocation')
31
      else
32 33 34
        if (!canRunChromium)
          ValidationMessage.hint('Cannot find $_name. Try setting '
            '$kChromeEnvironment to a $_name executable.')
35
        else
36
          ValidationMessage('$_name at $chromiumSearchLocation'),
37
    ];
38
    if (!canRunChromium) {
39 40 41
      return ValidationResult(
        ValidationType.missing,
        messages,
42
        statusInfo: 'Cannot find $_name executable at $chromiumSearchLocation',
43 44 45 46 47 48 49 50
      );
    }
    return ValidationResult(
      ValidationType.installed,
      messages,
    );
  }
}
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70

/// A validator that checks whether Chrome is installed and can run.
class ChromeValidator extends ChromiumValidator {
  const ChromeValidator({
    @required Platform platform,
    @required ChromiumLauncher chromiumLauncher,
  }) : _platform = platform,
       _chromiumLauncher = chromiumLauncher,
       super('Chrome - develop for the web');

  @override
  final Platform _platform;

  @override
  final ChromiumLauncher _chromiumLauncher;

  @override
  String get _name => 'Chrome';
}

71
/// A validator that checks whether Edge is installed and can run.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
class EdgeValidator extends ChromiumValidator {
  const EdgeValidator({
    @required Platform platform,
    @required ChromiumLauncher chromiumLauncher,
  }) : _platform = platform,
       _chromiumLauncher = chromiumLauncher,
       super('Edge - develop for the web');

  @override
  final Platform _platform;

  @override
  final ChromiumLauncher _chromiumLauncher;

  @override
  String get _name => 'Edge';
}