1 // Copyright 2015 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 "base/logging.h"
6 #include "chrome/app/chrome_command_ids.h"
7 #include "chrome/browser/media/router/media_router_factory.h"
8 #include "chrome/browser/media/router/media_router_mojo_impl.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/singleton_tabs.h"
12 #include "chrome/browser/ui/toolbar/media_router_contextual_menu.h"
13 #include "chrome/grit/generated_resources.h"
14 #include "extensions/common/constants.h"
15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/models/menu_model_delegate.h"
18 MediaRouterContextualMenu::MediaRouterContextualMenu(Browser
* browser
)
21 menu_model_
.AddItemWithStringId(IDC_MEDIA_ROUTER_ABOUT
,
22 IDS_MEDIA_ROUTER_ABOUT
);
23 menu_model_
.AddSeparator(ui::NORMAL_SEPARATOR
);
24 menu_model_
.AddItemWithStringId(IDC_MEDIA_ROUTER_LEARN_MORE
,
25 IDS_MEDIA_ROUTER_LEARN_MORE
);
26 menu_model_
.AddItemWithStringId(IDC_MEDIA_ROUTER_HELP
,
27 IDS_MEDIA_ROUTER_HELP
);
28 menu_model_
.AddSeparator(ui::NORMAL_SEPARATOR
);
29 menu_model_
.AddItemWithStringId(IDC_MEDIA_ROUTER_REPORT_ISSUE
,
30 IDS_MEDIA_ROUTER_REPORT_ISSUE
);
33 MediaRouterContextualMenu::~MediaRouterContextualMenu() {
36 bool MediaRouterContextualMenu::IsCommandIdChecked(int command_id
) const {
40 bool MediaRouterContextualMenu::IsCommandIdEnabled(int command_id
) const {
44 bool MediaRouterContextualMenu::GetAcceleratorForCommandId(
46 ui::Accelerator
* accelerator
) {
50 base::string16
MediaRouterContextualMenu::GetLabelForCommandId(
51 int command_id
) const {
54 case IDC_MEDIA_ROUTER_ABOUT
:
55 string_id
= IDS_MEDIA_ROUTER_ABOUT
;
57 case IDC_MEDIA_ROUTER_HELP
:
58 string_id
= IDS_MEDIA_ROUTER_HELP
;
60 case IDC_MEDIA_ROUTER_LEARN_MORE
:
61 string_id
= IDS_MEDIA_ROUTER_LEARN_MORE
;
63 case IDC_MEDIA_ROUTER_REPORT_ISSUE
:
64 string_id
= IDS_MEDIA_ROUTER_REPORT_ISSUE
;
68 return base::string16();
71 return l10n_util::GetStringUTF16(string_id
);
74 void MediaRouterContextualMenu::ExecuteCommand(int command_id
,
76 const char kAboutPageUrl
[] =
77 "https://www.google.com/chrome/devices/chromecast/";
78 const char kCastHelpCenterPageUrl
[] =
79 "https://support.google.com/chromecast#topic=3058948";
80 const char kCastLearnMorePageUrl
[] =
81 "https://www.google.com/chrome/devices/chromecast/learn.html";
84 case IDC_MEDIA_ROUTER_ABOUT
:
85 chrome::ShowSingletonTab(browser_
, GURL(kAboutPageUrl
));
87 case IDC_MEDIA_ROUTER_HELP
:
88 chrome::ShowSingletonTab(browser_
, GURL(kCastHelpCenterPageUrl
));
90 case IDC_MEDIA_ROUTER_LEARN_MORE
:
91 chrome::ShowSingletonTab(browser_
, GURL(kCastLearnMorePageUrl
));
93 case IDC_MEDIA_ROUTER_REPORT_ISSUE
:
101 void MediaRouterContextualMenu::ReportIssue() {
102 // Opens feedback page loaded from the media router extension.
103 // This is temporary until feedback UI is redesigned.
104 media_router::MediaRouterMojoImpl
* media_router
=
105 static_cast<media_router::MediaRouterMojoImpl
*>(
106 media_router::MediaRouterFactory::GetApiForBrowserContext(
107 static_cast<content::BrowserContext
*>(browser_
->profile())));
108 if (media_router
->media_route_provider_extension_id().empty())
110 std::string
feedback_url(extensions::kExtensionScheme
+
111 std::string(url::kStandardSchemeSeparator
) +
112 media_router
->media_route_provider_extension_id() +
114 chrome::ShowSingletonTab(browser_
, GURL(feedback_url
));