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 <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include "content/public/browser/notification_details.h" | 34 #include "content/public/browser/notification_details.h" |
35 #include "content/public/browser/notification_source.h" | 35 #include "content/public/browser/notification_source.h" |
36 #include "content/public/browser/notification_types.h" | 36 #include "content/public/browser/notification_types.h" |
37 #include "webkit/plugins/webplugininfo.h" | 37 #include "webkit/plugins/webplugininfo.h" |
38 | 38 |
39 namespace { | 39 namespace { |
40 | 40 |
41 void EnableInternalPDFPluginForTab(TabContentsWrapper* preview_tab) { | 41 void EnableInternalPDFPluginForTab(TabContentsWrapper* preview_tab) { |
42 // Always enable the internal PDF plugin for the print preview page. | 42 // Always enable the internal PDF plugin for the print preview page. |
43 ChromePluginServiceFilter::GetInstance()->OverridePluginForTab( | 43 ChromePluginServiceFilter::GetInstance()->OverridePluginForTab( |
44 preview_tab->render_view_host()->process()->GetID(), | 44 preview_tab->tab_contents()->render_view_host()->process()->GetID(), |
45 preview_tab->render_view_host()->routing_id(), | 45 preview_tab->tab_contents()->render_view_host()->routing_id(), |
46 GURL(), | 46 GURL(), |
47 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName)); | 47 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName)); |
48 } | 48 } |
49 | 49 |
50 class PrintPreviewTabDelegate : public HtmlDialogUIDelegate { | 50 class PrintPreviewTabDelegate : public HtmlDialogUIDelegate { |
51 public: | 51 public: |
52 explicit PrintPreviewTabDelegate(TabContentsWrapper* initiator_tab); | 52 explicit PrintPreviewTabDelegate(TabContentsWrapper* initiator_tab); |
53 virtual ~PrintPreviewTabDelegate(); | 53 virtual ~PrintPreviewTabDelegate(); |
54 | 54 |
55 virtual bool IsDialogModal() const OVERRIDE; | 55 virtual bool IsDialogModal() const OVERRIDE; |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 void PrintPreviewTabController::OnRendererProcessClosed( | 236 void PrintPreviewTabController::OnRendererProcessClosed( |
237 content::RenderProcessHost* rph) { | 237 content::RenderProcessHost* rph) { |
238 // Store tabs in a vector and deal with them after iterating through | 238 // Store tabs in a vector and deal with them after iterating through |
239 // |preview_tab_map_| because RemoveFooTab() can change |preview_tab_map_|. | 239 // |preview_tab_map_| because RemoveFooTab() can change |preview_tab_map_|. |
240 std::vector<TabContentsWrapper*> closed_initiator_tabs; | 240 std::vector<TabContentsWrapper*> closed_initiator_tabs; |
241 std::vector<TabContentsWrapper*> closed_preview_tabs; | 241 std::vector<TabContentsWrapper*> closed_preview_tabs; |
242 for (PrintPreviewTabMap::iterator iter = preview_tab_map_.begin(); | 242 for (PrintPreviewTabMap::iterator iter = preview_tab_map_.begin(); |
243 iter != preview_tab_map_.end(); ++iter) { | 243 iter != preview_tab_map_.end(); ++iter) { |
244 TabContentsWrapper* preview_tab = iter->first; | 244 TabContentsWrapper* preview_tab = iter->first; |
245 TabContentsWrapper* initiator_tab = iter->second; | 245 TabContentsWrapper* initiator_tab = iter->second; |
246 if (preview_tab->render_view_host()->process() == rph) { | 246 if (preview_tab->tab_contents()->render_view_host()->process() == rph) { |
247 closed_preview_tabs.push_back(preview_tab); | 247 closed_preview_tabs.push_back(preview_tab); |
248 } else if (initiator_tab && | 248 } else if (initiator_tab && |
249 initiator_tab->render_view_host()->process() == rph) { | 249 initiator_tab->tab_contents()->render_view_host()->process() |
| 250 == rph) { |
250 closed_initiator_tabs.push_back(initiator_tab); | 251 closed_initiator_tabs.push_back(initiator_tab); |
251 } | 252 } |
252 } | 253 } |
253 | 254 |
254 for (size_t i = 0; i < closed_preview_tabs.size(); ++i) { | 255 for (size_t i = 0; i < closed_preview_tabs.size(); ++i) { |
255 RemovePreviewTab(closed_preview_tabs[i]); | 256 RemovePreviewTab(closed_preview_tabs[i]); |
256 PrintPreviewUI* print_preview_ui = | 257 PrintPreviewUI* print_preview_ui = |
257 static_cast<PrintPreviewUI*>(closed_preview_tabs[i]->web_ui()); | 258 static_cast<PrintPreviewUI*>( |
| 259 closed_preview_tabs[i]->tab_contents()->web_ui()); |
258 if (print_preview_ui) | 260 if (print_preview_ui) |
259 print_preview_ui->OnPrintPreviewTabClosed(); | 261 print_preview_ui->OnPrintPreviewTabClosed(); |
260 } | 262 } |
261 | 263 |
262 for (size_t i = 0; i < closed_initiator_tabs.size(); ++i) | 264 for (size_t i = 0; i < closed_initiator_tabs.size(); ++i) |
263 RemoveInitiatorTab(closed_initiator_tabs[i], false); | 265 RemoveInitiatorTab(closed_initiator_tabs[i], false); |
264 } | 266 } |
265 | 267 |
266 void PrintPreviewTabController::OnTabContentsDestroyed( | 268 void PrintPreviewTabController::OnTabContentsDestroyed( |
267 TabContentsWrapper* tab) { | 269 TabContentsWrapper* tab) { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 | 389 |
388 AddObservers(initiator_tab); | 390 AddObservers(initiator_tab); |
389 AddObservers(preview_tab); | 391 AddObservers(preview_tab); |
390 | 392 |
391 return preview_tab; | 393 return preview_tab; |
392 } | 394 } |
393 | 395 |
394 void PrintPreviewTabController::SetInitiatorTabURLAndTitle( | 396 void PrintPreviewTabController::SetInitiatorTabURLAndTitle( |
395 TabContentsWrapper* preview_tab) { | 397 TabContentsWrapper* preview_tab) { |
396 TabContentsWrapper* initiator_tab = GetInitiatorTab(preview_tab); | 398 TabContentsWrapper* initiator_tab = GetInitiatorTab(preview_tab); |
397 if (initiator_tab && preview_tab->web_ui()) { | 399 if (initiator_tab && preview_tab->tab_contents()->web_ui()) { |
398 PrintPreviewUI* print_preview_ui = | 400 PrintPreviewUI* print_preview_ui = |
399 static_cast<PrintPreviewUI*>(preview_tab->web_ui()); | 401 static_cast<PrintPreviewUI*>(preview_tab->tab_contents()->web_ui()); |
400 print_preview_ui->SetInitiatorTabURLAndTitle( | 402 print_preview_ui->SetInitiatorTabURLAndTitle( |
401 initiator_tab->tab_contents()->GetURL().spec(), | 403 initiator_tab->tab_contents()->GetURL().spec(), |
402 initiator_tab->print_view_manager()->RenderSourceName()); | 404 initiator_tab->print_view_manager()->RenderSourceName()); |
403 } | 405 } |
404 } | 406 } |
405 | 407 |
406 void PrintPreviewTabController::AddObservers(TabContentsWrapper* tab) { | 408 void PrintPreviewTabController::AddObservers(TabContentsWrapper* tab) { |
407 TabContents* contents = tab->tab_contents(); | 409 TabContents* contents = tab->tab_contents(); |
408 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, | 410 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
409 content::Source<TabContents>(contents)); | 411 content::Source<TabContents>(contents)); |
410 registrar_.Add( | 412 registrar_.Add( |
411 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 413 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
412 content::Source<NavigationController>(&contents->controller())); | 414 content::Source<NavigationController>(&contents->controller())); |
413 | 415 |
414 // Multiple sites may share the same RenderProcessHost, so check if this | 416 // Multiple sites may share the same RenderProcessHost, so check if this |
415 // notification has already been added. | 417 // notification has already been added. |
416 content::RenderProcessHost* rph = tab->render_view_host()->process(); | 418 content::RenderProcessHost* rph = |
| 419 tab->tab_contents()->render_view_host()->process(); |
417 if (!registrar_.IsRegistered(this, | 420 if (!registrar_.IsRegistered(this, |
418 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 421 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
419 content::Source<content::RenderProcessHost>( | 422 content::Source<content::RenderProcessHost>( |
420 rph))) { | 423 rph))) { |
421 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 424 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
422 content::Source<content::RenderProcessHost>(rph)); | 425 content::Source<content::RenderProcessHost>(rph)); |
423 } | 426 } |
424 } | 427 } |
425 | 428 |
426 void PrintPreviewTabController::RemoveObservers(TabContentsWrapper* tab) { | 429 void PrintPreviewTabController::RemoveObservers(TabContentsWrapper* tab) { |
427 TabContents* contents = tab->tab_contents(); | 430 TabContents* contents = tab->tab_contents(); |
428 registrar_.Remove(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, | 431 registrar_.Remove(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
429 content::Source<TabContents>(contents)); | 432 content::Source<TabContents>(contents)); |
430 registrar_.Remove( | 433 registrar_.Remove( |
431 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 434 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
432 content::Source<NavigationController>(&contents->controller())); | 435 content::Source<NavigationController>(&contents->controller())); |
433 | 436 |
434 // Multiple sites may share the same RenderProcessHost, so check if this | 437 // Multiple sites may share the same RenderProcessHost, so check if this |
435 // notification has already been added. | 438 // notification has already been added. |
436 content::RenderProcessHost* rph = tab->render_view_host()->process(); | 439 content::RenderProcessHost* rph = |
| 440 tab->tab_contents()->render_view_host()->process(); |
437 if (registrar_.IsRegistered(this, | 441 if (registrar_.IsRegistered(this, |
438 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 442 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
439 content::Source<content::RenderProcessHost>( | 443 content::Source<content::RenderProcessHost>( |
440 rph))) { | 444 rph))) { |
441 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 445 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
442 content::Source<content::RenderProcessHost>(rph)); | 446 content::Source<content::RenderProcessHost>(rph)); |
443 } | 447 } |
444 } | 448 } |
445 | 449 |
446 void PrintPreviewTabController::RemoveInitiatorTab( | 450 void PrintPreviewTabController::RemoveInitiatorTab( |
447 TabContentsWrapper* initiator_tab, bool is_navigation) { | 451 TabContentsWrapper* initiator_tab, bool is_navigation) { |
448 TabContentsWrapper* preview_tab = GetPrintPreviewForTab(initiator_tab); | 452 TabContentsWrapper* preview_tab = GetPrintPreviewForTab(initiator_tab); |
449 DCHECK(preview_tab); | 453 DCHECK(preview_tab); |
450 // Update the map entry first, so when the print preview tab gets destroyed | 454 // Update the map entry first, so when the print preview tab gets destroyed |
451 // and reaches RemovePreviewTab(), it does not attempt to also remove the | 455 // and reaches RemovePreviewTab(), it does not attempt to also remove the |
452 // initiator tab's observers. | 456 // initiator tab's observers. |
453 preview_tab_map_[preview_tab] = NULL; | 457 preview_tab_map_[preview_tab] = NULL; |
454 RemoveObservers(initiator_tab); | 458 RemoveObservers(initiator_tab); |
455 | 459 |
456 // For the navigation case, PrintPreviewDone() has already been called in | 460 // For the navigation case, PrintPreviewDone() has already been called in |
457 // PrintPreviewMessageHandler::NavigateToPendingEntry(). | 461 // PrintPreviewMessageHandler::NavigateToPendingEntry(). |
458 if (!is_navigation) | 462 if (!is_navigation) |
459 initiator_tab->print_view_manager()->PrintPreviewDone(); | 463 initiator_tab->print_view_manager()->PrintPreviewDone(); |
460 | 464 |
461 // Initiator tab is closed. Close the print preview tab too. | 465 // Initiator tab is closed. Close the print preview tab too. |
462 PrintPreviewUI* print_preview_ui = | 466 PrintPreviewUI* print_preview_ui = |
463 static_cast<PrintPreviewUI*>(preview_tab->web_ui()); | 467 static_cast<PrintPreviewUI*>(preview_tab->tab_contents()->web_ui()); |
464 if (print_preview_ui) | 468 if (print_preview_ui) |
465 print_preview_ui->OnInitiatorTabClosed(); | 469 print_preview_ui->OnInitiatorTabClosed(); |
466 } | 470 } |
467 | 471 |
468 void PrintPreviewTabController::RemovePreviewTab( | 472 void PrintPreviewTabController::RemovePreviewTab( |
469 TabContentsWrapper* preview_tab) { | 473 TabContentsWrapper* preview_tab) { |
470 // Remove the initiator tab's observers before erasing the mapping. | 474 // Remove the initiator tab's observers before erasing the mapping. |
471 TabContentsWrapper* initiator_tab = GetInitiatorTab(preview_tab); | 475 TabContentsWrapper* initiator_tab = GetInitiatorTab(preview_tab); |
472 if (initiator_tab) { | 476 if (initiator_tab) { |
473 RemoveObservers(initiator_tab); | 477 RemoveObservers(initiator_tab); |
474 initiator_tab->print_view_manager()->PrintPreviewDone(); | 478 initiator_tab->print_view_manager()->PrintPreviewDone(); |
475 } | 479 } |
476 | 480 |
477 // Print preview TabContents is destroyed. Notify |PrintPreviewUI| to abort | 481 // Print preview TabContents is destroyed. Notify |PrintPreviewUI| to abort |
478 // the initiator tab preview request. | 482 // the initiator tab preview request. |
479 PrintPreviewUI* print_preview_ui = | 483 PrintPreviewUI* print_preview_ui = |
480 static_cast<PrintPreviewUI*>(preview_tab->web_ui()); | 484 static_cast<PrintPreviewUI*>(preview_tab->tab_contents()->web_ui()); |
481 if (print_preview_ui) | 485 if (print_preview_ui) |
482 print_preview_ui->OnTabDestroyed(); | 486 print_preview_ui->OnTabDestroyed(); |
483 | 487 |
484 preview_tab_map_.erase(preview_tab); | 488 preview_tab_map_.erase(preview_tab); |
485 RemoveObservers(preview_tab); | 489 RemoveObservers(preview_tab); |
486 } | 490 } |
487 | 491 |
488 } // namespace printing | 492 } // namespace printing |
OLD | NEW |