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

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
« no previous file with comments | « chrome/browser/ui/webui/print_preview_ui.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 67
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()),
77 handler_(NULL),
76 source_is_modifiable_(true), 78 source_is_modifiable_(true),
77 tab_closed_(false) { 79 tab_closed_(false) {
80 printing::PrintPreviewTabController* controller =
81 printing::PrintPreviewTabController::GetInstance();
82 is_dummy_ = (!controller || !controller->is_creating_print_preview_tab());
83
84 // Set up the chrome://print/ data source.
85 Profile* profile = Profile::FromBrowserContext(contents->browser_context());
86 profile->GetChromeURLDataManager()->AddDataSource(
87 new PrintPreviewDataSource(is_dummy_));
88 if (is_dummy_)
89 return;
90
78 // WebUI owns |handler_|. 91 // WebUI owns |handler_|.
79 handler_ = new PrintPreviewHandler(); 92 handler_ = new PrintPreviewHandler();
80 AddMessageHandler(handler_->Attach(this)); 93 AddMessageHandler(handler_->Attach(this));
81 94
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(); 95 preview_ui_addr_str_ = GetPrintPreviewUIAddress();
88
89 g_print_preview_request_id_map.Get().Set(preview_ui_addr_str_, -1); 96 g_print_preview_request_id_map.Get().Set(preview_ui_addr_str_, -1);
90 } 97 }
91 98
92 PrintPreviewUI::~PrintPreviewUI() { 99 PrintPreviewUI::~PrintPreviewUI() {
100 if (is_dummy_)
101 return;
102
93 print_preview_data_service()->RemoveEntry(preview_ui_addr_str_); 103 print_preview_data_service()->RemoveEntry(preview_ui_addr_str_);
94
95 g_print_preview_request_id_map.Get().Erase(preview_ui_addr_str_); 104 g_print_preview_request_id_map.Get().Erase(preview_ui_addr_str_);
96 } 105 }
97 106
98 void PrintPreviewUI::GetPrintPreviewDataForIndex( 107 void PrintPreviewUI::GetPrintPreviewDataForIndex(
99 int index, 108 int index,
100 scoped_refptr<RefCountedBytes>* data) { 109 scoped_refptr<RefCountedBytes>* data) {
101 print_preview_data_service()->GetDataEntry(preview_ui_addr_str_, index, data); 110 print_preview_data_service()->GetDataEntry(preview_ui_addr_str_, index, data);
102 } 111 }
103 112
104 void PrintPreviewUI::SetPrintPreviewDataForIndex(int index, 113 void PrintPreviewUI::SetPrintPreviewDataForIndex(int index,
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate(); 302 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate();
294 if (!delegate) 303 if (!delegate)
295 return; 304 return;
296 delegate->GetHtmlDialogUIDelegate()->OnDialogClosed(""); 305 delegate->GetHtmlDialogUIDelegate()->OnDialogClosed("");
297 delegate->OnDialogCloseFromWebUI(); 306 delegate->OnDialogCloseFromWebUI();
298 } 307 }
299 308
300 void PrintPreviewUI::OnReloadPrintersList() { 309 void PrintPreviewUI::OnReloadPrintersList() {
301 CallJavascriptFunction("reloadPrintersList"); 310 CallJavascriptFunction("reloadPrintersList");
302 } 311 }
OLDNEW
« no previous file with comments | « 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