Chromium Code Reviews| 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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 return BrowserWindow::CreateBrowserWindow(browser); | 239 return BrowserWindow::CreateBrowserWindow(browser); |
| 240 } | 240 } |
| 241 | 241 |
| 242 #if defined(OS_CHROMEOS) | 242 #if defined(OS_CHROMEOS) |
| 243 chrome::HostDesktopType kDefaultHostDesktopType = chrome::HOST_DESKTOP_TYPE_ASH; | 243 chrome::HostDesktopType kDefaultHostDesktopType = chrome::HOST_DESKTOP_TYPE_ASH; |
| 244 #else | 244 #else |
| 245 chrome::HostDesktopType kDefaultHostDesktopType = | 245 chrome::HostDesktopType kDefaultHostDesktopType = |
| 246 chrome::HOST_DESKTOP_TYPE_NATIVE; | 246 chrome::HOST_DESKTOP_TYPE_NATIVE; |
| 247 #endif | 247 #endif |
| 248 | 248 |
| 249 bool ShouldReloadCrashedTab(WebContents* contents) { | |
| 250 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
| 251 if (!command_line.HasSwitch(switches::kReloadKilledTabs)) | |
| 252 return false; | |
| 253 | |
| 254 base::TerminationStatus crashed_status = contents->GetCrashedStatus(); | |
| 255 | |
| 256 return crashed_status == base::TERMINATION_STATUS_ABNORMAL_TERMINATION || | |
| 257 crashed_status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED || | |
| 258 crashed_status == base::TERMINATION_STATUS_PROCESS_CRASHED; | |
| 259 } | |
| 249 | 260 |
| 250 } // namespace | 261 } // namespace |
| 251 | 262 |
| 252 //////////////////////////////////////////////////////////////////////////////// | 263 //////////////////////////////////////////////////////////////////////////////// |
| 253 // Browser, CreateParams: | 264 // Browser, CreateParams: |
| 254 | 265 |
| 255 Browser::CreateParams::CreateParams() | 266 Browser::CreateParams::CreateParams() |
| 256 : type(TYPE_TABBED), | 267 : type(TYPE_TABBED), |
| 257 profile(NULL), | 268 profile(NULL), |
| 258 host_desktop_type(kDefaultHostDesktopType), | 269 host_desktop_type(kDefaultHostDesktopType), |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 640 content::Source<Browser>(this), | 651 content::Source<Browser>(this), |
| 641 content::NotificationService::NoDetails()); | 652 content::NotificationService::NoDetails()); |
| 642 | 653 |
| 643 chrome::CloseAllTabs(this); | 654 chrome::CloseAllTabs(this); |
| 644 } | 655 } |
| 645 | 656 |
| 646 void Browser::OnWindowActivated() { | 657 void Browser::OnWindowActivated() { |
| 647 // On some platforms we want to automatically reload tabs that are | 658 // On some platforms we want to automatically reload tabs that are |
| 648 // killed when the user selects them. | 659 // killed when the user selects them. |
| 649 WebContents* contents = chrome::GetActiveWebContents(this); | 660 WebContents* contents = chrome::GetActiveWebContents(this); |
| 650 if (contents && contents->GetCrashedStatus() == | 661 if (contents && ShouldReloadCrashedTab(contents)) { |
|
sky
2012/11/01 21:37:36
nit: in general no {} for single line ifs.
simonhong_
2012/11/01 21:47:52
Done.
Thank you!
On 2012/11/01 21:37:36, sky wrot
| |
| 651 base::TERMINATION_STATUS_PROCESS_WAS_KILLED) { | 662 chrome::Reload(this, CURRENT_TAB); |
| 652 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 653 switches::kReloadKilledTabs)) { | |
| 654 chrome::Reload(this, CURRENT_TAB); | |
| 655 } | |
| 656 } | 663 } |
| 657 } | 664 } |
| 658 | 665 |
| 659 //////////////////////////////////////////////////////////////////////////////// | 666 //////////////////////////////////////////////////////////////////////////////// |
| 660 // In-progress download termination handling: | 667 // In-progress download termination handling: |
| 661 | 668 |
| 662 void Browser::InProgressDownloadResponse(bool cancel_downloads) { | 669 void Browser::InProgressDownloadResponse(bool cancel_downloads) { |
| 663 if (cancel_downloads) { | 670 if (cancel_downloads) { |
| 664 cancel_download_confirmation_state_ = RESPONSE_RECEIVED; | 671 cancel_download_confirmation_state_ = RESPONSE_RECEIVED; |
| 665 chrome::CloseWindow(this); | 672 chrome::CloseWindow(this); |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1071 window_->GetLocationBar()->SaveStateToContents(contents->web_contents()); | 1078 window_->GetLocationBar()->SaveStateToContents(contents->web_contents()); |
| 1072 } | 1079 } |
| 1073 | 1080 |
| 1074 void Browser::ActiveTabChanged(TabContents* old_contents, | 1081 void Browser::ActiveTabChanged(TabContents* old_contents, |
| 1075 TabContents* new_contents, | 1082 TabContents* new_contents, |
| 1076 int index, | 1083 int index, |
| 1077 bool user_gesture) { | 1084 bool user_gesture) { |
| 1078 // On some platforms we want to automatically reload tabs that are | 1085 // On some platforms we want to automatically reload tabs that are |
| 1079 // killed when the user selects them. | 1086 // killed when the user selects them. |
| 1080 bool did_reload = false; | 1087 bool did_reload = false; |
| 1081 if (user_gesture && new_contents->web_contents()->GetCrashedStatus() == | 1088 if (user_gesture && ShouldReloadCrashedTab(new_contents->web_contents())) { |
| 1082 base::TERMINATION_STATUS_PROCESS_WAS_KILLED) { | |
| 1083 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); | |
| 1084 if (parsed_command_line.HasSwitch(switches::kReloadKilledTabs)) { | |
| 1085 LOG(WARNING) << "Reloading killed tab at " << index; | 1089 LOG(WARNING) << "Reloading killed tab at " << index; |
| 1086 static int reload_count = 0; | 1090 static int reload_count = 0; |
| 1087 UMA_HISTOGRAM_CUSTOM_COUNTS( | 1091 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 1088 "Tabs.SadTab.ReloadCount", ++reload_count, 1, 1000, 50); | 1092 "Tabs.SadTab.ReloadCount", ++reload_count, 1, 1000, 50); |
| 1089 chrome::Reload(this, CURRENT_TAB); | 1093 chrome::Reload(this, CURRENT_TAB); |
| 1090 did_reload = true; | 1094 did_reload = true; |
| 1091 } | |
| 1092 } | 1095 } |
| 1093 | 1096 |
| 1094 // Discarded tabs always get reloaded. | 1097 // Discarded tabs always get reloaded. |
| 1095 if (!did_reload && tab_strip_model_->IsTabDiscarded(index)) { | 1098 if (!did_reload && tab_strip_model_->IsTabDiscarded(index)) { |
| 1096 LOG(WARNING) << "Reloading discarded tab at " << index; | 1099 LOG(WARNING) << "Reloading discarded tab at " << index; |
| 1097 static int reload_count = 0; | 1100 static int reload_count = 0; |
| 1098 UMA_HISTOGRAM_CUSTOM_COUNTS( | 1101 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 1099 "Tabs.Discard.ReloadCount", ++reload_count, 1, 1000, 50); | 1102 "Tabs.Discard.ReloadCount", ++reload_count, 1, 1000, 50); |
| 1100 chrome::Reload(this, CURRENT_TAB); | 1103 chrome::Reload(this, CURRENT_TAB); |
| 1101 } | 1104 } |
| (...skipping 1209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2311 if (contents && !allow_js_access) { | 2314 if (contents && !allow_js_access) { |
| 2312 contents->web_contents()->GetController().LoadURL( | 2315 contents->web_contents()->GetController().LoadURL( |
| 2313 target_url, | 2316 target_url, |
| 2314 content::Referrer(), | 2317 content::Referrer(), |
| 2315 content::PAGE_TRANSITION_LINK, | 2318 content::PAGE_TRANSITION_LINK, |
| 2316 std::string()); // No extra headers. | 2319 std::string()); // No extra headers. |
| 2317 } | 2320 } |
| 2318 | 2321 |
| 2319 return contents != NULL; | 2322 return contents != NULL; |
| 2320 } | 2323 } |
| OLD | NEW |