| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/frame/system_menu_model_builder.h" | 5 #include "chrome/browser/ui/views/frame/system_menu_model_builder.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
| 10 #include "chrome/browser/ui/browser_commands.h" | 10 #include "chrome/browser/ui/browser_commands.h" |
| 11 #include "chrome/browser/ui/host_desktop.h" | 11 #include "chrome/browser/ui/host_desktop.h" |
| 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 12 #include "chrome/browser/ui/toolbar/wrench_menu_model.h" | 13 #include "chrome/browser/ui/toolbar/wrench_menu_model.h" |
| 13 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/common/url_constants.h" |
| 14 #include "chrome/grit/generated_resources.h" | 16 #include "chrome/grit/generated_resources.h" |
| 15 #include "ui/base/accelerators/accelerator.h" | 17 #include "ui/base/accelerators/accelerator.h" |
| 16 #include "ui/base/models/simple_menu_model.h" | 18 #include "ui/base/models/simple_menu_model.h" |
| 17 | 19 |
| 18 #if defined(OS_CHROMEOS) | 20 #if defined(OS_CHROMEOS) |
| 19 #include "ash/session/session_state_delegate.h" | 21 #include "ash/session/session_state_delegate.h" |
| 20 #include "ash/shell.h" | 22 #include "ash/shell.h" |
| 21 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 23 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| 22 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" | 24 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" |
| 23 #include "chrome/browser/ui/browser_window.h" | 25 #include "chrome/browser/ui/browser_window.h" |
| 24 #include "components/user_manager/user_info.h" | 26 #include "components/user_manager/user_info.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 26 #endif | 28 #endif |
| 27 | 29 |
| 30 namespace { |
| 31 |
| 32 // Given a |browser| that's an app or popup window, checks if it's hosting the |
| 33 // settings page. |
| 34 bool IsChromeSettingsAppOrPopupWindow(Browser* browser) { |
| 35 DCHECK(browser); |
| 36 TabStripModel* tab_strip = browser->tab_strip_model(); |
| 37 DCHECK_EQ(1, tab_strip->count()); |
| 38 const GURL gurl(tab_strip->GetWebContentsAt(0)->GetURL()); |
| 39 if (gurl.SchemeIs(content::kChromeUIScheme) && |
| 40 gurl.host().find(chrome::kChromeUISettingsHost) != std::string::npos) { |
| 41 return true; |
| 42 } |
| 43 return false; |
| 44 } |
| 45 |
| 46 } // namespace |
| 47 |
| 28 SystemMenuModelBuilder::SystemMenuModelBuilder( | 48 SystemMenuModelBuilder::SystemMenuModelBuilder( |
| 29 ui::AcceleratorProvider* provider, | 49 ui::AcceleratorProvider* provider, |
| 30 Browser* browser) | 50 Browser* browser) |
| 31 : menu_delegate_(provider, browser) { | 51 : menu_delegate_(provider, browser) { |
| 32 } | 52 } |
| 33 | 53 |
| 34 SystemMenuModelBuilder::~SystemMenuModelBuilder() { | 54 SystemMenuModelBuilder::~SystemMenuModelBuilder() { |
| 35 } | 55 } |
| 36 | 56 |
| 37 void SystemMenuModelBuilder::Init() { | 57 void SystemMenuModelBuilder::Init() { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 encoding_menu_contents_.get()); | 121 encoding_menu_contents_.get()); |
| 102 if (browser()->is_app() && chrome::CanOpenTaskManager()) { | 122 if (browser()->is_app() && chrome::CanOpenTaskManager()) { |
| 103 model->AddSeparator(ui::NORMAL_SEPARATOR); | 123 model->AddSeparator(ui::NORMAL_SEPARATOR); |
| 104 model->AddItemWithStringId(IDC_TASK_MANAGER, IDS_TASK_MANAGER); | 124 model->AddItemWithStringId(IDC_TASK_MANAGER, IDS_TASK_MANAGER); |
| 105 } | 125 } |
| 106 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 126 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 107 model->AddSeparator(ui::NORMAL_SEPARATOR); | 127 model->AddSeparator(ui::NORMAL_SEPARATOR); |
| 108 model->AddItemWithStringId(IDC_CLOSE_WINDOW, IDS_CLOSE); | 128 model->AddItemWithStringId(IDC_CLOSE_WINDOW, IDS_CLOSE); |
| 109 #endif | 129 #endif |
| 110 | 130 |
| 111 AppendTeleportMenu(model); | 131 // Avoid appending the teleport menu for the settings window. This window's |
| 132 // presentation is unique: it's a normal browser window with an app-like |
| 133 // frame, which doesn't have a user icon badge. Thus if teleported it's not |
| 134 // clear what user it applies to. Rather than bother to implement badging just |
| 135 // for this rare case, simply prevent the user from teleporting the window. |
| 136 if (!IsChromeSettingsAppOrPopupWindow(browser())) |
| 137 AppendTeleportMenu(model); |
| 112 } | 138 } |
| 113 | 139 |
| 114 void SystemMenuModelBuilder::AddFrameToggleItems(ui::SimpleMenuModel* model) { | 140 void SystemMenuModelBuilder::AddFrameToggleItems(ui::SimpleMenuModel* model) { |
| 115 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 141 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 116 switches::kDebugEnableFrameToggle)) { | 142 switches::kDebugEnableFrameToggle)) { |
| 117 model->AddSeparator(ui::NORMAL_SEPARATOR); | 143 model->AddSeparator(ui::NORMAL_SEPARATOR); |
| 118 model->AddItem(IDC_DEBUG_FRAME_TOGGLE, | 144 model->AddItem(IDC_DEBUG_FRAME_TOGGLE, |
| 119 base::ASCIIToUTF16("Toggle Frame Type")); | 145 base::ASCIIToUTF16("Toggle Frame Type")); |
| 120 } | 146 } |
| 121 } | 147 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 const user_manager::UserInfo* user_info = delegate->GetUserInfo(user_index); | 181 const user_manager::UserInfo* user_info = delegate->GetUserInfo(user_index); |
| 156 model->AddItem( | 182 model->AddItem( |
| 157 user_index == 1 ? IDC_VISIT_DESKTOP_OF_LRU_USER_2 | 183 user_index == 1 ? IDC_VISIT_DESKTOP_OF_LRU_USER_2 |
| 158 : IDC_VISIT_DESKTOP_OF_LRU_USER_3, | 184 : IDC_VISIT_DESKTOP_OF_LRU_USER_3, |
| 159 l10n_util::GetStringFUTF16(IDS_VISIT_DESKTOP_OF_LRU_USER, | 185 l10n_util::GetStringFUTF16(IDS_VISIT_DESKTOP_OF_LRU_USER, |
| 160 user_info->GetDisplayName(), | 186 user_info->GetDisplayName(), |
| 161 base::ASCIIToUTF16(user_info->GetEmail()))); | 187 base::ASCIIToUTF16(user_info->GetEmail()))); |
| 162 } | 188 } |
| 163 #endif | 189 #endif |
| 164 } | 190 } |
| OLD | NEW |