Infobar material design refresh: layout
[chromium-blink-merge.git] / chrome / browser / ui / toolbar / media_router_contextual_menu.cc
blob3732064f13737b2aecea87cfdaa198e915eda06f
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)
19 : browser_(browser),
20 menu_model_(this) {
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 {
37 return false;
40 bool MediaRouterContextualMenu::IsCommandIdEnabled(int command_id) const {
41 return true;
44 bool MediaRouterContextualMenu::GetAcceleratorForCommandId(
45 int command_id,
46 ui::Accelerator* accelerator) {
47 return false;
50 base::string16 MediaRouterContextualMenu::GetLabelForCommandId(
51 int command_id) const {
52 int string_id;
53 switch (command_id) {
54 case IDC_MEDIA_ROUTER_ABOUT:
55 string_id = IDS_MEDIA_ROUTER_ABOUT;
56 break;
57 case IDC_MEDIA_ROUTER_HELP:
58 string_id = IDS_MEDIA_ROUTER_HELP;
59 break;
60 case IDC_MEDIA_ROUTER_LEARN_MORE:
61 string_id = IDS_MEDIA_ROUTER_LEARN_MORE;
62 break;
63 case IDC_MEDIA_ROUTER_REPORT_ISSUE:
64 string_id = IDS_MEDIA_ROUTER_REPORT_ISSUE;
65 break;
66 default:
67 NOTREACHED();
68 return base::string16();
71 return l10n_util::GetStringUTF16(string_id);
74 void MediaRouterContextualMenu::ExecuteCommand(int command_id,
75 int event_flags) {
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";
83 switch (command_id) {
84 case IDC_MEDIA_ROUTER_ABOUT:
85 chrome::ShowSingletonTab(browser_, GURL(kAboutPageUrl));
86 break;
87 case IDC_MEDIA_ROUTER_HELP:
88 chrome::ShowSingletonTab(browser_, GURL(kCastHelpCenterPageUrl));
89 break;
90 case IDC_MEDIA_ROUTER_LEARN_MORE:
91 chrome::ShowSingletonTab(browser_, GURL(kCastLearnMorePageUrl));
92 break;
93 case IDC_MEDIA_ROUTER_REPORT_ISSUE:
94 ReportIssue();
95 break;
96 default:
97 NOTREACHED();
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())
109 return;
110 std::string feedback_url(extensions::kExtensionScheme +
111 std::string(url::kStandardSchemeSeparator) +
112 media_router->media_route_provider_extension_id() +
113 "/feedback.html");
114 chrome::ShowSingletonTab(browser_, GURL(feedback_url));