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

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

Issue 7082032: Preview tab data source. (Sample CL) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 9 years, 6 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/ui/webui/print_preview_ui_html_source.h" 5 #include "chrome/browser/ui/webui/print_preview_data_source.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector>
9 8
10 #include "base/message_loop.h" 9 #include "base/message_loop.h"
11 #include "base/shared_memory.h"
12 #include "base/string_piece.h" 10 #include "base/string_piece.h"
13 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
14 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/printing/print_preview_data_service.h"
15 #include "chrome/common/jstemplate_builder.h" 14 #include "chrome/common/jstemplate_builder.h"
16 #include "chrome/common/url_constants.h" 15 #include "chrome/common/url_constants.h"
17 #include "grit/browser_resources.h" 16 #include "grit/browser_resources.h"
18 #include "grit/chromium_strings.h" 17 #include "grit/chromium_strings.h"
19 #include "grit/generated_resources.h" 18 #include "grit/generated_resources.h"
20 #include "grit/google_chrome_strings.h" 19 #include "grit/google_chrome_strings.h"
21 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/base/resource/resource_bundle.h" 21 #include "ui/base/resource/resource_bundle.h"
23 22
24 namespace { 23 namespace {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 localized_strings->SetString(std::string("pageRangeInstruction"), 100 localized_strings->SetString(std::string("pageRangeInstruction"),
102 l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_PAGE_RANGE_INSTRUCTION)); 101 l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_PAGE_RANGE_INSTRUCTION));
103 localized_strings->SetString(std::string("copiesInstruction"), 102 localized_strings->SetString(std::string("copiesInstruction"),
104 l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_COPIES_INSTRUCTION)); 103 l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_COPIES_INSTRUCTION));
105 localized_strings->SetString(std::string("managePrinters"), 104 localized_strings->SetString(std::string("managePrinters"),
106 l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_MANAGE_PRINTERS)); 105 l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_MANAGE_PRINTERS));
107 } 106 }
108 107
109 } // namespace 108 } // namespace
110 109
111 PrintPreviewUIHTMLSource::PrintPreviewUIHTMLSource() 110 PrintPreviewDataSource::PrintPreviewDataSource(PrintPreviewUI* preview_ui)
112 : DataSource(chrome::kChromeUIPrintHost, MessageLoop::current()), 111 : DataSource(chrome::kChromeUIPrintHost, MessageLoop::current()),
113 data_(std::make_pair(static_cast<base::SharedMemory*>(NULL), 0U)) { 112 preview_ui_(preview_ui) {
113 printf("data source: %p\n", preview_ui_);
114 } 114 }
115 115
116 PrintPreviewUIHTMLSource::~PrintPreviewUIHTMLSource() { 116 PrintPreviewDataSource::~PrintPreviewDataSource() {
117 delete data_.first;
118 } 117 }
119 118
120 void PrintPreviewUIHTMLSource::GetPrintPreviewData(PrintPreviewData* data) { 119 void PrintPreviewDataSource::StartDataRequest(const std::string& path,
121 *data = data_; 120 bool is_incognito,
122 } 121 int request_id) {
122 scoped_refptr<RefCountedBytes> data(new RefCountedBytes);
123 123
124 void PrintPreviewUIHTMLSource::SetPrintPreviewData( 124 if (path == "print.pdf") {
125 const PrintPreviewData& data) { 125 PrintPreviewDataService::GetInstance()->GetDataEntry(preview_ui_,
126 delete data_.first; 126 &data);
127 data_ = data; 127 }
128 }
129 128
130 void PrintPreviewUIHTMLSource::StartDataRequest(const std::string& path,
131 bool is_incognito,
132 int request_id) {
133 if (path.empty()) { 129 if (path.empty()) {
134 // Print Preview Index page. 130 // Print Preview Index page.
135 DictionaryValue localized_strings; 131 DictionaryValue localized_strings;
136 SetLocalizedStrings(&localized_strings); 132 SetLocalizedStrings(&localized_strings);
137 SetFontAndTextDirection(&localized_strings); 133 SetFontAndTextDirection(&localized_strings);
138 134
139 static const base::StringPiece print_html( 135 static const base::StringPiece print_html(
140 ResourceBundle::GetSharedInstance().GetRawDataResource( 136 ResourceBundle::GetSharedInstance().GetRawDataResource(
141 IDR_PRINT_PREVIEW_HTML)); 137 IDR_PRINT_PREVIEW_HTML));
142 const std::string full_html = jstemplate_builder::GetI18nTemplateHtml( 138 const std::string full_html = jstemplate_builder::GetI18nTemplateHtml(
143 print_html, &localized_strings); 139 print_html, &localized_strings);
144 140
145 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); 141 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes);
146 html_bytes->data.resize(full_html.size()); 142 html_bytes->data.resize(full_html.size());
147 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); 143 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin());
148 144
149 SendResponse(request_id, html_bytes); 145 SendResponse(request_id, html_bytes);
150 return; 146 return;
151 } else if (path == "print.pdf" && data_.first) { 147 } else if (path == "print.pdf" && data->front()) {
152 // Print Preview data. 148 // Print Preview data.
153 char* preview_data = reinterpret_cast<char*>(data_.first->memory()); 149 SendResponse(request_id, data);
154 uint32 preview_data_size = data_.second;
155
156 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes);
157 html_bytes->data.resize(preview_data_size);
158 std::vector<unsigned char>::iterator it = html_bytes->data.begin();
159 for (uint32 i = 0; i < preview_data_size; ++i, ++it)
160 *it = *(preview_data + i);
161 SendResponse(request_id, html_bytes);
162 return; 150 return;
163 } else { 151 } else {
164 // Invalid request. 152 // Invalid request.
165 scoped_refptr<RefCountedBytes> empty_bytes(new RefCountedBytes); 153 scoped_refptr<RefCountedBytes> empty_bytes(new RefCountedBytes);
166 SendResponse(request_id, empty_bytes); 154 SendResponse(request_id, empty_bytes);
167 return; 155 return;
168 } 156 }
169 } 157 }
170 158
171 std::string PrintPreviewUIHTMLSource::GetMimeType( 159 std::string PrintPreviewDataSource::GetMimeType(const std::string& path) const {
172 const std::string& path) const {
173 // Print Preview Index page.
174 if (path.empty()) 160 if (path.empty())
175 return "text/html"; 161 return "text/html"; // Print Preview Index Page.
176 // Print Preview data. 162 return "application/pdf"; // Print Preview data
177 return "application/pdf";
178 } 163 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/print_preview_data_source.h ('k') | chrome/browser/ui/webui/print_preview_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698