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

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

Issue 18540: Don't expose the go and star button views directly through the BrowserWindow ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 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 | « chrome/browser/browser.h ('k') | chrome/browser/browser_commands_unittest.cc » ('j') | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/idle_timer.h" 6 #include "base/idle_timer.h"
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "chrome/app/chrome_dll_resource.h" 9 #include "chrome/app/chrome_dll_resource.h"
10 #include "chrome/browser/browser_list.h" 10 #include "chrome/browser/browser_list.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 #include "chrome/browser/status_bubble.h" 52 #include "chrome/browser/status_bubble.h"
53 #include "chrome/browser/tab_contents/interstitial_page.h" 53 #include "chrome/browser/tab_contents/interstitial_page.h"
54 #include "chrome/browser/tab_contents/navigation_controller.h" 54 #include "chrome/browser/tab_contents/navigation_controller.h"
55 #include "chrome/browser/tab_contents/navigation_entry.h" 55 #include "chrome/browser/tab_contents/navigation_entry.h"
56 #include "chrome/browser/tab_contents/site_instance.h" 56 #include "chrome/browser/tab_contents/site_instance.h"
57 #include "chrome/browser/tab_contents/web_contents_view.h" 57 #include "chrome/browser/tab_contents/web_contents_view.h"
58 #include "chrome/browser/task_manager.h" 58 #include "chrome/browser/task_manager.h"
59 #include "chrome/browser/user_data_manager.h" 59 #include "chrome/browser/user_data_manager.h"
60 #include "chrome/browser/view_ids.h" 60 #include "chrome/browser/view_ids.h"
61 #include "chrome/browser/views/download_tab_view.h" 61 #include "chrome/browser/views/download_tab_view.h"
62 #include "chrome/browser/views/go_button.h"
63 #include "chrome/browser/views/location_bar_view.h" 62 #include "chrome/browser/views/location_bar_view.h"
64 #include "chrome/browser/views/new_profile_dialog.h" 63 #include "chrome/browser/views/new_profile_dialog.h"
65 #include "chrome/browser/views/select_profile_dialog.h" 64 #include "chrome/browser/views/select_profile_dialog.h"
66 #include "chrome/browser/views/toolbar_star_toggle.h"
67 #include "chrome/browser/window_sizer.h" 65 #include "chrome/browser/window_sizer.h"
68 #include "chrome/common/l10n_util.h" 66 #include "chrome/common/l10n_util.h"
69 #include "chrome/common/win_util.h" 67 #include "chrome/common/win_util.h"
70 68
71 #include "chromium_strings.h" 69 #include "chromium_strings.h"
72 #include "generated_resources.h" 70 #include "generated_resources.h"
73 71
74 #endif // OS_WIN 72 #endif // OS_WIN
75 73
76 using base::TimeDelta; 74 using base::TimeDelta;
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 } 723 }
726 724
727 void Browser::Exit() { 725 void Browser::Exit() {
728 UserMetrics::RecordAction(L"Exit", profile_); 726 UserMetrics::RecordAction(L"Exit", profile_);
729 BrowserList::CloseAllBrowsers(true); 727 BrowserList::CloseAllBrowsers(true);
730 } 728 }
731 729
732 void Browser::BookmarkCurrentPage() { 730 void Browser::BookmarkCurrentPage() {
733 UserMetrics::RecordAction(L"Star", profile_); 731 UserMetrics::RecordAction(L"Star", profile_);
734 732
735 TabContents* tab = GetSelectedTabContents(); 733 TabContents* contents = GetSelectedTabContents();
736 if (!tab->AsWebContents()) 734 BookmarkModel* model = contents->profile()->GetBookmarkModel();
737 return;
738
739 WebContents* rvh = tab->AsWebContents();
740 BookmarkModel* model = tab->profile()->GetBookmarkModel();
741 if (!model || !model->IsLoaded()) 735 if (!model || !model->IsLoaded())
742 return; // Ignore requests until bookmarks are loaded. 736 return; // Ignore requests until bookmarks are loaded.
743 737
744 NavigationEntry* entry = rvh->controller()->GetActiveEntry(); 738 NavigationEntry* entry = contents->controller()->GetActiveEntry();
745 if (!entry) 739 if (!entry)
746 return; // Can't star if there is no URL. 740 return; // Can't star if there is no URL.
747 const GURL& url = entry->display_url(); 741 const GURL& url = entry->display_url();
748 if (url.is_empty() || !url.is_valid()) 742 if (url.is_empty() || !url.is_valid())
749 return; 743 return;
750 744
751 if (window_->GetStarButton()) { 745 model->SetURLStarred(url, entry->title(), true);
752 if (!window_->GetStarButton()->is_bubble_showing()) { 746 if (!window_->IsBookmarkBubbleVisible())
753 const bool newly_bookmarked = !model->IsBookmarked(url); 747 window_->ShowBookmarkBubble(url, model->IsBookmarked(url));
754 if (newly_bookmarked) {
755 model->SetURLStarred(url, entry->title(), true);
756 if (!model->IsBookmarked(url)) {
757 // Starring failed. This shouldn't happen.
758 NOTREACHED();
759 return;
760 }
761 }
762 window_->GetStarButton()->ShowStarBubble(url, newly_bookmarked);
763 }
764 } else if (model->IsBookmarked(url)) {
765 // If we can't find the star button and the user wanted to unstar it,
766 // go ahead and unstar it without showing the bubble.
767 model->SetURLStarred(url, std::wstring(), false);
768 }
769 } 748 }
770 749
771 void Browser::ViewSource() { 750 void Browser::ViewSource() {
772 UserMetrics::RecordAction(L"ViewSource", profile_); 751 UserMetrics::RecordAction(L"ViewSource", profile_);
773 752
774 TabContents* current_tab = GetSelectedTabContents(); 753 TabContents* current_tab = GetSelectedTabContents();
775 NavigationEntry* entry = current_tab->controller()->GetLastCommittedEntry(); 754 NavigationEntry* entry = current_tab->controller()->GetLastCommittedEntry();
776 if (entry) { 755 if (entry) {
777 GURL url("view-source:" + entry->url().spec()); 756 GURL url("view-source:" + entry->url().spec());
778 OpenURL(url, GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK); 757 OpenURL(url, GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK);
(...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after
1759 1738
1760 void Browser::ToolbarSizeChanged(TabContents* source, bool is_animating) { 1739 void Browser::ToolbarSizeChanged(TabContents* source, bool is_animating) {
1761 if (source == GetSelectedTabContents() || source == NULL) { 1740 if (source == GetSelectedTabContents() || source == NULL) {
1762 // This will refresh the shelf if needed. 1741 // This will refresh the shelf if needed.
1763 window_->SelectedTabToolbarSizeChanged(is_animating); 1742 window_->SelectedTabToolbarSizeChanged(is_animating);
1764 } 1743 }
1765 } 1744 }
1766 1745
1767 void Browser::URLStarredChanged(TabContents* source, bool starred) { 1746 void Browser::URLStarredChanged(TabContents* source, bool starred) {
1768 if (source == GetSelectedTabContents()) 1747 if (source == GetSelectedTabContents())
1769 SetStarredButtonToggled(starred); 1748 window_->SetStarredState(starred);
1770 } 1749 }
1771 1750
1772 void Browser::ContentsMouseEvent(TabContents* source, UINT message) { 1751 void Browser::ContentsMouseEvent(TabContents* source, UINT message) {
1773 if (!GetStatusBubble()) 1752 if (!GetStatusBubble())
1774 return; 1753 return;
1775 1754
1776 if (source == GetSelectedTabContents()) { 1755 if (source == GetSelectedTabContents()) {
1777 if (message == WM_MOUSEMOVE) { 1756 if (message == WM_MOUSEMOVE) {
1778 GetStatusBubble()->MouseMoved(); 1757 GetStatusBubble()->MouseMoved();
1779 } else if (message == WM_MOUSELEAVE) { 1758 } else if (message == WM_MOUSELEAVE) {
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
2068 2047
2069 // Initialize commands available only for web content. 2048 // Initialize commands available only for web content.
2070 { 2049 {
2071 WebContents* web_contents = current_tab->AsWebContents(); 2050 WebContents* web_contents = current_tab->AsWebContents();
2072 bool is_web_contents = web_contents != NULL; 2051 bool is_web_contents = web_contents != NULL;
2073 2052
2074 // Page-related commands 2053 // Page-related commands
2075 // Only allow bookmarking for tabbed browsers. 2054 // Only allow bookmarking for tabbed browsers.
2076 command_updater_.UpdateCommandEnabled(IDC_STAR, 2055 command_updater_.UpdateCommandEnabled(IDC_STAR,
2077 is_web_contents && (type() == TYPE_NORMAL)); 2056 is_web_contents && (type() == TYPE_NORMAL));
2078 SetStarredButtonToggled(is_web_contents && web_contents->is_starred()); 2057 window_->SetStarredState(is_web_contents && web_contents->is_starred());
2079 // View-source should not be enabled if already in view-source mode. 2058 // View-source should not be enabled if already in view-source mode.
2080 command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE, 2059 command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE,
2081 is_web_contents && (current_tab->type() != TAB_CONTENTS_VIEW_SOURCE) && 2060 is_web_contents && (current_tab->type() != TAB_CONTENTS_VIEW_SOURCE) &&
2082 current_tab->controller()->GetActiveEntry()); 2061 current_tab->controller()->GetActiveEntry());
2083 command_updater_.UpdateCommandEnabled(IDC_PRINT, is_web_contents); 2062 command_updater_.UpdateCommandEnabled(IDC_PRINT, is_web_contents);
2084 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, 2063 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE,
2085 is_web_contents && SavePackage::IsSavableURL(current_tab->GetURL())); 2064 is_web_contents && SavePackage::IsSavableURL(current_tab->GetURL()));
2086 command_updater_.UpdateCommandEnabled(IDC_ENCODING_MENU, 2065 command_updater_.UpdateCommandEnabled(IDC_ENCODING_MENU,
2087 is_web_contents && 2066 is_web_contents &&
2088 SavePackage::IsSavableContents(web_contents->contents_mime_type()) && 2067 SavePackage::IsSavableContents(web_contents->contents_mime_type()) &&
(...skipping 11 matching lines...) Expand all
2100 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, is_web_contents); 2079 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, is_web_contents);
2101 2080
2102 // Show various bits of UI 2081 // Show various bits of UI
2103 command_updater_.UpdateCommandEnabled(IDC_JS_CONSOLE, is_web_contents); 2082 command_updater_.UpdateCommandEnabled(IDC_JS_CONSOLE, is_web_contents);
2104 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, 2083 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS,
2105 is_web_contents && !current_tab->GetFavIcon().isNull()); 2084 is_web_contents && !current_tab->GetFavIcon().isNull());
2106 } 2085 }
2107 } 2086 }
2108 2087
2109 void Browser::UpdateStopGoState(bool is_loading) { 2088 void Browser::UpdateStopGoState(bool is_loading) {
2110 GoButton* go_button = GetGoButton(); 2089 window_->UpdateStopGoState(is_loading);
2111 if (go_button)
2112 go_button->ChangeMode(is_loading ? GoButton::MODE_STOP : GoButton::MODE_GO);
2113 command_updater_.UpdateCommandEnabled(IDC_GO, !is_loading); 2090 command_updater_.UpdateCommandEnabled(IDC_GO, !is_loading);
2114 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); 2091 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading);
2115 } 2092 }
2116 2093
2117 void Browser::SetStarredButtonToggled(bool starred) {
2118 ToolbarStarToggle* star_button = window_->GetStarButton();
2119 if (star_button)
2120 star_button->SetToggled(starred);
2121 }
2122
2123 #if defined(OS_WIN) 2094 #if defined(OS_WIN)
2124 2095
2125 /////////////////////////////////////////////////////////////////////////////// 2096 ///////////////////////////////////////////////////////////////////////////////
2126 // Browser, UI update coalescing and handling (private): 2097 // Browser, UI update coalescing and handling (private):
2127 2098
2128 void Browser::UpdateToolbar(bool should_restore_state) { 2099 void Browser::UpdateToolbar(bool should_restore_state) {
2129 window_->UpdateToolbar(GetSelectedTabContents(), should_restore_state); 2100 window_->UpdateToolbar(GetSelectedTabContents(), should_restore_state);
2130 } 2101 }
2131 2102
2132 void Browser::ScheduleUIUpdate(const TabContents* source, 2103 void Browser::ScheduleUIUpdate(const TabContents* source,
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
2252 2223
2253 #endif // OS_WIN 2224 #endif // OS_WIN
2254 2225
2255 /////////////////////////////////////////////////////////////////////////////// 2226 ///////////////////////////////////////////////////////////////////////////////
2256 // Browser, Getters for UI (private): 2227 // Browser, Getters for UI (private):
2257 2228
2258 LocationBarView* Browser::GetLocationBarView() const { 2229 LocationBarView* Browser::GetLocationBarView() const {
2259 return window_->GetLocationBarView(); 2230 return window_->GetLocationBarView();
2260 } 2231 }
2261 2232
2262 GoButton* Browser::GetGoButton() {
2263 return window_->GetGoButton();
2264 }
2265
2266 StatusBubble* Browser::GetStatusBubble() { 2233 StatusBubble* Browser::GetStatusBubble() {
2267 return window_->GetStatusBubble(); 2234 return window_->GetStatusBubble();
2268 } 2235 }
2269 2236
2270 #if defined(OS_WIN) 2237 #if defined(OS_WIN)
2271 /////////////////////////////////////////////////////////////////////////////// 2238 ///////////////////////////////////////////////////////////////////////////////
2272 // Browser, Session restore functions (private): 2239 // Browser, Session restore functions (private):
2273 2240
2274 void Browser::SyncHistoryWithTabs(int index) { 2241 void Browser::SyncHistoryWithTabs(int index) {
2275 if (!profile()->HasSessionService()) 2242 if (!profile()->HasSessionService())
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
2448 std::wstring window_pref(prefs::kBrowserWindowPlacement); 2415 std::wstring window_pref(prefs::kBrowserWindowPlacement);
2449 window_pref.append(L"_"); 2416 window_pref.append(L"_");
2450 window_pref.append(app_name); 2417 window_pref.append(app_name);
2451 PrefService* prefs = g_browser_process->local_state(); 2418 PrefService* prefs = g_browser_process->local_state();
2452 DCHECK(prefs); 2419 DCHECK(prefs);
2453 2420
2454 prefs->RegisterDictionaryPref(window_pref.c_str()); 2421 prefs->RegisterDictionaryPref(window_pref.c_str());
2455 } 2422 }
2456 2423
2457 #endif // OS_WIN 2424 #endif // OS_WIN
OLDNEW
« no previous file with comments | « chrome/browser/browser.h ('k') | chrome/browser/browser_commands_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698