blob: 620df4bac14453995833729b5ab94bd929f07038 [file] [log] [blame]
[email protected]a817ed392014-06-27 05:03:001// 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.
4
5#include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
6
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"
[email protected]a817ed392014-06-27 05:03:0012#include "url/url_util.h"
13
14ChromeAutocompleteSchemeClassifier::ChromeAutocompleteSchemeClassifier(
15 Profile* profile)
16 : profile_(profile) {
17}
18
19ChromeAutocompleteSchemeClassifier::~ChromeAutocompleteSchemeClassifier() {
20}
21
Steven Holte3696c9412017-08-24 18:38:0322metrics::OmniboxInputType
[email protected]a817ed392014-06-27 05:03:0023ChromeAutocompleteSchemeClassifier::GetInputTypeForScheme(
24 const std::string& scheme) const {
David Bienvenu6fcc5932018-04-10 19:11:5525 if (scheme.empty()) {
26 return metrics::OmniboxInputType::INVALID;
27 }
[email protected]a817ed392014-06-27 05:03:0028 if (base::IsStringASCII(scheme) &&
29 (ProfileIOData::IsHandledProtocol(scheme) ||
brettwbc17d2c82015-06-09 22:39:0830 base::LowerCaseEqualsASCII(scheme, content::kViewSourceScheme) ||
31 base::LowerCaseEqualsASCII(scheme, url::kJavaScriptScheme) ||
32 base::LowerCaseEqualsASCII(scheme, url::kDataScheme))) {
[email protected]a817ed392014-06-27 05:03:0033 return metrics::OmniboxInputType::URL;
34 }
35
36 // Also check for schemes registered via registerProtocolHandler(), which
37 // can be handled by web pages/apps.
[email protected]a23abe472014-07-29 23:46:3138 ProtocolHandlerRegistry* registry = profile_ ?
39 ProtocolHandlerRegistryFactory::GetForBrowserContext(profile_) : NULL;
[email protected]a817ed392014-06-27 05:03:0040 if (registry && registry->IsHandledProtocol(scheme))
41 return metrics::OmniboxInputType::URL;
42
43 // Not an internal protocol; check if it's an external protocol, i.e. one
44 // that's registered on the user's OS and will shell out to another program.
45 //
46 // We need to do this after the checks above because some internally
47 // handlable schemes (e.g. "javascript") may be treated as "blocked" by the
48 // external protocol handler because we don't want pages to open them, but
49 // users still can.
[email protected]a817ed392014-06-27 05:03:0050 const ExternalProtocolHandler::BlockState block_state =
ramyasharma2c618e172017-02-06 05:41:3451 ExternalProtocolHandler::GetBlockState(scheme, profile_);
[email protected]a817ed392014-06-27 05:03:0052 switch (block_state) {
53 case ExternalProtocolHandler::DONT_BLOCK:
54 return metrics::OmniboxInputType::URL;
55
56 case ExternalProtocolHandler::BLOCK:
57 // If we don't want the user to open the URL, don't let it be navigated
58 // to at all.
59 return metrics::OmniboxInputType::QUERY;
60
David Bienvenu6fcc5932018-04-10 19:11:5561 case ExternalProtocolHandler::UNKNOWN: {
David Bienvenubedfe9f2018-05-03 18:50:2562#if defined(OS_LINUX)
63 // Linux impl of GetApplicationNameForProtocol doesn't distinguish
64 // between URL schemes with handers and those without. This will
65 // make the default behaviour be search on Linux.
66 return metrics::OmniboxInputType::INVALID;
67#endif // defined(OS_LINUX)
David Bienvenu6fcc5932018-04-10 19:11:5568 // If block state is unknown, check if there is an application registered
69 // for the url scheme.
70 GURL url(scheme + "://");
71 base::string16 application_name =
72 shell_integration::GetApplicationNameForProtocol(url);
73 return application_name.empty() ? metrics::OmniboxInputType::INVALID
74 : metrics::OmniboxInputType::URL;
75 }
[email protected]a817ed392014-06-27 05:03:0076 }
David Bienvenu6fcc5932018-04-10 19:11:5577 NOTREACHED();
78 return metrics::OmniboxInputType::INVALID;
[email protected]a817ed392014-06-27 05:03:0079}