web_validator.dart 2.52 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
import 'package:meta/meta.dart';

7
import '../base/platform.dart';
8 9 10
import '../doctor.dart';
import 'chrome.dart';

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

15 16 17
  Platform get _platform;
  ChromiumLauncher get _chromiumLauncher;
  String get _name;
18 19 20

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

/// 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';
}

/// A validator that checks whethere Edge is installed and can run.
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';
}