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_dialog_cloud.h" | 5 #include "chrome/browser/printing/print_dialog_cloud.h" |
6 | 6 |
7 | 7 |
8 #include "base/base64.h" | 8 #include "base/base64.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 void CloudPrintDataSender::SendPrintData() { | 214 void CloudPrintDataSender::SendPrintData() { |
215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
216 if (!data_ || !data_->size()) | 216 if (!data_ || !data_->size()) |
217 return; | 217 return; |
218 | 218 |
219 std::string base64_data; | 219 std::string base64_data; |
220 base::Base64Encode( | 220 base::Base64Encode( |
221 base::StringPiece(reinterpret_cast<const char*>(data_->front()), | 221 base::StringPiece(reinterpret_cast<const char*>(data_->front()), |
222 data_->size()), | 222 data_->size()), |
223 &base64_data); | 223 &base64_data); |
224 data_ = NULL; | |
225 std::string header("data:"); | 224 std::string header("data:"); |
226 header.append(file_type_); | 225 header.append(file_type_); |
227 header.append(";base64,"); | 226 header.append(";base64,"); |
228 base64_data.insert(0, header); | 227 base64_data.insert(0, header); |
229 | 228 |
230 base::AutoLock lock(lock_); | 229 base::AutoLock lock(lock_); |
231 if (helper_) { | 230 if (helper_) { |
232 StringValue title(print_job_title_); | 231 StringValue title(print_job_title_); |
233 StringValue ticket(print_ticket_); | 232 StringValue ticket(print_ticket_); |
234 // TODO(abodenha): Change Javascript call to pass in print ticket | 233 // TODO(abodenha): Change Javascript call to pass in print ticket |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 const content::NotificationDetails& details) { | 324 const content::NotificationDetails& details) { |
326 switch (type) { | 325 switch (type) { |
327 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { | 326 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { |
328 NavigationEntry* entry = | 327 NavigationEntry* entry = |
329 web_ui()->GetWebContents()->GetController().GetActiveEntry(); | 328 web_ui()->GetWebContents()->GetController().GetActiveEntry(); |
330 if (entry) | 329 if (entry) |
331 NavigationToURLDidCloseDialog(entry->GetURL()); | 330 NavigationToURLDidCloseDialog(entry->GetURL()); |
332 break; | 331 break; |
333 } | 332 } |
334 case content::NOTIFICATION_LOAD_STOP: { | 333 case content::NOTIFICATION_LOAD_STOP: { |
335 // Take the opportunity to set some (minimal) additional | |
336 // script permissions required for the web UI. | |
337 GURL url = web_ui()->GetWebContents()->GetURL(); | 334 GURL url = web_ui()->GetWebContents()->GetURL(); |
338 GURL dialog_url = CloudPrintURL( | 335 if (IsCloudPrintDialogUrl(url)) { |
339 Profile::FromWebUI(web_ui())).GetCloudPrintServiceDialogURL(); | 336 // Take the opportunity to set some (minimal) additional |
340 if (url.host() == dialog_url.host() && | 337 // script permissions required for the web UI. |
341 url.path() == dialog_url.path() && | |
342 url.scheme() == dialog_url.scheme()) { | |
343 RenderViewHost* rvh = web_ui()->GetWebContents()->GetRenderViewHost(); | 338 RenderViewHost* rvh = web_ui()->GetWebContents()->GetRenderViewHost(); |
344 if (rvh) { | 339 if (rvh) { |
345 WebPreferences webkit_prefs = rvh->GetWebkitPreferences(); | 340 WebPreferences webkit_prefs = rvh->GetWebkitPreferences(); |
346 webkit_prefs.allow_scripts_to_close_windows = true; | 341 webkit_prefs.allow_scripts_to_close_windows = true; |
347 rvh->UpdateWebkitPreferences(webkit_prefs); | 342 rvh->UpdateWebkitPreferences(webkit_prefs); |
348 } else { | 343 } else { |
349 NOTREACHED(); | 344 NOTREACHED(); |
350 } | 345 } |
| 346 // Choose one or the other. If you need to debug, bring up the |
| 347 // debugger. You can then use the various chrome.send() |
| 348 // registrations above to kick of the various function calls, |
| 349 // including chrome.send("SendPrintData") in the javaScript |
| 350 // console and watch things happen with: |
| 351 // HandleShowDebugger(NULL); |
| 352 HandleSendPrintData(NULL); |
351 } | 353 } |
352 | |
353 // Choose one or the other. If you need to debug, bring up the | |
354 // debugger. You can then use the various chrome.send() | |
355 // registrations above to kick of the various function calls, | |
356 // including chrome.send("SendPrintData") in the javaScript | |
357 // console and watch things happen with: | |
358 // HandleShowDebugger(NULL); | |
359 HandleSendPrintData(NULL); | |
360 break; | 354 break; |
361 } | 355 } |
362 } | 356 } |
363 } | 357 } |
364 | 358 |
365 void CloudPrintFlowHandler::HandleShowDebugger(const ListValue* args) { | 359 void CloudPrintFlowHandler::HandleShowDebugger(const ListValue* args) { |
366 ShowDebugger(); | 360 ShowDebugger(); |
367 } | 361 } |
368 | 362 |
369 void CloudPrintFlowHandler::ShowDebugger() { | 363 void CloudPrintFlowHandler::ShowDebugger() { |
370 if (web_ui()) { | 364 if (web_ui()) { |
371 RenderViewHost* rvh = web_ui()->GetWebContents()->GetRenderViewHost(); | 365 RenderViewHost* rvh = web_ui()->GetWebContents()->GetRenderViewHost(); |
372 if (rvh) | 366 if (rvh) |
373 DevToolsWindow::OpenDevToolsWindow(rvh); | 367 DevToolsWindow::OpenDevToolsWindow(rvh); |
374 } | 368 } |
375 } | 369 } |
376 | 370 |
377 scoped_refptr<CloudPrintDataSender> | 371 scoped_refptr<CloudPrintDataSender> |
378 CloudPrintFlowHandler::CreateCloudPrintDataSender() { | 372 CloudPrintFlowHandler::CreateCloudPrintDataSender() { |
379 DCHECK(web_ui()); | 373 DCHECK(web_ui()); |
380 print_data_helper_.reset(new CloudPrintDataSenderHelper(web_ui())); | 374 print_data_helper_.reset(new CloudPrintDataSenderHelper(web_ui())); |
381 scoped_refptr<CloudPrintDataSender> sender( | 375 scoped_refptr<CloudPrintDataSender> sender( |
382 new CloudPrintDataSender(print_data_helper_.get(), print_job_title_, | 376 new CloudPrintDataSender(print_data_helper_.get(), print_job_title_, |
383 print_ticket_, file_type_, data_)); | 377 print_ticket_, file_type_, data_)); |
384 data_ = NULL; | |
385 return sender; | 378 return sender; |
386 } | 379 } |
387 | 380 |
388 void CloudPrintFlowHandler::HandleSendPrintData(const ListValue* args) { | 381 void CloudPrintFlowHandler::HandleSendPrintData(const ListValue* args) { |
389 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
390 // This will cancel any ReadPrintDataFile() or SendPrintDataFile() | 383 // This will cancel any ReadPrintDataFile() or SendPrintDataFile() |
391 // requests in flight (this is anticipation of when setting page | 384 // requests in flight (this is anticipation of when setting page |
392 // setup parameters becomes asynchronous and may be set while some | 385 // setup parameters becomes asynchronous and may be set while some |
393 // data is in flight). Then we can clear out the print data. | 386 // data is in flight). Then we can clear out the print data. |
394 CancelAnyRunningTask(); | 387 CancelAnyRunningTask(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 Profile* profile = Profile::FromWebUI(web_ui()); | 447 Profile* profile = Profile::FromWebUI(web_ui()); |
455 profile->GetPrefs()->SetInteger(prefs::kCloudPrintDialogWidth, | 448 profile->GetPrefs()->SetInteger(prefs::kCloudPrintDialogWidth, |
456 size.width()); | 449 size.width()); |
457 profile->GetPrefs()->SetInteger(prefs::kCloudPrintDialogHeight, | 450 profile->GetPrefs()->SetInteger(prefs::kCloudPrintDialogHeight, |
458 size.height()); | 451 size.height()); |
459 } | 452 } |
460 } | 453 } |
461 | 454 |
462 bool CloudPrintFlowHandler::NavigationToURLDidCloseDialog(const GURL& url) { | 455 bool CloudPrintFlowHandler::NavigationToURLDidCloseDialog(const GURL& url) { |
463 if (close_after_signin_) { | 456 if (close_after_signin_) { |
464 GURL dialog_url = CloudPrintURL( | 457 if (IsCloudPrintDialogUrl(url)) { |
465 Profile::FromWebUI(web_ui())).GetCloudPrintServiceURL(); | |
466 | |
467 if (url.host() == dialog_url.host() && | |
468 StartsWithASCII(url.path(), dialog_url.path(), false) && | |
469 url.scheme() == dialog_url.scheme()) { | |
470 StoreDialogClientSize(); | 458 StoreDialogClientSize(); |
471 web_ui()->GetWebContents()->GetRenderViewHost()->ClosePage(); | 459 web_ui()->GetWebContents()->GetRenderViewHost()->ClosePage(); |
472 callback_.Run(); | 460 callback_.Run(); |
473 return true; | 461 return true; |
474 } | 462 } |
475 } | 463 } |
476 return false; | 464 return false; |
477 } | 465 } |
478 | 466 |
| 467 bool CloudPrintFlowHandler::IsCloudPrintDialogUrl(const GURL& url) { |
| 468 GURL cloud_print_url = |
| 469 CloudPrintURL(Profile::FromWebUI(web_ui())).GetCloudPrintServiceURL(); |
| 470 return url.host() == cloud_print_url.host() && |
| 471 StartsWithASCII(url.path(), cloud_print_url.path(), false) && |
| 472 url.scheme() == cloud_print_url.scheme(); |
| 473 } |
| 474 |
479 CloudPrintWebDialogDelegate::CloudPrintWebDialogDelegate( | 475 CloudPrintWebDialogDelegate::CloudPrintWebDialogDelegate( |
480 content::BrowserContext* browser_context, | 476 content::BrowserContext* browser_context, |
481 gfx::NativeWindow modal_parent, | 477 gfx::NativeWindow modal_parent, |
482 const base::RefCountedMemory* data, | 478 const base::RefCountedMemory* data, |
483 const std::string& json_arguments, | 479 const std::string& json_arguments, |
484 const string16& print_job_title, | 480 const string16& print_job_title, |
485 const string16& print_ticket, | 481 const string16& print_ticket, |
486 const std::string& file_type, | 482 const std::string& file_type, |
487 bool close_after_signin, | 483 bool close_after_signin, |
488 const base::Closure& callback) | 484 const base::Closure& callback) |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 print_job_print_ticket, | 775 print_job_print_ticket, |
780 file_type, | 776 file_type, |
781 delete_on_close); | 777 delete_on_close); |
782 return true; | 778 return true; |
783 } | 779 } |
784 } | 780 } |
785 return false; | 781 return false; |
786 } | 782 } |
787 | 783 |
788 } // end namespace | 784 } // end namespace |
OLD | NEW |