OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser.h" | 5 #include "chrome/browser/ui/browser.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <shellapi.h> | 9 #include <shellapi.h> |
10 #endif // OS_WIN | 10 #endif // OS_WIN |
(...skipping 3930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3941 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui); | 3941 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui); |
3942 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui); | 3942 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui); |
3943 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui); | 3943 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui); |
3944 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_VERTICAL_TABS, show_main_ui); | 3944 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_VERTICAL_TABS, show_main_ui); |
3945 command_updater_.UpdateCommandEnabled(IDC_COMPACT_NAVBAR, show_main_ui); | 3945 command_updater_.UpdateCommandEnabled(IDC_COMPACT_NAVBAR, show_main_ui); |
3946 #if defined (ENABLE_PROFILING) && !defined(NO_TCMALLOC) | 3946 #if defined (ENABLE_PROFILING) && !defined(NO_TCMALLOC) |
3947 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui); | 3947 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui); |
3948 #endif | 3948 #endif |
3949 } | 3949 } |
3950 | 3950 |
3951 bool Browser::HasInternalURL(const NavigationEntry* entry) const { | |
brettw
2011/07/06 16:55:24
When you move this above, please be sure to write
| |
3952 if (!entry) | |
3953 return false; | |
3954 | |
3955 // Check the |virtual_url()| first. This catches regular chrome:// URLs | |
3956 // including URLs that were rewritten (such as chrome://bookmarks). | |
3957 if (entry->virtual_url().SchemeIs(chrome::kChromeUIScheme)) | |
3958 return true; | |
3959 | |
3960 // If the |virtual_url()| isn't a chrome:// URL, check if it's actually | |
3961 // view-source: of a chrome:// URL. | |
3962 if (entry->virtual_url().SchemeIs(chrome::kViewSourceScheme)) | |
3963 return entry->url().SchemeIs(chrome::kChromeUIScheme); | |
3964 | |
3965 return false; | |
3966 } | |
3967 | |
3951 void Browser::UpdateCommandsForTabState() { | 3968 void Browser::UpdateCommandsForTabState() { |
3952 TabContents* current_tab = GetSelectedTabContents(); | 3969 TabContents* current_tab = GetSelectedTabContents(); |
3953 TabContentsWrapper* current_tab_wrapper = GetSelectedTabContentsWrapper(); | 3970 TabContentsWrapper* current_tab_wrapper = GetSelectedTabContentsWrapper(); |
3954 if (!current_tab || !current_tab_wrapper) // May be NULL during tab restore. | 3971 if (!current_tab || !current_tab_wrapper) // May be NULL during tab restore. |
3955 return; | 3972 return; |
3956 | 3973 |
3957 // Navigation commands | 3974 // Navigation commands |
3958 NavigationController& nc = current_tab->controller(); | 3975 NavigationController& nc = current_tab->controller(); |
3959 command_updater_.UpdateCommandEnabled(IDC_BACK, nc.CanGoBack()); | 3976 command_updater_.UpdateCommandEnabled(IDC_BACK, nc.CanGoBack()); |
3960 command_updater_.UpdateCommandEnabled(IDC_FORWARD, nc.CanGoForward()); | 3977 command_updater_.UpdateCommandEnabled(IDC_FORWARD, nc.CanGoForward()); |
(...skipping 10 matching lines...) Expand all Loading... | |
3971 window_->SetStarredState( | 3988 window_->SetStarredState( |
3972 current_tab_wrapper->bookmark_tab_helper()->is_starred()); | 3989 current_tab_wrapper->bookmark_tab_helper()->is_starred()); |
3973 command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE, | 3990 command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE, |
3974 current_tab->controller().CanViewSource()); | 3991 current_tab->controller().CanViewSource()); |
3975 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, | 3992 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, |
3976 current_tab->ShouldDisplayURL() && current_tab->GetURL().is_valid()); | 3993 current_tab->ShouldDisplayURL() && current_tab->GetURL().is_valid()); |
3977 if (is_devtools()) | 3994 if (is_devtools()) |
3978 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false); | 3995 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false); |
3979 | 3996 |
3980 // Changing the encoding is not possible on Chrome-internal webpages. | 3997 // Changing the encoding is not possible on Chrome-internal webpages. |
3981 // Instead of using GetURL here, we use url() (which is the "real" url of the | 3998 bool is_chrome_internal = HasInternalURL(nc.GetActiveEntry()); |
3982 // page) from the NavigationEntry because its reflects their origin rather | |
3983 // than the display one (returned by GetURL) which may be different (like | |
3984 // having "view-source:" on the front). | |
3985 NavigationEntry* active_entry = nc.GetActiveEntry(); | |
3986 bool is_chrome_internal = (active_entry ? | |
3987 active_entry->url().SchemeIs(chrome::kChromeUIScheme) : false); | |
3988 command_updater_.UpdateCommandEnabled(IDC_ENCODING_MENU, | 3999 command_updater_.UpdateCommandEnabled(IDC_ENCODING_MENU, |
3989 !is_chrome_internal && SavePackage::IsSavableContents( | 4000 !is_chrome_internal && SavePackage::IsSavableContents( |
3990 current_tab->contents_mime_type())); | 4001 current_tab->contents_mime_type())); |
3991 | 4002 |
3992 // Show various bits of UI | 4003 // Show various bits of UI |
3993 // TODO(pinkerton): Disable app-mode in the model until we implement it | 4004 // TODO(pinkerton): Disable app-mode in the model until we implement it |
3994 // on the Mac. Be sure to remove both ifdefs. http://crbug.com/13148 | 4005 // on the Mac. Be sure to remove both ifdefs. http://crbug.com/13148 |
3995 #if !defined(OS_MACOSX) | 4006 #if !defined(OS_MACOSX) |
3996 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, | 4007 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, |
3997 web_app::IsValidUrl(current_tab->GetURL())); | 4008 web_app::IsValidUrl(current_tab->GetURL())); |
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4721 // end up querying state once they process the tab switch. | 4732 // end up querying state once they process the tab switch. |
4722 return; | 4733 return; |
4723 } | 4734 } |
4724 | 4735 |
4725 BookmarkBar::AnimateChangeType animate_type = | 4736 BookmarkBar::AnimateChangeType animate_type = |
4726 (reason == BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE) ? | 4737 (reason == BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE) ? |
4727 BookmarkBar::ANIMATE_STATE_CHANGE : | 4738 BookmarkBar::ANIMATE_STATE_CHANGE : |
4728 BookmarkBar::DONT_ANIMATE_STATE_CHANGE; | 4739 BookmarkBar::DONT_ANIMATE_STATE_CHANGE; |
4729 window_->BookmarkBarStateChanged(animate_type); | 4740 window_->BookmarkBarStateChanged(animate_type); |
4730 } | 4741 } |
OLD | NEW |