OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_dialog_controller.h" | 5 #include "chrome/browser/printing/print_preview_dialog_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 if (!preview_dialog) | 175 if (!preview_dialog) |
176 return CreatePrintPreviewDialog(initiator); | 176 return CreatePrintPreviewDialog(initiator); |
177 | 177 |
178 // Show the initiator holding the existing preview dialog. | 178 // Show the initiator holding the existing preview dialog. |
179 initiator->GetDelegate()->ActivateContents(initiator); | 179 initiator->GetDelegate()->ActivateContents(initiator); |
180 return preview_dialog; | 180 return preview_dialog; |
181 } | 181 } |
182 | 182 |
183 WebContents* PrintPreviewDialogController::GetPrintPreviewForContents( | 183 WebContents* PrintPreviewDialogController::GetPrintPreviewForContents( |
184 WebContents* contents) const { | 184 WebContents* contents) const { |
| 185 |
| 186 // If this WebContents relies on another for its preview dialog, we |
| 187 // need to act as if we are looking for the proxied content's dialog. |
| 188 PrintPreviewDialogMap::const_iterator proxied = |
| 189 proxied_dialog_map_.find(contents); |
| 190 if (proxied != proxied_dialog_map_.end()) { |
| 191 contents = const_cast<WebContents*>(proxied->second); |
| 192 } |
| 193 |
185 // |preview_dialog_map_| is keyed by the preview dialog, so if find() | 194 // |preview_dialog_map_| is keyed by the preview dialog, so if find() |
186 // succeeds, then |contents| is the preview dialog. | 195 // succeeds, then |contents| is the preview dialog. |
187 PrintPreviewDialogMap::const_iterator it = preview_dialog_map_.find(contents); | 196 PrintPreviewDialogMap::const_iterator it = preview_dialog_map_.find(contents); |
188 if (it != preview_dialog_map_.end()) | 197 if (it != preview_dialog_map_.end()) |
189 return contents; | 198 return contents; |
190 | 199 |
191 for (it = preview_dialog_map_.begin(); | 200 for (it = preview_dialog_map_.begin(); |
192 it != preview_dialog_map_.end(); | 201 it != preview_dialog_map_.end(); |
193 ++it) { | 202 ++it) { |
194 // If |contents| is an initiator. | 203 // If |contents| is an initiator. |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 // Add an entry to the map. | 376 // Add an entry to the map. |
368 preview_dialog_map_[preview_dialog] = initiator; | 377 preview_dialog_map_[preview_dialog] = initiator; |
369 waiting_for_new_preview_page_ = true; | 378 waiting_for_new_preview_page_ = true; |
370 | 379 |
371 AddObservers(initiator); | 380 AddObservers(initiator); |
372 AddObservers(preview_dialog); | 381 AddObservers(preview_dialog); |
373 | 382 |
374 return preview_dialog; | 383 return preview_dialog; |
375 } | 384 } |
376 | 385 |
| 386 void PrintPreviewDialogController::AddProxyDialogForWebContents( |
| 387 WebContents* source, WebContents* target) { |
| 388 proxied_dialog_map_[source] = target; |
| 389 } |
| 390 |
| 391 void PrintPreviewDialogController::RemoveProxyDialogForWebContents( |
| 392 WebContents* source) { |
| 393 proxied_dialog_map_.erase(source); |
| 394 } |
| 395 |
377 void PrintPreviewDialogController::SaveInitiatorTitle( | 396 void PrintPreviewDialogController::SaveInitiatorTitle( |
378 WebContents* preview_dialog) { | 397 WebContents* preview_dialog) { |
379 WebContents* initiator = GetInitiator(preview_dialog); | 398 WebContents* initiator = GetInitiator(preview_dialog); |
380 if (initiator && preview_dialog->GetWebUI()) { | 399 if (initiator && preview_dialog->GetWebUI()) { |
381 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 400 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
382 preview_dialog->GetWebUI()->GetController()); | 401 preview_dialog->GetWebUI()->GetController()); |
383 print_preview_ui->SetInitiatorTitle( | 402 print_preview_ui->SetInitiatorTitle( |
384 PrintViewManager::FromWebContents(initiator)->RenderSourceName()); | 403 PrintViewManager::FromWebContents(initiator)->RenderSourceName()); |
385 } | 404 } |
386 } | 405 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 static_cast<PrintPreviewUI*>(web_ui->GetController()); | 475 static_cast<PrintPreviewUI*>(web_ui->GetController()); |
457 if (print_preview_ui) | 476 if (print_preview_ui) |
458 print_preview_ui->OnPrintPreviewDialogDestroyed(); | 477 print_preview_ui->OnPrintPreviewDialogDestroyed(); |
459 } | 478 } |
460 | 479 |
461 preview_dialog_map_.erase(preview_dialog); | 480 preview_dialog_map_.erase(preview_dialog); |
462 RemoveObservers(preview_dialog); | 481 RemoveObservers(preview_dialog); |
463 } | 482 } |
464 | 483 |
465 } // namespace printing | 484 } // namespace printing |
OLD | NEW |