Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(295)

Side by Side Diff: chrome/browser/printing/print_preview_dialog_controller.cc

Issue 2108833002: Remove Simplify Page option from Print Preview (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: less and more Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <string> 10 #include <string>
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 DCHECK(initiator); 178 DCHECK(initiator);
179 179
180 // Get the print preview dialog for |initiator|. 180 // Get the print preview dialog for |initiator|.
181 WebContents* preview_dialog = GetPrintPreviewForContents(initiator); 181 WebContents* preview_dialog = GetPrintPreviewForContents(initiator);
182 if (preview_dialog) { 182 if (preview_dialog) {
183 // Show the initiator holding the existing preview dialog. 183 // Show the initiator holding the existing preview dialog.
184 initiator->GetDelegate()->ActivateContents(initiator); 184 initiator->GetDelegate()->ActivateContents(initiator);
185 return preview_dialog; 185 return preview_dialog;
186 } 186 }
187 187
188 // We should only create a dialog if the initiator has not been proxied.
189 if (GetProxyDialogTarget(initiator) == initiator)
190 return CreatePrintPreviewDialog(initiator);
191
192 return nullptr; 188 return nullptr;
193 } 189 }
194 190
195 WebContents* PrintPreviewDialogController::GetPrintPreviewForContents( 191 WebContents* PrintPreviewDialogController::GetPrintPreviewForContents(
196 WebContents* contents) const { 192 WebContents* contents) const {
197 // If this WebContents relies on another for its preview dialog, we
198 // need to act as if we are looking for the proxied content's dialog.
199 contents = GetProxyDialogTarget(contents);
200
201 // |preview_dialog_map_| is keyed by the preview dialog, so if find() 193 // |preview_dialog_map_| is keyed by the preview dialog, so if find()
202 // succeeds, then |contents| is the preview dialog. 194 // succeeds, then |contents| is the preview dialog.
203 PrintPreviewDialogMap::const_iterator it = preview_dialog_map_.find(contents); 195 PrintPreviewDialogMap::const_iterator it = preview_dialog_map_.find(contents);
204 if (it != preview_dialog_map_.end()) 196 if (it != preview_dialog_map_.end())
205 return contents; 197 return contents;
206 198
207 for (it = preview_dialog_map_.begin(); 199 for (it = preview_dialog_map_.begin();
208 it != preview_dialog_map_.end(); 200 it != preview_dialog_map_.end();
209 ++it) { 201 ++it) {
210 // If |contents| is an initiator. 202 // If |contents| is an initiator.
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 380
389 // Make the print preview WebContents show up in the task manager. 381 // Make the print preview WebContents show up in the task manager.
390 task_management::WebContentsTags::CreateForPrintingContents(preview_dialog); 382 task_management::WebContentsTags::CreateForPrintingContents(preview_dialog);
391 383
392 AddObservers(initiator); 384 AddObservers(initiator);
393 AddObservers(preview_dialog); 385 AddObservers(preview_dialog);
394 386
395 return preview_dialog; 387 return preview_dialog;
396 } 388 }
397 389
398 void PrintPreviewDialogController::AddProxyDialogForWebContents(
399 WebContents* source,
400 WebContents* target) {
401 proxied_dialog_map_[source] = target;
402 }
403
404 void PrintPreviewDialogController::RemoveProxyDialogForWebContents(
405 WebContents* source) {
406 proxied_dialog_map_.erase(source);
407 }
408
409 WebContents* PrintPreviewDialogController::GetProxyDialogTarget(
410 WebContents* source) const {
411 PrintPreviewDialogMap::const_iterator proxied =
412 proxied_dialog_map_.find(source);
413 return proxied == proxied_dialog_map_.end() ? source : proxied->second;
414 }
415
416 void PrintPreviewDialogController::SaveInitiatorTitle( 390 void PrintPreviewDialogController::SaveInitiatorTitle(
417 WebContents* preview_dialog) { 391 WebContents* preview_dialog) {
418 WebContents* initiator = GetInitiator(preview_dialog); 392 WebContents* initiator = GetInitiator(preview_dialog);
419 if (initiator && preview_dialog->GetWebUI()) { 393 if (initiator && preview_dialog->GetWebUI()) {
420 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( 394 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
421 preview_dialog->GetWebUI()->GetController()); 395 preview_dialog->GetWebUI()->GetController());
422 print_preview_ui->SetInitiatorTitle( 396 print_preview_ui->SetInitiatorTitle(
423 PrintViewManager::FromWebContents(initiator)->RenderSourceName()); 397 PrintViewManager::FromWebContents(initiator)->RenderSourceName());
424 } 398 }
425 } 399 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 if (initiator) { 460 if (initiator) {
487 RemoveObservers(initiator); 461 RemoveObservers(initiator);
488 PrintViewManager::FromWebContents(initiator)->PrintPreviewDone(); 462 PrintViewManager::FromWebContents(initiator)->PrintPreviewDone();
489 } 463 }
490 464
491 preview_dialog_map_.erase(preview_dialog); 465 preview_dialog_map_.erase(preview_dialog);
492 RemoveObservers(preview_dialog); 466 RemoveObservers(preview_dialog);
493 } 467 }
494 468
495 } // namespace printing 469 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698