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