Chromium Code Reviews| 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/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/printing/background_printing_manager.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" |
| 22 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 | 155 |
| 155 void PrintPreviewTabController::OnRendererProcessClosed( | 156 void PrintPreviewTabController::OnRendererProcessClosed( |
| 156 RenderProcessHost* rph) { | 157 RenderProcessHost* rph) { |
| 157 for (PrintPreviewTabMap::iterator iter = preview_tab_map_.begin(); | 158 for (PrintPreviewTabMap::iterator iter = preview_tab_map_.begin(); |
| 158 iter != preview_tab_map_.end(); ++iter) { | 159 iter != preview_tab_map_.end(); ++iter) { |
| 159 if (iter->second != NULL && | 160 if (iter->second != NULL && |
| 160 iter->second->render_view_host()->process() == rph) { | 161 iter->second->render_view_host()->process() == rph) { |
| 161 TabContents* preview_tab = GetPrintPreviewForTab(iter->second); | 162 TabContents* preview_tab = GetPrintPreviewForTab(iter->second); |
| 162 PrintPreviewUI* print_preview_ui = | 163 PrintPreviewUI* print_preview_ui = |
| 163 static_cast<PrintPreviewUI*>(preview_tab->web_ui()); | 164 static_cast<PrintPreviewUI*>(preview_tab->web_ui()); |
| 164 print_preview_ui->OnInitiatorTabCrashed(); | 165 print_preview_ui->OnInitiatorTabCrashed(); |
|
kmadhusu
2011/08/19 17:13:04
If the hidden initiator tab is crashed, you need t
Sheridan Rawlins
2011/08/25 22:52:55
Done.
| |
| 165 } | 166 } |
| 166 } | 167 } |
| 167 } | 168 } |
| 168 | 169 |
| 169 void PrintPreviewTabController::OnTabContentsDestroyed(TabContents* tab) { | 170 void PrintPreviewTabController::OnTabContentsDestroyed(TabContents* tab) { |
| 170 TabContents* preview_tab = GetPrintPreviewForTab(tab); | 171 TabContents* preview_tab = GetPrintPreviewForTab(tab); |
| 171 if (!preview_tab) | 172 if (!preview_tab) |
| 172 return; | 173 return; |
| 173 | 174 |
| 174 if (tab == preview_tab) { | 175 if (tab == preview_tab) { |
| 175 // Remove the initiator tab's observers before erasing the mapping. | 176 // Remove the initiator tab's observers before erasing the mapping. |
| 176 TabContents* initiator_tab = GetInitiatorTab(tab); | 177 TabContents* initiator_tab = GetInitiatorTab(tab); |
| 177 if (initiator_tab) | 178 if (initiator_tab) |
| 178 RemoveObservers(initiator_tab); | 179 RemoveObservers(initiator_tab); |
| 179 | 180 |
| 180 // Print preview tab contents are destroyed. Notify |PrintPreviewUI| to | 181 // Print preview tab contents are destroyed. Notify |PrintPreviewUI| to |
| 181 // abort the initiator tab preview request. | 182 // abort the initiator tab preview request. |
| 182 if (IsPrintPreviewTab(tab) && tab->web_ui()) { | 183 if (IsPrintPreviewTab(tab) && tab->web_ui()) { |
| 183 PrintPreviewUI* print_preview_ui = | 184 PrintPreviewUI* print_preview_ui = |
| 184 static_cast<PrintPreviewUI*>(tab->web_ui()); | 185 static_cast<PrintPreviewUI*>(tab->web_ui()); |
| 185 print_preview_ui->OnTabDestroyed(); | 186 print_preview_ui->OnTabDestroyed(); |
| 186 } | 187 } |
| 187 | 188 |
| 189 // Release the initiator tab contents now, possibly deleting if owned. | |
| 190 if (initiator_tab) { | |
| 191 TabContentsWrapper* initiator_wrapper = | |
|
kmadhusu
2011/08/19 17:13:04
You can move line #179 to here.
Sheridan Rawlins
2011/08/25 22:52:55
Done.
| |
| 192 TabContentsWrapper::GetCurrentWrapperForContents(initiator_tab); | |
| 193 g_browser_process->background_printing_manager()-> | |
| 194 ReleaseInitiatorTabContents(initiator_wrapper); | |
| 195 } | |
| 188 // Erase the map entry. | 196 // Erase the map entry. |
| 189 preview_tab_map_.erase(tab); | 197 preview_tab_map_.erase(tab); |
| 190 } else { | 198 } else { |
| 191 // Initiator tab is closed. Disable the controls in preview tab. | 199 // Initiator tab is closed. Disable the controls in preview tab. |
| 192 if (preview_tab->web_ui()) { | 200 if (preview_tab->web_ui()) { |
| 193 PrintPreviewUI* print_preview_ui = | 201 PrintPreviewUI* print_preview_ui = |
| 194 static_cast<PrintPreviewUI*>(preview_tab->web_ui()); | 202 static_cast<PrintPreviewUI*>(preview_tab->web_ui()); |
| 195 print_preview_ui->OnInitiatorTabClosed(); | 203 print_preview_ui->OnInitiatorTabClosed(); |
| 196 } | 204 } |
| 197 | 205 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 transition_type == PageTransition::FORWARD_BACK && | 249 transition_type == PageTransition::FORWARD_BACK && |
| 242 nav_type == NavigationType::EXISTING_PAGE) { | 250 nav_type == NavigationType::EXISTING_PAGE) { |
| 243 return; | 251 return; |
| 244 } | 252 } |
| 245 } | 253 } |
| 246 | 254 |
| 247 RemoveObservers(tab); | 255 RemoveObservers(tab); |
| 248 if (source_tab_is_preview_tab) { | 256 if (source_tab_is_preview_tab) { |
| 249 // Remove the initiator tab's observers before erasing the mapping. | 257 // Remove the initiator tab's observers before erasing the mapping. |
| 250 TabContents* initiator_tab = GetInitiatorTab(tab); | 258 TabContents* initiator_tab = GetInitiatorTab(tab); |
| 251 if (initiator_tab) | 259 if (initiator_tab) { |
| 252 RemoveObservers(initiator_tab); | 260 RemoveObservers(initiator_tab); |
| 261 TabContentsWrapper* initiator_wrapper = | |
| 262 TabContentsWrapper::GetCurrentWrapperForContents(initiator_tab); | |
| 263 g_browser_process->background_printing_manager()-> | |
| 264 ReleaseInitiatorTabContents(initiator_wrapper); | |
| 265 } | |
| 253 preview_tab_map_.erase(tab); | 266 preview_tab_map_.erase(tab); |
| 254 } else { | 267 } else { |
| 255 preview_tab_map_[preview_tab] = NULL; | 268 preview_tab_map_[preview_tab] = NULL; |
| 256 | 269 |
| 257 // Initiator tab is closed. Disable the controls in preview tab. | 270 // Initiator tab is closed. Disable the controls in preview tab. |
| 258 if (preview_tab->web_ui()) { | 271 if (preview_tab->web_ui()) { |
| 259 PrintPreviewUI* print_preview_ui = | 272 PrintPreviewUI* print_preview_ui = |
| 260 static_cast<PrintPreviewUI*>(preview_tab->web_ui()); | 273 static_cast<PrintPreviewUI*>(preview_tab->web_ui()); |
| 261 print_preview_ui->OnInitiatorTabClosed(); | 274 print_preview_ui->OnInitiatorTabClosed(); |
| 262 } | 275 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 RenderProcessHost* rph = tab->render_view_host()->process(); | 375 RenderProcessHost* rph = tab->render_view_host()->process(); |
| 363 if (registrar_.IsRegistered(this, | 376 if (registrar_.IsRegistered(this, |
| 364 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 377 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
| 365 Source<RenderProcessHost>(rph))) { | 378 Source<RenderProcessHost>(rph))) { |
| 366 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 379 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
| 367 Source<RenderProcessHost>(rph)); | 380 Source<RenderProcessHost>(rph)); |
| 368 } | 381 } |
| 369 } | 382 } |
| 370 | 383 |
| 371 } // namespace printing | 384 } // namespace printing |
| OLD | NEW |