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

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

Issue 2566153007: Implement PrintBrowser functionality. (Closed)
Patch Set: Fix git weirdness Created 4 years 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>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/auto_reset.h" 13 #include "base/auto_reset.h"
14 #include "base/command_line.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "base/path_service.h" 16 #include "base/path_service.h"
16 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
17 #include "build/build_config.h" 18 #include "build/build_config.h"
18 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/chrome_notification_types.h" 20 #include "chrome/browser/chrome_notification_types.h"
20 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" 21 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
21 #include "chrome/browser/printing/print_view_manager.h" 22 #include "chrome/browser/printing/print_view_manager.h"
22 #include "chrome/browser/task_manager/web_contents_tags.h" 23 #include "chrome/browser/task_manager/web_contents_tags.h"
23 #include "chrome/browser/ui/browser.h" 24 #include "chrome/browser/ui/browser.h"
25 #include "chrome/browser/ui/browser_commands.h"
24 #include "chrome/browser/ui/browser_finder.h" 26 #include "chrome/browser/ui/browser_finder.h"
27 #include "chrome/browser/ui/browser_list.h"
28 #include "chrome/browser/ui/browser_navigator.h"
25 #include "chrome/browser/ui/browser_window.h" 29 #include "chrome/browser/ui/browser_window.h"
30 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
26 #include "chrome/browser/ui/webui/chrome_web_contents_handler.h" 31 #include "chrome/browser/ui/webui/chrome_web_contents_handler.h"
27 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" 32 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"
28 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" 33 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
29 #include "chrome/common/chrome_paths.h" 34 #include "chrome/common/chrome_paths.h"
35 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/url_constants.h" 36 #include "chrome/common/url_constants.h"
31 #include "components/guest_view/browser/guest_view_base.h" 37 #include "components/guest_view/browser/guest_view_base.h"
32 #include "components/web_modal/web_contents_modal_dialog_host.h" 38 #include "components/web_modal/web_contents_modal_dialog_host.h"
33 #include "content/public/browser/host_zoom_map.h" 39 #include "content/public/browser/host_zoom_map.h"
34 #include "content/public/browser/navigation_controller.h" 40 #include "content/public/browser/navigation_controller.h"
35 #include "content/public/browser/navigation_details.h" 41 #include "content/public/browser/navigation_details.h"
36 #include "content/public/browser/navigation_entry.h" 42 #include "content/public/browser/navigation_entry.h"
37 #include "content/public/browser/notification_details.h" 43 #include "content/public/browser/notification_details.h"
38 #include "content/public/browser/notification_source.h" 44 #include "content/public/browser/notification_source.h"
39 #include "content/public/browser/web_contents.h" 45 #include "content/public/browser/web_contents.h"
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 342
337 // Cloud print sign-in causes a reload. 343 // Cloud print sign-in causes a reload.
338 if (!waiting_for_new_preview_page_ && 344 if (!waiting_for_new_preview_page_ &&
339 ui::PageTransitionCoreTypeIs(transition_type, 345 ui::PageTransitionCoreTypeIs(transition_type,
340 ui::PAGE_TRANSITION_RELOAD) && 346 ui::PAGE_TRANSITION_RELOAD) &&
341 nav_type == content::NAVIGATION_TYPE_EXISTING_PAGE && 347 nav_type == content::NAVIGATION_TYPE_EXISTING_PAGE &&
342 IsPrintPreviewURL(details->previous_url)) { 348 IsPrintPreviewURL(details->previous_url)) {
343 return; 349 return;
344 } 350 }
345 } 351 }
352 #if BUILDFLAG(ENABLE_PRINT_BROWSER)
353 // If in PrintBrowser mode, navigation away from the print UI is fine
354 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
355 bool print_browser_enabled =
356 command_line->HasSwitch(switches::kEnablePrintBrowser);
357 if (print_browser_enabled)
358 return;
359 #endif
346 NOTREACHED(); 360 NOTREACHED();
347 return; 361 return;
348 } 362 }
349 if (details) { 363 if (details) {
350 ui::PageTransition type = details->entry->GetTransitionType(); 364 ui::PageTransition type = details->entry->GetTransitionType();
351 content::NavigationType nav_type = details->type; 365 content::NavigationType nav_type = details->type;
352 if (nav_type == content::NAVIGATION_TYPE_EXISTING_PAGE && 366 if (nav_type == content::NAVIGATION_TYPE_EXISTING_PAGE &&
353 (ui::PageTransitionTypeIncludingQualifiersIs( 367 (ui::PageTransitionTypeIncludingQualifiersIs(
354 type, 368 type,
355 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | 369 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED |
356 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR)) || 370 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR)) ||
357 ui::PageTransitionTypeIncludingQualifiersIs(type, 371 ui::PageTransitionTypeIncludingQualifiersIs(type,
358 ui::PAGE_TRANSITION_LINK))) 372 ui::PAGE_TRANSITION_LINK)))
359 return; 373 return;
360 } 374 }
361 375
362 RemoveInitiator(contents); 376 RemoveInitiator(contents);
363 } 377 }
364 378
365 WebContents* PrintPreviewDialogController::CreatePrintPreviewDialog( 379 WebContents* PrintPreviewDialogController::CreatePrintPreviewDialog(
366 WebContents* initiator) { 380 WebContents* initiator) {
367 base::AutoReset<bool> auto_reset(&is_creating_print_preview_dialog_, true); 381 base::AutoReset<bool> auto_reset(&is_creating_print_preview_dialog_, true);
368 382
369 // The dialog delegates are deleted when the dialog is closed. 383 WebContents* preview_dialog;
370 ConstrainedWebDialogDelegate* web_dialog_delegate =
371 ShowConstrainedWebDialog(initiator->GetBrowserContext(),
372 new PrintPreviewDialogDelegate(initiator),
373 initiator);
374 384
375 WebContents* preview_dialog = web_dialog_delegate->GetWebContents(); 385 #if BUILDFLAG(ENABLE_PRINT_BROWSER)
386 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
387 bool print_browser_enabled =
388 command_line->HasSwitch(switches::kEnablePrintBrowser);
389 if (!print_browser_enabled) {
390 #endif
391 // The dialog delegates are deleted when the dialog is closed.
392 ConstrainedWebDialogDelegate* web_dialog_delegate =
393 ShowConstrainedWebDialog(initiator->GetBrowserContext(),
394 new PrintPreviewDialogDelegate(initiator),
395 initiator);
396
397 preview_dialog = web_dialog_delegate->GetWebContents();
398 #if BUILDFLAG(ENABLE_PRINT_BROWSER)
399 } else {
400 // If in PrintBrowser mode, swap |initiator| with a newly-created
401 // |preview_dialog| and navigate |preview_dialog| to the print UI
402 Browser* browser =
403 chrome::FindBrowserWithWindow(initiator->GetTopLevelNativeWindow());
404 preview_dialog =
405 WebContents::Create(WebContents::CreateParams(browser->profile()));
406 CoreTabHelper::FromWebContents(initiator)->delegate()->SwapTabContents(
rbpotter 2016/12/16 20:05:28 I think you need to ensure the initiator web conte
407 initiator, preview_dialog, false, false);
408 browser->OpenURL(content::OpenURLParams(
409 GURL(chrome::kChromeUIPrintURL), content::Referrer(),
410 WindowOpenDisposition::CURRENT_TAB, ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
411 false));
412 }
413 #endif
376 414
377 // Clear the zoom level for the print preview dialog so it isn't affected by 415 // Clear the zoom level for the print preview dialog so it isn't affected by
378 // the default zoom level. This also controls the zoom level of the OOP PDF 416 // the default zoom level. This also controls the zoom level of the OOP PDF
379 // extension when iframed by the print preview dialog. 417 // extension when iframed by the print preview dialog.
380 GURL print_url(chrome::kChromeUIPrintURL); 418 GURL print_url(chrome::kChromeUIPrintURL);
381 content::HostZoomMap::Get(preview_dialog->GetSiteInstance()) 419 content::HostZoomMap::Get(preview_dialog->GetSiteInstance())
382 ->SetZoomLevelForHostAndScheme(print_url.scheme(), print_url.host(), 0); 420 ->SetZoomLevelForHostAndScheme(print_url.scheme(), print_url.host(), 0);
383 PrintViewManager::CreateForWebContents(preview_dialog); 421 PrintViewManager::CreateForWebContents(preview_dialog);
384 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( 422 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
385 preview_dialog); 423 preview_dialog);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 if (initiator) { 525 if (initiator) {
488 RemoveObservers(initiator); 526 RemoveObservers(initiator);
489 PrintViewManager::FromWebContents(initiator)->PrintPreviewDone(); 527 PrintViewManager::FromWebContents(initiator)->PrintPreviewDone();
490 } 528 }
491 529
492 preview_dialog_map_.erase(preview_dialog); 530 preview_dialog_map_.erase(preview_dialog);
493 RemoveObservers(preview_dialog); 531 RemoveObservers(preview_dialog);
494 } 532 }
495 533
496 } // namespace printing 534 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698