| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 #include "chrome/browser/instant/instant_unload_handler.h" | 62 #include "chrome/browser/instant/instant_unload_handler.h" |
| 63 #include "chrome/browser/intents/register_intent_handler_infobar_delegate.h" | 63 #include "chrome/browser/intents/register_intent_handler_infobar_delegate.h" |
| 64 #include "chrome/browser/intents/web_intents_registry_factory.h" | 64 #include "chrome/browser/intents/web_intents_registry_factory.h" |
| 65 #include "chrome/browser/net/browser_url_util.h" | 65 #include "chrome/browser/net/browser_url_util.h" |
| 66 #include "chrome/browser/net/url_fixer_upper.h" | 66 #include "chrome/browser/net/url_fixer_upper.h" |
| 67 #include "chrome/browser/notifications/notification_ui_manager.h" | 67 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 68 #include "chrome/browser/platform_util.h" | 68 #include "chrome/browser/platform_util.h" |
| 69 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 69 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 70 #include "chrome/browser/prefs/pref_service.h" | 70 #include "chrome/browser/prefs/pref_service.h" |
| 71 #include "chrome/browser/prerender/prerender_tab_helper.h" | 71 #include "chrome/browser/prerender/prerender_tab_helper.h" |
| 72 #include "chrome/browser/printing/background_printing_manager.h" | |
| 73 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" | 72 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" |
| 74 #include "chrome/browser/printing/print_preview_tab_controller.h" | 73 #include "chrome/browser/printing/print_preview_tab_controller.h" |
| 75 #include "chrome/browser/printing/print_view_manager.h" | 74 #include "chrome/browser/printing/print_view_manager.h" |
| 76 #include "chrome/browser/profiles/profile.h" | 75 #include "chrome/browser/profiles/profile.h" |
| 77 #include "chrome/browser/sessions/restore_tab_helper.h" | 76 #include "chrome/browser/sessions/restore_tab_helper.h" |
| 78 #include "chrome/browser/sessions/session_service.h" | 77 #include "chrome/browser/sessions/session_service.h" |
| 79 #include "chrome/browser/sessions/session_service_factory.h" | 78 #include "chrome/browser/sessions/session_service_factory.h" |
| 80 #include "chrome/browser/sessions/session_types.h" | 79 #include "chrome/browser/sessions/session_types.h" |
| 81 #include "chrome/browser/sessions/tab_restore_service.h" | 80 #include "chrome/browser/sessions/tab_restore_service.h" |
| 82 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 81 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
| (...skipping 3358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3441 void Browser::CloseContents(TabContents* source) { | 3440 void Browser::CloseContents(TabContents* source) { |
| 3442 if (is_attempting_to_close_browser_) { | 3441 if (is_attempting_to_close_browser_) { |
| 3443 // If we're trying to close the browser, just clear the state related to | 3442 // If we're trying to close the browser, just clear the state related to |
| 3444 // waiting for unload to fire. Don't actually try to close the tab as it | 3443 // waiting for unload to fire. Don't actually try to close the tab as it |
| 3445 // will go down the slow shutdown path instead of the fast path of killing | 3444 // will go down the slow shutdown path instead of the fast path of killing |
| 3446 // all the renderer processes. | 3445 // all the renderer processes. |
| 3447 ClearUnloadState(source, true); | 3446 ClearUnloadState(source, true); |
| 3448 return; | 3447 return; |
| 3449 } | 3448 } |
| 3450 | 3449 |
| 3451 // Various sites have a pattern which open a new window with output formatted | |
| 3452 // for printing, then include a print button, which does window.print(); | |
| 3453 // window.close(); An example is printing Virgin America boarding | |
| 3454 // pass. Instead of closing, when a print tab is associated with this tab, | |
| 3455 // tell the BackgroundPrintingManager to own it, which causes it to be | |
| 3456 // hidden and eventually closed when the print window is closed. | |
| 3457 TabContentsWrapper* source_wrapper = | |
| 3458 TabContentsWrapper::GetCurrentWrapperForContents(source); | |
| 3459 if (g_browser_process->background_printing_manager()-> | |
| 3460 OwnInitiatorTab(source_wrapper)) { | |
| 3461 return; | |
| 3462 } | |
| 3463 | |
| 3464 int index = tab_handler_->GetTabStripModel()->GetWrapperIndex(source); | 3450 int index = tab_handler_->GetTabStripModel()->GetWrapperIndex(source); |
| 3465 if (index == TabStripModel::kNoTab) { | 3451 if (index == TabStripModel::kNoTab) { |
| 3466 NOTREACHED() << "CloseContents called for tab not in our strip"; | 3452 NOTREACHED() << "CloseContents called for tab not in our strip"; |
| 3467 return; | 3453 return; |
| 3468 } | 3454 } |
| 3469 tab_handler_->GetTabStripModel()->CloseTabContentsAt( | 3455 tab_handler_->GetTabStripModel()->CloseTabContentsAt( |
| 3470 index, | 3456 index, |
| 3471 TabStripModel::CLOSE_CREATE_HISTORICAL_TAB); | 3457 TabStripModel::CLOSE_CREATE_HISTORICAL_TAB); |
| 3472 } | 3458 } |
| 3473 | 3459 |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3724 NavigationType::Type navigation_type) { | 3710 NavigationType::Type navigation_type) { |
| 3725 // Don't update history if running as app. | 3711 // Don't update history if running as app. |
| 3726 return !IsApplication(); | 3712 return !IsApplication(); |
| 3727 } | 3713 } |
| 3728 | 3714 |
| 3729 void Browser::ContentRestrictionsChanged(TabContents* source) { | 3715 void Browser::ContentRestrictionsChanged(TabContents* source) { |
| 3730 UpdateCommandsForContentRestrictionState(); | 3716 UpdateCommandsForContentRestrictionState(); |
| 3731 } | 3717 } |
| 3732 | 3718 |
| 3733 void Browser::RendererUnresponsive(TabContents* source) { | 3719 void Browser::RendererUnresponsive(TabContents* source) { |
| 3720 // Ignore hangs if print preview is open. |
| 3721 TabContentsWrapper* source_wrapper = |
| 3722 TabContentsWrapper::GetCurrentWrapperForContents(source); |
| 3723 if (source_wrapper) { |
| 3724 printing::PrintPreviewTabController* controller = |
| 3725 printing::PrintPreviewTabController::GetInstance(); |
| 3726 if (controller) { |
| 3727 TabContentsWrapper* preview_tab = |
| 3728 controller->GetPrintPreviewForTab(source_wrapper); |
| 3729 if (preview_tab && preview_tab != source_wrapper) { |
| 3730 return; |
| 3731 } |
| 3732 } |
| 3733 } |
| 3734 |
| 3734 browser::ShowHungRendererDialog(source); | 3735 browser::ShowHungRendererDialog(source); |
| 3735 } | 3736 } |
| 3736 | 3737 |
| 3737 void Browser::RendererResponsive(TabContents* source) { | 3738 void Browser::RendererResponsive(TabContents* source) { |
| 3738 browser::HideHungRendererDialog(source); | 3739 browser::HideHungRendererDialog(source); |
| 3739 } | 3740 } |
| 3740 | 3741 |
| 3741 void Browser::WorkerCrashed(TabContents* source) { | 3742 void Browser::WorkerCrashed(TabContents* source) { |
| 3742 TabContentsWrapper* wrapper = | 3743 TabContentsWrapper* wrapper = |
| 3743 TabContentsWrapper::GetCurrentWrapperForContents(source); | 3744 TabContentsWrapper::GetCurrentWrapperForContents(source); |
| (...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4491 IDC_COPY, !(restrictions & CONTENT_RESTRICTION_COPY)); | 4492 IDC_COPY, !(restrictions & CONTENT_RESTRICTION_COPY)); |
| 4492 command_updater_.UpdateCommandEnabled( | 4493 command_updater_.UpdateCommandEnabled( |
| 4493 IDC_CUT, !(restrictions & CONTENT_RESTRICTION_CUT)); | 4494 IDC_CUT, !(restrictions & CONTENT_RESTRICTION_CUT)); |
| 4494 command_updater_.UpdateCommandEnabled( | 4495 command_updater_.UpdateCommandEnabled( |
| 4495 IDC_PASTE, !(restrictions & CONTENT_RESTRICTION_PASTE)); | 4496 IDC_PASTE, !(restrictions & CONTENT_RESTRICTION_PASTE)); |
| 4496 UpdateSaveAsState(restrictions); | 4497 UpdateSaveAsState(restrictions); |
| 4497 UpdatePrintingState(restrictions); | 4498 UpdatePrintingState(restrictions); |
| 4498 } | 4499 } |
| 4499 | 4500 |
| 4500 void Browser::UpdatePrintingState(int content_restrictions) { | 4501 void Browser::UpdatePrintingState(int content_restrictions) { |
| 4501 bool enabled = true; | 4502 bool print_enabled = true; |
| 4502 bool selected_tab_is_preview_tab = false; | 4503 bool advanced_print_enabled = true; |
| 4503 if (content_restrictions & CONTENT_RESTRICTION_PRINT) { | 4504 if (g_browser_process->local_state()) { |
| 4504 enabled = false; | 4505 print_enabled = |
| 4505 selected_tab_is_preview_tab = | 4506 g_browser_process->local_state()->GetBoolean(prefs::kPrintingEnabled); |
| 4506 printing::PrintPreviewTabController::IsPrintPreviewTab( | 4507 advanced_print_enabled = print_enabled; |
| 4507 GetSelectedTabContentsWrapper()); | |
| 4508 } else if (g_browser_process->local_state()) { | |
| 4509 enabled = g_browser_process->local_state()-> | |
| 4510 GetBoolean(prefs::kPrintingEnabled); | |
| 4511 } | 4508 } |
| 4512 command_updater_.UpdateCommandEnabled(IDC_PRINT, enabled); | 4509 if (print_enabled) { |
| 4510 // Cannot print when a constrained window is showing because print preview |
| 4511 // is also a constrained window. |
| 4512 TabContentsWrapper* wrapper = GetSelectedTabContentsWrapper(); |
| 4513 bool has_constrained_window = (wrapper && |
| 4514 wrapper->constrained_window_tab_helper()->constrained_window_count()); |
| 4515 if (has_constrained_window || |
| 4516 content_restrictions & CONTENT_RESTRICTION_PRINT) { |
| 4517 print_enabled = false; |
| 4518 advanced_print_enabled = false; |
| 4519 } |
| 4520 printing::PrintPreviewTabController* controller = |
| 4521 printing::PrintPreviewTabController::GetInstance(); |
| 4522 if (controller && |
| 4523 controller->GetPrintPreviewForTab(GetSelectedTabContentsWrapper())) { |
| 4524 advanced_print_enabled = true; |
| 4525 } |
| 4526 } |
| 4527 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled); |
| 4513 command_updater_.UpdateCommandEnabled(IDC_ADVANCED_PRINT, | 4528 command_updater_.UpdateCommandEnabled(IDC_ADVANCED_PRINT, |
| 4514 selected_tab_is_preview_tab ? true : | 4529 advanced_print_enabled); |
| 4515 enabled); | |
| 4516 } | 4530 } |
| 4517 | 4531 |
| 4518 void Browser::UpdateReloadStopState(bool is_loading, bool force) { | 4532 void Browser::UpdateReloadStopState(bool is_loading, bool force) { |
| 4519 window_->UpdateReloadStopState(is_loading, force); | 4533 window_->UpdateReloadStopState(is_loading, force); |
| 4520 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); | 4534 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); |
| 4521 } | 4535 } |
| 4522 | 4536 |
| 4523 void Browser::UpdateCommandsForDevTools() { | 4537 void Browser::UpdateCommandsForDevTools() { |
| 4524 bool dev_tools_enabled = | 4538 bool dev_tools_enabled = |
| 4525 !profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled); | 4539 !profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled); |
| (...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5287 window_->GetLocationBar()->ShowFirstRunBubble(bubble_type); | 5301 window_->GetLocationBar()->ShowFirstRunBubble(bubble_type); |
| 5288 } else if (is_type_tabbed()) { | 5302 } else if (is_type_tabbed()) { |
| 5289 GlobalErrorService* service = | 5303 GlobalErrorService* service = |
| 5290 GlobalErrorServiceFactory::GetForProfile(profile()); | 5304 GlobalErrorServiceFactory::GetForProfile(profile()); |
| 5291 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); | 5305 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); |
| 5292 if (error) { | 5306 if (error) { |
| 5293 error->ShowBubbleView(this); | 5307 error->ShowBubbleView(this); |
| 5294 } | 5308 } |
| 5295 } | 5309 } |
| 5296 } | 5310 } |
| OLD | NEW |