| 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/printing/print_preview_tab_controller.h" | 5 #include "chrome/browser/printing/print_preview_tab_controller.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/printing/background_printing_manager.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/sessions/restore_tab_helper.h" | 14 #include "chrome/browser/sessions/restore_tab_helper.h" |
| 14 #include "chrome/browser/tabs/tab_strip_model.h" | 15 #include "chrome/browser/tabs/tab_strip_model.h" |
| 15 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_list.h" | 17 #include "chrome/browser/ui/browser_list.h" |
| 17 #include "chrome/browser/ui/browser_navigator.h" | 18 #include "chrome/browser/ui/browser_navigator.h" |
| 18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 19 #include "chrome/browser/ui/webui/print_preview_ui.h" | 20 #include "chrome/browser/ui/webui/print_preview_ui.h" |
| 20 #include "chrome/common/chrome_content_client.h" | 21 #include "chrome/common/chrome_content_client.h" |
| 21 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 NOTREACHED(); | 156 NOTREACHED(); |
| 156 break; | 157 break; |
| 157 } | 158 } |
| 158 } | 159 } |
| 159 } | 160 } |
| 160 | 161 |
| 161 void PrintPreviewTabController::OnRendererProcessClosed( | 162 void PrintPreviewTabController::OnRendererProcessClosed( |
| 162 RenderProcessHost* rph) { | 163 RenderProcessHost* rph) { |
| 163 for (PrintPreviewTabMap::iterator iter = preview_tab_map_.begin(); | 164 for (PrintPreviewTabMap::iterator iter = preview_tab_map_.begin(); |
| 164 iter != preview_tab_map_.end(); ++iter) { | 165 iter != preview_tab_map_.end(); ++iter) { |
| 165 if (iter->second != NULL && | 166 TabContents* initiator_tab = iter->second; |
| 166 iter->second->render_view_host()->process() == rph) { | 167 if (initiator_tab != NULL && |
| 167 TabContents* preview_tab = GetPrintPreviewForTab(iter->second); | 168 initiator_tab->render_view_host()->process() == rph) { |
| 169 // Release the initiator tab contents, possibly deleting if owned. |
| 170 RemoveObservers(initiator_tab); |
| 171 TabContentsWrapper* initiator_wrapper = |
| 172 TabContentsWrapper::GetCurrentWrapperForContents(initiator_tab); |
| 173 g_browser_process->background_printing_manager()-> |
| 174 ReleaseInitiatorTabContents(initiator_wrapper); |
| 175 |
| 176 TabContents* preview_tab = GetPrintPreviewForTab(initiator_tab); |
| 168 PrintPreviewUI* print_preview_ui = | 177 PrintPreviewUI* print_preview_ui = |
| 169 static_cast<PrintPreviewUI*>(preview_tab->web_ui()); | 178 static_cast<PrintPreviewUI*>(preview_tab->web_ui()); |
| 170 print_preview_ui->OnInitiatorTabCrashed(); | 179 print_preview_ui->OnInitiatorTabCrashed(); |
| 171 } | 180 } |
| 172 } | 181 } |
| 173 } | 182 } |
| 174 | 183 |
| 175 void PrintPreviewTabController::OnTabContentsDestroyed(TabContents* tab) { | 184 void PrintPreviewTabController::OnTabContentsDestroyed(TabContents* tab) { |
| 176 TabContents* preview_tab = GetPrintPreviewForTab(tab); | 185 TabContents* preview_tab = GetPrintPreviewForTab(tab); |
| 177 if (!preview_tab) | 186 if (!preview_tab) |
| 178 return; | 187 return; |
| 179 | 188 |
| 180 if (tab == preview_tab) { | 189 if (tab == preview_tab) { |
| 181 // Remove the initiator tab's observers before erasing the mapping. | |
| 182 TabContents* initiator_tab = GetInitiatorTab(tab); | |
| 183 if (initiator_tab) | |
| 184 RemoveObservers(initiator_tab); | |
| 185 | |
| 186 // Print preview tab contents are destroyed. Notify |PrintPreviewUI| to | 190 // Print preview tab contents are destroyed. Notify |PrintPreviewUI| to |
| 187 // abort the initiator tab preview request. | 191 // abort the initiator tab preview request. |
| 188 if (IsPrintPreviewTab(tab) && tab->web_ui()) { | 192 if (IsPrintPreviewTab(tab) && tab->web_ui()) { |
| 189 PrintPreviewUI* print_preview_ui = | 193 PrintPreviewUI* print_preview_ui = |
| 190 static_cast<PrintPreviewUI*>(tab->web_ui()); | 194 static_cast<PrintPreviewUI*>(tab->web_ui()); |
| 191 print_preview_ui->OnTabDestroyed(); | 195 print_preview_ui->OnTabDestroyed(); |
| 192 } | 196 } |
| 193 | 197 |
| 198 // Remove the initiator tab's observers before erasing the mapping. Also |
| 199 // release the initiator tab contents, possibly deleting if owned. |
| 200 TabContents* initiator_tab = GetInitiatorTab(tab); |
| 201 if (initiator_tab) { |
| 202 RemoveObservers(initiator_tab); |
| 203 TabContentsWrapper* initiator_wrapper = |
| 204 TabContentsWrapper::GetCurrentWrapperForContents(initiator_tab); |
| 205 g_browser_process->background_printing_manager()-> |
| 206 ReleaseInitiatorTabContents(initiator_wrapper); |
| 207 } |
| 194 // Erase the map entry. | 208 // Erase the map entry. |
| 195 preview_tab_map_.erase(tab); | 209 preview_tab_map_.erase(tab); |
| 196 } else { | 210 } else { |
| 197 // Initiator tab is closed. Disable the controls in preview tab. | 211 // Initiator tab is closed. Disable the controls in preview tab. |
| 198 if (preview_tab->web_ui()) { | 212 if (preview_tab->web_ui()) { |
| 199 PrintPreviewUI* print_preview_ui = | 213 PrintPreviewUI* print_preview_ui = |
| 200 static_cast<PrintPreviewUI*>(preview_tab->web_ui()); | 214 static_cast<PrintPreviewUI*>(preview_tab->web_ui()); |
| 201 print_preview_ui->OnInitiatorTabClosed(); | 215 print_preview_ui->OnInitiatorTabClosed(); |
| 202 } | 216 } |
| 203 | 217 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 nav_type == NavigationType::EXISTING_PAGE) { | 255 nav_type == NavigationType::EXISTING_PAGE) { |
| 242 return; | 256 return; |
| 243 } | 257 } |
| 244 } | 258 } |
| 245 | 259 |
| 246 RemoveObservers(tab); | 260 RemoveObservers(tab); |
| 247 ResetPreviewTabOverrideTitle(preview_tab); | 261 ResetPreviewTabOverrideTitle(preview_tab); |
| 248 if (source_tab_is_preview_tab) { | 262 if (source_tab_is_preview_tab) { |
| 249 // Remove the initiator tab's observers before erasing the mapping. | 263 // Remove the initiator tab's observers before erasing the mapping. |
| 250 TabContents* initiator_tab = GetInitiatorTab(tab); | 264 TabContents* initiator_tab = GetInitiatorTab(tab); |
| 251 if (initiator_tab) | 265 if (initiator_tab) { |
| 252 RemoveObservers(initiator_tab); | 266 RemoveObservers(initiator_tab); |
| 267 TabContentsWrapper* initiator_wrapper = |
| 268 TabContentsWrapper::GetCurrentWrapperForContents(initiator_tab); |
| 269 g_browser_process->background_printing_manager()-> |
| 270 ReleaseInitiatorTabContents(initiator_wrapper); |
| 271 } |
| 253 preview_tab_map_.erase(tab); | 272 preview_tab_map_.erase(tab); |
| 254 } else { | 273 } else { |
| 255 preview_tab_map_[preview_tab] = NULL; | 274 preview_tab_map_[preview_tab] = NULL; |
| 256 | 275 |
| 257 // Initiator tab is closed. Disable the controls in preview tab. | 276 // Initiator tab is closed. Disable the controls in preview tab. |
| 258 if (preview_tab->web_ui()) { | 277 if (preview_tab->web_ui()) { |
| 259 PrintPreviewUI* print_preview_ui = | 278 PrintPreviewUI* print_preview_ui = |
| 260 static_cast<PrintPreviewUI*>(preview_tab->web_ui()); | 279 static_cast<PrintPreviewUI*>(preview_tab->web_ui()); |
| 261 print_preview_ui->OnInitiatorTabClosed(); | 280 print_preview_ui->OnInitiatorTabClosed(); |
| 262 } | 281 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 RenderProcessHost* rph = tab->render_view_host()->process(); | 396 RenderProcessHost* rph = tab->render_view_host()->process(); |
| 378 if (registrar_.IsRegistered(this, | 397 if (registrar_.IsRegistered(this, |
| 379 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 398 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
| 380 Source<RenderProcessHost>(rph))) { | 399 Source<RenderProcessHost>(rph))) { |
| 381 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 400 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
| 382 Source<RenderProcessHost>(rph)); | 401 Source<RenderProcessHost>(rph)); |
| 383 } | 402 } |
| 384 } | 403 } |
| 385 | 404 |
| 386 } // namespace printing | 405 } // namespace printing |
| OLD | NEW |