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 "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "components/pdf/common/pdf_messages.h" | |
9 #include "components/pdf/renderer/pdf_accessibility_tree.h" | 8 #include "components/pdf/renderer/pdf_accessibility_tree.h" |
| 9 #include "content/public/common/associated_interface_provider.h" |
10 #include "content/public/common/referrer.h" | 10 #include "content/public/common/referrer.h" |
11 #include "content/public/renderer/pepper_plugin_instance.h" | 11 #include "content/public/renderer/pepper_plugin_instance.h" |
12 #include "content/public/renderer/render_frame.h" | 12 #include "content/public/renderer/render_frame.h" |
13 #include "content/public/renderer/render_thread.h" | 13 #include "content/public/renderer/render_thread.h" |
14 #include "content/public/renderer/renderer_ppapi_host.h" | 14 #include "content/public/renderer/renderer_ppapi_host.h" |
15 #include "ppapi/host/dispatch_host_message.h" | 15 #include "ppapi/host/dispatch_host_message.h" |
16 #include "ppapi/host/host_message_context.h" | 16 #include "ppapi/host/host_message_context.h" |
17 #include "ppapi/host/ppapi_host.h" | 17 #include "ppapi/host/ppapi_host.h" |
18 #include "ppapi/proxy/host_dispatcher.h" | 18 #include "ppapi/proxy/host_dispatcher.h" |
19 #include "ppapi/proxy/ppapi_messages.h" | 19 #include "ppapi/proxy/ppapi_messages.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 if (!render_frame) | 111 if (!render_frame) |
112 return PP_ERROR_FAILED; | 112 return PP_ERROR_FAILED; |
113 | 113 |
114 render_frame->PluginDidStopLoading(); | 114 render_frame->PluginDidStopLoading(); |
115 return PP_OK; | 115 return PP_OK; |
116 } | 116 } |
117 | 117 |
118 int32_t PepperPDFHost::OnHostMsgSetContentRestriction( | 118 int32_t PepperPDFHost::OnHostMsgSetContentRestriction( |
119 ppapi::host::HostMessageContext* context, | 119 ppapi::host::HostMessageContext* context, |
120 int restrictions) { | 120 int restrictions) { |
121 content::RenderFrame* render_frame = GetRenderFrame(); | 121 mojom::PdfService* service = GetRemotePdfService(); |
122 if (!render_frame) | 122 if (!service) |
123 return PP_ERROR_FAILED; | 123 return PP_ERROR_FAILED; |
124 | 124 |
125 render_frame->Send(new PDFHostMsg_PDFUpdateContentRestrictions( | 125 service->UpdateContentRestrictions(restrictions); |
126 render_frame->GetRoutingID(), restrictions)); | |
127 return PP_OK; | 126 return PP_OK; |
128 } | 127 } |
129 | 128 |
130 int32_t PepperPDFHost::OnHostMsgUserMetricsRecordAction( | 129 int32_t PepperPDFHost::OnHostMsgUserMetricsRecordAction( |
131 ppapi::host::HostMessageContext* context, | 130 ppapi::host::HostMessageContext* context, |
132 const std::string& action) { | 131 const std::string& action) { |
133 if (action.empty()) | 132 if (action.empty()) |
134 return PP_ERROR_FAILED; | 133 return PP_ERROR_FAILED; |
135 content::RenderThread::Get()->RecordComputedAction(action); | 134 content::RenderThread::Get()->RecordComputedAction(action); |
136 return PP_OK; | 135 return PP_OK; |
137 } | 136 } |
138 | 137 |
139 int32_t PepperPDFHost::OnHostMsgHasUnsupportedFeature( | 138 int32_t PepperPDFHost::OnHostMsgHasUnsupportedFeature( |
140 ppapi::host::HostMessageContext* context) { | 139 ppapi::host::HostMessageContext* context) { |
141 content::RenderFrame* render_frame = GetRenderFrame(); | 140 mojom::PdfService* service = GetRemotePdfService(); |
142 if (!render_frame) | 141 if (!service) |
143 return PP_ERROR_FAILED; | 142 return PP_ERROR_FAILED; |
144 | 143 |
145 render_frame->Send( | 144 service->HasUnsupportedFeature(); |
146 new PDFHostMsg_PDFHasUnsupportedFeature(render_frame->GetRoutingID())); | |
147 return PP_OK; | 145 return PP_OK; |
148 } | 146 } |
149 | 147 |
150 int32_t PepperPDFHost::OnHostMsgPrint( | 148 int32_t PepperPDFHost::OnHostMsgPrint( |
151 ppapi::host::HostMessageContext* context) { | 149 ppapi::host::HostMessageContext* context) { |
152 return InvokePrintingForInstance(pp_instance()) ? PP_OK : PP_ERROR_FAILED; | 150 return InvokePrintingForInstance(pp_instance()) ? PP_OK : PP_ERROR_FAILED; |
153 } | 151 } |
154 | 152 |
155 int32_t PepperPDFHost::OnHostMsgSaveAs( | 153 int32_t PepperPDFHost::OnHostMsgSaveAs( |
156 ppapi::host::HostMessageContext* context) { | 154 ppapi::host::HostMessageContext* context) { |
157 content::PepperPluginInstance* instance = | 155 content::PepperPluginInstance* instance = |
158 host_->GetPluginInstance(pp_instance()); | 156 host_->GetPluginInstance(pp_instance()); |
159 if (!instance) | 157 if (!instance) |
160 return PP_ERROR_FAILED; | 158 return PP_ERROR_FAILED; |
161 | 159 |
162 content::RenderFrame* render_frame = instance->GetRenderFrame(); | |
163 if (!render_frame) | |
164 return PP_ERROR_FAILED; | |
165 | |
166 GURL url = instance->GetPluginURL(); | 160 GURL url = instance->GetPluginURL(); |
167 content::Referrer referrer; | 161 content::Referrer referrer; |
168 referrer.url = url; | 162 referrer.url = url; |
169 referrer.policy = blink::WebReferrerPolicyDefault; | 163 referrer.policy = blink::WebReferrerPolicyDefault; |
170 referrer = content::Referrer::SanitizeForRequest(url, referrer); | 164 referrer = content::Referrer::SanitizeForRequest(url, referrer); |
171 render_frame->Send( | 165 |
172 new PDFHostMsg_PDFSaveURLAs(render_frame->GetRoutingID(), url, referrer)); | 166 mojom::PdfService* service = GetRemotePdfService(); |
| 167 if (!service) |
| 168 return PP_ERROR_FAILED; |
| 169 |
| 170 service->SaveUrlAs(url, referrer); |
173 return PP_OK; | 171 return PP_OK; |
174 } | 172 } |
175 | 173 |
176 int32_t PepperPDFHost::OnHostMsgSetSelectedText( | 174 int32_t PepperPDFHost::OnHostMsgSetSelectedText( |
177 ppapi::host::HostMessageContext* context, | 175 ppapi::host::HostMessageContext* context, |
178 const base::string16& selected_text) { | 176 const base::string16& selected_text) { |
179 content::PepperPluginInstance* instance = | 177 content::PepperPluginInstance* instance = |
180 host_->GetPluginInstance(pp_instance()); | 178 host_->GetPluginInstance(pp_instance()); |
181 if (!instance) | 179 if (!instance) |
182 return PP_ERROR_FAILED; | 180 return PP_ERROR_FAILED; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 base::MakeUnique<PdfAccessibilityTree>(host_, pp_instance()); | 232 base::MakeUnique<PdfAccessibilityTree>(host_, pp_instance()); |
235 } | 233 } |
236 } | 234 } |
237 | 235 |
238 content::RenderFrame* PepperPDFHost::GetRenderFrame() { | 236 content::RenderFrame* PepperPDFHost::GetRenderFrame() { |
239 content::PepperPluginInstance* instance = | 237 content::PepperPluginInstance* instance = |
240 host_->GetPluginInstance(pp_instance()); | 238 host_->GetPluginInstance(pp_instance()); |
241 return instance ? instance->GetRenderFrame() : nullptr; | 239 return instance ? instance->GetRenderFrame() : nullptr; |
242 } | 240 } |
243 | 241 |
| 242 mojom::PdfService* PepperPDFHost::GetRemotePdfService() { |
| 243 content::RenderFrame* render_frame = GetRenderFrame(); |
| 244 if (!render_frame) |
| 245 return nullptr; |
| 246 |
| 247 if (!remote_pdf_service_) { |
| 248 render_frame->GetRemoteAssociatedInterfaces()->GetInterface( |
| 249 &remote_pdf_service_); |
| 250 } |
| 251 return remote_pdf_service_.get(); |
| 252 } |
| 253 |
244 } // namespace pdf | 254 } // namespace pdf |
OLD | NEW |