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

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

Issue 4396001: Merge 64807 & 64824 - Cloud Print Dialog work (Closed) Base URL: svn://svn.chromium.org/chrome/branches/552/src/
Patch Set: Created 10 years, 1 month 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #include "chrome/browser/printing/print_dialog_cloud_internal.h" 6 #include "chrome/browser/printing/print_dialog_cloud_internal.h"
7 7
8 #include "app/l10n_util.h" 8 #include "app/l10n_util.h"
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/json/json_reader.h" 11 #include "base/json/json_reader.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/browser_list.h" 13 #include "chrome/browser/browser_list.h"
14 #include "chrome/browser/chrome_thread.h" 14 #include "chrome/browser/chrome_thread.h"
15 #include "chrome/browser/debugger/devtools_manager.h" 15 #include "chrome/browser/debugger/devtools_manager.h"
16 #include "chrome/browser/dom_ui/dom_ui.h" 16 #include "chrome/browser/dom_ui/dom_ui.h"
17 #include "chrome/browser/dom_ui/dom_ui_util.h" 17 #include "chrome/browser/dom_ui/dom_ui_util.h"
18 #include "chrome/browser/dom_ui/html_dialog_ui.h" 18 #include "chrome/browser/prefs/pref_service.h"
19 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" 19 #include "chrome/browser/printing/cloud_print/cloud_print_url.h"
20 #include "chrome/browser/profile.h"
20 #include "chrome/browser/renderer_host/render_view_host.h" 21 #include "chrome/browser/renderer_host/render_view_host.h"
21 #include "chrome/browser/tab_contents/tab_contents.h" 22 #include "chrome/browser/tab_contents/tab_contents.h"
23 #include "chrome/browser/tab_contents/tab_contents_view.h"
22 #include "chrome/common/notification_observer.h" 24 #include "chrome/common/notification_observer.h"
23 #include "chrome/common/notification_registrar.h" 25 #include "chrome/common/notification_registrar.h"
24 #include "chrome/common/notification_source.h" 26 #include "chrome/common/notification_source.h"
25 #include "chrome/common/notification_type.h" 27 #include "chrome/common/notification_type.h"
28 #include "chrome/common/pref_names.h"
26 #include "chrome/common/render_messages_params.h" 29 #include "chrome/common/render_messages_params.h"
27 #include "chrome/common/url_constants.h" 30 #include "chrome/common/url_constants.h"
28 #include "webkit/glue/webpreferences.h" 31 #include "webkit/glue/webpreferences.h"
29 32
30 #include "grit/generated_resources.h" 33 #include "grit/generated_resources.h"
31 34
32 // This module implements the UI support in Chrome for cloud printing. 35 // This module implements the UI support in Chrome for cloud printing.
33 // This means hosting a dialog containing HTML/JavaScript and using 36 // This means hosting a dialog containing HTML/JavaScript and using
34 // the published cloud print user interface integration APIs to get 37 // the published cloud print user interface integration APIs to get
35 // page setup settings from the dialog contents and provide the 38 // page setup settings from the dialog contents and provide the
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // When the dialog contents are finished (by either being cancelled or 88 // When the dialog contents are finished (by either being cancelled or
86 // hitting the print button), the delegate is notified, and responds 89 // hitting the print button), the delegate is notified, and responds
87 // that the dialog should be closed, at which point things are torn 90 // that the dialog should be closed, at which point things are torn
88 // down and released. 91 // down and released.
89 92
90 // TODO(scottbyer): 93 // TODO(scottbyer):
91 // http://code.google.com/p/chromium/issues/detail?id=44093 The 94 // http://code.google.com/p/chromium/issues/detail?id=44093 The
92 // high-level flow (where the PDF data is generated before even 95 // high-level flow (where the PDF data is generated before even
93 // bringing up the dialog) isn't what we want. 96 // bringing up the dialog) isn't what we want.
94 97
95
96 namespace internal_cloud_print_helpers { 98 namespace internal_cloud_print_helpers {
97 99
98 bool GetRealOrInt(const DictionaryValue& dictionary, 100 bool GetRealOrInt(const DictionaryValue& dictionary,
99 const std::string& path, 101 const std::string& path,
100 double* out_value) { 102 double* out_value) {
101 if (!dictionary.GetReal(path, out_value)) { 103 if (!dictionary.GetReal(path, out_value)) {
102 int int_value = 0; 104 int int_value = 0;
103 if (!dictionary.GetInteger(path, &int_value)) 105 if (!dictionary.GetInteger(path, &int_value))
104 return false; 106 return false;
105 *out_value = int_value; 107 *out_value = int_value;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 // reference to it, so when the task that is calling it finishes and 220 // reference to it, so when the task that is calling it finishes and
219 // removes it's reference, it goes away. 221 // removes it's reference, it goes away.
220 void CloudPrintFlowHandler::CancelAnyRunningTask() { 222 void CloudPrintFlowHandler::CancelAnyRunningTask() {
221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
222 if (print_data_sender_.get()) { 224 if (print_data_sender_.get()) {
223 print_data_sender_->CancelPrintDataFile(); 225 print_data_sender_->CancelPrintDataFile();
224 print_data_sender_ = NULL; 226 print_data_sender_ = NULL;
225 } 227 }
226 } 228 }
227 229
228
229 void CloudPrintFlowHandler::RegisterMessages() { 230 void CloudPrintFlowHandler::RegisterMessages() {
230 if (!dom_ui_) 231 if (!dom_ui_)
231 return; 232 return;
232 233
233 // TODO(scottbyer) - This is where we will register messages for the 234 // TODO(scottbyer) - This is where we will register messages for the
234 // UI JS to use. Needed: Call to update page setup parameters. 235 // UI JS to use. Needed: Call to update page setup parameters.
235 dom_ui_->RegisterMessageCallback( 236 dom_ui_->RegisterMessageCallback(
236 "ShowDebugger", 237 "ShowDebugger",
237 NewCallback(this, &CloudPrintFlowHandler::HandleShowDebugger)); 238 NewCallback(this, &CloudPrintFlowHandler::HandleShowDebugger));
238 dom_ui_->RegisterMessageCallback( 239 dom_ui_->RegisterMessageCallback(
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 return; 352 return;
352 } 353 }
353 354
354 // TODO(scottbyer) - Here is where we would kick the originating 355 // TODO(scottbyer) - Here is where we would kick the originating
355 // renderer thread with these new parameters in order to get it to 356 // renderer thread with these new parameters in order to get it to
356 // re-generate the PDF and hand it back to us. window.print() is 357 // re-generate the PDF and hand it back to us. window.print() is
357 // currently synchronous, so there's a lot of work to do to get to 358 // currently synchronous, so there's a lot of work to do to get to
358 // that point. 359 // that point.
359 } 360 }
360 361
362 void CloudPrintFlowHandler::StoreDialogClientSize() const {
363 if (dom_ui_ && dom_ui_->tab_contents() && dom_ui_->tab_contents()->view()) {
364 gfx::Size size = dom_ui_->tab_contents()->view()->GetContainerSize();
365 dom_ui_->GetProfile()->GetPrefs()->SetInteger(
366 prefs::kCloudPrintDialogWidth, size.width());
367 dom_ui_->GetProfile()->GetPrefs()->SetInteger(
368 prefs::kCloudPrintDialogHeight, size.height());
369 }
370 }
371
361 CloudPrintHtmlDialogDelegate::CloudPrintHtmlDialogDelegate( 372 CloudPrintHtmlDialogDelegate::CloudPrintHtmlDialogDelegate(
362 const FilePath& path_to_pdf, 373 const FilePath& path_to_pdf,
363 int width, int height, 374 int width, int height,
364 const std::string& json_arguments, 375 const std::string& json_arguments,
365 const string16& print_job_title) 376 const string16& print_job_title)
366 : flow_handler_(new CloudPrintFlowHandler(path_to_pdf, print_job_title)), 377 : flow_handler_(new CloudPrintFlowHandler(path_to_pdf, print_job_title)),
367 owns_flow_handler_(true) { 378 owns_flow_handler_(true) {
368 Init(width, height, json_arguments); 379 Init(width, height, json_arguments);
369 } 380 }
370 381
(...skipping 27 matching lines...) Expand all
398 if (owns_flow_handler_) { 409 if (owns_flow_handler_) {
399 delete flow_handler_; 410 delete flow_handler_;
400 } 411 }
401 } 412 }
402 413
403 bool CloudPrintHtmlDialogDelegate::IsDialogModal() const { 414 bool CloudPrintHtmlDialogDelegate::IsDialogModal() const {
404 return true; 415 return true;
405 } 416 }
406 417
407 std::wstring CloudPrintHtmlDialogDelegate::GetDialogTitle() const { 418 std::wstring CloudPrintHtmlDialogDelegate::GetDialogTitle() const {
408 return l10n_util::GetString(IDS_CLOUD_PRINT_TITLE); 419 return std::wstring();
409 } 420 }
410 421
411 GURL CloudPrintHtmlDialogDelegate::GetDialogContentURL() const { 422 GURL CloudPrintHtmlDialogDelegate::GetDialogContentURL() const {
412 return params_.url; 423 return params_.url;
413 } 424 }
414 425
415 void CloudPrintHtmlDialogDelegate::GetDOMMessageHandlers( 426 void CloudPrintHtmlDialogDelegate::GetDOMMessageHandlers(
416 std::vector<DOMMessageHandler*>* handlers) const { 427 std::vector<DOMMessageHandler*>* handlers) const {
417 handlers->push_back(flow_handler_); 428 handlers->push_back(flow_handler_);
418 // We don't own flow_handler_ anymore, but it sticks around until at 429 // We don't own flow_handler_ anymore, but it sticks around until at
419 // least right after OnDialogClosed() is called (and this object is 430 // least right after OnDialogClosed() is called (and this object is
420 // destroyed). 431 // destroyed).
421 owns_flow_handler_ = false; 432 owns_flow_handler_ = false;
422 } 433 }
423 434
424 void CloudPrintHtmlDialogDelegate::GetDialogSize(gfx::Size* size) const { 435 void CloudPrintHtmlDialogDelegate::GetDialogSize(gfx::Size* size) const {
425 size->set_width(params_.width); 436 size->set_width(params_.width);
426 size->set_height(params_.height); 437 size->set_height(params_.height);
427 } 438 }
428 439
429 std::string CloudPrintHtmlDialogDelegate::GetDialogArgs() const { 440 std::string CloudPrintHtmlDialogDelegate::GetDialogArgs() const {
430 return params_.json_input; 441 return params_.json_input;
431 } 442 }
432 443
433 void CloudPrintHtmlDialogDelegate::OnDialogClosed( 444 void CloudPrintHtmlDialogDelegate::OnDialogClosed(
434 const std::string& json_retval) { 445 const std::string& json_retval) {
446 // Get the final dialog size and store it.
447 flow_handler_->StoreDialogClientSize();
435 delete this; 448 delete this;
436 } 449 }
437 450
438 void CloudPrintHtmlDialogDelegate::OnCloseContents(TabContents* source, 451 void CloudPrintHtmlDialogDelegate::OnCloseContents(TabContents* source,
439 bool* out_close_dialog) { 452 bool* out_close_dialog) {
440 if (out_close_dialog) 453 if (out_close_dialog)
441 *out_close_dialog = true; 454 *out_close_dialog = true;
442 } 455 }
443 456
457 bool CloudPrintHtmlDialogDelegate::ShouldShowDialogTitle() const {
458 return false;
459 }
460
444 } // end of namespace internal_cloud_print_helpers 461 } // end of namespace internal_cloud_print_helpers
445 462
446 // static, called on the IO thread. This is the main entry point into 463 // static, called on the IO thread. This is the main entry point into
447 // creating the dialog. 464 // creating the dialog.
448 465
449 // TODO(scottbyer): The signature here will need to change as the 466 // TODO(scottbyer): The signature here will need to change as the
450 // workflow through the printing code changes to allow for dynamically 467 // workflow through the printing code changes to allow for dynamically
451 // changing page setup parameters while the dialog is active. 468 // changing page setup parameters while the dialog is active.
452 void PrintDialogCloud::CreatePrintDialogForPdf(const FilePath& path_to_pdf) { 469 void PrintDialogCloud::CreatePrintDialogForPdf(const FilePath& path_to_pdf) {
453 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 470 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
(...skipping 12 matching lines...) Expand all
466 // Initialize the print dialog. Called on the UI thread. 483 // Initialize the print dialog. Called on the UI thread.
467 PrintDialogCloud::PrintDialogCloud(const FilePath& path_to_pdf) 484 PrintDialogCloud::PrintDialogCloud(const FilePath& path_to_pdf)
468 : browser_(BrowserList::GetLastActive()) { 485 : browser_(BrowserList::GetLastActive()) {
469 486
470 // TODO(scottbyer): Verify GAIA login valid, execute GAIA login if not (should 487 // TODO(scottbyer): Verify GAIA login valid, execute GAIA login if not (should
471 // be distilled out of bookmark sync.) 488 // be distilled out of bookmark sync.)
472 string16 print_job_title; 489 string16 print_job_title;
473 if (browser_ && browser_->GetSelectedTabContents()) 490 if (browser_ && browser_->GetSelectedTabContents())
474 print_job_title = browser_->GetSelectedTabContents()->GetTitle(); 491 print_job_title = browser_->GetSelectedTabContents()->GetTitle();
475 492
476 // TODO(scottbyer): Get the dialog width, height from the dialog 493 const int kDefaultWidth = 497;
477 // contents, and take the screen size into account. 494 const int kDefaultHeight = 332;
495
496 PrefService* pref_service = browser_->GetProfile()->GetPrefs();
497 DCHECK(pref_service);
498 if (!pref_service->FindPreference(prefs::kCloudPrintDialogWidth)) {
499 pref_service->RegisterIntegerPref(prefs::kCloudPrintDialogWidth,
500 kDefaultWidth);
501 }
502 if (!pref_service->FindPreference(prefs::kCloudPrintDialogHeight)) {
503 pref_service->RegisterIntegerPref(prefs::kCloudPrintDialogHeight,
504 kDefaultHeight);
505 }
506
507 int width = pref_service->GetInteger(prefs::kCloudPrintDialogWidth);
508 int height = pref_service->GetInteger(prefs::kCloudPrintDialogHeight);
478 HtmlDialogUIDelegate* dialog_delegate = 509 HtmlDialogUIDelegate* dialog_delegate =
479 new internal_cloud_print_helpers::CloudPrintHtmlDialogDelegate( 510 new internal_cloud_print_helpers::CloudPrintHtmlDialogDelegate(
480 path_to_pdf, 500, 400, std::string(), print_job_title); 511 path_to_pdf, width, height, std::string(), print_job_title);
481 browser_->BrowserShowHtmlDialog(dialog_delegate, NULL); 512 browser_->BrowserShowHtmlDialog(dialog_delegate, NULL);
482 } 513 }
483 514
484 PrintDialogCloud::~PrintDialogCloud() { 515 PrintDialogCloud::~PrintDialogCloud() {
485 } 516 }
OLDNEW
« no previous file with comments | « chrome/browser/printing/cloud_print/cloud_print_setup_flow.h ('k') | chrome/browser/printing/print_dialog_cloud_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698