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

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

Issue 7063030: PrintPreview: Print Preview is not staying associated with initiator renderer. (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_factory.h"
14 #include "chrome/browser/printing/print_preview_data_service.h"
15 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/common/jstemplate_builder.h" 16 #include "chrome/common/jstemplate_builder.h"
16 #include "chrome/common/url_constants.h" 17 #include "chrome/common/url_constants.h"
17 #include "grit/browser_resources.h" 18 #include "grit/browser_resources.h"
18 #include "grit/chromium_strings.h" 19 #include "grit/chromium_strings.h"
19 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
20 #include "grit/google_chrome_strings.h" 21 #include "grit/google_chrome_strings.h"
21 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/base/resource/resource_bundle.h" 23 #include "ui/base/resource/resource_bundle.h"
23 24
24 namespace { 25 namespace {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 localized_strings->SetString(std::string("pageRangeInstruction"), 102 localized_strings->SetString(std::string("pageRangeInstruction"),
102 l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_PAGE_RANGE_INSTRUCTION)); 103 l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_PAGE_RANGE_INSTRUCTION));
103 localized_strings->SetString(std::string("copiesInstruction"), 104 localized_strings->SetString(std::string("copiesInstruction"),
104 l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_COPIES_INSTRUCTION)); 105 l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_COPIES_INSTRUCTION));
105 localized_strings->SetString(std::string("managePrinters"), 106 localized_strings->SetString(std::string("managePrinters"),
106 l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_MANAGE_PRINTERS)); 107 l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_MANAGE_PRINTERS));
107 } 108 }
108 109
109 } // namespace 110 } // namespace
110 111
111 PrintPreviewUIHTMLSource::PrintPreviewUIHTMLSource() 112 PrintPreviewDataSource::PrintPreviewDataSource(Profile* profile)
112 : DataSource(chrome::kChromeUIPrintHost, MessageLoop::current()), 113 : DataSource(chrome::kChromeUIPrintHost, MessageLoop::current()),
113 data_(std::make_pair(static_cast<base::SharedMemory*>(NULL), 0U)) { 114 profile_(profile) {
114 } 115 }
115 116
116 PrintPreviewUIHTMLSource::~PrintPreviewUIHTMLSource() { 117 PrintPreviewDataSource::~PrintPreviewDataSource() {
117 delete data_.first;
118 } 118 }
119 119
120 void PrintPreviewUIHTMLSource::GetPrintPreviewData(PrintPreviewData* data) { 120 void PrintPreviewDataSource::StartDataRequest(const std::string& path,
121 *data = data_; 121 bool is_incognito,
122 } 122 int request_id) {
123 scoped_refptr<RefCountedBytes> data(new RefCountedBytes);
124 size_t index = path.find("/print.pdf");
123 125
124 void PrintPreviewUIHTMLSource::SetPrintPreviewData( 126 bool preview_data_requested = index != std::string::npos;
125 const PrintPreviewData& data) { 127 if (preview_data_requested) {
126 delete data_.first; 128 PrintPreviewDataServiceFactory::GetForProfile(profile_)->
127 data_ = data; 129 GetDataEntry(path.substr(0, index), &data);
128 } 130 }
129 131
130 void PrintPreviewUIHTMLSource::StartDataRequest(const std::string& path,
131 bool is_incognito,
132 int request_id) {
133 if (path.empty()) { 132 if (path.empty()) {
134 // Print Preview Index page. 133 // Print Preview Index page.
135 DictionaryValue localized_strings; 134 DictionaryValue localized_strings;
136 SetLocalizedStrings(&localized_strings); 135 SetLocalizedStrings(&localized_strings);
137 SetFontAndTextDirection(&localized_strings); 136 SetFontAndTextDirection(&localized_strings);
138 137
139 static const base::StringPiece print_html( 138 static const base::StringPiece print_html(
140 ResourceBundle::GetSharedInstance().GetRawDataResource( 139 ResourceBundle::GetSharedInstance().GetRawDataResource(
141 IDR_PRINT_PREVIEW_HTML)); 140 IDR_PRINT_PREVIEW_HTML));
142 const std::string full_html = jstemplate_builder::GetI18nTemplateHtml( 141 const std::string full_html = jstemplate_builder::GetI18nTemplateHtml(
143 print_html, &localized_strings); 142 print_html, &localized_strings);
144 143
145 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); 144 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes);
146 html_bytes->data.resize(full_html.size()); 145 html_bytes->data.resize(full_html.size());
147 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); 146 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin());
148 147
149 SendResponse(request_id, html_bytes); 148 SendResponse(request_id, html_bytes);
150 return; 149 return;
151 } else if (path == "print.pdf" && data_.first) { 150 } else if (preview_data_requested && data->front()) {
152 // Print Preview data. 151 // Print Preview data.
153 char* preview_data = reinterpret_cast<char*>(data_.first->memory()); 152 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; 153 return;
163 } else { 154 } else {
164 // Invalid request. 155 // Invalid request.
165 scoped_refptr<RefCountedBytes> empty_bytes(new RefCountedBytes); 156 scoped_refptr<RefCountedBytes> empty_bytes(new RefCountedBytes);
166 SendResponse(request_id, empty_bytes); 157 SendResponse(request_id, empty_bytes);
167 return; 158 return;
168 } 159 }
169 } 160 }
170 161
171 std::string PrintPreviewUIHTMLSource::GetMimeType( 162 std::string PrintPreviewDataSource::GetMimeType(const std::string& path) const {
172 const std::string& path) const {
173 // Print Preview Index page.
174 if (path.empty()) 163 if (path.empty())
175 return "text/html"; 164 return "text/html"; // Print Preview Index Page.
176 // Print Preview data. 165 return "application/pdf"; // Print Preview data
177 return "application/pdf";
178 } 166 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698