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

Unified Diff: chrome/browser/dom_ui/print_preview_ui.cc

Issue 6334010: Print Preview: Store preview data in the print preview handler.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/dom_ui/print_preview_ui.cc
===================================================================
--- chrome/browser/dom_ui/print_preview_ui.cc (revision 72691)
+++ chrome/browser/dom_ui/print_preview_ui.cc (working copy)
@@ -5,8 +5,11 @@
#include "chrome/browser/dom_ui/print_preview_ui.h"
#include <algorithm>
+#include <string>
+#include <vector>
#include "base/message_loop.h"
+#include "base/shared_memory.h"
#include "base/singleton.h"
#include "base/string_piece.h"
#include "base/values.h"
@@ -66,7 +69,7 @@
class PrintPreviewUIHTMLSource : public ChromeURLDataManager::DataSource {
public:
- PrintPreviewUIHTMLSource();
+ explicit PrintPreviewUIHTMLSource(PrintPreviewHandler* handler);
virtual ~PrintPreviewUIHTMLSource();
// Called when the network layer has requested a resource underneath
@@ -77,11 +80,14 @@
virtual std::string GetMimeType(const std::string&) const;
private:
+ PrintPreviewHandler* handler_;
+
DISALLOW_COPY_AND_ASSIGN(PrintPreviewUIHTMLSource);
};
-PrintPreviewUIHTMLSource::PrintPreviewUIHTMLSource()
- : DataSource(chrome::kChromeUIPrintHost, MessageLoop::current()) {
+PrintPreviewUIHTMLSource::PrintPreviewUIHTMLSource(PrintPreviewHandler* handler)
James Hawkins 2011/01/31 18:39:38 After reading through the flow, it seems the best
+ : DataSource(chrome::kChromeUIPrintHost, MessageLoop::current()),
+ handler_(handler) {
}
PrintPreviewUIHTMLSource::~PrintPreviewUIHTMLSource() {}
@@ -89,8 +95,8 @@
void PrintPreviewUIHTMLSource::StartDataRequest(const std::string& path,
bool is_off_the_record,
int request_id) {
- // Print Preview Index page.
if (path.empty()) {
+ // Print Preview Index page.
DictionaryValue localized_strings;
SetLocalizedStrings(&localized_strings);
SetFontAndTextDirection(&localized_strings);
@@ -107,12 +113,27 @@
SendResponse(request_id, html_bytes);
return;
+ } else if (path == "print.pdf") {
+ // Print Preview data.
+ PrintPreviewHandler::PrintPreviewData data;
+ handler_->GetPrintPreviewData(&data);
+
+ uint32 preview_data_size = data.second;
+ char* preview_data = reinterpret_cast<char*>(data.first->memory());
+
+ scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes);
+ html_bytes->data.resize(preview_data_size);
+ std::vector<unsigned char>::iterator it = html_bytes->data.begin();
+ for (uint32 i = 0; i < preview_data_size; ++i, ++it)
+ *it = *(preview_data + i);
+ SendResponse(request_id, html_bytes);
+ return;
+ } else {
+ // Invalid request.
+ scoped_refptr<RefCountedBytes> empty_bytes(new RefCountedBytes);
+ SendResponse(request_id, empty_bytes);
+ return;
}
-
- // Print Preview data.
- NOTIMPLEMENTED() << "No PDF for you";
- scoped_refptr<RefCountedBytes> data_bytes(new RefCountedBytes);
- SendResponse(request_id, data_bytes);
}
std::string PrintPreviewUIHTMLSource::GetMimeType(
@@ -132,8 +153,8 @@
PrintPreviewUI::PrintPreviewUI(TabContents* contents) : DOMUI(contents) {
// PrintPreviewUI owns |handler|.
- PrintPreviewHandler* handler = new PrintPreviewHandler();
- AddMessageHandler(handler->Attach(this));
+ handler_ = new PrintPreviewHandler();
+ AddMessageHandler(handler_->Attach(this));
// Set up the chrome://print/ source.
BrowserThread::PostTask(
@@ -141,8 +162,12 @@
NewRunnableMethod(
ChromeURLDataManager::GetInstance(),
&ChromeURLDataManager::AddDataSource,
- make_scoped_refptr(new PrintPreviewUIHTMLSource())));
+ make_scoped_refptr(new PrintPreviewUIHTMLSource(handler_))));
}
PrintPreviewUI::~PrintPreviewUI() {
}
+
+PrintPreviewHandler* PrintPreviewUI::handler() {
+ return handler_;
+}

Powered by Google App Engine
This is Rietveld 408576698