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

Unified Diff: extensions/browser/api/printer_provider_internal/printer_provider_internal_api.cc

Issue 973993003: Instead of ArrayBuffer, pass blob with printerProvider.onPrintRequested (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase & add ext fun histogram Created 5 years, 10 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: extensions/browser/api/printer_provider_internal/printer_provider_internal_api.cc
diff --git a/extensions/browser/api/printer_provider_internal/printer_provider_internal_api.cc b/extensions/browser/api/printer_provider_internal/printer_provider_internal_api.cc
index e8879659d2a49b1fd64737c70868739221991123..8914616fb8bf720a66ec0cd0dfbebb8017f2597a 100644
--- a/extensions/browser/api/printer_provider_internal/printer_provider_internal_api.cc
+++ b/extensions/browser/api/printer_provider_internal/printer_provider_internal_api.cc
@@ -4,8 +4,26 @@
#include "extensions/browser/api/printer_provider_internal/printer_provider_internal_api.h"
+#include <string>
+#include <vector>
+
+#include "base/bind.h"
+#include "base/guid.h"
#include "base/lazy_instance.h"
+#include "base/location.h"
+#include "base/memory/ref_counted_memory.h"
+#include "base/memory/scoped_ptr.h"
#include "base/values.h"
+#include "content/public/browser/blob_handle.h"
+#include "content/public/browser/browser_context.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/web_contents.h"
+#include "extensions/browser/api/printer_provider/printer_provider_api.h"
+#include "extensions/browser/api/printer_provider/printer_provider_api_factory.h"
+#include "extensions/browser/api/printer_provider/printer_provider_print_job.h"
+#include "extensions/browser/blob_holder.h"
#include "extensions/common/api/printer_provider.h"
#include "extensions/common/api/printer_provider_internal.h"
@@ -146,4 +164,78 @@ PrinterProviderInternalReportPrintersFunction::Run() {
return RespondNow(NoArguments());
}
+PrinterProviderInternalGetPrintDataFunction::
+ PrinterProviderInternalGetPrintDataFunction() {
+}
+
+PrinterProviderInternalGetPrintDataFunction::
+ ~PrinterProviderInternalGetPrintDataFunction() {
+}
+
+ExtensionFunction::ResponseAction
+PrinterProviderInternalGetPrintDataFunction::Run() {
+ scoped_ptr<internal_api::GetPrintData::Params> params(
+ internal_api::GetPrintData::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+
+ const PrinterProviderPrintJob* job =
+ PrinterProviderAPIFactory::GetInstance()
+ ->GetForBrowserContext(browser_context())
+ ->GetPrintJob(extension(), params->request_id);
+ if (!job)
+ return RespondNow(Error("Print request not found."));
+
+ if (job->document_bytes.get()) {
+ // |job->document_bytes| are passed to the callback to make sure the ref
+ // counted memory does not go away before the memory backed blob is created.
+ content::BrowserContext::CreateMemoryBackedBlob(
+ browser_context(), job->document_bytes->front_as<char>(),
+ job->document_bytes->size(),
+ base::Bind(&PrinterProviderInternalGetPrintDataFunction::OnBlob, this,
+ job->content_type, job->document_bytes->size(),
+ job->document_bytes));
+ } else if (!job->document_path.empty()) {
+ content::BrowserContext::CreateFileBackedBlob(
+ browser_context(), job->document_path, 0 /* offset */,
+ job->file_info.size, job->file_info.last_modified,
+ base::Bind(&PrinterProviderInternalGetPrintDataFunction::OnBlob, this,
+ job->content_type, job->file_info.size,
+ scoped_refptr<base::RefCountedMemory>()));
+ } else {
+ return RespondNow(Error("Job data not set"));
+ }
+ return RespondLater();
+}
+
+void PrinterProviderInternalGetPrintDataFunction::OnBlob(
+ const std::string& type,
+ int size,
+ const scoped_refptr<base::RefCountedMemory>& data,
+ scoped_ptr<content::BlobHandle> blob) {
+ if (!blob) {
+ SetError("Unable to create the blob.");
+ SendResponse(false);
+ return;
+ }
+
+ internal_api::BlobInfo info;
+ info.blob_uuid = blob->GetUUID();
+ info.type = type;
+ info.size = size;
+
+ std::vector<std::string> uuids;
+ uuids.push_back(blob->GetUUID());
+
+ content::WebContents* contents =
+ content::WebContents::FromRenderViewHost(render_view_host());
+ extensions::BlobHolder* holder =
+ extensions::BlobHolder::FromRenderProcessHost(
+ contents->GetRenderProcessHost());
+ holder->HoldBlobReference(blob.Pass());
+
+ results_ = internal_api::GetPrintData::Results::Create(info);
+ SetTransferredBlobUUIDs(uuids);
+ SendResponse(true);
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698