| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/renderer/plugins/pdf_plugin_placeholder.h" | 5 #include "chrome/renderer/plugins/pdf_plugin_placeholder.h" |
| 6 | 6 |
| 7 #include "chrome/common/render_messages.h" |
| 7 #include "chrome/grit/renderer_resources.h" | 8 #include "chrome/grit/renderer_resources.h" |
| 9 #include "content/public/renderer/render_thread.h" |
| 8 #include "gin/object_template_builder.h" | 10 #include "gin/object_template_builder.h" |
| 9 #include "ui/base/resource/resource_bundle.h" | 11 #include "ui/base/resource/resource_bundle.h" |
| 10 #include "ui/base/webui/jstemplate_builder.h" | 12 #include "ui/base/webui/jstemplate_builder.h" |
| 11 | 13 |
| 12 gin::WrapperInfo PDFPluginPlaceholder::kWrapperInfo = {gin::kEmbedderNativeGin}; | 14 gin::WrapperInfo PDFPluginPlaceholder::kWrapperInfo = {gin::kEmbedderNativeGin}; |
| 13 | 15 |
| 14 PDFPluginPlaceholder::PDFPluginPlaceholder(content::RenderFrame* render_frame, | 16 PDFPluginPlaceholder::PDFPluginPlaceholder(content::RenderFrame* render_frame, |
| 15 const blink::WebPluginParams& params, | 17 const blink::WebPluginParams& params, |
| 16 const std::string& html_data) | 18 const std::string& html_data) |
| 17 : plugins::PluginPlaceholderBase(render_frame, params, html_data) {} | 19 : plugins::PluginPlaceholderBase(render_frame, params, html_data) {} |
| 18 | 20 |
| 19 PDFPluginPlaceholder::~PDFPluginPlaceholder() {} | 21 PDFPluginPlaceholder::~PDFPluginPlaceholder() {} |
| 20 | 22 |
| 21 PDFPluginPlaceholder* PDFPluginPlaceholder::CreatePDFPlaceholder( | 23 PDFPluginPlaceholder* PDFPluginPlaceholder::CreatePDFPlaceholder( |
| 22 content::RenderFrame* render_frame, | 24 content::RenderFrame* render_frame, |
| 23 const blink::WebPluginParams& params) { | 25 const blink::WebPluginParams& params) { |
| 24 const base::StringPiece template_html( | 26 const base::StringPiece template_html( |
| 25 ResourceBundle::GetSharedInstance().GetRawDataResource( | 27 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 26 IDR_PDF_PLUGIN_HTML)); | 28 IDR_PDF_PLUGIN_HTML)); |
| 27 base::DictionaryValue values; | 29 base::DictionaryValue values; |
| 30 values.SetString("fileName", GURL(params.url).ExtractFileName()); |
| 28 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values); | 31 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values); |
| 29 return new PDFPluginPlaceholder(render_frame, params, html_data); | 32 return new PDFPluginPlaceholder(render_frame, params, html_data); |
| 30 } | 33 } |
| 31 | 34 |
| 32 v8::Local<v8::Value> PDFPluginPlaceholder::GetV8Handle(v8::Isolate* isolate) { | 35 v8::Local<v8::Value> PDFPluginPlaceholder::GetV8Handle(v8::Isolate* isolate) { |
| 33 return gin::CreateHandle(isolate, this).ToV8(); | 36 return gin::CreateHandle(isolate, this).ToV8(); |
| 34 } | 37 } |
| 35 | 38 |
| 36 gin::ObjectTemplateBuilder PDFPluginPlaceholder::GetObjectTemplateBuilder( | 39 gin::ObjectTemplateBuilder PDFPluginPlaceholder::GetObjectTemplateBuilder( |
| 37 v8::Isolate* isolate) { | 40 v8::Isolate* isolate) { |
| 38 return gin::Wrappable<PDFPluginPlaceholder>::GetObjectTemplateBuilder(isolate) | 41 return gin::Wrappable<PDFPluginPlaceholder>::GetObjectTemplateBuilder(isolate) |
| 39 .SetMethod<void (PDFPluginPlaceholder::*)()>( | 42 .SetMethod<void (PDFPluginPlaceholder::*)()>( |
| 40 "downloadPDF", &PDFPluginPlaceholder::DownloadPDFCallback); | 43 "downloadPDF", &PDFPluginPlaceholder::DownloadPDFCallback); |
| 41 } | 44 } |
| 42 | 45 |
| 43 void PDFPluginPlaceholder::DownloadPDFCallback() { | 46 void PDFPluginPlaceholder::DownloadPDFCallback() { |
| 44 // TODO(amberwon): Implement starting PDF download. | 47 content::RenderThread::Get()->Send( |
| 48 new ChromeViewHostMsg_DownloadPDF(routing_id(), GetPluginParams().url)); |
| 45 } | 49 } |
| OLD | NEW |