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

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

Issue 6783005: Print Preview: Set a print job's title and url correctly. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_view_manager.h" 5 #include "chrome/browser/printing/print_view_manager.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/printing/print_job.h" 10 #include "chrome/browser/printing/print_job.h"
11 #include "chrome/browser/printing/print_job_manager.h" 11 #include "chrome/browser/printing/print_job_manager.h"
12 #include "chrome/browser/printing/print_preview_tab_controller.h"
12 #include "chrome/browser/printing/printer_query.h" 13 #include "chrome/browser/printing/printer_query.h"
14 #include "chrome/browser/ui/webui/print_preview_ui.h"
13 #include "chrome/common/print_messages.h" 15 #include "chrome/common/print_messages.h"
14 #include "content/browser/renderer_host/render_view_host.h" 16 #include "content/browser/renderer_host/render_view_host.h"
15 #include "content/browser/tab_contents/navigation_entry.h" 17 #include "content/browser/tab_contents/navigation_entry.h"
16 #include "content/browser/tab_contents/tab_contents.h" 18 #include "content/browser/tab_contents/tab_contents.h"
17 #include "content/common/notification_details.h" 19 #include "content/common/notification_details.h"
18 #include "content/common/notification_source.h" 20 #include "content/common/notification_source.h"
19 #include "grit/generated_resources.h" 21 #include "grit/generated_resources.h"
20 #include "printing/native_metafile.h" 22 #include "printing/native_metafile.h"
21 #include "printing/native_metafile_factory.h" 23 #include "printing/native_metafile_factory.h"
22 #include "printing/printed_document.h" 24 #include "printing/printed_document.h"
23 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
24 26
25 using base::TimeDelta; 27 using base::TimeDelta;
26 28
29 namespace {
30
31 string16 GenerateRenderSourceName(TabContents* tab_contents) {
32 string16 name(tab_contents->GetTitle());
33 if (name.empty())
34 name = l10n_util::GetStringUTF16(IDS_DEFAULT_PRINT_DOCUMENT_TITLE);
35 return name;
36 }
37
38 } // namespace
39
27 namespace printing { 40 namespace printing {
28 41
29 PrintViewManager::PrintViewManager(TabContents* tab_contents) 42 PrintViewManager::PrintViewManager(TabContents* tab_contents)
30 : TabContentsObserver(tab_contents), 43 : TabContentsObserver(tab_contents),
31 number_pages_(0), 44 number_pages_(0),
32 waiting_to_print_(false), 45 waiting_to_print_(false),
33 printing_succeeded_(false), 46 printing_succeeded_(false),
34 inside_inner_message_loop_(false) { 47 inside_inner_message_loop_(false),
48 is_title_overridden_(false) {
35 #if defined(OS_POSIX) && !defined(OS_MACOSX) 49 #if defined(OS_POSIX) && !defined(OS_MACOSX)
36 expecting_first_page_ = true; 50 expecting_first_page_ = true;
37 #endif 51 #endif
38 } 52 }
39 53
40 PrintViewManager::~PrintViewManager() { 54 PrintViewManager::~PrintViewManager() {
41 DisconnectFromCurrentPrintJob(); 55 DisconnectFromCurrentPrintJob();
42 } 56 }
43 57
44 void PrintViewManager::StopNavigation() { 58 void PrintViewManager::StopNavigation() {
45 // Cancel the current job, wait for the worker to finish. 59 // Cancel the current job, wait for the worker to finish.
46 TerminatePrintJob(true); 60 TerminatePrintJob(true);
47 } 61 }
48 62
49 void PrintViewManager::RenderViewGone() { 63 void PrintViewManager::RenderViewGone() {
50 if (!print_job_.get()) 64 if (!print_job_.get())
51 return; 65 return;
52 66
53 scoped_refptr<PrintedDocument> document(print_job_->document()); 67 scoped_refptr<PrintedDocument> document(print_job_->document());
54 if (document) { 68 if (document) {
55 // If IsComplete() returns false, the document isn't completely rendered. 69 // If IsComplete() returns false, the document isn't completely rendered.
56 // Since our renderer is gone, there's nothing to do, cancel it. Otherwise, 70 // Since our renderer is gone, there's nothing to do, cancel it. Otherwise,
57 // the print job may finish without problem. 71 // the print job may finish without problem.
58 TerminatePrintJob(!document->IsComplete()); 72 TerminatePrintJob(!document->IsComplete());
59 } 73 }
60 } 74 }
61 75
76 void PrintViewManager::OverrideTitle(TabContents* tab_contents) {
77 is_title_overridden_ = true;
78 overridden_title_ = GenerateRenderSourceName(tab_contents);
79 }
80
62 string16 PrintViewManager::RenderSourceName() { 81 string16 PrintViewManager::RenderSourceName() {
63 string16 name(tab_contents()->GetTitle()); 82 if (is_title_overridden_)
64 if (name.empty()) 83 return overridden_title_;
65 name = l10n_util::GetStringUTF16(IDS_DEFAULT_PRINT_DOCUMENT_TITLE); 84 return GenerateRenderSourceName(tab_contents());
66 return name;
67 } 85 }
68 86
69 GURL PrintViewManager::RenderSourceUrl() { 87 GURL PrintViewManager::RenderSourceUrl() {
70 NavigationEntry* entry = tab_contents()->controller().GetActiveEntry(); 88 NavigationEntry* entry = tab_contents()->controller().GetActiveEntry();
71 if (entry) 89 if (entry)
72 return entry->virtual_url(); 90 return entry->virtual_url();
73 else 91 return GURL();
74 return GURL();
75 } 92 }
76 93
77 void PrintViewManager::OnDidGetPrintedPagesCount(int cookie, int number_pages) { 94 void PrintViewManager::OnDidGetPrintedPagesCount(int cookie, int number_pages) {
78 DCHECK_GT(cookie, 0); 95 DCHECK_GT(cookie, 0);
79 DCHECK_GT(number_pages, 0); 96 DCHECK_GT(number_pages, 0);
80 number_pages_ = number_pages; 97 number_pages_ = number_pages;
81 if (!OpportunisticallyCreatePrintJob(cookie)) 98 if (!OpportunisticallyCreatePrintJob(cookie))
82 return; 99 return;
83 100
84 PrintedDocument* document = print_job_->document(); 101 PrintedDocument* document = print_job_->document();
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 return false; 448 return false;
432 } 449 }
433 450
434 // Settings are already loaded. Go ahead. This will set 451 // Settings are already loaded. Go ahead. This will set
435 // print_job_->is_job_pending() to true. 452 // print_job_->is_job_pending() to true.
436 print_job_->StartPrinting(); 453 print_job_->StartPrinting();
437 return true; 454 return true;
438 } 455 }
439 456
440 } // namespace printing 457 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698