blob: 2694473bbb5805ec179b80f28a79fc301078f00c [file] [log] [blame]
juncaibf183dd2016-05-27 16:57:241// Copyright 2016 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
juncaibadc1daa2016-07-11 20:36:545#include "chrome/browser/chooser_controller/chooser_controller.h"
juncaibf183dd2016-05-27 16:57:246
juncaic1bb01a2016-09-29 22:20:197#include "base/logging.h"
juncaia29e116d2016-07-13 02:53:348#include "base/strings/utf_string_conversions.h"
juncaia29e116d2016-07-13 02:53:349#include "components/url_formatter/elide_url.h"
juncaibf183dd2016-05-27 16:57:2410#include "content/public/browser/render_frame_host.h"
juncaia29e116d2016-07-13 02:53:3411#include "content/public/browser/web_contents.h"
Reilly Grant409406c2018-04-05 18:03:0512#include "extensions/buildflags/buildflags.h"
juncaia29e116d2016-07-13 02:53:3413#include "ui/base/l10n/l10n_util.h"
juncai474e1e12016-06-29 01:56:4614#include "url/origin.h"
juncaibf183dd2016-05-27 16:57:2415
Reilly Grant409406c2018-04-05 18:03:0516#if BUILDFLAG(ENABLE_EXTENSIONS)
17#include "extensions/browser/extension_registry.h"
18#include "extensions/common/constants.h"
19#endif
20
reillygf50d8d32017-03-14 22:55:0021namespace {
juncaibf183dd2016-05-27 16:57:2422
reillygf50d8d32017-03-14 22:55:0023base::string16 CreateTitle(content::RenderFrameHost* render_frame_host,
24 int title_string_id_origin,
25 int title_string_id_extension) {
26 url::Origin origin = render_frame_host->GetLastCommittedOrigin();
juncaia29e116d2016-07-13 02:53:3427
Reilly Grant409406c2018-04-05 18:03:0528#if BUILDFLAG(ENABLE_EXTENSIONS)
juncaia29e116d2016-07-13 02:53:3429 if (origin.scheme() == extensions::kExtensionScheme) {
30 content::WebContents* web_contents =
reillygf50d8d32017-03-14 22:55:0031 content::WebContents::FromRenderFrameHost(render_frame_host);
juncaia29e116d2016-07-13 02:53:3432 content::BrowserContext* browser_context =
33 web_contents->GetBrowserContext();
34 extensions::ExtensionRegistry* extension_registry =
35 extensions::ExtensionRegistry::Get(browser_context);
36 if (extension_registry) {
37 const extensions::Extension* extension =
38 extension_registry->enabled_extensions().GetByID(origin.host());
39 if (extension) {
reillygf50d8d32017-03-14 22:55:0040 return l10n_util::GetStringFUTF16(title_string_id_extension,
juncai6d9f7732016-07-14 00:46:5441 base::UTF8ToUTF16(extension->name()));
juncaia29e116d2016-07-13 02:53:3442 }
43 }
44 }
Reilly Grant409406c2018-04-05 18:03:0545#endif
juncaia29e116d2016-07-13 02:53:3446
47 return l10n_util::GetStringFUTF16(
reillygf50d8d32017-03-14 22:55:0048 title_string_id_origin,
juncaia29e116d2016-07-13 02:53:3449 url_formatter::FormatOriginForSecurityDisplay(
50 origin, url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC));
juncaibf183dd2016-05-27 16:57:2451}
juncai3ecef4e2016-08-23 00:10:1652
reillygf50d8d32017-03-14 22:55:0053} // namespace
54
55ChooserController::ChooserController(content::RenderFrameHost* owner,
56 int title_string_id_origin,
57 int title_string_id_extension) {
58 if (owner) {
59 title_ =
60 CreateTitle(owner, title_string_id_origin, title_string_id_extension);
61 }
62}
63
64ChooserController::~ChooserController() {}
65
66base::string16 ChooserController::GetTitle() const {
67 return title_;
68}
69
juncai3ecef4e2016-08-23 00:10:1670bool ChooserController::ShouldShowIconBeforeText() const {
71 return false;
72}
73
Bret Sepulvedaa4975e7a5e2017-12-18 23:16:3874bool ChooserController::ShouldShowHelpButton() const {
juncai43003622016-11-29 20:43:1875 return true;
76}
77
Bret Sepulvedaa4975e7a5e2017-12-18 23:16:3878bool ChooserController::ShouldShowReScanButton() const {
79 return false;
80}
81
juncai0f6d2792016-11-23 18:38:0782bool ChooserController::AllowMultipleSelection() const {
83 return false;
84}
85
juncai3ecef4e2016-08-23 00:10:1686int ChooserController::GetSignalStrengthLevel(size_t index) const {
87 return -1;
88}
juncai87d09292016-09-15 04:02:5389
90bool ChooserController::IsConnected(size_t index) const {
91 return false;
92}
93
94bool ChooserController::IsPaired(size_t index) const {
95 return false;
96}
juncaic1bb01a2016-09-29 22:20:1997
Bret Sepulvedae6e84f72017-10-20 03:37:4098void ChooserController::RefreshOptions() {
99 NOTREACHED();
100}
101
102base::string16 ChooserController::GetStatus() const {
103 return base::string16();
104}
105
juncaic1bb01a2016-09-29 22:20:19106void ChooserController::OpenAdapterOffHelpUrl() const {
107 NOTREACHED();
108}