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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 : type_(type), | 240 : type_(type), |
241 profile_(profile), | 241 profile_(profile), |
242 window_(NULL), | 242 window_(NULL), |
243 ALLOW_THIS_IN_INITIALIZER_LIST( | 243 ALLOW_THIS_IN_INITIALIZER_LIST( |
244 tab_handler_(TabHandler::CreateTabHandler(this))), | 244 tab_handler_(TabHandler::CreateTabHandler(this))), |
245 command_updater_(this), | 245 command_updater_(this), |
246 toolbar_model_(this), | 246 toolbar_model_(this), |
247 chrome_updater_factory_(this), | 247 chrome_updater_factory_(this), |
248 is_attempting_to_close_browser_(false), | 248 is_attempting_to_close_browser_(false), |
249 cancel_download_confirmation_state_(NOT_PROMPTED), | 249 cancel_download_confirmation_state_(NOT_PROMPTED), |
250 maximized_state_(MAXIMIZED_STATE_DEFAULT), | 250 show_state_(ui::SHOW_STATE_DEFAULT), |
251 method_factory_(this), | 251 method_factory_(this), |
252 block_command_execution_(false), | 252 block_command_execution_(false), |
253 last_blocked_command_id_(-1), | 253 last_blocked_command_id_(-1), |
254 last_blocked_command_disposition_(CURRENT_TAB), | 254 last_blocked_command_disposition_(CURRENT_TAB), |
255 pending_web_app_action_(NONE), | 255 pending_web_app_action_(NONE), |
256 ALLOW_THIS_IN_INITIALIZER_LIST( | 256 ALLOW_THIS_IN_INITIALIZER_LIST( |
257 tab_restore_service_delegate_( | 257 tab_restore_service_delegate_( |
258 new BrowserTabRestoreServiceDelegate(this))), | 258 new BrowserTabRestoreServiceDelegate(this))), |
259 ALLOW_THIS_IN_INITIALIZER_LIST( | 259 ALLOW_THIS_IN_INITIALIZER_LIST( |
260 synced_window_delegate_( | 260 synced_window_delegate_( |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 // or the window belongs to DevTools. | 844 // or the window belongs to DevTools. |
845 return browser_defaults::kRestorePopups || is_devtools(); | 845 return browser_defaults::kRestorePopups || is_devtools(); |
846 case TYPE_PANEL: | 846 case TYPE_PANEL: |
847 // Do not save the window placement of panels. | 847 // Do not save the window placement of panels. |
848 return false; | 848 return false; |
849 default: | 849 default: |
850 return false; | 850 return false; |
851 } | 851 } |
852 } | 852 } |
853 | 853 |
854 void Browser::SaveWindowPlacement(const gfx::Rect& bounds, bool maximized) { | 854 void Browser::SaveWindowPlacement(const gfx::Rect& bounds, |
| 855 ui::WindowShowState show_state) { |
855 // Save to the session storage service, used when reloading a past session. | 856 // Save to the session storage service, used when reloading a past session. |
856 // Note that we don't want to be the ones who cause lazy initialization of | 857 // Note that we don't want to be the ones who cause lazy initialization of |
857 // the session service. This function gets called during initial window | 858 // the session service. This function gets called during initial window |
858 // showing, and we don't want to bring in the session service this early. | 859 // showing, and we don't want to bring in the session service this early. |
859 SessionService* session_service = | 860 SessionService* session_service = |
860 SessionServiceFactory::GetForProfileIfExisting(profile()); | 861 SessionServiceFactory::GetForProfileIfExisting(profile()); |
861 if (session_service) | 862 if (session_service) |
862 session_service->SetWindowBounds(session_id_, bounds, maximized); | 863 session_service->SetWindowBounds(session_id_, bounds, show_state); |
863 } | 864 } |
864 | 865 |
865 gfx::Rect Browser::GetSavedWindowBounds() const { | 866 gfx::Rect Browser::GetSavedWindowBounds() const { |
866 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); | 867 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
867 bool record_mode = parsed_command_line.HasSwitch(switches::kRecordMode); | 868 bool record_mode = parsed_command_line.HasSwitch(switches::kRecordMode); |
868 bool playback_mode = parsed_command_line.HasSwitch(switches::kPlaybackMode); | 869 bool playback_mode = parsed_command_line.HasSwitch(switches::kPlaybackMode); |
869 if (record_mode || playback_mode) { | 870 if (record_mode || playback_mode) { |
870 // In playback/record mode we always fix the size of the browser and | 871 // In playback/record mode we always fix the size of the browser and |
871 // move it to (0,0). The reason for this is two reasons: First we want | 872 // move it to (0,0). The reason for this is two reasons: First we want |
872 // resize/moves in the playback to still work, and Second we want | 873 // resize/moves in the playback to still work, and Second we want |
873 // playbacks to work (as much as possible) on machines w/ different | 874 // playbacks to work (as much as possible) on machines w/ different |
874 // screen sizes. | 875 // screen sizes. |
875 return gfx::Rect(0, 0, 800, 600); | 876 return gfx::Rect(0, 0, 800, 600); |
876 } | 877 } |
877 | 878 |
878 gfx::Rect restored_bounds = override_bounds_; | 879 gfx::Rect restored_bounds = override_bounds_; |
879 bool maximized; | 880 bool maximized; |
880 WindowSizer::GetBrowserWindowBounds(app_name_, restored_bounds, this, | 881 WindowSizer::GetBrowserWindowBounds(app_name_, restored_bounds, this, |
881 &restored_bounds, &maximized); | 882 &restored_bounds, &maximized); |
882 return restored_bounds; | 883 return restored_bounds; |
883 } | 884 } |
884 | 885 |
885 // TODO(beng): obtain maximized state some other way so we don't need to go | 886 // TODO(beng): obtain maximized state some other way so we don't need to go |
886 // through all this hassle. | 887 // through all this hassle. |
887 bool Browser::GetSavedMaximizedState() const { | 888 ui::WindowShowState Browser::GetSavedWindowShowState() const { |
888 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kStartMaximized)) | 889 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kStartMaximized)) |
889 return true; | 890 return ui::SHOW_STATE_MAXIMIZED; |
890 | 891 |
891 if (maximized_state_ == MAXIMIZED_STATE_MAXIMIZED) | 892 if (show_state_ != ui::SHOW_STATE_DEFAULT) |
892 return true; | 893 return show_state_; |
893 if (maximized_state_ == MAXIMIZED_STATE_UNMAXIMIZED) | |
894 return false; | |
895 | 894 |
896 // An explicit maximized state was not set. Query the window sizer. | 895 // An explicit maximized state was not set. Query the window sizer. |
897 gfx::Rect restored_bounds; | 896 gfx::Rect restored_bounds; |
898 bool maximized = false; | 897 bool maximized = false; |
899 WindowSizer::GetBrowserWindowBounds(app_name_, restored_bounds, this, | 898 WindowSizer::GetBrowserWindowBounds(app_name_, restored_bounds, this, |
900 &restored_bounds, &maximized); | 899 &restored_bounds, &maximized); |
901 return maximized; | 900 return maximized ? ui::SHOW_STATE_MAXIMIZED : ui::SHOW_STATE_NORMAL; |
902 } | 901 } |
903 | 902 |
904 SkBitmap Browser::GetCurrentPageIcon() const { | 903 SkBitmap Browser::GetCurrentPageIcon() const { |
905 TabContentsWrapper* contents = GetSelectedTabContentsWrapper(); | 904 TabContentsWrapper* contents = GetSelectedTabContentsWrapper(); |
906 // |contents| can be NULL since GetCurrentPageIcon() is called by the window | 905 // |contents| can be NULL since GetCurrentPageIcon() is called by the window |
907 // during the window's creation (before tabs have been added). | 906 // during the window's creation (before tabs have been added). |
908 return contents ? contents->favicon_tab_helper()->GetFavicon() : SkBitmap(); | 907 return contents ? contents->favicon_tab_helper()->GetFavicon() : SkBitmap(); |
909 } | 908 } |
910 | 909 |
911 string16 Browser::GetWindowTitleForCurrentTab() const { | 910 string16 Browser::GetWindowTitleForCurrentTab() const { |
(...skipping 1799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2711 bool maximize) { | 2710 bool maximize) { |
2712 DCHECK(CanSupportWindowFeature(FEATURE_TABSTRIP)); | 2711 DCHECK(CanSupportWindowFeature(FEATURE_TABSTRIP)); |
2713 | 2712 |
2714 gfx::Rect new_window_bounds = window_bounds; | 2713 gfx::Rect new_window_bounds = window_bounds; |
2715 if (dock_info.GetNewWindowBounds(&new_window_bounds, &maximize)) | 2714 if (dock_info.GetNewWindowBounds(&new_window_bounds, &maximize)) |
2716 dock_info.AdjustOtherWindowBounds(); | 2715 dock_info.AdjustOtherWindowBounds(); |
2717 | 2716 |
2718 // Create an empty new browser window the same size as the old one. | 2717 // Create an empty new browser window the same size as the old one. |
2719 Browser* browser = new Browser(TYPE_TABBED, profile_); | 2718 Browser* browser = new Browser(TYPE_TABBED, profile_); |
2720 browser->set_override_bounds(new_window_bounds); | 2719 browser->set_override_bounds(new_window_bounds); |
2721 browser->set_maximized_state( | 2720 browser->set_show_state( |
2722 maximize ? MAXIMIZED_STATE_MAXIMIZED : MAXIMIZED_STATE_UNMAXIMIZED); | 2721 maximize ? ui::SHOW_STATE_MAXIMIZED : ui::SHOW_STATE_NORMAL); |
2723 browser->InitBrowserWindow(); | 2722 browser->InitBrowserWindow(); |
2724 browser->tabstrip_model()->AppendTabContents(detached_contents, true); | 2723 browser->tabstrip_model()->AppendTabContents(detached_contents, true); |
2725 // Make sure the loading state is updated correctly, otherwise the throbber | 2724 // Make sure the loading state is updated correctly, otherwise the throbber |
2726 // won't start if the page is loading. | 2725 // won't start if the page is loading. |
2727 browser->LoadingStateChanged(detached_contents->tab_contents()); | 2726 browser->LoadingStateChanged(detached_contents->tab_contents()); |
2728 return browser; | 2727 return browser; |
2729 } | 2728 } |
2730 | 2729 |
2731 int Browser::GetDragActions() const { | 2730 int Browser::GetDragActions() const { |
2732 return TabStripModelDelegate::TAB_TEAROFF_ACTION | (tab_count() > 1 ? | 2731 return TabStripModelDelegate::TAB_TEAROFF_ACTION | (tab_count() > 1 ? |
(...skipping 2142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4875 } | 4874 } |
4876 | 4875 |
4877 void Browser::ShowSyncSetup() { | 4876 void Browser::ShowSyncSetup() { |
4878 ProfileSyncService* service = | 4877 ProfileSyncService* service = |
4879 profile()->GetOriginalProfile()->GetProfileSyncService(); | 4878 profile()->GetOriginalProfile()->GetProfileSyncService(); |
4880 if (service->HasSyncSetupCompleted()) | 4879 if (service->HasSyncSetupCompleted()) |
4881 ShowOptionsTab(chrome::kSyncSetupSubPage); | 4880 ShowOptionsTab(chrome::kSyncSetupSubPage); |
4882 else | 4881 else |
4883 service->ShowLoginDialog(); | 4882 service->ShowLoginDialog(); |
4884 } | 4883 } |
OLD | NEW |