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