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

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

Issue 740983002: Implement window.print() on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: typos, sorry Created 6 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_job_worker.h" 5 #include "chrome/browser/printing/print_job_worker.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/values.h" 12 #include "base/values.h"
13
14 #if defined(OS_ANDROID)
15 #include "chrome/browser/android/tab_android.h"
16 #endif
17
13 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/chrome_notification_types.h" 19 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/printing/print_job.h" 20 #include "chrome/browser/printing/print_job.h"
16 #include "chrome/grit/generated_resources.h" 21 #include "chrome/grit/generated_resources.h"
17 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/notification_service.h" 23 #include "content/public/browser/notification_service.h"
19 #include "content/public/browser/render_view_host.h" 24 #include "content/public/browser/render_view_host.h"
20 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
21 #include "printing/print_job_constants.h" 26 #include "printing/print_job_constants.h"
22 #include "printing/printed_document.h" 27 #include "printing/printed_document.h"
(...skipping 14 matching lines...) Expand all
37 } 42 }
38 43
39 class PrintingContextDelegate : public PrintingContext::Delegate { 44 class PrintingContextDelegate : public PrintingContext::Delegate {
40 public: 45 public:
41 PrintingContextDelegate(int render_process_id, int render_view_id); 46 PrintingContextDelegate(int render_process_id, int render_view_id);
42 ~PrintingContextDelegate() override; 47 ~PrintingContextDelegate() override;
43 48
44 gfx::NativeView GetParentView() override; 49 gfx::NativeView GetParentView() override;
45 std::string GetAppLocale() override; 50 std::string GetAppLocale() override;
46 51
52 void SetPendingPrint() override;
53
47 private: 54 private:
48 int render_process_id_; 55 int render_process_id_;
49 int render_view_id_; 56 int render_view_id_;
50 }; 57 };
51 58
52 PrintingContextDelegate::PrintingContextDelegate(int render_process_id, 59 PrintingContextDelegate::PrintingContextDelegate(int render_process_id,
53 int render_view_id) 60 int render_view_id)
54 : render_process_id_(render_process_id), 61 : render_process_id_(render_process_id),
55 render_view_id_(render_view_id) { 62 render_view_id_(render_view_id) {
56 } 63 }
57 64
58 PrintingContextDelegate::~PrintingContextDelegate() { 65 PrintingContextDelegate::~PrintingContextDelegate() {
59 } 66 }
60 67
61 gfx::NativeView PrintingContextDelegate::GetParentView() { 68 gfx::NativeView PrintingContextDelegate::GetParentView() {
62 DCHECK_CURRENTLY_ON(BrowserThread::UI); 69 DCHECK_CURRENTLY_ON(BrowserThread::UI);
63 content::RenderViewHost* view = 70 content::RenderViewHost* view =
64 content::RenderViewHost::FromID(render_process_id_, render_view_id_); 71 content::RenderViewHost::FromID(render_process_id_, render_view_id_);
65 if (!view) 72 if (!view)
66 return NULL; 73 return NULL;
67 content::WebContents* wc = content::WebContents::FromRenderViewHost(view); 74 content::WebContents* wc = content::WebContents::FromRenderViewHost(view);
68 return wc ? wc->GetNativeView() : NULL; 75 return wc ? wc->GetNativeView() : NULL;
69 } 76 }
70 77
71 std::string PrintingContextDelegate::GetAppLocale() { 78 std::string PrintingContextDelegate::GetAppLocale() {
72 return g_browser_process->GetApplicationLocale(); 79 return g_browser_process->GetApplicationLocale();
73 } 80 }
74 81
82 void PrintingContextDelegate::SetPendingPrint() {
83 LOG(INFO) << "DGN PrintingContextDelegate::SetPendingPrint";
84 #if defined(OS_ANDROID)
85 // Tab (Printable) needed to print. How to call it without the tab directly?
86 // Removing the dependency on chrome would make it easier to move it to
87 // printing_context_android
88 content::RenderViewHost* view = content::RenderViewHost::FromID(
89 render_process_id_, render_view_id_);
90 DCHECK(view);
91 content::WebContents* wc = content::WebContents::FromRenderViewHost(view);
92 TabAndroid* tab = TabAndroid::FromWebContents(wc);
93 if (tab) tab->SetPendingPrint();
94 #endif
95 }
96
97
75 void NotificationCallback(PrintJobWorkerOwner* print_job, 98 void NotificationCallback(PrintJobWorkerOwner* print_job,
76 JobEventDetails::Type detail_type, 99 JobEventDetails::Type detail_type,
77 PrintedDocument* document, 100 PrintedDocument* document,
78 PrintedPage* page) { 101 PrintedPage* page) {
79 JobEventDetails* details = new JobEventDetails(detail_type, document, page); 102 JobEventDetails* details = new JobEventDetails(detail_type, document, page);
80 content::NotificationService::current()->Notify( 103 content::NotificationService::current()->Notify(
81 chrome::NOTIFICATION_PRINT_JOB_EVENT, 104 chrome::NOTIFICATION_PRINT_JOB_EVENT,
82 // We know that is is a PrintJob object in this circumstance. 105 // We know that is is a PrintJob object in this circumstance.
83 content::Source<PrintJob>(static_cast<PrintJob*>(print_job)), 106 content::Source<PrintJob>(static_cast<PrintJob*>(print_job)),
84 content::Details<JobEventDetails>(details)); 107 content::Details<JobEventDetails>(details));
(...skipping 20 matching lines...) Expand all
105 DCHECK(owner_->RunsTasksOnCurrentThread()); 128 DCHECK(owner_->RunsTasksOnCurrentThread());
106 Stop(); 129 Stop();
107 } 130 }
108 131
109 void PrintJobWorker::SetNewOwner(PrintJobWorkerOwner* new_owner) { 132 void PrintJobWorker::SetNewOwner(PrintJobWorkerOwner* new_owner) {
110 DCHECK(page_number_ == PageNumber::npos()); 133 DCHECK(page_number_ == PageNumber::npos());
111 owner_ = new_owner; 134 owner_ = new_owner;
112 } 135 }
113 136
114 void PrintJobWorker::GetSettings( 137 void PrintJobWorker::GetSettings(
115 bool ask_user_for_settings, 138 GetSettingsAskParam ask_settings_type,
116 int document_page_count, 139 int document_page_count,
117 bool has_selection, 140 bool has_selection,
118 MarginType margin_type) { 141 MarginType margin_type) {
119 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 142 DCHECK(task_runner_->RunsTasksOnCurrentThread());
120 DCHECK_EQ(page_number_, PageNumber::npos()); 143 DCHECK_EQ(page_number_, PageNumber::npos());
121 144
122 // Recursive task processing is needed for the dialog in case it needs to be 145 // Recursive task processing is needed for the dialog in case it needs to be
123 // destroyed by a task. 146 // destroyed by a task.
124 // TODO(thestig): This code is wrong. SetNestableTasksAllowed(true) is needed 147 // TODO(thestig): This code is wrong. SetNestableTasksAllowed(true) is needed
125 // on the thread where the PrintDlgEx is called, and definitely both calls 148 // on the thread where the PrintDlgEx is called, and definitely both calls
126 // should happen on the same thread. See http://crbug.com/73466 149 // should happen on the same thread. See http://crbug.com/73466
127 // MessageLoop::current()->SetNestableTasksAllowed(true); 150 // MessageLoop::current()->SetNestableTasksAllowed(true);
128 printing_context_->set_margin_type(margin_type); 151 printing_context_->set_margin_type(margin_type);
129 152
130 // When we delegate to a destination, we don't ask the user for settings. 153 // When we delegate to a destination, we don't ask the user for settings.
131 // TODO(mad): Ask the destination for settings. 154 // TODO(mad): Ask the destination for settings.
132 if (ask_user_for_settings) { 155 if (ask_settings_type == GetSettingsAskParam::ASK_USER) {
133 BrowserThread::PostTask( 156 BrowserThread::PostTask(
134 BrowserThread::UI, FROM_HERE, 157 BrowserThread::UI, FROM_HERE,
135 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_), 158 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_),
136 base::Bind(&PrintJobWorker::GetSettingsWithUI, 159 base::Bind(&PrintJobWorker::GetSettingsWithUI,
137 base::Unretained(this), 160 base::Unretained(this),
138 document_page_count, 161 document_page_count,
139 has_selection))); 162 has_selection)));
163 } else if (ask_settings_type == GetSettingsAskParam::SYSTEM_SPECIFIC) {
164 LOG(INFO) << "DGN SYSTEM_SPECIFIC! ";
165 BrowserThread::PostTask(
166 BrowserThread::UI, FROM_HERE,
167 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_),
168 base::Bind(&PrintJobWorker::ShowSystemDialog,
169 base::Unretained(this))));
140 } else { 170 } else {
141 BrowserThread::PostTask( 171 BrowserThread::PostTask(
142 BrowserThread::UI, FROM_HERE, 172 BrowserThread::UI, FROM_HERE,
143 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_), 173 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_),
144 base::Bind(&PrintJobWorker::UseDefaultSettings, 174 base::Bind(&PrintJobWorker::UseDefaultSettings,
145 base::Unretained(this)))); 175 base::Unretained(this))));
146 } 176 }
147 } 177 }
148 178
179 void PrintJobWorker::ShowSystemDialog() {
180 DCHECK_CURRENTLY_ON(BrowserThread::UI);
181 LOG(INFO) << "DGN ShowSystemDialog";
182
183 if (printing_context_ == NULL) LOG(INFO) << "DGN printing_context_ is NULL";
184
185 printing_context_delegate_->SetPendingPrint();
186 printing_context_->RequestSystemDialog(
187 base::Bind(&PrintJobWorker::GetSettingsDone,
188 base::Unretained(this)));
189 }
190
149 void PrintJobWorker::SetSettings( 191 void PrintJobWorker::SetSettings(
150 scoped_ptr<base::DictionaryValue> new_settings) { 192 scoped_ptr<base::DictionaryValue> new_settings) {
151 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 193 DCHECK(task_runner_->RunsTasksOnCurrentThread());
152 194
153 BrowserThread::PostTask( 195 BrowserThread::PostTask(
154 BrowserThread::UI, 196 BrowserThread::UI,
155 FROM_HERE, 197 FROM_HERE,
156 base::Bind(&HoldRefCallback, 198 base::Bind(&HoldRefCallback,
157 make_scoped_refptr(owner_), 199 make_scoped_refptr(owner_),
158 base::Bind(&PrintJobWorker::UpdatePrintSettings, 200 base::Bind(&PrintJobWorker::UpdatePrintSettings,
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 document_, 445 document_,
404 scoped_refptr<PrintedPage>())); 446 scoped_refptr<PrintedPage>()));
405 Cancel(); 447 Cancel();
406 448
407 // Makes sure the variables are reinitialized. 449 // Makes sure the variables are reinitialized.
408 document_ = NULL; 450 document_ = NULL;
409 page_number_ = PageNumber::npos(); 451 page_number_ = PageNumber::npos();
410 } 452 }
411 453
412 } // namespace printing 454 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698