OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 // defined(OS_WIN) | 10 #endif // defined(OS_WIN) |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 #include "chrome/browser/ui/browser_navigator.h" | 100 #include "chrome/browser/ui/browser_navigator.h" |
101 #include "chrome/browser/ui/browser_tab_contents.h" | 101 #include "chrome/browser/ui/browser_tab_contents.h" |
102 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" | 102 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" |
103 #include "chrome/browser/ui/browser_tab_strip_model_delegate.h" | 103 #include "chrome/browser/ui/browser_tab_strip_model_delegate.h" |
104 #include "chrome/browser/ui/browser_tabstrip.h" | 104 #include "chrome/browser/ui/browser_tabstrip.h" |
105 #include "chrome/browser/ui/browser_toolbar_model_delegate.h" | 105 #include "chrome/browser/ui/browser_toolbar_model_delegate.h" |
106 #include "chrome/browser/ui/browser_ui_prefs.h" | 106 #include "chrome/browser/ui/browser_ui_prefs.h" |
107 #include "chrome/browser/ui/browser_window.h" | 107 #include "chrome/browser/ui/browser_window.h" |
108 #include "chrome/browser/ui/chrome_pages.h" | 108 #include "chrome/browser/ui/chrome_pages.h" |
109 #include "chrome/browser/ui/chrome_select_file_policy.h" | 109 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| 110 #include "chrome/browser/ui/fast_unload_controller.h" |
110 #include "chrome/browser/ui/find_bar/find_bar.h" | 111 #include "chrome/browser/ui/find_bar/find_bar.h" |
111 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 112 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
112 #include "chrome/browser/ui/find_bar/find_tab_helper.h" | 113 #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
113 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" | 114 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" |
114 #include "chrome/browser/ui/global_error/global_error.h" | 115 #include "chrome/browser/ui/global_error/global_error.h" |
115 #include "chrome/browser/ui/global_error/global_error_service.h" | 116 #include "chrome/browser/ui/global_error/global_error_service.h" |
116 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 117 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
117 #include "chrome/browser/ui/omnibox/location_bar.h" | 118 #include "chrome/browser/ui/omnibox/location_bar.h" |
118 #include "chrome/browser/ui/search/search_delegate.h" | 119 #include "chrome/browser/ui/search/search_delegate.h" |
119 #include "chrome/browser/ui/search/search_model.h" | 120 #include "chrome/browser/ui/search/search_model.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 "https://www.google.com/support/chrome/bin/request.py?contact_type=" | 226 "https://www.google.com/support/chrome/bin/request.py?contact_type=" |
226 "broken_website&format=inproduct&p.page_title=$1&p.page_url=$2"; | 227 "broken_website&format=inproduct&p.page_title=$1&p.page_url=$2"; |
227 | 228 |
228 // How long we wait before updating the browser chrome while loading a page. | 229 // How long we wait before updating the browser chrome while loading a page. |
229 const int kUIUpdateCoalescingTimeMS = 200; | 230 const int kUIUpdateCoalescingTimeMS = 200; |
230 | 231 |
231 BrowserWindow* CreateBrowserWindow(Browser* browser) { | 232 BrowserWindow* CreateBrowserWindow(Browser* browser) { |
232 return BrowserWindow::CreateBrowserWindow(browser); | 233 return BrowserWindow::CreateBrowserWindow(browser); |
233 } | 234 } |
234 | 235 |
| 236 // Is the fast tab unload experiment enabled? |
| 237 bool IsFastTabUnloadEnabled() { |
| 238 return CommandLine::ForCurrentProcess()->HasSwitch( |
| 239 switches::kEnableFastUnload); |
| 240 } |
| 241 |
235 } // namespace | 242 } // namespace |
236 | 243 |
237 //////////////////////////////////////////////////////////////////////////////// | 244 //////////////////////////////////////////////////////////////////////////////// |
238 // Browser, CreateParams: | 245 // Browser, CreateParams: |
239 | 246 |
240 Browser::CreateParams::CreateParams(Profile* profile, | 247 Browser::CreateParams::CreateParams(Profile* profile, |
241 chrome::HostDesktopType host_desktop_type) | 248 chrome::HostDesktopType host_desktop_type) |
242 : type(TYPE_TABBED), | 249 : type(TYPE_TABBED), |
243 profile(profile), | 250 profile(profile), |
244 host_desktop_type(host_desktop_type), | 251 host_desktop_type(host_desktop_type), |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 tab_strip_model_(new TabStripModel(tab_strip_model_delegate_.get(), | 331 tab_strip_model_(new TabStripModel(tab_strip_model_delegate_.get(), |
325 params.profile)), | 332 params.profile)), |
326 app_name_(params.app_name), | 333 app_name_(params.app_name), |
327 app_type_(params.app_type), | 334 app_type_(params.app_type), |
328 chrome_updater_factory_(this), | 335 chrome_updater_factory_(this), |
329 cancel_download_confirmation_state_(NOT_PROMPTED), | 336 cancel_download_confirmation_state_(NOT_PROMPTED), |
330 override_bounds_(params.initial_bounds), | 337 override_bounds_(params.initial_bounds), |
331 initial_show_state_(params.initial_show_state), | 338 initial_show_state_(params.initial_show_state), |
332 is_session_restore_(params.is_session_restore), | 339 is_session_restore_(params.is_session_restore), |
333 host_desktop_type_(params.host_desktop_type), | 340 host_desktop_type_(params.host_desktop_type), |
334 unload_controller_(new chrome::UnloadController(this)), | |
335 weak_factory_(this), | 341 weak_factory_(this), |
336 content_setting_bubble_model_delegate_( | 342 content_setting_bubble_model_delegate_( |
337 new BrowserContentSettingBubbleModelDelegate(this)), | 343 new BrowserContentSettingBubbleModelDelegate(this)), |
338 toolbar_model_delegate_(new BrowserToolbarModelDelegate(this)), | 344 toolbar_model_delegate_(new BrowserToolbarModelDelegate(this)), |
339 tab_restore_service_delegate_(new BrowserTabRestoreServiceDelegate(this)), | 345 tab_restore_service_delegate_(new BrowserTabRestoreServiceDelegate(this)), |
340 synced_window_delegate_(new BrowserSyncedWindowDelegate(this)), | 346 synced_window_delegate_(new BrowserSyncedWindowDelegate(this)), |
341 bookmark_bar_state_(BookmarkBar::HIDDEN), | 347 bookmark_bar_state_(BookmarkBar::HIDDEN), |
342 command_controller_(new chrome::BrowserCommandController( | 348 command_controller_(new chrome::BrowserCommandController( |
343 this, g_browser_process->profile_manager())), | 349 this, g_browser_process->profile_manager())), |
344 window_has_shown_(false) { | 350 window_has_shown_(false) { |
345 // If this causes a crash then a window is being opened using a profile type | 351 // If this causes a crash then a window is being opened using a profile type |
346 // that is disallowed by policy. The crash prevents the disabled window type | 352 // that is disallowed by policy. The crash prevents the disabled window type |
347 // from opening at all, but the path that triggered it should be fixed. | 353 // from opening at all, but the path that triggered it should be fixed. |
348 CHECK(IncognitoModePrefs::CanOpenBrowser(profile_)); | 354 CHECK(IncognitoModePrefs::CanOpenBrowser(profile_)); |
349 | 355 |
| 356 // TODO(jeremy): Move to initializer list once flag is removed. |
| 357 if (IsFastTabUnloadEnabled()) |
| 358 fast_unload_controller_.reset(new chrome::FastUnloadController(this)); |
| 359 else |
| 360 unload_controller_.reset(new chrome::UnloadController(this)); |
| 361 |
350 if (!app_name_.empty()) | 362 if (!app_name_.empty()) |
351 chrome::RegisterAppPrefs(app_name_, profile_); | 363 chrome::RegisterAppPrefs(app_name_, profile_); |
352 tab_strip_model_->AddObserver(this); | 364 tab_strip_model_->AddObserver(this); |
353 | 365 |
354 toolbar_model_.reset(new ToolbarModelImpl(toolbar_model_delegate_.get())); | 366 toolbar_model_.reset(new ToolbarModelImpl(toolbar_model_delegate_.get())); |
355 search_model_.reset(new SearchModel()); | 367 search_model_.reset(new SearchModel()); |
356 search_delegate_.reset( | 368 search_delegate_.reset( |
357 new SearchDelegate(search_model_.get(), toolbar_model_.get())); | 369 new SearchDelegate(search_model_.get(), toolbar_model_.get())); |
358 | 370 |
359 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 371 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 } | 589 } |
578 } | 590 } |
579 | 591 |
580 /////////////////////////////////////////////////////////////////////////////// | 592 /////////////////////////////////////////////////////////////////////////////// |
581 // Browser, OnBeforeUnload handling: | 593 // Browser, OnBeforeUnload handling: |
582 | 594 |
583 bool Browser::ShouldCloseWindow() { | 595 bool Browser::ShouldCloseWindow() { |
584 if (!CanCloseWithInProgressDownloads()) | 596 if (!CanCloseWithInProgressDownloads()) |
585 return false; | 597 return false; |
586 | 598 |
| 599 if (IsFastTabUnloadEnabled()) |
| 600 return fast_unload_controller_->ShouldCloseWindow(); |
587 return unload_controller_->ShouldCloseWindow(); | 601 return unload_controller_->ShouldCloseWindow(); |
588 } | 602 } |
589 | 603 |
| 604 bool Browser::HasCompletedUnloadProcessing() const { |
| 605 DCHECK(IsFastTabUnloadEnabled()); |
| 606 return fast_unload_controller_->HasCompletedUnloadProcessing(); |
| 607 } |
| 608 |
590 bool Browser::IsAttemptingToCloseBrowser() const { | 609 bool Browser::IsAttemptingToCloseBrowser() const { |
| 610 if (IsFastTabUnloadEnabled()) |
| 611 return fast_unload_controller_->is_attempting_to_close_browser(); |
591 return unload_controller_->is_attempting_to_close_browser(); | 612 return unload_controller_->is_attempting_to_close_browser(); |
592 } | 613 } |
593 | 614 |
594 void Browser::OnWindowClosing() { | 615 void Browser::OnWindowClosing() { |
595 if (!ShouldCloseWindow()) | 616 if (!ShouldCloseWindow()) |
596 return; | 617 return; |
597 | 618 |
598 // Application should shutdown on last window close if the user is explicitly | 619 // Application should shutdown on last window close if the user is explicitly |
599 // trying to quit, or if there is nothing keeping the browser alive (such as | 620 // trying to quit, or if there is nothing keeping the browser alive (such as |
600 // AppController on the Mac, or BackgroundContentsService for background | 621 // AppController on the Mac, or BackgroundContentsService for background |
(...skipping 23 matching lines...) Expand all Loading... |
624 | 645 |
625 if (tab_restore_service && is_type_tabbed() && tab_strip_model_->count()) | 646 if (tab_restore_service && is_type_tabbed() && tab_strip_model_->count()) |
626 tab_restore_service->BrowserClosing(tab_restore_service_delegate()); | 647 tab_restore_service->BrowserClosing(tab_restore_service_delegate()); |
627 | 648 |
628 // TODO(sky): convert session/tab restore to use notification. | 649 // TODO(sky): convert session/tab restore to use notification. |
629 content::NotificationService::current()->Notify( | 650 content::NotificationService::current()->Notify( |
630 chrome::NOTIFICATION_BROWSER_CLOSING, | 651 chrome::NOTIFICATION_BROWSER_CLOSING, |
631 content::Source<Browser>(this), | 652 content::Source<Browser>(this), |
632 content::NotificationService::NoDetails()); | 653 content::NotificationService::NoDetails()); |
633 | 654 |
634 tab_strip_model_->CloseAllTabs(); | 655 if (!IsFastTabUnloadEnabled()) |
| 656 tab_strip_model_->CloseAllTabs(); |
635 } | 657 } |
636 | 658 |
637 //////////////////////////////////////////////////////////////////////////////// | 659 //////////////////////////////////////////////////////////////////////////////// |
638 // In-progress download termination handling: | 660 // In-progress download termination handling: |
639 | 661 |
640 void Browser::InProgressDownloadResponse(bool cancel_downloads) { | 662 void Browser::InProgressDownloadResponse(bool cancel_downloads) { |
641 if (cancel_downloads) { | 663 if (cancel_downloads) { |
642 cancel_download_confirmation_state_ = RESPONSE_RECEIVED; | 664 cancel_download_confirmation_state_ = RESPONSE_RECEIVED; |
643 chrome::CloseWindow(this); | 665 chrome::CloseWindow(this); |
644 return; | 666 return; |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1163 } | 1185 } |
1164 return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut); | 1186 return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut); |
1165 } | 1187 } |
1166 | 1188 |
1167 void Browser::HandleKeyboardEvent(content::WebContents* source, | 1189 void Browser::HandleKeyboardEvent(content::WebContents* source, |
1168 const NativeWebKeyboardEvent& event) { | 1190 const NativeWebKeyboardEvent& event) { |
1169 window()->HandleKeyboardEvent(event); | 1191 window()->HandleKeyboardEvent(event); |
1170 } | 1192 } |
1171 | 1193 |
1172 bool Browser::TabsNeedBeforeUnloadFired() { | 1194 bool Browser::TabsNeedBeforeUnloadFired() { |
| 1195 if (IsFastTabUnloadEnabled()) |
| 1196 return fast_unload_controller_->TabsNeedBeforeUnloadFired(); |
1173 return unload_controller_->TabsNeedBeforeUnloadFired(); | 1197 return unload_controller_->TabsNeedBeforeUnloadFired(); |
1174 } | 1198 } |
1175 | 1199 |
1176 bool Browser::IsMouseLocked() const { | 1200 bool Browser::IsMouseLocked() const { |
1177 return fullscreen_controller_->IsMouseLocked(); | 1201 return fullscreen_controller_->IsMouseLocked(); |
1178 } | 1202 } |
1179 | 1203 |
1180 void Browser::OnWindowDidShow() { | 1204 void Browser::OnWindowDidShow() { |
1181 if (window_has_shown_) | 1205 if (window_has_shown_) |
1182 return; | 1206 return; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1299 bool is_loading = source->IsLoading(); | 1323 bool is_loading = source->IsLoading(); |
1300 command_controller_->LoadingStateChanged(is_loading, false); | 1324 command_controller_->LoadingStateChanged(is_loading, false); |
1301 if (GetStatusBubble()) { | 1325 if (GetStatusBubble()) { |
1302 GetStatusBubble()->SetStatus(CoreTabHelper::FromWebContents( | 1326 GetStatusBubble()->SetStatus(CoreTabHelper::FromWebContents( |
1303 tab_strip_model_->GetActiveWebContents())->GetStatusText()); | 1327 tab_strip_model_->GetActiveWebContents())->GetStatusText()); |
1304 } | 1328 } |
1305 } | 1329 } |
1306 } | 1330 } |
1307 | 1331 |
1308 void Browser::CloseContents(WebContents* source) { | 1332 void Browser::CloseContents(WebContents* source) { |
1309 if (unload_controller_->CanCloseContents(source)) | 1333 bool can_close_contents; |
| 1334 if (IsFastTabUnloadEnabled()) |
| 1335 can_close_contents = fast_unload_controller_->CanCloseContents(source); |
| 1336 else |
| 1337 can_close_contents = unload_controller_->CanCloseContents(source); |
| 1338 |
| 1339 if (can_close_contents) |
1310 chrome::CloseWebContents(this, source, true); | 1340 chrome::CloseWebContents(this, source, true); |
1311 } | 1341 } |
1312 | 1342 |
1313 void Browser::MoveContents(WebContents* source, const gfx::Rect& pos) { | 1343 void Browser::MoveContents(WebContents* source, const gfx::Rect& pos) { |
1314 if (!IsPopupOrPanel(source)) { | 1344 if (!IsPopupOrPanel(source)) { |
1315 NOTREACHED() << "moving invalid browser type"; | 1345 NOTREACHED() << "moving invalid browser type"; |
1316 return; | 1346 return; |
1317 } | 1347 } |
1318 window_->SetBounds(pos); | 1348 window_->SetBounds(pos); |
1319 } | 1349 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1362 return false; | 1392 return false; |
1363 } | 1393 } |
1364 | 1394 |
1365 gfx::Rect Browser::GetRootWindowResizerRect() const { | 1395 gfx::Rect Browser::GetRootWindowResizerRect() const { |
1366 return window_->GetRootWindowResizerRect(); | 1396 return window_->GetRootWindowResizerRect(); |
1367 } | 1397 } |
1368 | 1398 |
1369 void Browser::BeforeUnloadFired(WebContents* web_contents, | 1399 void Browser::BeforeUnloadFired(WebContents* web_contents, |
1370 bool proceed, | 1400 bool proceed, |
1371 bool* proceed_to_fire_unload) { | 1401 bool* proceed_to_fire_unload) { |
1372 *proceed_to_fire_unload = | 1402 if (IsFastTabUnloadEnabled()) { |
1373 unload_controller_->BeforeUnloadFired(web_contents, proceed); | 1403 *proceed_to_fire_unload = |
| 1404 fast_unload_controller_->BeforeUnloadFired(web_contents, proceed); |
| 1405 } else { |
| 1406 *proceed_to_fire_unload = |
| 1407 unload_controller_->BeforeUnloadFired(web_contents, proceed); |
| 1408 } |
1374 } | 1409 } |
1375 | 1410 |
1376 bool Browser::ShouldFocusLocationBarByDefault(WebContents* source) { | 1411 bool Browser::ShouldFocusLocationBarByDefault(WebContents* source) { |
1377 const content::NavigationEntry* entry = | 1412 const content::NavigationEntry* entry = |
1378 source->GetController().GetActiveEntry(); | 1413 source->GetController().GetActiveEntry(); |
1379 if (entry) { | 1414 if (entry) { |
1380 GURL url = entry->GetURL(); | 1415 GURL url = entry->GetURL(); |
1381 GURL virtual_url = entry->GetVirtualURL(); | 1416 GURL virtual_url = entry->GetVirtualURL(); |
1382 if ((url.SchemeIs(chrome::kChromeUIScheme) && | 1417 if ((url.SchemeIs(chrome::kChromeUIScheme) && |
1383 url.host() == chrome::kChromeUINewTabHost) || | 1418 url.host() == chrome::kChromeUINewTabHost) || |
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2213 if (contents && !allow_js_access) { | 2248 if (contents && !allow_js_access) { |
2214 contents->web_contents()->GetController().LoadURL( | 2249 contents->web_contents()->GetController().LoadURL( |
2215 target_url, | 2250 target_url, |
2216 content::Referrer(), | 2251 content::Referrer(), |
2217 content::PAGE_TRANSITION_LINK, | 2252 content::PAGE_TRANSITION_LINK, |
2218 std::string()); // No extra headers. | 2253 std::string()); // No extra headers. |
2219 } | 2254 } |
2220 | 2255 |
2221 return contents != NULL; | 2256 return contents != NULL; |
2222 } | 2257 } |
OLD | NEW |