| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/views/toolbar_view.h" | 5 #include "chrome/browser/views/toolbar_view.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "app/drag_drop_types.h" | 9 #include "app/drag_drop_types.h" |
| 10 #include "app/gfx/canvas.h" | 10 #include "app/gfx/canvas.h" |
| 11 #include "app/l10n_util.h" | 11 #include "app/l10n_util.h" |
| 12 #include "app/os_exchange_data.h" | 12 #include "app/os_exchange_data.h" |
| 13 #include "app/resource_bundle.h" | 13 #include "app/resource_bundle.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/keyboard_codes.h" | 15 #include "base/keyboard_codes.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| 18 #include "chrome/app/chrome_dll_resource.h" | 18 #include "chrome/app/chrome_dll_resource.h" |
| 19 #include "chrome/browser/back_forward_menu_model_views.h" | |
| 20 #include "chrome/browser/bookmarks/bookmark_model.h" | 19 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 21 #include "chrome/browser/browser.h" | 20 #include "chrome/browser/browser.h" |
| 22 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
| 23 #include "chrome/browser/browser_theme_provider.h" | 22 #include "chrome/browser/browser_theme_provider.h" |
| 24 #include "chrome/browser/browser_window.h" | 23 #include "chrome/browser/browser_window.h" |
| 25 #include "chrome/browser/character_encoding.h" | 24 #include "chrome/browser/character_encoding.h" |
| 26 #include "chrome/browser/defaults.h" | 25 #include "chrome/browser/defaults.h" |
| 27 #include "chrome/browser/encoding_menu_controller.h" | 26 #include "chrome/browser/encoding_menu_controller.h" |
| 28 #include "chrome/browser/metrics/user_metrics.h" | 27 #include "chrome/browser/metrics/user_metrics.h" |
| 29 #include "chrome/browser/profile.h" | 28 #include "chrome/browser/profile.h" |
| 30 #include "chrome/browser/sync/profile_sync_service.h" | 29 #include "chrome/browser/sync/profile_sync_service.h" |
| 31 #include "chrome/browser/sync/sync_ui_util.h" | 30 #include "chrome/browser/sync/sync_ui_util.h" |
| 32 #include "chrome/browser/tab_contents/navigation_controller.h" | 31 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 33 #include "chrome/browser/tab_contents/navigation_entry.h" | 32 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 34 #include "chrome/browser/user_data_manager.h" | |
| 35 #include "chrome/browser/views/bookmark_menu_button.h" | 33 #include "chrome/browser/views/bookmark_menu_button.h" |
| 36 #include "chrome/browser/views/browser_actions_container.h" | 34 #include "chrome/browser/views/browser_actions_container.h" |
| 37 #include "chrome/browser/views/event_utils.h" | 35 #include "chrome/browser/views/event_utils.h" |
| 38 #include "chrome/browser/views/go_button.h" | 36 #include "chrome/browser/views/go_button.h" |
| 39 #include "chrome/browser/views/location_bar_view.h" | 37 #include "chrome/browser/views/location_bar_view.h" |
| 40 #include "chrome/browser/views/toolbar_star_toggle.h" | 38 #include "chrome/browser/views/toolbar_star_toggle.h" |
| 41 #include "chrome/browser/view_ids.h" | 39 #include "chrome/browser/view_ids.h" |
| 42 #include "chrome/common/chrome_constants.h" | 40 #include "chrome/common/chrome_constants.h" |
| 43 #include "chrome/common/chrome_switches.h" | 41 #include "chrome/common/chrome_switches.h" |
| 44 #include "chrome/common/notification_service.h" | 42 #include "chrome/common/notification_service.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 home_(NULL), | 85 home_(NULL), |
| 88 star_(NULL), | 86 star_(NULL), |
| 89 location_bar_(NULL), | 87 location_bar_(NULL), |
| 90 go_(NULL), | 88 go_(NULL), |
| 91 browser_actions_(NULL), | 89 browser_actions_(NULL), |
| 92 page_menu_(NULL), | 90 page_menu_(NULL), |
| 93 app_menu_(NULL), | 91 app_menu_(NULL), |
| 94 bookmark_menu_(NULL), | 92 bookmark_menu_(NULL), |
| 95 profile_(NULL), | 93 profile_(NULL), |
| 96 browser_(browser), | 94 browser_(browser), |
| 97 profiles_menu_contents_(NULL), | 95 profiles_menu_contents_(NULL) { |
| 98 ALLOW_THIS_IN_INITIALIZER_LIST( | |
| 99 profiles_helper_(new GetProfilesHelper(this))) { | |
| 100 browser_->command_updater()->AddCommandObserver(IDC_BACK, this); | 96 browser_->command_updater()->AddCommandObserver(IDC_BACK, this); |
| 101 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this); | 97 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this); |
| 102 browser_->command_updater()->AddCommandObserver(IDC_RELOAD, this); | 98 browser_->command_updater()->AddCommandObserver(IDC_RELOAD, this); |
| 103 browser_->command_updater()->AddCommandObserver(IDC_HOME, this); | 99 browser_->command_updater()->AddCommandObserver(IDC_HOME, this); |
| 104 browser_->command_updater()->AddCommandObserver(IDC_BOOKMARK_PAGE, this); | 100 browser_->command_updater()->AddCommandObserver(IDC_BOOKMARK_PAGE, this); |
| 105 if (browser->type() == Browser::TYPE_NORMAL) | 101 if (browser->type() == Browser::TYPE_NORMAL) |
| 106 display_mode_ = DISPLAYMODE_NORMAL; | 102 display_mode_ = DISPLAYMODE_NORMAL; |
| 107 else | 103 else |
| 108 display_mode_ = DISPLAYMODE_LOCATION; | 104 display_mode_ = DISPLAYMODE_LOCATION; |
| 109 | 105 |
| 110 if (!kPopupBackgroundEdge) { | 106 if (!kPopupBackgroundEdge) { |
| 111 kPopupBackgroundEdge = ResourceBundle::GetSharedInstance().GetBitmapNamed( | 107 kPopupBackgroundEdge = ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 112 IDR_LOCATIONBG_POPUPMODE_EDGE); | 108 IDR_LOCATIONBG_POPUPMODE_EDGE); |
| 113 } | 109 } |
| 114 } | 110 } |
| 115 | 111 |
| 116 ToolbarView::~ToolbarView() { | |
| 117 profiles_helper_->OnDelegateDeleted(); | |
| 118 } | |
| 119 | |
| 120 void ToolbarView::Init(Profile* profile) { | 112 void ToolbarView::Init(Profile* profile) { |
| 121 back_menu_model_.reset(new BackForwardMenuModelViews( | 113 back_menu_model_.reset(new BackForwardMenuModelViews( |
| 122 browser_, BackForwardMenuModel::BACKWARD_MENU, GetWidget())); | 114 browser_, BackForwardMenuModel::BACKWARD_MENU, GetWidget())); |
| 123 forward_menu_model_.reset(new BackForwardMenuModelViews( | 115 forward_menu_model_.reset(new BackForwardMenuModelViews( |
| 124 browser_, BackForwardMenuModel::FORWARD_MENU, GetWidget())); | 116 browser_, BackForwardMenuModel::FORWARD_MENU, GetWidget())); |
| 125 | 117 |
| 126 // Create all the individual Views in the Toolbar. | 118 // Create all the individual Views in the Toolbar. |
| 127 CreateLeftSideControls(); | 119 CreateLeftSideControls(); |
| 128 CreateCenterStack(profile); | 120 CreateCenterStack(profile); |
| 129 CreateRightSideControls(profile); | 121 CreateRightSideControls(profile); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 break; | 165 break; |
| 174 case VIEW_ID_APP_MENU: | 166 case VIEW_ID_APP_MENU: |
| 175 RunAppMenu(pt); | 167 RunAppMenu(pt); |
| 176 break; | 168 break; |
| 177 default: | 169 default: |
| 178 NOTREACHED() << "Invalid source menu."; | 170 NOTREACHED() << "Invalid source menu."; |
| 179 } | 171 } |
| 180 } | 172 } |
| 181 | 173 |
| 182 //////////////////////////////////////////////////////////////////////////////// | 174 //////////////////////////////////////////////////////////////////////////////// |
| 183 // ToolbarView, GetProfilesHelper::Delegate implementation: | |
| 184 | |
| 185 void ToolbarView::OnGetProfilesDone( | |
| 186 const std::vector<std::wstring>& profiles) { | |
| 187 // Nothing to do if the menu has gone away. | |
| 188 if (!profiles_menu_contents_.get()) | |
| 189 return; | |
| 190 | |
| 191 // Store the latest list of profiles in the browser. | |
| 192 browser_->set_user_data_dir_profiles(profiles); | |
| 193 | |
| 194 // Add direct sub menu items for profiles. | |
| 195 std::vector<std::wstring>::const_iterator iter = profiles.begin(); | |
| 196 for (int i = IDC_NEW_WINDOW_PROFILE_0; | |
| 197 (i <= IDC_NEW_WINDOW_PROFILE_LAST) && (iter != profiles.end()); | |
| 198 ++i, ++iter) | |
| 199 profiles_menu_contents_->AddItem(i, WideToUTF16Hack(*iter)); | |
| 200 | |
| 201 // If there are more profiles then show "Other" link. | |
| 202 if (iter != profiles.end()) { | |
| 203 profiles_menu_contents_->AddSeparator(); | |
| 204 profiles_menu_contents_->AddItemWithStringId(IDC_SELECT_PROFILE, | |
| 205 IDS_SELECT_PROFILE); | |
| 206 } | |
| 207 | |
| 208 // Always show a link to select a new profile. | |
| 209 profiles_menu_contents_->AddSeparator(); | |
| 210 profiles_menu_contents_->AddItemWithStringId( | |
| 211 IDC_NEW_PROFILE, | |
| 212 IDS_SELECT_PROFILE_DIALOG_NEW_PROFILE_ENTRY); | |
| 213 } | |
| 214 | |
| 215 //////////////////////////////////////////////////////////////////////////////// | |
| 216 // ToolbarView, LocationBarView::Delegate implementation: | 175 // ToolbarView, LocationBarView::Delegate implementation: |
| 217 | 176 |
| 218 TabContents* ToolbarView::GetTabContents() { | 177 TabContents* ToolbarView::GetTabContents() { |
| 219 return browser_->GetSelectedTabContents(); | 178 return browser_->GetSelectedTabContents(); |
| 220 } | 179 } |
| 221 | 180 |
| 222 void ToolbarView::OnInputInProgress(bool in_progress) { | 181 void ToolbarView::OnInputInProgress(bool in_progress) { |
| 223 // The edit should make sure we're only notified when something changes. | 182 // The edit should make sure we're only notified when something changes. |
| 224 DCHECK(model_->input_in_progress() != in_progress); | 183 DCHECK(model_->input_in_progress() != in_progress); |
| 225 | 184 |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 bookmark_menu_->SetIcon(*tp->GetBitmapNamed(IDR_MENU_BOOKMARK)); | 722 bookmark_menu_->SetIcon(*tp->GetBitmapNamed(IDR_MENU_BOOKMARK)); |
| 764 } | 723 } |
| 765 | 724 |
| 766 void ToolbarView::RunPageMenu(const gfx::Point& pt) { | 725 void ToolbarView::RunPageMenu(const gfx::Point& pt) { |
| 767 page_menu_model_.reset(new PageMenuModel(this, browser_)); | 726 page_menu_model_.reset(new PageMenuModel(this, browser_)); |
| 768 page_menu_menu_.reset(new views::Menu2(page_menu_model_.get())); | 727 page_menu_menu_.reset(new views::Menu2(page_menu_model_.get())); |
| 769 page_menu_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); | 728 page_menu_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); |
| 770 } | 729 } |
| 771 | 730 |
| 772 void ToolbarView::RunAppMenu(const gfx::Point& pt) { | 731 void ToolbarView::RunAppMenu(const gfx::Point& pt) { |
| 773 CreateAppMenu(); | 732 // We always rebuild the app menu so that we can get the current state of |
| 733 // the sync system. |
| 734 app_menu_model_.reset(new AppMenuModel(this, browser_)); |
| 735 app_menu_menu_.reset(new views::Menu2(app_menu_model_.get())); |
| 774 app_menu_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); | 736 app_menu_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); |
| 775 } | 737 } |
| 776 | |
| 777 void ToolbarView::CreateAppMenu() { | |
| 778 // We always rebuild the app menu so that we can get the current state of | |
| 779 // the sync system. | |
| 780 | |
| 781 app_menu_contents_.reset(new menus::SimpleMenuModel(this)); | |
| 782 app_menu_contents_->AddItemWithStringId(IDC_NEW_TAB, IDS_NEW_TAB); | |
| 783 app_menu_contents_->AddItemWithStringId(IDC_NEW_WINDOW, IDS_NEW_WINDOW); | |
| 784 app_menu_contents_->AddItemWithStringId(IDC_NEW_INCOGNITO_WINDOW, | |
| 785 IDS_NEW_INCOGNITO_WINDOW); | |
| 786 // Enumerate profiles asynchronously and then create the parent menu item. | |
| 787 // We will create the child menu items for this once the asynchronous call is | |
| 788 // done. See OnGetProfilesDone(). | |
| 789 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
| 790 if (command_line.HasSwitch(switches::kEnableUserDataDirProfiles) && | |
| 791 !profiles_menu_contents_.get()) { | |
| 792 profiles_helper_->GetProfiles(NULL); | |
| 793 profiles_menu_contents_.reset(new menus::SimpleMenuModel(this)); | |
| 794 app_menu_contents_->AddSubMenuWithStringId(IDS_PROFILE_MENU, | |
| 795 profiles_menu_contents_.get()); | |
| 796 } | |
| 797 | |
| 798 app_menu_contents_->AddSeparator(); | |
| 799 app_menu_contents_->AddCheckItemWithStringId(IDC_SHOW_BOOKMARK_BAR, | |
| 800 IDS_SHOW_BOOKMARK_BAR); | |
| 801 app_menu_contents_->AddItemWithStringId(IDC_FULLSCREEN, IDS_FULLSCREEN); | |
| 802 app_menu_contents_->AddSeparator(); | |
| 803 app_menu_contents_->AddItemWithStringId(IDC_SHOW_HISTORY, IDS_SHOW_HISTORY); | |
| 804 app_menu_contents_->AddItemWithStringId(IDC_SHOW_BOOKMARK_MANAGER, | |
| 805 IDS_BOOKMARK_MANAGER); | |
| 806 app_menu_contents_->AddItemWithStringId(IDC_SHOW_DOWNLOADS, | |
| 807 IDS_SHOW_DOWNLOADS); | |
| 808 | |
| 809 // Create the manage extensions menu item. | |
| 810 app_menu_contents_->AddItemWithStringId(IDC_MANAGE_EXTENSIONS, | |
| 811 IDS_SHOW_EXTENSIONS); | |
| 812 | |
| 813 app_menu_contents_->AddSeparator(); | |
| 814 if (ProfileSyncService::IsSyncEnabled()) { | |
| 815 string16 label; | |
| 816 string16 link; | |
| 817 // TODO(akalin): use sync_ui_util::GetStatus instead. | |
| 818 sync_ui_util::MessageType type = sync_ui_util::GetStatusLabels( | |
| 819 browser_->profile()->GetOriginalProfile()->GetProfileSyncService(), | |
| 820 &label, &link); | |
| 821 label = type == sync_ui_util::SYNCED ? | |
| 822 l10n_util::GetStringUTF16(IDS_SYNC_MENU_BOOKMARKS_SYNCED_LABEL) : | |
| 823 type == sync_ui_util::SYNC_ERROR ? | |
| 824 l10n_util::GetStringUTF16(IDS_SYNC_MENU_BOOKMARK_SYNC_ERROR_LABEL) : | |
| 825 l10n_util::GetStringUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL); | |
| 826 app_menu_contents_->AddItem(IDC_SYNC_BOOKMARKS, label); | |
| 827 app_menu_contents_->AddSeparator(); | |
| 828 } | |
| 829 app_menu_contents_->AddItem(IDC_OPTIONS, | |
| 830 l10n_util::GetStringFUTF16( | |
| 831 IDS_OPTIONS, | |
| 832 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); | |
| 833 app_menu_contents_->AddItem(IDC_ABOUT, | |
| 834 l10n_util::GetStringFUTF16( | |
| 835 IDS_ABOUT, | |
| 836 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); | |
| 837 app_menu_contents_->AddItemWithStringId(IDC_HELP_PAGE, IDS_HELP_PAGE); | |
| 838 if (browser_defaults::kShowExitMenuItem) { | |
| 839 app_menu_contents_->AddSeparator(); | |
| 840 app_menu_contents_->AddItemWithStringId(IDC_EXIT, IDS_EXIT); | |
| 841 } | |
| 842 | |
| 843 app_menu_menu_.reset(new views::Menu2(app_menu_contents_.get())); | |
| 844 } | |
| OLD | NEW |