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

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

Issue 9003014: Replace WebUI::tab_contents() with web_contents() and switch all users to use web_contents.h inst... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 months 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "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"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/json/json_reader.h" 13 #include "base/json/json_reader.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/browser/browser_process_impl.h" 16 #include "chrome/browser/browser_process_impl.h"
17 #include "chrome/browser/debugger/devtools_window.h" 17 #include "chrome/browser/debugger/devtools_window.h"
18 #include "chrome/browser/prefs/pref_service.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/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/profiles/profile_manager.h" 21 #include "chrome/browser/profiles/profile_manager.h"
22 #include "chrome/browser/ui/browser_dialogs.h" 22 #include "chrome/browser/ui/browser_dialogs.h"
23 #include "chrome/browser/ui/browser_list.h" 23 #include "chrome/browser/ui/browser_list.h"
24 #include "chrome/browser/ui/dialog_style.h" 24 #include "chrome/browser/ui/dialog_style.h"
25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
25 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
27 #include "chrome/common/print_messages.h" 28 #include "chrome/common/print_messages.h"
28 #include "chrome/common/url_constants.h" 29 #include "chrome/common/url_constants.h"
29 #include "content/browser/renderer_host/render_view_host.h" 30 #include "content/browser/renderer_host/render_view_host.h"
30 #include "content/browser/tab_contents/tab_contents.h" 31 #include "content/browser/tab_contents/navigation_controller.h"
31 #include "content/browser/tab_contents/tab_contents_view.h" 32 #include "content/browser/tab_contents/tab_contents_view.h"
32 #include "content/browser/webui/web_ui.h" 33 #include "content/browser/webui/web_ui.h"
33 #include "content/public/browser/browser_thread.h" 34 #include "content/public/browser/browser_thread.h"
34 #include "content/public/browser/navigation_entry.h" 35 #include "content/public/browser/navigation_entry.h"
35 #include "content/public/browser/notification_registrar.h" 36 #include "content/public/browser/notification_registrar.h"
36 #include "content/public/browser/notification_source.h" 37 #include "content/public/browser/notification_source.h"
37 #include "content/public/browser/notification_types.h" 38 #include "content/public/browser/notification_types.h"
39 #include "content/public/browser/web_contents.h"
38 #include "ui/base/l10n/l10n_util.h" 40 #include "ui/base/l10n/l10n_util.h"
39 #include "webkit/glue/webpreferences.h" 41 #include "webkit/glue/webpreferences.h"
40 42
41 #include "grit/generated_resources.h" 43 #include "grit/generated_resources.h"
42 44
43 // This module implements the UI support in Chrome for cloud printing. 45 // This module implements the UI support in Chrome for cloud printing.
44 // This means hosting a dialog containing HTML/JavaScript and using 46 // This means hosting a dialog containing HTML/JavaScript and using
45 // the published cloud print user interface integration APIs to get 47 // the published cloud print user interface integration APIs to get
46 // page setup settings from the dialog contents and provide the 48 // page setup settings from the dialog contents and provide the
47 // generated print data to the dialog contents for uploading to the 49 // generated print data to the dialog contents for uploading to the
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 web_ui()->RegisterMessageCallback("SendPrintData", 295 web_ui()->RegisterMessageCallback("SendPrintData",
294 base::Bind(&CloudPrintFlowHandler::HandleSendPrintData, 296 base::Bind(&CloudPrintFlowHandler::HandleSendPrintData,
295 base::Unretained(this))); 297 base::Unretained(this)));
296 web_ui()->RegisterMessageCallback("SetPageParameters", 298 web_ui()->RegisterMessageCallback("SetPageParameters",
297 base::Bind(&CloudPrintFlowHandler::HandleSetPageParameters, 299 base::Bind(&CloudPrintFlowHandler::HandleSetPageParameters,
298 base::Unretained(this))); 300 base::Unretained(this)));
299 301
300 // Register for appropriate notifications, and re-direct the URL 302 // Register for appropriate notifications, and re-direct the URL
301 // to the real server URL, now that we've gotten an HTML dialog 303 // to the real server URL, now that we've gotten an HTML dialog
302 // going. 304 // going.
303 NavigationController* controller = &web_ui()->tab_contents()->GetController(); 305 NavigationController* controller = &web_ui()->web_contents()->GetController();
304 NavigationEntry* pending_entry = controller->GetPendingEntry(); 306 NavigationEntry* pending_entry = controller->GetPendingEntry();
305 if (pending_entry) { 307 if (pending_entry) {
306 Profile* profile = Profile::FromWebUI(web_ui()); 308 Profile* profile = Profile::FromWebUI(web_ui());
307 pending_entry->SetURL( 309 pending_entry->SetURL(
308 CloudPrintURL(profile).GetCloudPrintServiceDialogURL()); 310 CloudPrintURL(profile).GetCloudPrintServiceDialogURL());
309 } 311 }
310 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, 312 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP,
311 content::Source<NavigationController>(controller)); 313 content::Source<NavigationController>(controller));
312 } 314 }
313 315
314 void CloudPrintFlowHandler::Observe( 316 void CloudPrintFlowHandler::Observe(
315 int type, 317 int type,
316 const content::NotificationSource& source, 318 const content::NotificationSource& source,
317 const content::NotificationDetails& details) { 319 const content::NotificationDetails& details) {
318 if (type == content::NOTIFICATION_LOAD_STOP) { 320 if (type == content::NOTIFICATION_LOAD_STOP) {
319 // Take the opportunity to set some (minimal) additional 321 // Take the opportunity to set some (minimal) additional
320 // script permissions required for the web UI. 322 // script permissions required for the web UI.
321 GURL url = web_ui()->tab_contents()->GetURL(); 323 GURL url = web_ui()->web_contents()->GetURL();
322 GURL dialog_url = CloudPrintURL( 324 GURL dialog_url = CloudPrintURL(
323 Profile::FromWebUI(web_ui())).GetCloudPrintServiceDialogURL(); 325 Profile::FromWebUI(web_ui())).GetCloudPrintServiceDialogURL();
324 if (url.host() == dialog_url.host() && 326 if (url.host() == dialog_url.host() &&
325 url.path() == dialog_url.path() && 327 url.path() == dialog_url.path() &&
326 url.scheme() == dialog_url.scheme()) { 328 url.scheme() == dialog_url.scheme()) {
327 RenderViewHost* rvh = web_ui()->tab_contents()->GetRenderViewHost(); 329 RenderViewHost* rvh = web_ui()->web_contents()->GetRenderViewHost();
328 if (rvh && rvh->delegate()) { 330 if (rvh && rvh->delegate()) {
329 WebPreferences webkit_prefs = rvh->delegate()->GetWebkitPrefs(); 331 WebPreferences webkit_prefs = rvh->delegate()->GetWebkitPrefs();
330 webkit_prefs.allow_scripts_to_close_windows = true; 332 webkit_prefs.allow_scripts_to_close_windows = true;
331 rvh->UpdateWebkitPreferences(webkit_prefs); 333 rvh->UpdateWebkitPreferences(webkit_prefs);
332 } else { 334 } else {
333 DCHECK(false); 335 DCHECK(false);
334 } 336 }
335 } 337 }
336 338
337 // Choose one or the other. If you need to debug, bring up the 339 // Choose one or the other. If you need to debug, bring up the
338 // debugger. You can then use the various chrome.send() 340 // debugger. You can then use the various chrome.send()
339 // registrations above to kick of the various function calls, 341 // registrations above to kick of the various function calls,
340 // including chrome.send("SendPrintData") in the javaScript 342 // including chrome.send("SendPrintData") in the javaScript
341 // console and watch things happen with: 343 // console and watch things happen with:
342 // HandleShowDebugger(NULL); 344 // HandleShowDebugger(NULL);
343 HandleSendPrintData(NULL); 345 HandleSendPrintData(NULL);
344 } 346 }
345 } 347 }
346 348
347 void CloudPrintFlowHandler::HandleShowDebugger(const ListValue* args) { 349 void CloudPrintFlowHandler::HandleShowDebugger(const ListValue* args) {
348 ShowDebugger(); 350 ShowDebugger();
349 } 351 }
350 352
351 void CloudPrintFlowHandler::ShowDebugger() { 353 void CloudPrintFlowHandler::ShowDebugger() {
352 if (web_ui()) { 354 if (web_ui()) {
353 RenderViewHost* rvh = web_ui()->tab_contents()->GetRenderViewHost(); 355 RenderViewHost* rvh = web_ui()->web_contents()->GetRenderViewHost();
354 if (rvh) 356 if (rvh)
355 DevToolsWindow::OpenDevToolsWindow(rvh); 357 DevToolsWindow::OpenDevToolsWindow(rvh);
356 } 358 }
357 } 359 }
358 360
359 scoped_refptr<CloudPrintDataSender> 361 scoped_refptr<CloudPrintDataSender>
360 CloudPrintFlowHandler::CreateCloudPrintDataSender() { 362 CloudPrintFlowHandler::CreateCloudPrintDataSender() {
361 DCHECK(web_ui()); 363 DCHECK(web_ui());
362 print_data_helper_.reset(new CloudPrintDataSenderHelper(web_ui())); 364 print_data_helper_.reset(new CloudPrintDataSenderHelper(web_ui()));
363 return new CloudPrintDataSender(print_data_helper_.get(), 365 return new CloudPrintDataSender(print_data_helper_.get(),
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 } 423 }
422 424
423 // TODO(scottbyer) - Here is where we would kick the originating 425 // TODO(scottbyer) - Here is where we would kick the originating
424 // renderer thread with these new parameters in order to get it to 426 // renderer thread with these new parameters in order to get it to
425 // re-generate the PDF data and hand it back to us. window.print() is 427 // re-generate the PDF data and hand it back to us. window.print() is
426 // currently synchronous, so there's a lot of work to do to get to 428 // currently synchronous, so there's a lot of work to do to get to
427 // that point. 429 // that point.
428 } 430 }
429 431
430 void CloudPrintFlowHandler::StoreDialogClientSize() const { 432 void CloudPrintFlowHandler::StoreDialogClientSize() const {
431 if (web_ui() && web_ui()->tab_contents() && 433 if (web_ui() && web_ui()->web_contents() &&
432 web_ui()->tab_contents()->GetView()) { 434 web_ui()->web_contents()->GetView()) {
433 gfx::Size size = web_ui()->tab_contents()->GetView()->GetContainerSize(); 435 gfx::Size size = web_ui()->web_contents()->GetView()->GetContainerSize();
434 Profile* profile = Profile::FromWebUI(web_ui()); 436 Profile* profile = Profile::FromWebUI(web_ui());
435 profile->GetPrefs()->SetInteger(prefs::kCloudPrintDialogWidth, 437 profile->GetPrefs()->SetInteger(prefs::kCloudPrintDialogWidth,
436 size.width()); 438 size.width());
437 profile->GetPrefs()->SetInteger(prefs::kCloudPrintDialogHeight, 439 profile->GetPrefs()->SetInteger(prefs::kCloudPrintDialogHeight,
438 size.height()); 440 size.height());
439 } 441 }
440 } 442 }
441 443
442 CloudPrintHtmlDialogDelegate::CloudPrintHtmlDialogDelegate( 444 CloudPrintHtmlDialogDelegate::CloudPrintHtmlDialogDelegate(
443 const FilePath& path_to_file, 445 const FilePath& path_to_file,
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 bool modal, 595 bool modal,
594 bool delete_on_close) { 596 bool delete_on_close) {
595 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 597 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
596 Browser* browser = BrowserList::GetLastActive(); 598 Browser* browser = BrowserList::GetLastActive();
597 599
598 const int kDefaultWidth = 497; 600 const int kDefaultWidth = 497;
599 const int kDefaultHeight = 332; 601 const int kDefaultHeight = 332;
600 string16 job_title = print_job_title; 602 string16 job_title = print_job_title;
601 Profile* profile = NULL; 603 Profile* profile = NULL;
602 if (modal) { 604 if (modal) {
603 DCHECK(browser); 605 if (job_title.empty()) {
604 if (job_title.empty() && browser->GetSelectedTabContents()) 606 WebContents* web_contents =
605 job_title = browser->GetSelectedTabContents()->GetTitle(); 607 browser->GetSelectedTabContentsWrapper()->web_contents();
608 if (web_contents)
609 job_title = web_contents->GetTitle();
610 }
606 profile = browser->GetProfile(); 611 profile = browser->GetProfile();
607 } else { 612 } else {
608 std::vector<Profile*> loaded_profiles = 613 std::vector<Profile*> loaded_profiles =
609 g_browser_process->profile_manager()->GetLoadedProfiles(); 614 g_browser_process->profile_manager()->GetLoadedProfiles();
610 DCHECK_GT(loaded_profiles.size(), 0U); 615 DCHECK_GT(loaded_profiles.size(), 0U);
611 profile = loaded_profiles[0]; 616 profile = loaded_profiles[0];
612 } 617 }
613 DCHECK(profile); 618 DCHECK(profile);
614 PrefService* pref_service = profile->GetPrefs(); 619 PrefService* pref_service = profile->GetPrefs();
615 DCHECK(pref_service); 620 DCHECK(pref_service);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 file_type, 723 file_type,
719 false, 724 false,
720 delete_on_close); 725 delete_on_close);
721 return true; 726 return true;
722 } 727 }
723 } 728 }
724 return false; 729 return false;
725 } 730 }
726 731
727 } // end namespace 732 } // end namespace
OLDNEW
« no previous file with comments | « chrome/browser/printing/cloud_print/cloud_print_setup_flow.cc ('k') | chrome/browser/profiles/profile.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698