| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/pdf/renderer/pepper_pdf_host.h" | 5 #include "components/pdf/renderer/pepper_pdf_host.h" |
| 6 | 6 |
| 7 #include "components/pdf/common/pdf_messages.h" | 7 #include "components/pdf/common/pdf_messages.h" |
| 8 #include "components/strings/grit/components_strings.h" | |
| 9 #include "content/public/common/referrer.h" | 8 #include "content/public/common/referrer.h" |
| 10 #include "content/public/renderer/pepper_plugin_instance.h" | 9 #include "content/public/renderer/pepper_plugin_instance.h" |
| 11 #include "content/public/renderer/render_thread.h" | 10 #include "content/public/renderer/render_thread.h" |
| 12 #include "content/public/renderer/render_view.h" | 11 #include "content/public/renderer/render_view.h" |
| 13 #include "content/public/renderer/renderer_ppapi_host.h" | 12 #include "content/public/renderer/renderer_ppapi_host.h" |
| 14 #include "ppapi/host/dispatch_host_message.h" | 13 #include "ppapi/host/dispatch_host_message.h" |
| 15 #include "ppapi/host/host_message_context.h" | 14 #include "ppapi/host/host_message_context.h" |
| 16 #include "ppapi/host/ppapi_host.h" | 15 #include "ppapi/host/ppapi_host.h" |
| 17 #include "ppapi/proxy/host_dispatcher.h" | 16 #include "ppapi/proxy/host_dispatcher.h" |
| 18 #include "ppapi/proxy/ppapi_messages.h" | 17 #include "ppapi/proxy/ppapi_messages.h" |
| 19 #include "ppapi/proxy/ppb_image_data_proxy.h" | 18 #include "ppapi/proxy/ppb_image_data_proxy.h" |
| 20 #include "ppapi/shared_impl/ppb_image_data_shared.h" | 19 #include "ppapi/shared_impl/ppb_image_data_shared.h" |
| 21 #include "ppapi/shared_impl/scoped_pp_resource.h" | 20 #include "ppapi/shared_impl/scoped_pp_resource.h" |
| 22 #include "ppapi/thunk/enter.h" | 21 #include "ppapi/thunk/enter.h" |
| 23 #include "ppapi/thunk/ppb_image_data_api.h" | 22 #include "ppapi/thunk/ppb_image_data_api.h" |
| 24 #include "third_party/WebKit/public/web/WebDocument.h" | 23 #include "third_party/WebKit/public/web/WebDocument.h" |
| 25 #include "third_party/WebKit/public/web/WebElement.h" | 24 #include "third_party/WebKit/public/web/WebElement.h" |
| 26 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 25 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 27 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 26 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
| 28 #include "third_party/WebKit/public/web/WebView.h" | 27 #include "third_party/WebKit/public/web/WebView.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | |
| 30 #include "ui/base/layout.h" | |
| 31 #include "ui/base/resource/resource_bundle.h" | |
| 32 #include "ui/gfx/geometry/point.h" | |
| 33 | 28 |
| 34 namespace pdf { | 29 namespace pdf { |
| 35 | 30 |
| 36 namespace { | 31 namespace { |
| 37 // --single-process model may fail in CHECK(!g_print_client) if there exist | 32 // --single-process model may fail in CHECK(!g_print_client) if there exist |
| 38 // more than two RenderThreads, so here we use TLS for g_print_client. | 33 // more than two RenderThreads, so here we use TLS for g_print_client. |
| 39 // See http://crbug.com/457580. | 34 // See http://crbug.com/457580. |
| 40 base::LazyInstance<base::ThreadLocalPointer<PepperPDFHost::PrintClient>>::Leaky | 35 base::LazyInstance<base::ThreadLocalPointer<PepperPDFHost::PrintClient>>::Leaky |
| 41 g_print_client_tls = LAZY_INSTANCE_INITIALIZER; | 36 g_print_client_tls = LAZY_INSTANCE_INITIALIZER; |
| 42 | 37 |
| 43 std::string GetStringResource(PP_ResourceString string_id) { | |
| 44 int resource_id = 0; | |
| 45 switch (string_id) { | |
| 46 case PP_RESOURCESTRING_PDFGETPASSWORD: | |
| 47 resource_id = IDS_PDF_NEED_PASSWORD; | |
| 48 break; | |
| 49 case PP_RESOURCESTRING_PDFLOADING: | |
| 50 resource_id = IDS_PDF_PAGE_LOADING; | |
| 51 break; | |
| 52 case PP_RESOURCESTRING_PDFLOAD_FAILED: | |
| 53 resource_id = IDS_PDF_PAGE_LOAD_FAILED; | |
| 54 break; | |
| 55 case PP_RESOURCESTRING_PDFPROGRESSLOADING: | |
| 56 resource_id = IDS_PDF_PROGRESS_LOADING; | |
| 57 break; | |
| 58 } | |
| 59 | |
| 60 return l10n_util::GetStringUTF8(resource_id); | |
| 61 } | |
| 62 | |
| 63 } // namespace | 38 } // namespace |
| 64 | 39 |
| 65 PepperPDFHost::PepperPDFHost(content::RendererPpapiHost* host, | 40 PepperPDFHost::PepperPDFHost(content::RendererPpapiHost* host, |
| 66 PP_Instance instance, | 41 PP_Instance instance, |
| 67 PP_Resource resource) | 42 PP_Resource resource) |
| 68 : ppapi::host::ResourceHost(host->GetPpapiHost(), instance, resource), | 43 : ppapi::host::ResourceHost(host->GetPpapiHost(), instance, resource), |
| 69 host_(host) {} | 44 host_(host) {} |
| 70 | 45 |
| 71 PepperPDFHost::~PepperPDFHost() {} | 46 PepperPDFHost::~PepperPDFHost() {} |
| 72 | 47 |
| 73 // static | 48 // static |
| 74 bool PepperPDFHost::InvokePrintingForInstance(PP_Instance instance_id) { | 49 bool PepperPDFHost::InvokePrintingForInstance(PP_Instance instance_id) { |
| 75 return g_print_client_tls.Pointer()->Get() | 50 return g_print_client_tls.Pointer()->Get() |
| 76 ? g_print_client_tls.Pointer()->Get()->Print(instance_id) | 51 ? g_print_client_tls.Pointer()->Get()->Print(instance_id) |
| 77 : false; | 52 : false; |
| 78 } | 53 } |
| 79 | 54 |
| 80 // static | 55 // static |
| 81 void PepperPDFHost::SetPrintClient(PepperPDFHost::PrintClient* client) { | 56 void PepperPDFHost::SetPrintClient(PepperPDFHost::PrintClient* client) { |
| 82 CHECK(!g_print_client_tls.Pointer()->Get()) | 57 CHECK(!g_print_client_tls.Pointer()->Get()) |
| 83 << "There should only be a single PrintClient for one RenderThread."; | 58 << "There should only be a single PrintClient for one RenderThread."; |
| 84 g_print_client_tls.Pointer()->Set(client); | 59 g_print_client_tls.Pointer()->Set(client); |
| 85 } | 60 } |
| 86 | 61 |
| 87 int32_t PepperPDFHost::OnResourceMessageReceived( | 62 int32_t PepperPDFHost::OnResourceMessageReceived( |
| 88 const IPC::Message& msg, | 63 const IPC::Message& msg, |
| 89 ppapi::host::HostMessageContext* context) { | 64 ppapi::host::HostMessageContext* context) { |
| 90 PPAPI_BEGIN_MESSAGE_MAP(PepperPDFHost, msg) | 65 PPAPI_BEGIN_MESSAGE_MAP(PepperPDFHost, msg) |
| 91 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_PDF_GetLocalizedString, | |
| 92 OnHostMsgGetLocalizedString) | |
| 93 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_PDF_DidStartLoading, | 66 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_PDF_DidStartLoading, |
| 94 OnHostMsgDidStartLoading) | 67 OnHostMsgDidStartLoading) |
| 95 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_PDF_DidStopLoading, | 68 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_PDF_DidStopLoading, |
| 96 OnHostMsgDidStopLoading) | 69 OnHostMsgDidStopLoading) |
| 97 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_PDF_UserMetricsRecordAction, | 70 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_PDF_UserMetricsRecordAction, |
| 98 OnHostMsgUserMetricsRecordAction) | 71 OnHostMsgUserMetricsRecordAction) |
| 99 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_PDF_HasUnsupportedFeature, | 72 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_PDF_HasUnsupportedFeature, |
| 100 OnHostMsgHasUnsupportedFeature) | 73 OnHostMsgHasUnsupportedFeature) |
| 101 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_PDF_Print, OnHostMsgPrint) | 74 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_PDF_Print, OnHostMsgPrint) |
| 102 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_PDF_SaveAs, | 75 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_PDF_SaveAs, |
| 103 OnHostMsgSaveAs) | 76 OnHostMsgSaveAs) |
| 104 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_PDF_SetSelectedText, | 77 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_PDF_SetSelectedText, |
| 105 OnHostMsgSetSelectedText) | 78 OnHostMsgSetSelectedText) |
| 106 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_PDF_SetLinkUnderCursor, | 79 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_PDF_SetLinkUnderCursor, |
| 107 OnHostMsgSetLinkUnderCursor) | 80 OnHostMsgSetLinkUnderCursor) |
| 108 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_PDF_SetContentRestriction, | 81 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_PDF_SetContentRestriction, |
| 109 OnHostMsgSetContentRestriction) | 82 OnHostMsgSetContentRestriction) |
| 110 PPAPI_END_MESSAGE_MAP() | 83 PPAPI_END_MESSAGE_MAP() |
| 111 return PP_ERROR_FAILED; | 84 return PP_ERROR_FAILED; |
| 112 } | 85 } |
| 113 | 86 |
| 114 int32_t PepperPDFHost::OnHostMsgGetLocalizedString( | |
| 115 ppapi::host::HostMessageContext* context, | |
| 116 PP_ResourceString string_id) { | |
| 117 std::string rv = GetStringResource(string_id); | |
| 118 context->reply_msg = PpapiPluginMsg_PDF_GetLocalizedStringReply(rv); | |
| 119 return PP_OK; | |
| 120 } | |
| 121 | |
| 122 int32_t PepperPDFHost::OnHostMsgDidStartLoading( | 87 int32_t PepperPDFHost::OnHostMsgDidStartLoading( |
| 123 ppapi::host::HostMessageContext* context) { | 88 ppapi::host::HostMessageContext* context) { |
| 124 content::PepperPluginInstance* instance = | 89 content::PepperPluginInstance* instance = |
| 125 host_->GetPluginInstance(pp_instance()); | 90 host_->GetPluginInstance(pp_instance()); |
| 126 if (!instance) | 91 if (!instance) |
| 127 return PP_ERROR_FAILED; | 92 return PP_ERROR_FAILED; |
| 128 instance->GetRenderView()->DidStartLoading(); | 93 instance->GetRenderView()->DidStartLoading(); |
| 129 return PP_OK; | 94 return PP_OK; |
| 130 } | 95 } |
| 131 | 96 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 const std::string& url) { | 179 const std::string& url) { |
| 215 content::PepperPluginInstance* instance = | 180 content::PepperPluginInstance* instance = |
| 216 host_->GetPluginInstance(pp_instance()); | 181 host_->GetPluginInstance(pp_instance()); |
| 217 if (!instance) | 182 if (!instance) |
| 218 return PP_ERROR_FAILED; | 183 return PP_ERROR_FAILED; |
| 219 instance->SetLinkUnderCursor(url); | 184 instance->SetLinkUnderCursor(url); |
| 220 return PP_OK; | 185 return PP_OK; |
| 221 } | 186 } |
| 222 | 187 |
| 223 } // namespace pdf | 188 } // namespace pdf |
| OLD | NEW |