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

Side by Side Diff: chrome/browser/ui/webui/print_preview_ui.cc

Issue 8872051: Print preview: Display a dummy page when a user visits chrome://print directly. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years 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/ui/webui/print_preview_ui.h" 5 #include "chrome/browser/ui/webui/print_preview_ui.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/synchronization/lock.h" 12 #include "base/synchronization/lock.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/printing/background_printing_manager.h" 15 #include "chrome/browser/printing/background_printing_manager.h"
16 #include "chrome/browser/printing/print_preview_data_service.h" 16 #include "chrome/browser/printing/print_preview_data_service.h"
17 #include "chrome/browser/printing/print_preview_tab_controller.h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
19 #include "chrome/browser/ui/webui/html_dialog_ui.h" 20 #include "chrome/browser/ui/webui/html_dialog_ui.h"
20 #include "chrome/browser/ui/webui/print_preview_data_source.h" 21 #include "chrome/browser/ui/webui/print_preview_data_source.h"
21 #include "chrome/browser/ui/webui/print_preview_handler.h" 22 #include "chrome/browser/ui/webui/print_preview_handler.h"
22 #include "chrome/common/print_messages.h" 23 #include "chrome/common/print_messages.h"
23 #include "content/browser/tab_contents/tab_contents.h" 24 #include "content/browser/tab_contents/tab_contents.h"
24 #include "printing/page_size_margins.h" 25 #include "printing/page_size_margins.h"
25 #include "printing/print_job_constants.h" 26 #include "printing/print_job_constants.h"
26 27
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 // Written to on the UI thread, read from any thread. 68 // Written to on the UI thread, read from any thread.
68 base::LazyInstance<PrintPreviewRequestIdMapWithLock> 69 base::LazyInstance<PrintPreviewRequestIdMapWithLock>
69 g_print_preview_request_id_map = LAZY_INSTANCE_INITIALIZER; 70 g_print_preview_request_id_map = LAZY_INSTANCE_INITIALIZER;
70 71
71 } // namespace 72 } // namespace
72 73
73 PrintPreviewUI::PrintPreviewUI(TabContents* contents) 74 PrintPreviewUI::PrintPreviewUI(TabContents* contents)
74 : ConstrainedHtmlUI(contents), 75 : ConstrainedHtmlUI(contents),
75 initial_preview_start_time_(base::TimeTicks::Now()), 76 initial_preview_start_time_(base::TimeTicks::Now()),
76 source_is_modifiable_(true), 77 source_is_modifiable_(true),
77 tab_closed_(false) { 78 tab_closed_(false),
79 is_dummy_(false) {
80 printing::PrintPreviewTabController* controller =
81 printing::PrintPreviewTabController::GetInstance();
82 if (!controller || !controller->is_creating_print_preview_tab())
83 is_dummy_ = true;
84
85 // Set up the chrome://print/ data source.
86 Profile* profile = Profile::FromBrowserContext(contents->browser_context());
87 profile->GetChromeURLDataManager()->AddDataSource(
88 new PrintPreviewDataSource(is_dummy_));
89 if (is_dummy_)
90 return;
91
78 // WebUI owns |handler_|. 92 // WebUI owns |handler_|.
79 handler_ = new PrintPreviewHandler(); 93 handler_ = new PrintPreviewHandler();
80 AddMessageHandler(handler_->Attach(this)); 94 AddMessageHandler(handler_->Attach(this));
81 95
82 // Set up the chrome://print/ data source.
83 Profile* profile = Profile::FromBrowserContext(contents->browser_context());
84 profile->GetChromeURLDataManager()->AddDataSource(
85 new PrintPreviewDataSource());
86
87 preview_ui_addr_str_ = GetPrintPreviewUIAddress(); 96 preview_ui_addr_str_ = GetPrintPreviewUIAddress();
88
89 g_print_preview_request_id_map.Get().Set(preview_ui_addr_str_, -1); 97 g_print_preview_request_id_map.Get().Set(preview_ui_addr_str_, -1);
90 } 98 }
91 99
92 PrintPreviewUI::~PrintPreviewUI() { 100 PrintPreviewUI::~PrintPreviewUI() {
101 if (is_dummy_)
102 return;
103
93 print_preview_data_service()->RemoveEntry(preview_ui_addr_str_); 104 print_preview_data_service()->RemoveEntry(preview_ui_addr_str_);
94
95 g_print_preview_request_id_map.Get().Erase(preview_ui_addr_str_); 105 g_print_preview_request_id_map.Get().Erase(preview_ui_addr_str_);
96 } 106 }
97 107
98 void PrintPreviewUI::GetPrintPreviewDataForIndex( 108 void PrintPreviewUI::GetPrintPreviewDataForIndex(
99 int index, 109 int index,
100 scoped_refptr<RefCountedBytes>* data) { 110 scoped_refptr<RefCountedBytes>* data) {
101 print_preview_data_service()->GetDataEntry(preview_ui_addr_str_, index, data); 111 print_preview_data_service()->GetDataEntry(preview_ui_addr_str_, index, data);
102 } 112 }
103 113
104 void PrintPreviewUI::SetPrintPreviewDataForIndex(int index, 114 void PrintPreviewUI::SetPrintPreviewDataForIndex(int index,
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate(); 303 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate();
294 if (!delegate) 304 if (!delegate)
295 return; 305 return;
296 delegate->GetHtmlDialogUIDelegate()->OnDialogClosed(""); 306 delegate->GetHtmlDialogUIDelegate()->OnDialogClosed("");
297 delegate->OnDialogCloseFromWebUI(); 307 delegate->OnDialogCloseFromWebUI();
298 } 308 }
299 309
300 void PrintPreviewUI::OnReloadPrintersList() { 310 void PrintPreviewUI::OnReloadPrintersList() {
301 CallJavascriptFunction("reloadPrintersList"); 311 CallJavascriptFunction("reloadPrintersList");
302 } 312 }
OLDNEW
« chrome/browser/ui/webui/print_preview_ui.h ('K') | « chrome/browser/ui/webui/print_preview_ui.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698