Chromium Code Reviews| Index: chrome/browser/printing/print_preview_dialog_controller.cc |
| diff --git a/chrome/browser/printing/print_preview_dialog_controller.cc b/chrome/browser/printing/print_preview_dialog_controller.cc |
| index b9413a0f7cee7f60dc6784884c23ffe8f572b8e8..6a71e2acd72df7f78f73e1fc49ea31608728dc47 100644 |
| --- a/chrome/browser/printing/print_preview_dialog_controller.cc |
| +++ b/chrome/browser/printing/print_preview_dialog_controller.cc |
| @@ -303,7 +303,7 @@ void PrintPreviewDialogController::EraseInitiatorTabInfo( |
| if (it == preview_dialog_map_.end()) |
| return; |
| - RemoveObservers(it->second); |
| + RemoveObservers(it->second, INITIATOR_TAB); |
| preview_dialog_map_[preview_dialog] = NULL; |
| } |
| @@ -361,35 +361,33 @@ void PrintPreviewDialogController::OnNavEntryCommitted( |
| return; |
| } |
| - if (contents == preview_dialog) { |
| - // Preview dialog navigated. |
| - if (details) { |
| - content::PageTransition transition_type = |
| - details->entry->GetTransitionType(); |
| - content::NavigationType nav_type = details->type; |
| - |
| - // New |preview_dialog| is created. Don't update/erase map entry. |
| - if (waiting_for_new_preview_page_ && |
| - transition_type == content::PAGE_TRANSITION_AUTO_TOPLEVEL && |
| - nav_type == content::NAVIGATION_TYPE_NEW_PAGE) { |
| - waiting_for_new_preview_page_ = false; |
| - SaveInitiatorTabTitle(preview_dialog); |
| - return; |
| - } |
| - |
| - // Cloud print sign-in causes a reload. |
| - if (!waiting_for_new_preview_page_ && |
| - transition_type == content::PAGE_TRANSITION_RELOAD && |
| - nav_type == content::NAVIGATION_TYPE_EXISTING_PAGE && |
| - IsPrintPreviewURL(details->previous_url)) { |
| - return; |
| - } |
| + DCHECK(contents == preview_dialog); |
|
Lei Zhang
2013/06/27 21:36:18
nit: DCHECK_EQ(preview_dialog, content);
Mike Wittman
2013/06/27 23:39:38
Done.
|
| + |
| + // Preview dialog navigated. |
| + if (details) { |
| + content::PageTransition transition_type = |
| + details->entry->GetTransitionType(); |
| + content::NavigationType nav_type = details->type; |
| + |
| + // New |preview_dialog| is created. Don't update/erase map entry. |
| + if (waiting_for_new_preview_page_ && |
| + transition_type == content::PAGE_TRANSITION_AUTO_TOPLEVEL && |
| + nav_type == content::NAVIGATION_TYPE_NEW_PAGE) { |
| + waiting_for_new_preview_page_ = false; |
| + SaveInitiatorTabTitle(preview_dialog); |
| + return; |
| + } |
| + |
| + // Cloud print sign-in causes a reload. |
| + if (!waiting_for_new_preview_page_ && |
| + transition_type == content::PAGE_TRANSITION_RELOAD && |
| + nav_type == content::NAVIGATION_TYPE_EXISTING_PAGE && |
| + IsPrintPreviewURL(details->previous_url)) { |
| + return; |
| } |
| - NOTREACHED(); |
| - return; |
| } |
| - RemoveInitiatorTab(contents); |
| + NOTREACHED(); |
| } |
| WebContents* PrintPreviewDialogController::CreatePrintPreviewDialog( |
| @@ -429,8 +427,8 @@ WebContents* PrintPreviewDialogController::CreatePrintPreviewDialog( |
| preview_dialog_map_[preview_dialog] = initiator_tab; |
| waiting_for_new_preview_page_ = true; |
| - AddObservers(initiator_tab); |
| - AddObservers(preview_dialog); |
| + AddObservers(initiator_tab, INITIATOR_TAB); |
| + AddObservers(preview_dialog, PREVIEW_TAB); |
| return preview_dialog; |
| } |
| @@ -446,11 +444,14 @@ void PrintPreviewDialogController::SaveInitiatorTabTitle( |
| } |
| } |
| -void PrintPreviewDialogController::AddObservers(WebContents* contents) { |
| +void PrintPreviewDialogController::AddObservers(WebContents* contents, |
| + TabType tab_type) { |
| registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| content::Source<WebContents>(contents)); |
| - registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| - content::Source<NavigationController>(&contents->GetController())); |
| + if (tab_type == PREVIEW_TAB) { |
| + registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| + content::Source<NavigationController>(&contents->GetController())); |
| + } |
| // Multiple sites may share the same RenderProcessHost, so check if this |
| // notification has already been added. |
| @@ -463,11 +464,14 @@ void PrintPreviewDialogController::AddObservers(WebContents* contents) { |
| } |
| } |
| -void PrintPreviewDialogController::RemoveObservers(WebContents* contents) { |
| +void PrintPreviewDialogController::RemoveObservers(WebContents* contents, |
| + TabType tab_type) { |
| registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| content::Source<WebContents>(contents)); |
| - registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| - content::Source<NavigationController>(&contents->GetController())); |
| + if (tab_type == PREVIEW_TAB) { |
| + registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| + content::Source<NavigationController>(&contents->GetController())); |
| + } |
| // Multiple sites may share the same RenderProcessHost, so check if this |
| // notification has already been added. |
| @@ -488,7 +492,7 @@ void PrintPreviewDialogController::RemoveInitiatorTab( |
| // and reaches RemovePreviewDialog(), it does not attempt to also remove the |
| // initiator tab's observers. |
| preview_dialog_map_[preview_dialog] = NULL; |
| - RemoveObservers(initiator_tab); |
| + RemoveObservers(initiator_tab, INITIATOR_TAB); |
| PrintViewManager::FromWebContents(initiator_tab)->PrintPreviewDone(); |
| @@ -504,7 +508,7 @@ void PrintPreviewDialogController::RemovePreviewDialog( |
| // Remove the initiator tab's observers before erasing the mapping. |
| WebContents* initiator_tab = GetInitiatorTab(preview_dialog); |
| if (initiator_tab) { |
| - RemoveObservers(initiator_tab); |
| + RemoveObservers(initiator_tab, INITIATOR_TAB); |
| PrintViewManager::FromWebContents(initiator_tab)->PrintPreviewDone(); |
| } |
| @@ -516,7 +520,7 @@ void PrintPreviewDialogController::RemovePreviewDialog( |
| print_preview_ui->OnPrintPreviewDialogDestroyed(); |
| preview_dialog_map_.erase(preview_dialog); |
| - RemoveObservers(preview_dialog); |
| + RemoveObservers(preview_dialog, PREVIEW_TAB); |
| } |
| } // namespace printing |