1 // Copyright 2020 The Chromium 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 
5 #include "weblayer/browser/url_bar/autocomplete_scheme_classifier_impl.h"
6 
7 #include "base/strings/string_util.h"
8 #include "content/public/common/url_constants.h"
9 #include "third_party/metrics_proto/omnibox_input_type.pb.h"
10 #include "url/url_constants.h"
11 
12 namespace weblayer {
13 
14 metrics::OmniboxInputType
GetInputTypeForScheme(const std::string & scheme) const15 AutocompleteSchemeClassifierImpl::GetInputTypeForScheme(
16     const std::string& scheme) const {
17   DCHECK_EQ(scheme, base::ToLowerASCII(scheme));
18 
19   // Check against an allowlist of schemes.
20   const char* kKnownURLSchemes[] = {
21       url::kHttpScheme,       url::kHttpsScheme,
22       url::kWsScheme,         url::kWssScheme,
23       url::kFileScheme,       url::kAboutScheme,
24       url::kFtpScheme,        url::kBlobScheme,
25       url::kFileSystemScheme, content::kViewSourceScheme,
26       url::kJavaScriptScheme};
27 
28   for (const char* known_scheme : kKnownURLSchemes) {
29     if (scheme == known_scheme)
30       return metrics::OmniboxInputType::URL;
31   }
32 
33   return metrics::OmniboxInputType::EMPTY;
34 }
35 
36 }  // namespace weblayer
37