Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / chrome / browser / autocomplete / chrome_autocomplete_scheme_classifier.cc
blob61e5f321711c20924751b080c88a4065c41711f7
1 // Copyright 2014 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.
5 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
7 #include "base/strings/string_util.h"
8 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
9 #include "chrome/browser/external_protocol/external_protocol_handler.h"
10 #include "chrome/browser/profiles/profile_io_data.h"
11 #include "content/public/common/url_constants.h"
12 #include "net/base/net_util.h"
13 #include "url/url_util.h"
15 ChromeAutocompleteSchemeClassifier::ChromeAutocompleteSchemeClassifier(
16 Profile* profile)
17 : profile_(profile) {
20 ChromeAutocompleteSchemeClassifier::~ChromeAutocompleteSchemeClassifier() {
23 metrics::OmniboxInputType::Type
24 ChromeAutocompleteSchemeClassifier::GetInputTypeForScheme(
25 const std::string& scheme) const {
26 if (base::IsStringASCII(scheme) &&
27 (ProfileIOData::IsHandledProtocol(scheme) ||
28 base::LowerCaseEqualsASCII(scheme, content::kViewSourceScheme) ||
29 base::LowerCaseEqualsASCII(scheme, url::kJavaScriptScheme) ||
30 base::LowerCaseEqualsASCII(scheme, url::kDataScheme))) {
31 return metrics::OmniboxInputType::URL;
34 // Also check for schemes registered via registerProtocolHandler(), which
35 // can be handled by web pages/apps.
36 ProtocolHandlerRegistry* registry = profile_ ?
37 ProtocolHandlerRegistryFactory::GetForBrowserContext(profile_) : NULL;
38 if (registry && registry->IsHandledProtocol(scheme))
39 return metrics::OmniboxInputType::URL;
41 // Not an internal protocol; check if it's an external protocol, i.e. one
42 // that's registered on the user's OS and will shell out to another program.
44 // We need to do this after the checks above because some internally
45 // handlable schemes (e.g. "javascript") may be treated as "blocked" by the
46 // external protocol handler because we don't want pages to open them, but
47 // users still can.
48 const ExternalProtocolHandler::BlockState block_state =
49 ExternalProtocolHandler::GetBlockState(scheme);
50 switch (block_state) {
51 case ExternalProtocolHandler::DONT_BLOCK:
52 return metrics::OmniboxInputType::URL;
54 case ExternalProtocolHandler::BLOCK:
55 // If we don't want the user to open the URL, don't let it be navigated
56 // to at all.
57 return metrics::OmniboxInputType::QUERY;
59 default:
60 return metrics::OmniboxInputType::INVALID;