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" | |
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 Loading... | |
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 // Not exposed to PrintingContext::Delegate because of dependency issues. | |
53 content::WebContents* GetWebContents(); | |
54 | |
47 private: | 55 private: |
48 int render_process_id_; | 56 int render_process_id_; |
49 int render_view_id_; | 57 int render_view_id_; |
50 }; | 58 }; |
51 | 59 |
52 PrintingContextDelegate::PrintingContextDelegate(int render_process_id, | 60 PrintingContextDelegate::PrintingContextDelegate(int render_process_id, |
53 int render_view_id) | 61 int render_view_id) |
54 : render_process_id_(render_process_id), | 62 : render_process_id_(render_process_id), |
55 render_view_id_(render_view_id) { | 63 render_view_id_(render_view_id) { |
56 } | 64 } |
57 | 65 |
58 PrintingContextDelegate::~PrintingContextDelegate() { | 66 PrintingContextDelegate::~PrintingContextDelegate() { |
59 } | 67 } |
60 | 68 |
61 gfx::NativeView PrintingContextDelegate::GetParentView() { | 69 gfx::NativeView PrintingContextDelegate::GetParentView() { |
62 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 70 content::WebContents* wc = GetWebContents(); |
63 content::RenderViewHost* view = | 71 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 } | 72 } |
70 | 73 |
71 std::string PrintingContextDelegate::GetAppLocale() { | 74 std::string PrintingContextDelegate::GetAppLocale() { |
72 return g_browser_process->GetApplicationLocale(); | 75 return g_browser_process->GetApplicationLocale(); |
73 } | 76 } |
74 | 77 |
78 content::WebContents* PrintingContextDelegate::GetWebContents() { | |
79 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
80 content::RenderViewHost* view = | |
81 content::RenderViewHost::FromID(render_process_id_, render_view_id_); | |
82 return view ? content::WebContents::FromRenderViewHost(view) : nullptr; | |
83 } | |
84 | |
75 void NotificationCallback(PrintJobWorkerOwner* print_job, | 85 void NotificationCallback(PrintJobWorkerOwner* print_job, |
76 JobEventDetails::Type detail_type, | 86 JobEventDetails::Type detail_type, |
77 PrintedDocument* document, | 87 PrintedDocument* document, |
78 PrintedPage* page) { | 88 PrintedPage* page) { |
79 JobEventDetails* details = new JobEventDetails(detail_type, document, page); | 89 JobEventDetails* details = new JobEventDetails(detail_type, document, page); |
80 content::NotificationService::current()->Notify( | 90 content::NotificationService::current()->Notify( |
81 chrome::NOTIFICATION_PRINT_JOB_EVENT, | 91 chrome::NOTIFICATION_PRINT_JOB_EVENT, |
82 // We know that is is a PrintJob object in this circumstance. | 92 // We know that is is a PrintJob object in this circumstance. |
83 content::Source<PrintJob>(static_cast<PrintJob*>(print_job)), | 93 content::Source<PrintJob>(static_cast<PrintJob*>(print_job)), |
84 content::Details<JobEventDetails>(details)); | 94 content::Details<JobEventDetails>(details)); |
(...skipping 20 matching lines...) Expand all Loading... | |
105 DCHECK(owner_->RunsTasksOnCurrentThread()); | 115 DCHECK(owner_->RunsTasksOnCurrentThread()); |
106 Stop(); | 116 Stop(); |
107 } | 117 } |
108 | 118 |
109 void PrintJobWorker::SetNewOwner(PrintJobWorkerOwner* new_owner) { | 119 void PrintJobWorker::SetNewOwner(PrintJobWorkerOwner* new_owner) { |
110 DCHECK(page_number_ == PageNumber::npos()); | 120 DCHECK(page_number_ == PageNumber::npos()); |
111 owner_ = new_owner; | 121 owner_ = new_owner; |
112 } | 122 } |
113 | 123 |
114 void PrintJobWorker::GetSettings( | 124 void PrintJobWorker::GetSettings( |
115 bool ask_user_for_settings, | 125 GetSettingsAskParam ask_settings_type, |
116 int document_page_count, | 126 int document_page_count, |
117 bool has_selection, | 127 bool has_selection, |
118 MarginType margin_type) { | 128 MarginType margin_type) { |
119 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 129 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
120 DCHECK_EQ(page_number_, PageNumber::npos()); | 130 DCHECK_EQ(page_number_, PageNumber::npos()); |
121 | 131 |
122 // Recursive task processing is needed for the dialog in case it needs to be | 132 // Recursive task processing is needed for the dialog in case it needs to be |
123 // destroyed by a task. | 133 // destroyed by a task. |
124 // TODO(thestig): This code is wrong. SetNestableTasksAllowed(true) is needed | 134 // TODO(thestig): This code is wrong. SetNestableTasksAllowed(true) is needed |
125 // on the thread where the PrintDlgEx is called, and definitely both calls | 135 // on the thread where the PrintDlgEx is called, and definitely both calls |
126 // should happen on the same thread. See http://crbug.com/73466 | 136 // should happen on the same thread. See http://crbug.com/73466 |
127 // MessageLoop::current()->SetNestableTasksAllowed(true); | 137 // MessageLoop::current()->SetNestableTasksAllowed(true); |
128 printing_context_->set_margin_type(margin_type); | 138 printing_context_->set_margin_type(margin_type); |
129 | 139 |
130 // When we delegate to a destination, we don't ask the user for settings. | 140 // When we delegate to a destination, we don't ask the user for settings. |
131 // TODO(mad): Ask the destination for settings. | 141 // TODO(mad): Ask the destination for settings. |
132 if (ask_user_for_settings) { | 142 if (ask_settings_type == GetSettingsAskParam::ASK_USER) { |
133 BrowserThread::PostTask( | 143 BrowserThread::PostTask( |
134 BrowserThread::UI, FROM_HERE, | 144 BrowserThread::UI, FROM_HERE, |
135 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_), | 145 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_), |
136 base::Bind(&PrintJobWorker::GetSettingsWithUI, | 146 base::Bind(&PrintJobWorker::GetSettingsWithUI, |
137 base::Unretained(this), | 147 base::Unretained(this), |
138 document_page_count, | 148 document_page_count, |
139 has_selection))); | 149 has_selection))); |
150 } else if (ask_settings_type == 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) tab->SetPendingPrint(); // If fails or is not called, attempting to | |
mlamouri (slow - plz ping)
2014/11/27 20:26:02
I believe the coding style says:
if (tab)
tab->S
dgn
2014/11/28 11:51:15
Done.
| |
176 // start a pending print does nothing and | |
177 // will notify that printing is finished. | |
178 #endif | |
179 | |
180 printing_context_->RequestSystemDialog( | |
181 base::Bind(&PrintJobWorker::GetSettingsDone, | |
182 base::Unretained(this))); | |
183 } | |
184 | |
149 void PrintJobWorker::SetSettings( | 185 void PrintJobWorker::SetSettings( |
150 scoped_ptr<base::DictionaryValue> new_settings) { | 186 scoped_ptr<base::DictionaryValue> new_settings) { |
151 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 187 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
152 | 188 |
153 BrowserThread::PostTask( | 189 BrowserThread::PostTask( |
154 BrowserThread::UI, | 190 BrowserThread::UI, |
155 FROM_HERE, | 191 FROM_HERE, |
156 base::Bind(&HoldRefCallback, | 192 base::Bind(&HoldRefCallback, |
157 make_scoped_refptr(owner_), | 193 make_scoped_refptr(owner_), |
158 base::Bind(&PrintJobWorker::UpdatePrintSettings, | 194 base::Bind(&PrintJobWorker::UpdatePrintSettings, |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
403 document_, | 439 document_, |
404 scoped_refptr<PrintedPage>())); | 440 scoped_refptr<PrintedPage>())); |
405 Cancel(); | 441 Cancel(); |
406 | 442 |
407 // Makes sure the variables are reinitialized. | 443 // Makes sure the variables are reinitialized. |
408 document_ = NULL; | 444 document_ = NULL; |
409 page_number_ = PageNumber::npos(); | 445 page_number_ = PageNumber::npos(); |
410 } | 446 } |
411 | 447 |
412 } // namespace printing | 448 } // namespace printing |
OLD | NEW |