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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 if (!preview_dialog) | 176 if (!preview_dialog) |
177 return CreatePrintPreviewDialog(initiator); | 177 return CreatePrintPreviewDialog(initiator); |
178 | 178 |
179 // Show the initiator holding the existing preview dialog. | 179 // Show the initiator holding the existing preview dialog. |
180 initiator->GetDelegate()->ActivateContents(initiator); | 180 initiator->GetDelegate()->ActivateContents(initiator); |
181 return preview_dialog; | 181 return preview_dialog; |
182 } | 182 } |
183 | 183 |
184 WebContents* PrintPreviewDialogController::GetPrintPreviewForContents( | 184 WebContents* PrintPreviewDialogController::GetPrintPreviewForContents( |
185 WebContents* contents) const { | 185 WebContents* contents) const { |
186 // If this WebContents relies on another for its preview dialog, we | 186 // If this WebContents relies on another for its preview dialog, look for the |
187 // need to act as if we are looking for the proxied content's dialog. | 187 // original initiator. |
188 PrintPreviewDialogMap::const_iterator proxied = | 188 DistilledContentsMap::const_iterator proxied = |
189 proxied_dialog_map_.find(contents); | 189 proxied_dialog_map_.find(contents); |
190 if (proxied != proxied_dialog_map_.end()) { | 190 if (proxied != proxied_dialog_map_.end()) { |
191 contents = proxied->second; | 191 contents = proxied->second; |
192 } | 192 } |
193 | 193 |
194 // |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() |
195 // succeeds, then |contents| is the preview dialog. | 195 // succeeds, then |contents| is the preview dialog. |
196 PrintPreviewDialogMap::const_iterator it = preview_dialog_map_.find(contents); | 196 PrintPreviewDialogMap::const_iterator it = preview_dialog_map_.find(contents); |
197 if (it != preview_dialog_map_.end()) | 197 if (it != preview_dialog_map_.end()) |
198 return contents; | 198 return contents; |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 // Make the print preview WebContents show up in the task manager. | 380 // Make the print preview WebContents show up in the task manager. |
381 task_management::WebContentsTags::CreateForPrintingContents(preview_dialog); | 381 task_management::WebContentsTags::CreateForPrintingContents(preview_dialog); |
382 | 382 |
383 AddObservers(initiator); | 383 AddObservers(initiator); |
384 AddObservers(preview_dialog); | 384 AddObservers(preview_dialog); |
385 | 385 |
386 return preview_dialog; | 386 return preview_dialog; |
387 } | 387 } |
388 | 388 |
389 void PrintPreviewDialogController::AddProxyDialogForWebContents( | 389 void PrintPreviewDialogController::AddProxyDialogForWebContents( |
390 WebContents* source, | 390 WebContents* distilled_contents, |
391 WebContents* target) { | 391 WebContents* initiator) { |
392 proxied_dialog_map_[source] = target; | 392 DCHECK(!ContainsKey(proxied_dialog_map_, distilled_contents)); |
| 393 proxied_dialog_map_[distilled_contents] = initiator; |
393 } | 394 } |
394 | 395 |
395 void PrintPreviewDialogController::RemoveProxyDialogForWebContents( | 396 void PrintPreviewDialogController::RemoveProxyDialogForWebContents( |
396 WebContents* source) { | 397 WebContents* distilled_contents) { |
397 proxied_dialog_map_.erase(source); | 398 size_t erased = proxied_dialog_map_.erase(distilled_contents); |
| 399 DCHECK_EQ(1U, erased); |
398 } | 400 } |
399 | 401 |
400 void PrintPreviewDialogController::SaveInitiatorTitle( | 402 void PrintPreviewDialogController::SaveInitiatorTitle( |
401 WebContents* preview_dialog) { | 403 WebContents* preview_dialog) { |
402 WebContents* initiator = GetInitiator(preview_dialog); | 404 WebContents* initiator = GetInitiator(preview_dialog); |
403 if (initiator && preview_dialog->GetWebUI()) { | 405 if (initiator && preview_dialog->GetWebUI()) { |
404 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 406 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
405 preview_dialog->GetWebUI()->GetController()); | 407 preview_dialog->GetWebUI()->GetController()); |
406 print_preview_ui->SetInitiatorTitle( | 408 print_preview_ui->SetInitiatorTitle( |
407 PrintViewManager::FromWebContents(initiator)->RenderSourceName()); | 409 PrintViewManager::FromWebContents(initiator)->RenderSourceName()); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 static_cast<PrintPreviewUI*>(web_ui->GetController()); | 481 static_cast<PrintPreviewUI*>(web_ui->GetController()); |
480 if (print_preview_ui) | 482 if (print_preview_ui) |
481 print_preview_ui->OnPrintPreviewDialogDestroyed(); | 483 print_preview_ui->OnPrintPreviewDialogDestroyed(); |
482 } | 484 } |
483 | 485 |
484 preview_dialog_map_.erase(preview_dialog); | 486 preview_dialog_map_.erase(preview_dialog); |
485 RemoveObservers(preview_dialog); | 487 RemoveObservers(preview_dialog); |
486 } | 488 } |
487 | 489 |
488 } // namespace printing | 490 } // namespace printing |
OLD | NEW |