Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1536)

Side by Side Diff: chrome/browser/browser.cc

Issue 1610012: Clean up some of the command-initializing code. No functional change.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/browser.h" 5 #include "chrome/browser/browser.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "app/animation.h" 10 #include "app/animation.h"
(...skipping 2757 matching lines...) Expand 10 before | Expand all | Expand 10 after
2768 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1256, true); 2768 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1256, true);
2769 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88598, true); 2769 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88598, true);
2770 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88598I, true); 2770 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88598I, true);
2771 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1255, true); 2771 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1255, true);
2772 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1258, true); 2772 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1258, true);
2773 2773
2774 // Clipboard commands 2774 // Clipboard commands
2775 command_updater_.UpdateCommandEnabled(IDC_CUT, true); 2775 command_updater_.UpdateCommandEnabled(IDC_CUT, true);
2776 command_updater_.UpdateCommandEnabled(IDC_COPY, true); 2776 command_updater_.UpdateCommandEnabled(IDC_COPY, true);
2777 command_updater_.UpdateCommandEnabled(IDC_PASTE, true); 2777 command_updater_.UpdateCommandEnabled(IDC_PASTE, true);
2778 command_updater_.UpdateCommandEnabled(IDC_COPY_URL, true);
2779
2780 // Find-in-page
2781 command_updater_.UpdateCommandEnabled(IDC_FIND, true);
2782 command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, true);
2783 command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, true);
2784 2778
2785 // Zoom 2779 // Zoom
2786 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true); 2780 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true);
2787 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true); 2781 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true);
2788 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, true); 2782 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, true);
2789 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true); 2783 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true);
2790 2784
2791 // Show various bits of UI 2785 // Show various bits of UI
2792 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, true); 2786 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, true);
2793 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, false); 2787 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, false);
(...skipping 18 matching lines...) Expand all
2812 command_updater_.UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS, 2806 command_updater_.UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS,
2813 enable_extensions); 2807 enable_extensions);
2814 2808
2815 #if defined(OS_CHROMEOS) 2809 #if defined(OS_CHROMEOS)
2816 command_updater_.UpdateCommandEnabled(IDC_SYSTEM_OPTIONS, true); 2810 command_updater_.UpdateCommandEnabled(IDC_SYSTEM_OPTIONS, true);
2817 command_updater_.UpdateCommandEnabled(IDC_INTERNET_OPTIONS, true); 2811 command_updater_.UpdateCommandEnabled(IDC_INTERNET_OPTIONS, true);
2818 #endif 2812 #endif
2819 2813
2820 // Initialize other commands based on the window type. 2814 // Initialize other commands based on the window type.
2821 bool normal_window = type() == TYPE_NORMAL; 2815 bool normal_window = type() == TYPE_NORMAL;
2816 bool non_devtools_window = type() != TYPE_DEVTOOLS;
2822 2817
2823 // Navigation commands 2818 // Navigation commands
2824 command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window); 2819 command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window);
2825 2820
2826 // Window management commands 2821 // Window management commands
2827 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window); 2822 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window);
2828 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, 2823 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB,
2829 normal_window); 2824 normal_window);
2830 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window); 2825 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window);
2831 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window); 2826 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window);
2832 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window); 2827 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window);
2833 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window); 2828 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window);
2834 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window); 2829 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window);
2835 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window); 2830 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window);
2836 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window); 2831 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window);
2837 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window); 2832 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window);
2838 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window); 2833 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window);
2839 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window); 2834 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window);
2840 command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window); 2835 command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window);
2841 command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB, 2836 command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB,
2842 !profile_->IsOffTheRecord()); 2837 !profile_->IsOffTheRecord());
2843 2838
2844 // Page-related commands 2839 // Page-related commands
2845 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_PAGE, normal_window); 2840 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_PAGE, normal_window);
2846 2841
2842 // Clipboard commands
2843 command_updater_.UpdateCommandEnabled(IDC_COPY_URL, non_devtools_window);
2844
2845 // Find-in-page
2846 command_updater_.UpdateCommandEnabled(IDC_FIND, non_devtools_window);
2847 command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, non_devtools_window);
2848 command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, non_devtools_window);
2849
2847 // Show various bits of UI 2850 // Show various bits of UI
2848 command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA, 2851 command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA, normal_window);
2849 normal_window);
2850 2852
2851 // Initialize other commands whose state changes based on fullscreen mode. 2853 // Initialize other commands whose state changes based on fullscreen mode.
2852 UpdateCommandsForFullscreenMode(false); 2854 UpdateCommandsForFullscreenMode(false);
2853 } 2855 }
2854 2856
2855 void Browser::UpdateCommandsForTabState() { 2857 void Browser::UpdateCommandsForTabState() {
2856 TabContents* current_tab = GetSelectedTabContents(); 2858 TabContents* current_tab = GetSelectedTabContents();
2857 if (!current_tab) // May be NULL during tab restore. 2859 if (!current_tab) // May be NULL during tab restore.
2858 return; 2860 return;
2859 2861
2860 // Navigation commands 2862 // Navigation commands
2861 NavigationController& nc = current_tab->controller(); 2863 NavigationController& nc = current_tab->controller();
2862 command_updater_.UpdateCommandEnabled(IDC_BACK, nc.CanGoBack()); 2864 command_updater_.UpdateCommandEnabled(IDC_BACK, nc.CanGoBack());
2863 command_updater_.UpdateCommandEnabled(IDC_FORWARD, nc.CanGoForward()); 2865 command_updater_.UpdateCommandEnabled(IDC_FORWARD, nc.CanGoForward());
2866 command_updater_.UpdateCommandEnabled(IDC_RELOAD,
2867 CanReloadContents(current_tab));
2868 command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE,
2869 CanReloadContents(current_tab));
2864 2870
2865 // Window management commands 2871 // Window management commands
2872 bool non_app_window = !(type() & TYPE_APP);
2866 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, 2873 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB,
2867 !(type() & TYPE_APP) && CanDuplicateContentsAt(selected_index())); 2874 non_app_window && CanDuplicateContentsAt(selected_index()));
2868 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, 2875 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB,
2869 !(type() & TYPE_APP) && tab_count() > 1); 2876 non_app_window && tab_count() > 1);
2870 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, 2877 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB,
2871 !(type() & TYPE_APP) && tab_count() > 1); 2878 non_app_window && tab_count() > 1);
2872
2873 // Current navigation entry, may be NULL.
2874 NavigationEntry* active_entry = nc.GetActiveEntry();
2875 2879
2876 // Page-related commands 2880 // Page-related commands
2877 window_->SetStarredState(current_tab->is_starred()); 2881 window_->SetStarredState(current_tab->is_starred());
2878 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS, 2882 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS,
2879 CanBookmarkAllTabs()); 2883 CanBookmarkAllTabs());
2880
2881 // View-source should not be enabled if already in view-source mode or
2882 // the source is not viewable.
2883 command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE, 2884 command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE,
2884 current_tab->controller().CanViewSource()); 2885 current_tab->controller().CanViewSource());
2885
2886 // Instead of using GetURL here, we use url() (which is the "real" url of the 2886 // Instead of using GetURL here, we use url() (which is the "real" url of the
2887 // page) from the NavigationEntry because its reflects their origin rather 2887 // page) from the NavigationEntry because its reflects their origin rather
2888 // than the display one (returned by GetURL) which may be different (like 2888 // than the display one (returned by GetURL) which may be different (like
2889 // having "view-source:" on the front). 2889 // having "view-source:" on the front).
2890 GURL savable_url = (active_entry) ? active_entry->url() : GURL(); 2890 NavigationEntry* active_entry = nc.GetActiveEntry();
2891 2891 bool is_savable_url =
2892 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, 2892 SavePackage::IsSavableURL(active_entry ? active_entry->url() : GURL());
2893 SavePackage::IsSavableURL(savable_url)); 2893 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, is_savable_url);
2894 command_updater_.UpdateCommandEnabled(IDC_ENCODING_MENU, 2894 command_updater_.UpdateCommandEnabled(IDC_ENCODING_MENU, is_savable_url &&
2895 SavePackage::IsSavableContents(current_tab->contents_mime_type()) && 2895 SavePackage::IsSavableContents(current_tab->contents_mime_type()));
2896 SavePackage::IsSavableURL(savable_url)); 2896 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION,
2897 2897 current_tab->ShouldDisplayURL() && current_tab->GetURL().is_valid());
2898 // Disable certain items if running DevTools
2899 command_updater_.UpdateCommandEnabled(IDC_RELOAD,
2900 CanReloadContents(current_tab));
2901 command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE,
2902 CanReloadContents(current_tab));
2903 bool enabled_for_non_devtools = type() != TYPE_DEVTOOLS;
2904 command_updater_.UpdateCommandEnabled(IDC_FIND, enabled_for_non_devtools);
2905 command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT,
2906 enabled_for_non_devtools);
2907 command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS,
2908 enabled_for_non_devtools);
2909 command_updater_.UpdateCommandEnabled(IDC_COPY_URL,
2910 enabled_for_non_devtools);
2911 2898
2912 // Show various bits of UI 2899 // Show various bits of UI
2913 // TODO(pinkerton): Disable app-mode in the model until we implement it 2900 // TODO(pinkerton): Disable app-mode in the model until we implement it
2914 // on the Mac. Be sure to remove both ifdefs. http://crbug.com/13148 2901 // on the Mac. Be sure to remove both ifdefs. http://crbug.com/13148
2915 #if !defined(OS_MACOSX) 2902 #if !defined(OS_MACOSX)
2916 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, 2903 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS,
2917 web_app::IsValidUrl(current_tab->GetURL())); 2904 web_app::IsValidUrl(current_tab->GetURL()));
2918 #endif 2905 #endif
2919 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION,
2920 current_tab->ShouldDisplayURL() && current_tab->GetURL().is_valid());
2921 } 2906 }
2922 2907
2923 void Browser::UpdateStopGoState(bool is_loading, bool force) { 2908 void Browser::UpdateStopGoState(bool is_loading, bool force) {
2924 window_->UpdateStopGoState(is_loading, force); 2909 window_->UpdateStopGoState(is_loading, force);
2925 command_updater_.UpdateCommandEnabled(IDC_GO, !is_loading); 2910 command_updater_.UpdateCommandEnabled(IDC_GO, !is_loading);
2926 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); 2911 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading);
2927 } 2912 }
2928 2913
2929 /////////////////////////////////////////////////////////////////////////////// 2914 ///////////////////////////////////////////////////////////////////////////////
2930 // Browser, UI update coalescing and handling (private): 2915 // Browser, UI update coalescing and handling (private):
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
3480 if (TabHasUnloadListener(contents)) { 3465 if (TabHasUnloadListener(contents)) {
3481 // If the page has unload listeners, then we tell the renderer to fire 3466 // If the page has unload listeners, then we tell the renderer to fire
3482 // them. Once they have fired, we'll get a message back saying whether 3467 // them. Once they have fired, we'll get a message back saying whether
3483 // to proceed closing the page or not, which sends us back to this method 3468 // to proceed closing the page or not, which sends us back to this method
3484 // with the HasUnloadListener bit cleared. 3469 // with the HasUnloadListener bit cleared.
3485 contents->render_view_host()->FirePageBeforeUnload(false); 3470 contents->render_view_host()->FirePageBeforeUnload(false);
3486 return true; 3471 return true;
3487 } 3472 }
3488 return false; 3473 return false;
3489 } 3474 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698