| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/toolbar/wrench_menu_model.h" | 5 #include "chrome/browser/ui/toolbar/wrench_menu_model.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 32 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 33 #include "chrome/browser/ui/toolbar/bookmark_sub_menu_model.h" | 33 #include "chrome/browser/ui/toolbar/bookmark_sub_menu_model.h" |
| 34 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" | 34 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" |
| 35 #include "chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h" | 35 #include "chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h" |
| 36 #include "chrome/browser/upgrade_detector.h" | 36 #include "chrome/browser/upgrade_detector.h" |
| 37 #include "chrome/common/chrome_paths.h" | 37 #include "chrome/common/chrome_paths.h" |
| 38 #include "chrome/common/chrome_switches.h" | 38 #include "chrome/common/chrome_switches.h" |
| 39 #include "chrome/common/pref_names.h" | 39 #include "chrome/common/pref_names.h" |
| 40 #include "chrome/common/profiling.h" | 40 #include "chrome/common/profiling.h" |
| 41 #include "components/signin/core/browser/signin_manager.h" | 41 #include "components/signin/core/browser/signin_manager.h" |
| 42 #include "components/signin/core/common/profile_management_switches.h" |
| 42 #include "content/public/browser/host_zoom_map.h" | 43 #include "content/public/browser/host_zoom_map.h" |
| 43 #include "content/public/browser/navigation_entry.h" | 44 #include "content/public/browser/navigation_entry.h" |
| 44 #include "content/public/browser/notification_service.h" | 45 #include "content/public/browser/notification_service.h" |
| 45 #include "content/public/browser/notification_source.h" | 46 #include "content/public/browser/notification_source.h" |
| 46 #include "content/public/browser/notification_types.h" | 47 #include "content/public/browser/notification_types.h" |
| 47 #include "content/public/browser/user_metrics.h" | 48 #include "content/public/browser/user_metrics.h" |
| 48 #include "content/public/browser/web_contents.h" | 49 #include "content/public/browser/web_contents.h" |
| 49 #include "grit/chromium_strings.h" | 50 #include "grit/chromium_strings.h" |
| 50 #include "grit/generated_resources.h" | 51 #include "grit/generated_resources.h" |
| 51 #include "grit/theme_resources.h" | 52 #include "grit/theme_resources.h" |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 } | 272 } |
| 272 | 273 |
| 273 bool WrenchMenuModel::IsItemForCommandIdDynamic(int command_id) const { | 274 bool WrenchMenuModel::IsItemForCommandIdDynamic(int command_id) const { |
| 274 return command_id == IDC_ZOOM_PERCENT_DISPLAY || | 275 return command_id == IDC_ZOOM_PERCENT_DISPLAY || |
| 275 #if defined(OS_MACOSX) | 276 #if defined(OS_MACOSX) |
| 276 command_id == IDC_FULLSCREEN || | 277 command_id == IDC_FULLSCREEN || |
| 277 #elif defined(OS_WIN) | 278 #elif defined(OS_WIN) |
| 278 command_id == IDC_PIN_TO_START_SCREEN || | 279 command_id == IDC_PIN_TO_START_SCREEN || |
| 279 #endif | 280 #endif |
| 280 command_id == IDC_UPGRADE_DIALOG || | 281 command_id == IDC_UPGRADE_DIALOG || |
| 281 command_id == IDC_SHOW_SIGNIN; | 282 (!switches::IsNewProfileManagement() && command_id == IDC_SHOW_SIGNIN); |
| 282 } | 283 } |
| 283 | 284 |
| 284 base::string16 WrenchMenuModel::GetLabelForCommandId(int command_id) const { | 285 base::string16 WrenchMenuModel::GetLabelForCommandId(int command_id) const { |
| 285 switch (command_id) { | 286 switch (command_id) { |
| 286 case IDC_ZOOM_PERCENT_DISPLAY: | 287 case IDC_ZOOM_PERCENT_DISPLAY: |
| 287 return zoom_label_; | 288 return zoom_label_; |
| 288 #if defined(OS_MACOSX) | 289 #if defined(OS_MACOSX) |
| 289 case IDC_FULLSCREEN: { | 290 case IDC_FULLSCREEN: { |
| 290 int string_id = IDS_ENTER_FULLSCREEN_MAC; // Default to Enter. | 291 int string_id = IDS_ENTER_FULLSCREEN_MAC; // Default to Enter. |
| 291 // Note: On startup, |window()| may be NULL. | 292 // Note: On startup, |window()| may be NULL. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 302 web_contents ? MetroPinTabHelper::FromWebContents(web_contents) | 303 web_contents ? MetroPinTabHelper::FromWebContents(web_contents) |
| 303 : NULL; | 304 : NULL; |
| 304 if (tab_helper && tab_helper->IsPinned()) | 305 if (tab_helper && tab_helper->IsPinned()) |
| 305 string_id = IDS_UNPIN_FROM_START_SCREEN; | 306 string_id = IDS_UNPIN_FROM_START_SCREEN; |
| 306 return l10n_util::GetStringUTF16(string_id); | 307 return l10n_util::GetStringUTF16(string_id); |
| 307 } | 308 } |
| 308 #endif | 309 #endif |
| 309 case IDC_UPGRADE_DIALOG: | 310 case IDC_UPGRADE_DIALOG: |
| 310 return GetUpgradeDialogMenuItemName(); | 311 return GetUpgradeDialogMenuItemName(); |
| 311 case IDC_SHOW_SIGNIN: | 312 case IDC_SHOW_SIGNIN: |
| 313 DCHECK(!switches::IsNewProfileManagement()); |
| 312 return signin_ui_util::GetSigninMenuLabel( | 314 return signin_ui_util::GetSigninMenuLabel( |
| 313 browser_->profile()->GetOriginalProfile()); | 315 browser_->profile()->GetOriginalProfile()); |
| 314 default: | 316 default: |
| 315 NOTREACHED(); | 317 NOTREACHED(); |
| 316 return base::string16(); | 318 return base::string16(); |
| 317 } | 319 } |
| 318 } | 320 } |
| 319 | 321 |
| 320 bool WrenchMenuModel::GetIconForCommandId(int command_id, | 322 bool WrenchMenuModel::GetIconForCommandId(int command_id, |
| 321 gfx::Image* icon) const { | 323 gfx::Image* icon) const { |
| 322 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 324 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 323 switch (command_id) { | 325 switch (command_id) { |
| 324 case IDC_UPGRADE_DIALOG: { | 326 case IDC_UPGRADE_DIALOG: { |
| 325 if (UpgradeDetector::GetInstance()->notify_upgrade()) { | 327 if (UpgradeDetector::GetInstance()->notify_upgrade()) { |
| 326 *icon = rb.GetNativeImageNamed( | 328 *icon = rb.GetNativeImageNamed( |
| 327 UpgradeDetector::GetInstance()->GetIconResourceID( | 329 UpgradeDetector::GetInstance()->GetIconResourceID( |
| 328 UpgradeDetector::UPGRADE_ICON_TYPE_MENU_ICON)); | 330 UpgradeDetector::UPGRADE_ICON_TYPE_MENU_ICON)); |
| 329 return true; | 331 return true; |
| 330 } | 332 } |
| 331 return false; | 333 return false; |
| 332 } | 334 } |
| 333 case IDC_SHOW_SIGNIN: { | 335 case IDC_SHOW_SIGNIN: { |
| 336 DCHECK(!switches::IsNewProfileManagement()); |
| 334 GlobalError* error = signin_ui_util::GetSignedInServiceError( | 337 GlobalError* error = signin_ui_util::GetSignedInServiceError( |
| 335 browser_->profile()->GetOriginalProfile()); | 338 browser_->profile()->GetOriginalProfile()); |
| 336 if (error) { | 339 if (error) { |
| 337 int icon_id = error->MenuItemIconResourceID(); | 340 int icon_id = error->MenuItemIconResourceID(); |
| 338 if (icon_id) { | 341 if (icon_id) { |
| 339 *icon = rb.GetNativeImageNamed(icon_id); | 342 *icon = rb.GetNativeImageNamed(icon_id); |
| 340 return true; | 343 return true; |
| 341 } | 344 } |
| 342 } | 345 } |
| 343 return false; | 346 return false; |
| 344 } | 347 } |
| 345 default: | 348 default: |
| 346 break; | 349 break; |
| 347 } | 350 } |
| 348 return false; | 351 return false; |
| 349 } | 352 } |
| 350 | 353 |
| 351 void WrenchMenuModel::ExecuteCommand(int command_id, int event_flags) { | 354 void WrenchMenuModel::ExecuteCommand(int command_id, int event_flags) { |
| 352 GlobalError* error = GlobalErrorServiceFactory::GetForProfile( | 355 GlobalError* error = GlobalErrorServiceFactory::GetForProfile( |
| 353 browser_->profile())->GetGlobalErrorByMenuItemCommandID(command_id); | 356 browser_->profile())->GetGlobalErrorByMenuItemCommandID(command_id); |
| 354 if (error) { | 357 if (error) { |
| 355 error->ExecuteMenuItem(browser_); | 358 error->ExecuteMenuItem(browser_); |
| 356 return; | 359 return; |
| 357 } | 360 } |
| 358 | 361 |
| 359 if (command_id == IDC_SHOW_SIGNIN) { | 362 if (!switches::IsNewProfileManagement() && command_id == IDC_SHOW_SIGNIN) { |
| 360 // If a custom error message is being shown, handle it. | 363 // If a custom error message is being shown, handle it. |
| 361 GlobalError* error = signin_ui_util::GetSignedInServiceError( | 364 GlobalError* error = signin_ui_util::GetSignedInServiceError( |
| 362 browser_->profile()->GetOriginalProfile()); | 365 browser_->profile()->GetOriginalProfile()); |
| 363 if (error) { | 366 if (error) { |
| 364 error->ExecuteMenuItem(browser_); | 367 error->ExecuteMenuItem(browser_); |
| 365 return; | 368 return; |
| 366 } | 369 } |
| 367 } | 370 } |
| 368 | 371 |
| 369 if (command_id == IDC_HELP_PAGE_VIA_MENU) | 372 if (command_id == IDC_HELP_PAGE_VIA_MENU) |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 if (is_new_menu) | 575 if (is_new_menu) |
| 573 CreateZoomMenu(is_new_menu); | 576 CreateZoomMenu(is_new_menu); |
| 574 else | 577 else |
| 575 AddSeparator(ui::NORMAL_SEPARATOR); | 578 AddSeparator(ui::NORMAL_SEPARATOR); |
| 576 | 579 |
| 577 AddItemWithStringId(IDC_SHOW_HISTORY, IDS_SHOW_HISTORY); | 580 AddItemWithStringId(IDC_SHOW_HISTORY, IDS_SHOW_HISTORY); |
| 578 AddItemWithStringId(IDC_SHOW_DOWNLOADS, IDS_SHOW_DOWNLOADS); | 581 AddItemWithStringId(IDC_SHOW_DOWNLOADS, IDS_SHOW_DOWNLOADS); |
| 579 AddSeparator(ui::NORMAL_SEPARATOR); | 582 AddSeparator(ui::NORMAL_SEPARATOR); |
| 580 | 583 |
| 581 #if !defined(OS_CHROMEOS) | 584 #if !defined(OS_CHROMEOS) |
| 582 // No "Sign in to Chromium..." menu item on ChromeOS. | 585 if (!switches::IsNewProfileManagement()) { |
| 583 SigninManager* signin = SigninManagerFactory::GetForProfile( | 586 // No "Sign in to Chromium..." menu item on ChromeOS. |
| 584 browser_->profile()->GetOriginalProfile()); | 587 SigninManager* signin = SigninManagerFactory::GetForProfile( |
| 585 if (signin && signin->IsSigninAllowed()) { | 588 browser_->profile()->GetOriginalProfile()); |
| 586 const base::string16 short_product_name = | 589 if (signin && signin->IsSigninAllowed()) { |
| 587 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME); | 590 const base::string16 short_product_name = |
| 588 AddItem(IDC_SHOW_SYNC_SETUP, l10n_util::GetStringFUTF16( | 591 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME); |
| 589 IDS_SYNC_MENU_PRE_SYNCED_LABEL, short_product_name)); | 592 AddItem(IDC_SHOW_SYNC_SETUP, l10n_util::GetStringFUTF16( |
| 590 AddSeparator(ui::NORMAL_SEPARATOR); | 593 IDS_SYNC_MENU_PRE_SYNCED_LABEL, short_product_name)); |
| 594 AddSeparator(ui::NORMAL_SEPARATOR); |
| 595 } |
| 591 } | 596 } |
| 592 #endif | 597 #endif |
| 593 | 598 |
| 594 AddItemWithStringId(IDC_OPTIONS, IDS_SETTINGS); | 599 AddItemWithStringId(IDC_OPTIONS, IDS_SETTINGS); |
| 595 | 600 |
| 596 #if defined(OS_CHROMEOS) | 601 #if defined(OS_CHROMEOS) |
| 597 if (CommandLine::ForCurrentProcess()->HasSwitch( | 602 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 598 chromeos::switches::kEnableRequestTabletSite)) | 603 chromeos::switches::kEnableRequestTabletSite)) |
| 599 AddCheckItemWithStringId(IDC_TOGGLE_REQUEST_TABLET_SITE, | 604 AddCheckItemWithStringId(IDC_TOGGLE_REQUEST_TABLET_SITE, |
| 600 IDS_TOGGLE_REQUEST_TABLET_SITE); | 605 IDS_TOGGLE_REQUEST_TABLET_SITE); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 } | 658 } |
| 654 | 659 |
| 655 void WrenchMenuModel::AddGlobalErrorMenuItems() { | 660 void WrenchMenuModel::AddGlobalErrorMenuItems() { |
| 656 // TODO(sail): Currently we only build the wrench menu once per browser | 661 // TODO(sail): Currently we only build the wrench menu once per browser |
| 657 // window. This means that if a new error is added after the menu is built | 662 // window. This means that if a new error is added after the menu is built |
| 658 // it won't show in the existing wrench menu. To fix this we need to some | 663 // it won't show in the existing wrench menu. To fix this we need to some |
| 659 // how update the menu if new errors are added. | 664 // how update the menu if new errors are added. |
| 660 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 665 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 661 // GetSignedInServiceErrors() can modify the global error list, so call it | 666 // GetSignedInServiceErrors() can modify the global error list, so call it |
| 662 // before iterating through that list below. | 667 // before iterating through that list below. |
| 663 std::vector<GlobalError*> signin_errors = | 668 std::vector<GlobalError*> signin_errors; |
| 664 signin_ui_util::GetSignedInServiceErrors( | 669 if (!switches::IsNewProfileManagement()) { |
| 670 signin_errors = signin_ui_util::GetSignedInServiceErrors( |
| 665 browser_->profile()->GetOriginalProfile()); | 671 browser_->profile()->GetOriginalProfile()); |
| 672 } |
| 666 const GlobalErrorService::GlobalErrorList& errors = | 673 const GlobalErrorService::GlobalErrorList& errors = |
| 667 GlobalErrorServiceFactory::GetForProfile(browser_->profile())->errors(); | 674 GlobalErrorServiceFactory::GetForProfile(browser_->profile())->errors(); |
| 668 for (GlobalErrorService::GlobalErrorList::const_iterator | 675 for (GlobalErrorService::GlobalErrorList::const_iterator |
| 669 it = errors.begin(); it != errors.end(); ++it) { | 676 it = errors.begin(); it != errors.end(); ++it) { |
| 670 GlobalError* error = *it; | 677 GlobalError* error = *it; |
| 671 DCHECK(error); | 678 DCHECK(error); |
| 672 if (error->HasMenuItem()) { | 679 if (error->HasMenuItem()) { |
| 673 #if !defined(OS_CHROMEOS) | 680 #if !defined(OS_CHROMEOS) |
| 674 // Don't add a signin error if it's already being displayed elsewhere. | 681 // Don't add a signin error if it's already being displayed elsewhere. |
| 675 if (std::find(signin_errors.begin(), signin_errors.end(), error) != | 682 if (std::find(signin_errors.begin(), signin_errors.end(), error) != |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 &enable_increment, &enable_decrement); | 766 &enable_increment, &enable_decrement); |
| 760 } | 767 } |
| 761 zoom_label_ = l10n_util::GetStringFUTF16( | 768 zoom_label_ = l10n_util::GetStringFUTF16( |
| 762 IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent)); | 769 IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent)); |
| 763 } | 770 } |
| 764 | 771 |
| 765 void WrenchMenuModel::OnZoomLevelChanged( | 772 void WrenchMenuModel::OnZoomLevelChanged( |
| 766 const content::HostZoomMap::ZoomLevelChange& change) { | 773 const content::HostZoomMap::ZoomLevelChange& change) { |
| 767 UpdateZoomControls(); | 774 UpdateZoomControls(); |
| 768 } | 775 } |
| OLD | NEW |