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

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: Mark histogram entries as unused 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 print_view_manager->PrintPreviewDone(); 172 print_view_manager->PrintPreviewDone();
173 } 173 }
174 } 174 }
175 175
176 WebContents* PrintPreviewDialogController::GetOrCreatePreviewDialog( 176 WebContents* PrintPreviewDialogController::GetOrCreatePreviewDialog(
177 WebContents* initiator) { 177 WebContents* initiator) {
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.
184 initiator->GetDelegate()->ActivateContents(initiator);
185 return preview_dialog;
186 }
187
188 // We should only create a dialog if the initiator has not been proxied.
189 if (GetProxyDialogTarget(initiator) == initiator)
190 return CreatePrintPreviewDialog(initiator); 183 return CreatePrintPreviewDialog(initiator);
191 184
192 return nullptr; 185 // Show the initiator holding the existing preview dialog.
186 initiator->GetDelegate()->ActivateContents(initiator);
187 return preview_dialog;
193 } 188 }
194 189
195 WebContents* PrintPreviewDialogController::GetPrintPreviewForContents( 190 WebContents* PrintPreviewDialogController::GetPrintPreviewForContents(
196 WebContents* contents) const { 191 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() 192 // |preview_dialog_map_| is keyed by the preview dialog, so if find()
202 // succeeds, then |contents| is the preview dialog. 193 // succeeds, then |contents| is the preview dialog.
203 PrintPreviewDialogMap::const_iterator it = preview_dialog_map_.find(contents); 194 PrintPreviewDialogMap::const_iterator it = preview_dialog_map_.find(contents);
204 if (it != preview_dialog_map_.end()) 195 if (it != preview_dialog_map_.end())
205 return contents; 196 return contents;
206 197
207 for (it = preview_dialog_map_.begin(); 198 for (it = preview_dialog_map_.begin();
208 it != preview_dialog_map_.end(); 199 it != preview_dialog_map_.end();
209 ++it) { 200 ++it) {
210 // If |contents| is an initiator. 201 // If |contents| is an initiator.
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 379
389 // Make the print preview WebContents show up in the task manager. 380 // Make the print preview WebContents show up in the task manager.
390 task_management::WebContentsTags::CreateForPrintingContents(preview_dialog); 381 task_management::WebContentsTags::CreateForPrintingContents(preview_dialog);
391 382
392 AddObservers(initiator); 383 AddObservers(initiator);
393 AddObservers(preview_dialog); 384 AddObservers(preview_dialog);
394 385
395 return preview_dialog; 386 return preview_dialog;
396 } 387 }
397 388
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( 389 void PrintPreviewDialogController::SaveInitiatorTitle(
417 WebContents* preview_dialog) { 390 WebContents* preview_dialog) {
418 WebContents* initiator = GetInitiator(preview_dialog); 391 WebContents* initiator = GetInitiator(preview_dialog);
419 if (initiator && preview_dialog->GetWebUI()) { 392 if (initiator && preview_dialog->GetWebUI()) {
420 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( 393 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
421 preview_dialog->GetWebUI()->GetController()); 394 preview_dialog->GetWebUI()->GetController());
422 print_preview_ui->SetInitiatorTitle( 395 print_preview_ui->SetInitiatorTitle(
423 PrintViewManager::FromWebContents(initiator)->RenderSourceName()); 396 PrintViewManager::FromWebContents(initiator)->RenderSourceName());
424 } 397 }
425 } 398 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 if (initiator) { 459 if (initiator) {
487 RemoveObservers(initiator); 460 RemoveObservers(initiator);
488 PrintViewManager::FromWebContents(initiator)->PrintPreviewDone(); 461 PrintViewManager::FromWebContents(initiator)->PrintPreviewDone();
489 } 462 }
490 463
491 preview_dialog_map_.erase(preview_dialog); 464 preview_dialog_map_.erase(preview_dialog);
492 RemoveObservers(preview_dialog); 465 RemoveObservers(preview_dialog);
493 } 466 }
494 467
495 } // namespace printing 468 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698