OLD | NEW |
---|---|
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" | |
Vitaly Buka (NO REVIEWS)
2014/12/09 23:46:48
put conditional includes after the main section of
dgn
2014/12/10 18:12:52
Done.
| |
16 #endif | |
13 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/chrome_notification_types.h" | 18 #include "chrome/browser/chrome_notification_types.h" |
15 #include "chrome/browser/printing/print_job.h" | 19 #include "chrome/browser/printing/print_job.h" |
16 #include "chrome/grit/generated_resources.h" | 20 #include "chrome/grit/generated_resources.h" |
17 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
19 #include "content/public/browser/render_view_host.h" | 23 #include "content/public/browser/render_view_host.h" |
20 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
21 #include "printing/print_job_constants.h" | 25 #include "printing/print_job_constants.h" |
22 #include "printing/printed_document.h" | 26 #include "printing/printed_document.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
37 } | 41 } |
38 | 42 |
39 class PrintingContextDelegate : public PrintingContext::Delegate { | 43 class PrintingContextDelegate : public PrintingContext::Delegate { |
40 public: | 44 public: |
41 PrintingContextDelegate(int render_process_id, int render_view_id); | 45 PrintingContextDelegate(int render_process_id, int render_view_id); |
42 ~PrintingContextDelegate() override; | 46 ~PrintingContextDelegate() override; |
43 | 47 |
44 gfx::NativeView GetParentView() override; | 48 gfx::NativeView GetParentView() override; |
45 std::string GetAppLocale() override; | 49 std::string GetAppLocale() override; |
46 | 50 |
51 // Not exposed to PrintingContext::Delegate because of dependency issues. | |
52 content::WebContents* GetWebContents(); | |
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() { |
Vitaly Buka (NO REVIEWS)
2014/12/09 23:46:48
you can send tiny separate CL for these PrintingCo
dgn
2014/12/10 18:12:52
Here it is: https://codereview.chromium.org/787783
| |
62 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 69 content::WebContents* wc = GetWebContents(); |
63 content::RenderViewHost* view = | 70 return wc ? wc->GetNativeView() : nullptr; |
64 content::RenderViewHost::FromID(render_process_id_, render_view_id_); | |
65 if (!view) | |
66 return NULL; | |
67 content::WebContents* wc = content::WebContents::FromRenderViewHost(view); | |
68 return wc ? wc->GetNativeView() : NULL; | |
69 } | 71 } |
70 | 72 |
71 std::string PrintingContextDelegate::GetAppLocale() { | 73 std::string PrintingContextDelegate::GetAppLocale() { |
72 return g_browser_process->GetApplicationLocale(); | 74 return g_browser_process->GetApplicationLocale(); |
73 } | 75 } |
74 | 76 |
77 content::WebContents* PrintingContextDelegate::GetWebContents() { | |
78 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
79 content::RenderViewHost* view = | |
80 content::RenderViewHost::FromID(render_process_id_, render_view_id_); | |
81 return view ? content::WebContents::FromRenderViewHost(view) : nullptr; | |
82 } | |
83 | |
75 void NotificationCallback(PrintJobWorkerOwner* print_job, | 84 void NotificationCallback(PrintJobWorkerOwner* print_job, |
76 JobEventDetails::Type detail_type, | 85 JobEventDetails::Type detail_type, |
77 PrintedDocument* document, | 86 PrintedDocument* document, |
78 PrintedPage* page) { | 87 PrintedPage* page) { |
79 JobEventDetails* details = new JobEventDetails(detail_type, document, page); | 88 JobEventDetails* details = new JobEventDetails(detail_type, document, page); |
80 content::NotificationService::current()->Notify( | 89 content::NotificationService::current()->Notify( |
81 chrome::NOTIFICATION_PRINT_JOB_EVENT, | 90 chrome::NOTIFICATION_PRINT_JOB_EVENT, |
82 // We know that is is a PrintJob object in this circumstance. | 91 // We know that is is a PrintJob object in this circumstance. |
83 content::Source<PrintJob>(static_cast<PrintJob*>(print_job)), | 92 content::Source<PrintJob>(static_cast<PrintJob*>(print_job)), |
84 content::Details<JobEventDetails>(details)); | 93 content::Details<JobEventDetails>(details)); |
(...skipping 20 matching lines...) Expand all Loading... | |
105 DCHECK(owner_->RunsTasksOnCurrentThread()); | 114 DCHECK(owner_->RunsTasksOnCurrentThread()); |
106 Stop(); | 115 Stop(); |
107 } | 116 } |
108 | 117 |
109 void PrintJobWorker::SetNewOwner(PrintJobWorkerOwner* new_owner) { | 118 void PrintJobWorker::SetNewOwner(PrintJobWorkerOwner* new_owner) { |
110 DCHECK(page_number_ == PageNumber::npos()); | 119 DCHECK(page_number_ == PageNumber::npos()); |
111 owner_ = new_owner; | 120 owner_ = new_owner; |
112 } | 121 } |
113 | 122 |
114 void PrintJobWorker::GetSettings( | 123 void PrintJobWorker::GetSettings( |
115 bool ask_user_for_settings, | 124 PrinterQuery::GetSettingsAskParam ask_settings_type, |
116 int document_page_count, | 125 int document_page_count, |
117 bool has_selection, | 126 bool has_selection, |
118 MarginType margin_type) { | 127 MarginType margin_type) { |
119 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 128 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
120 DCHECK_EQ(page_number_, PageNumber::npos()); | 129 DCHECK_EQ(page_number_, PageNumber::npos()); |
121 | 130 |
122 // Recursive task processing is needed for the dialog in case it needs to be | 131 // Recursive task processing is needed for the dialog in case it needs to be |
123 // destroyed by a task. | 132 // destroyed by a task. |
124 // TODO(thestig): This code is wrong. SetNestableTasksAllowed(true) is needed | 133 // TODO(thestig): This code is wrong. SetNestableTasksAllowed(true) is needed |
125 // on the thread where the PrintDlgEx is called, and definitely both calls | 134 // on the thread where the PrintDlgEx is called, and definitely both calls |
126 // should happen on the same thread. See http://crbug.com/73466 | 135 // should happen on the same thread. See http://crbug.com/73466 |
127 // MessageLoop::current()->SetNestableTasksAllowed(true); | 136 // MessageLoop::current()->SetNestableTasksAllowed(true); |
128 printing_context_->set_margin_type(margin_type); | 137 printing_context_->set_margin_type(margin_type); |
129 | 138 |
130 // When we delegate to a destination, we don't ask the user for settings. | 139 // When we delegate to a destination, we don't ask the user for settings. |
131 // TODO(mad): Ask the destination for settings. | 140 // TODO(mad): Ask the destination for settings. |
132 if (ask_user_for_settings) { | 141 if (ask_settings_type == PrinterQuery::GetSettingsAskParam::ASK_USER) { |
133 BrowserThread::PostTask( | 142 BrowserThread::PostTask( |
134 BrowserThread::UI, FROM_HERE, | 143 BrowserThread::UI, FROM_HERE, |
Vitaly Buka (NO REVIEWS)
2014/12/09 23:46:48
does android needs both branches: ASK_USER and SYS
dgn
2014/12/10 18:12:52
Yes. SYSTEM_SPECIFIC is related the call coming fr
| |
135 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_), | 144 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_), |
136 base::Bind(&PrintJobWorker::GetSettingsWithUI, | 145 base::Bind(&PrintJobWorker::GetSettingsWithUI, |
137 base::Unretained(this), | 146 base::Unretained(this), |
138 document_page_count, | 147 document_page_count, |
139 has_selection))); | 148 has_selection))); |
149 } else if (ask_settings_type == | |
150 PrinterQuery::GetSettingsAskParam::SYSTEM_SPECIFIC) { | |
151 LOG(INFO) << "DGN SYSTEM_SPECIFIC! "; | |
152 BrowserThread::PostTask( | |
153 BrowserThread::UI, FROM_HERE, | |
154 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_), | |
155 base::Bind(&PrintJobWorker::ShowSystemDialog, | |
156 base::Unretained(this)))); | |
140 } else { | 157 } else { |
141 BrowserThread::PostTask( | 158 BrowserThread::PostTask( |
142 BrowserThread::UI, FROM_HERE, | 159 BrowserThread::UI, FROM_HERE, |
143 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_), | 160 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_), |
144 base::Bind(&PrintJobWorker::UseDefaultSettings, | 161 base::Bind(&PrintJobWorker::UseDefaultSettings, |
145 base::Unretained(this)))); | 162 base::Unretained(this)))); |
146 } | 163 } |
147 } | 164 } |
148 | 165 |
166 void PrintJobWorker::ShowSystemDialog() { | |
167 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
168 LOG(INFO) << "DGN ShowSystemDialog"; | |
169 | |
170 #if defined(OS_ANDROID) | |
171 PrintingContextDelegate* pcd = | |
172 static_cast<PrintingContextDelegate*>(printing_context_delegate_.get()); | |
173 content::WebContents* wc = pcd->GetWebContents(); | |
174 TabAndroid* tab = TabAndroid::FromWebContents(wc); | |
175 if (tab) | |
176 tab->SetPendingPrint(); // If fails or is not called, attempting to start a | |
Vitaly Buka (NO REVIEWS)
2014/12/09 23:46:48
Comment makes if () body multily.
better to use
dgn
2014/12/10 18:12:52
Done.
| |
177 // pending print does nothing and will notify that | |
178 // printing is finished. | |
179 #endif | |
180 | |
181 printing_context_->RequestSystemDialog( | |
182 base::Bind(&PrintJobWorker::GetSettingsDone, | |
183 base::Unretained(this))); | |
184 } | |
185 | |
149 void PrintJobWorker::SetSettings( | 186 void PrintJobWorker::SetSettings( |
150 scoped_ptr<base::DictionaryValue> new_settings) { | 187 scoped_ptr<base::DictionaryValue> new_settings) { |
151 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 188 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
152 | 189 |
153 BrowserThread::PostTask( | 190 BrowserThread::PostTask( |
154 BrowserThread::UI, | 191 BrowserThread::UI, |
155 FROM_HERE, | 192 FROM_HERE, |
156 base::Bind(&HoldRefCallback, | 193 base::Bind(&HoldRefCallback, |
157 make_scoped_refptr(owner_), | 194 make_scoped_refptr(owner_), |
158 base::Bind(&PrintJobWorker::UpdatePrintSettings, | 195 base::Bind(&PrintJobWorker::UpdatePrintSettings, |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
403 document_, | 440 document_, |
404 scoped_refptr<PrintedPage>())); | 441 scoped_refptr<PrintedPage>())); |
405 Cancel(); | 442 Cancel(); |
406 | 443 |
407 // Makes sure the variables are reinitialized. | 444 // Makes sure the variables are reinitialized. |
408 document_ = NULL; | 445 document_ = NULL; |
409 page_number_ = PageNumber::npos(); | 446 page_number_ = PageNumber::npos(); |
410 } | 447 } |
411 | 448 |
412 } // namespace printing | 449 } // namespace printing |
OLD | NEW |