OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 return true; | 316 return true; |
317 } | 317 } |
318 | 318 |
319 } // namespace | 319 } // namespace |
320 | 320 |
321 //////////////////////////////////////////////////////////////////////////////// | 321 //////////////////////////////////////////////////////////////////////////////// |
322 // Browser, CreateParams: | 322 // Browser, CreateParams: |
323 | 323 |
324 Browser::CreateParams::CreateParams(Type type, Profile* profile) | 324 Browser::CreateParams::CreateParams(Type type, Profile* profile) |
325 : type(type), | 325 : type(type), |
326 profile(profile) { | 326 profile(profile), |
| 327 initial_show_state(ui::SHOW_STATE_DEFAULT), |
| 328 is_session_restore(false) { |
327 } | 329 } |
328 | 330 |
329 /////////////////////////////////////////////////////////////////////////////// | 331 /////////////////////////////////////////////////////////////////////////////// |
330 // Browser, Constructors, Creation, Showing: | 332 // Browser, Constructors, Creation, Showing: |
331 | 333 |
332 Browser::Browser(Type type, Profile* profile) | 334 Browser::Browser(Type type, Profile* profile) |
333 : type_(type), | 335 : type_(type), |
334 profile_(profile), | 336 profile_(profile), |
335 window_(NULL), | 337 window_(NULL), |
336 ALLOW_THIS_IN_INITIALIZER_LIST( | 338 ALLOW_THIS_IN_INITIALIZER_LIST( |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 | 483 |
482 // static | 484 // static |
483 Browser* Browser::Create(Profile* profile) { | 485 Browser* Browser::Create(Profile* profile) { |
484 Browser* browser = new Browser(TYPE_TABBED, profile); | 486 Browser* browser = new Browser(TYPE_TABBED, profile); |
485 browser->InitBrowserWindow(); | 487 browser->InitBrowserWindow(); |
486 return browser; | 488 return browser; |
487 } | 489 } |
488 | 490 |
489 // static | 491 // static |
490 Browser* Browser::CreateWithParams(const CreateParams& params) { | 492 Browser* Browser::CreateWithParams(const CreateParams& params) { |
| 493 if (!params.app_name.empty()) |
| 494 RegisterAppPrefs(params.app_name, params.profile); |
| 495 |
491 Browser* browser = new Browser(params.type, params.profile); | 496 Browser* browser = new Browser(params.type, params.profile); |
492 browser->app_name_ = params.app_name; | 497 browser->app_name_ = params.app_name; |
493 browser->set_override_bounds(params.initial_bounds); | 498 browser->set_override_bounds(params.initial_bounds); |
| 499 browser->set_show_state(params.initial_show_state); |
| 500 browser->set_is_session_restore(params.is_session_restore); |
| 501 |
494 browser->InitBrowserWindow(); | 502 browser->InitBrowserWindow(); |
495 return browser; | 503 return browser; |
496 } | 504 } |
497 | 505 |
498 // static | 506 // static |
499 Browser* Browser::CreateForType(Type type, Profile* profile) { | 507 Browser* Browser::CreateForType(Type type, Profile* profile) { |
500 CreateParams params(type, profile); | 508 CreateParams params(type, profile); |
501 return CreateWithParams(params); | 509 return CreateWithParams(params); |
502 } | 510 } |
503 | 511 |
504 // static | 512 // static |
505 Browser* Browser::CreateForApp(Type type, | 513 Browser* Browser::CreateForApp(Type type, |
506 const std::string& app_name, | 514 const std::string& app_name, |
507 const gfx::Rect& window_bounds, | 515 const gfx::Rect& window_bounds, |
508 Profile* profile) { | 516 Profile* profile) { |
509 DCHECK(type != TYPE_TABBED); | 517 DCHECK(type != TYPE_TABBED); |
510 DCHECK(!app_name.empty()); | 518 DCHECK(!app_name.empty()); |
511 | 519 |
512 RegisterAppPrefs(app_name, profile); | |
513 | |
514 #if !defined(OS_CHROMEOS) || defined(USE_AURA) | 520 #if !defined(OS_CHROMEOS) || defined(USE_AURA) |
515 if (type == TYPE_PANEL && | 521 if (type == TYPE_PANEL && |
516 !PanelManager::ShouldUsePanels( | 522 !PanelManager::ShouldUsePanels( |
517 web_app::GetExtensionIdFromApplicationName(app_name))) { | 523 web_app::GetExtensionIdFromApplicationName(app_name))) { |
518 type = TYPE_POPUP; | 524 type = TYPE_POPUP; |
519 } | 525 } |
520 #if defined(TOOLKIT_GTK) | 526 #if defined(TOOLKIT_GTK) |
521 // Panels are only supported on a white list of window managers for Linux. | 527 // Panels are only supported on a white list of window managers for Linux. |
522 if (type == TYPE_PANEL) { | 528 if (type == TYPE_PANEL) { |
523 ui::WindowManagerName wm_type = ui::GuessWindowManager(); | 529 ui::WindowManagerName wm_type = ui::GuessWindowManager(); |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
980 return name; | 986 return name; |
981 } | 987 } |
982 | 988 |
983 bool Browser::ShouldSaveWindowPlacement() const { | 989 bool Browser::ShouldSaveWindowPlacement() const { |
984 switch (type_) { | 990 switch (type_) { |
985 case TYPE_TABBED: | 991 case TYPE_TABBED: |
986 return true; | 992 return true; |
987 case TYPE_POPUP: | 993 case TYPE_POPUP: |
988 // Only save the window placement of popups if they are restored, | 994 // Only save the window placement of popups if they are restored, |
989 // or the window belongs to DevTools. | 995 // or the window belongs to DevTools. |
| 996 #if defined USE_AURA |
| 997 if (is_app()) |
| 998 return true; |
| 999 #endif |
990 return browser_defaults::kRestorePopups || is_devtools(); | 1000 return browser_defaults::kRestorePopups || is_devtools(); |
991 case TYPE_PANEL: | 1001 case TYPE_PANEL: |
992 // Do not save the window placement of panels. | 1002 // Do not save the window placement of panels. |
993 return false; | 1003 return false; |
994 default: | 1004 default: |
995 return false; | 1005 return false; |
996 } | 1006 } |
997 } | 1007 } |
998 | 1008 |
999 void Browser::SaveWindowPlacement(const gfx::Rect& bounds, | 1009 void Browser::SaveWindowPlacement(const gfx::Rect& bounds, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1039 int x, y; | 1049 int x, y; |
1040 if (ParseCommaSeparatedIntegers(str, &x, &y)) | 1050 if (ParseCommaSeparatedIntegers(str, &x, &y)) |
1041 restored_bounds.set_origin(gfx::Point(x, y)); | 1051 restored_bounds.set_origin(gfx::Point(x, y)); |
1042 } | 1052 } |
1043 | 1053 |
1044 return restored_bounds; | 1054 return restored_bounds; |
1045 } | 1055 } |
1046 | 1056 |
1047 ui::WindowShowState Browser::GetSavedWindowShowState() const { | 1057 ui::WindowShowState Browser::GetSavedWindowShowState() const { |
1048 // Only tabbed browsers use the command line or preference state. | 1058 // Only tabbed browsers use the command line or preference state. |
1049 if (!is_type_tabbed()) | 1059 bool show_state = !is_type_tabbed(); |
| 1060 |
| 1061 #if defined(USE_AURA) |
| 1062 // Apps save state on aura. |
| 1063 show_state &= !is_app(); |
| 1064 #endif |
| 1065 |
| 1066 if (show_state) |
1050 return show_state_; | 1067 return show_state_; |
1051 | 1068 |
1052 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kStartMaximized)) | 1069 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kStartMaximized)) |
1053 return ui::SHOW_STATE_MAXIMIZED; | 1070 return ui::SHOW_STATE_MAXIMIZED; |
1054 | 1071 |
1055 if (show_state_ != ui::SHOW_STATE_DEFAULT) | 1072 if (show_state_ != ui::SHOW_STATE_DEFAULT) |
1056 return show_state_; | 1073 return show_state_; |
1057 | 1074 |
1058 const DictionaryValue* window_pref = | 1075 const DictionaryValue* window_pref = |
1059 profile()->GetPrefs()->GetDictionary(GetWindowPlacementKey().c_str()); | 1076 profile()->GetPrefs()->GetDictionary(GetWindowPlacementKey().c_str()); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1156 | 1173 |
1157 // Don't use GetForProfileIfExisting here, we want to force creation of the | 1174 // Don't use GetForProfileIfExisting here, we want to force creation of the |
1158 // session service so that user can restore what was open. | 1175 // session service so that user can restore what was open. |
1159 SessionService* session_service = | 1176 SessionService* session_service = |
1160 SessionServiceFactory::GetForProfile(profile()); | 1177 SessionServiceFactory::GetForProfile(profile()); |
1161 if (session_service) | 1178 if (session_service) |
1162 session_service->WindowClosing(session_id()); | 1179 session_service->WindowClosing(session_id()); |
1163 | 1180 |
1164 TabRestoreService* tab_restore_service = | 1181 TabRestoreService* tab_restore_service = |
1165 TabRestoreServiceFactory::GetForProfile(profile()); | 1182 TabRestoreServiceFactory::GetForProfile(profile()); |
| 1183 |
| 1184 #if defined(USE_AURA) |
| 1185 if (tab_restore_service && is_app()) |
| 1186 tab_restore_service->BrowserClosing(tab_restore_service_delegate()); |
| 1187 #endif |
| 1188 |
1166 if (tab_restore_service && is_type_tabbed() && tab_count()) | 1189 if (tab_restore_service && is_type_tabbed() && tab_count()) |
1167 tab_restore_service->BrowserClosing(tab_restore_service_delegate()); | 1190 tab_restore_service->BrowserClosing(tab_restore_service_delegate()); |
1168 | 1191 |
1169 // TODO(sky): convert session/tab restore to use notification. | 1192 // TODO(sky): convert session/tab restore to use notification. |
1170 content::NotificationService::current()->Notify( | 1193 content::NotificationService::current()->Notify( |
1171 chrome::NOTIFICATION_BROWSER_CLOSING, | 1194 chrome::NOTIFICATION_BROWSER_CLOSING, |
1172 content::Source<Browser>(this), | 1195 content::Source<Browser>(this), |
1173 content::Details<bool>(&exiting)); | 1196 content::Details<bool>(&exiting)); |
1174 | 1197 |
1175 CloseAllTabs(); | 1198 CloseAllTabs(); |
(...skipping 4408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5584 ShowSingletonTabOverwritingNTP(params); | 5607 ShowSingletonTabOverwritingNTP(params); |
5585 } else { | 5608 } else { |
5586 LoginUIServiceFactory::GetForProfile( | 5609 LoginUIServiceFactory::GetForProfile( |
5587 profile()->GetOriginalProfile())->ShowLoginUI(); | 5610 profile()->GetOriginalProfile())->ShowLoginUI(); |
5588 } | 5611 } |
5589 } | 5612 } |
5590 | 5613 |
5591 void Browser::ToggleSpeechInput() { | 5614 void Browser::ToggleSpeechInput() { |
5592 GetSelectedWebContents()->GetRenderViewHost()->ToggleSpeechInput(); | 5615 GetSelectedWebContents()->GetRenderViewHost()->ToggleSpeechInput(); |
5593 } | 5616 } |
OLD | NEW |