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/pdf/renderer/pdf_accessibility_tree.h" | 8 #include "components/pdf/renderer/pdf_accessibility_tree.h" |
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" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 PPAPI_END_MESSAGE_MAP() | 93 PPAPI_END_MESSAGE_MAP() |
94 return PP_ERROR_FAILED; | 94 return PP_ERROR_FAILED; |
95 } | 95 } |
96 | 96 |
97 int32_t PepperPDFHost::OnHostMsgDidStartLoading( | 97 int32_t PepperPDFHost::OnHostMsgDidStartLoading( |
98 ppapi::host::HostMessageContext* context) { | 98 ppapi::host::HostMessageContext* context) { |
99 content::PepperPluginInstance* instance = | 99 content::PepperPluginInstance* instance = |
100 host_->GetPluginInstance(pp_instance()); | 100 host_->GetPluginInstance(pp_instance()); |
101 if (!instance) | 101 if (!instance) |
102 return PP_ERROR_FAILED; | 102 return PP_ERROR_FAILED; |
103 instance->GetRenderView()->DidStartLoading(); | 103 |
104 content::RenderView* render_view = instance->GetRenderView(); | |
105 if (!render_view) | |
106 return PP_ERROR_FAILED; | |
107 | |
108 render_view->DidStartLoading(); | |
tommycli
2016/07/22 21:47:37
Since this pattern is now repeated in many methods
Lei Zhang
2016/07/22 22:20:21
Done.
| |
104 return PP_OK; | 109 return PP_OK; |
105 } | 110 } |
106 | 111 |
107 int32_t PepperPDFHost::OnHostMsgDidStopLoading( | 112 int32_t PepperPDFHost::OnHostMsgDidStopLoading( |
108 ppapi::host::HostMessageContext* context) { | 113 ppapi::host::HostMessageContext* context) { |
109 content::PepperPluginInstance* instance = | 114 content::PepperPluginInstance* instance = |
110 host_->GetPluginInstance(pp_instance()); | 115 host_->GetPluginInstance(pp_instance()); |
111 if (!instance) | 116 if (!instance) |
112 return PP_ERROR_FAILED; | 117 return PP_ERROR_FAILED; |
113 instance->GetRenderView()->DidStopLoading(); | 118 |
119 content::RenderView* render_view = instance->GetRenderView(); | |
120 if (!render_view) | |
121 return PP_ERROR_FAILED; | |
122 | |
123 render_view->DidStopLoading(); | |
114 return PP_OK; | 124 return PP_OK; |
115 } | 125 } |
116 | 126 |
117 int32_t PepperPDFHost::OnHostMsgSetContentRestriction( | 127 int32_t PepperPDFHost::OnHostMsgSetContentRestriction( |
118 ppapi::host::HostMessageContext* context, | 128 ppapi::host::HostMessageContext* context, |
119 int restrictions) { | 129 int restrictions) { |
120 content::PepperPluginInstance* instance = | 130 content::PepperPluginInstance* instance = |
121 host_->GetPluginInstance(pp_instance()); | 131 host_->GetPluginInstance(pp_instance()); |
122 if (!instance) | 132 if (!instance) |
123 return PP_ERROR_FAILED; | 133 return PP_ERROR_FAILED; |
124 instance->GetRenderView()->Send(new PDFHostMsg_PDFUpdateContentRestrictions( | 134 |
125 instance->GetRenderView()->GetRoutingID(), restrictions)); | 135 content::RenderView* render_view = instance->GetRenderView(); |
136 if (!render_view) | |
137 return PP_ERROR_FAILED; | |
138 | |
139 render_view->Send(new PDFHostMsg_PDFUpdateContentRestrictions( | |
140 render_view->GetRoutingID(), restrictions)); | |
126 return PP_OK; | 141 return PP_OK; |
127 } | 142 } |
128 | 143 |
129 int32_t PepperPDFHost::OnHostMsgUserMetricsRecordAction( | 144 int32_t PepperPDFHost::OnHostMsgUserMetricsRecordAction( |
130 ppapi::host::HostMessageContext* context, | 145 ppapi::host::HostMessageContext* context, |
131 const std::string& action) { | 146 const std::string& action) { |
132 if (action.empty()) | 147 if (action.empty()) |
133 return PP_ERROR_FAILED; | 148 return PP_ERROR_FAILED; |
134 content::RenderThread::Get()->RecordComputedAction(action); | 149 content::RenderThread::Get()->RecordComputedAction(action); |
135 return PP_OK; | 150 return PP_OK; |
136 } | 151 } |
137 | 152 |
138 int32_t PepperPDFHost::OnHostMsgHasUnsupportedFeature( | 153 int32_t PepperPDFHost::OnHostMsgHasUnsupportedFeature( |
139 ppapi::host::HostMessageContext* context) { | 154 ppapi::host::HostMessageContext* context) { |
140 content::PepperPluginInstance* instance = | 155 content::PepperPluginInstance* instance = |
141 host_->GetPluginInstance(pp_instance()); | 156 host_->GetPluginInstance(pp_instance()); |
142 if (!instance) | 157 if (!instance) |
143 return PP_ERROR_FAILED; | 158 return PP_ERROR_FAILED; |
144 | 159 |
145 // TODO(thestig): Turn CHECKs into the proper if statement after figuring out | 160 content::RenderView* render_view = instance->GetRenderView(); |
146 // what's wrong for https://crbug.com/627814 | 161 if (!render_view) |
147 CHECK(instance->GetContainer()); | 162 return PP_ERROR_FAILED; |
148 CHECK(instance->GetContainer()->document().frame()); | 163 |
149 CHECK(instance->GetContainer()->document().frame()->view()); | |
150 blink::WebView* view = | |
151 instance->GetContainer()->document().frame()->view(); | |
152 content::RenderView* render_view = content::RenderView::FromWebView(view); | |
153 render_view->Send( | 164 render_view->Send( |
154 new PDFHostMsg_PDFHasUnsupportedFeature(render_view->GetRoutingID())); | 165 new PDFHostMsg_PDFHasUnsupportedFeature(render_view->GetRoutingID())); |
155 return PP_OK; | 166 return PP_OK; |
156 } | 167 } |
157 | 168 |
158 int32_t PepperPDFHost::OnHostMsgPrint( | 169 int32_t PepperPDFHost::OnHostMsgPrint( |
159 ppapi::host::HostMessageContext* context) { | 170 ppapi::host::HostMessageContext* context) { |
160 return InvokePrintingForInstance(pp_instance()) ? PP_OK : PP_ERROR_FAILED; | 171 return InvokePrintingForInstance(pp_instance()) ? PP_OK : PP_ERROR_FAILED; |
161 } | 172 } |
162 | 173 |
163 int32_t PepperPDFHost::OnHostMsgSaveAs( | 174 int32_t PepperPDFHost::OnHostMsgSaveAs( |
164 ppapi::host::HostMessageContext* context) { | 175 ppapi::host::HostMessageContext* context) { |
165 content::PepperPluginInstance* instance = | 176 content::PepperPluginInstance* instance = |
166 host_->GetPluginInstance(pp_instance()); | 177 host_->GetPluginInstance(pp_instance()); |
167 if (!instance) | 178 if (!instance) |
168 return PP_ERROR_FAILED; | 179 return PP_ERROR_FAILED; |
180 | |
181 content::RenderView* render_view = instance->GetRenderView(); | |
182 if (!render_view) | |
183 return PP_ERROR_FAILED; | |
184 | |
169 GURL url = instance->GetPluginURL(); | 185 GURL url = instance->GetPluginURL(); |
170 content::RenderView* render_view = instance->GetRenderView(); | |
171 content::Referrer referrer; | 186 content::Referrer referrer; |
172 referrer.url = url; | 187 referrer.url = url; |
173 referrer.policy = blink::WebReferrerPolicyDefault; | 188 referrer.policy = blink::WebReferrerPolicyDefault; |
174 referrer = content::Referrer::SanitizeForRequest(url, referrer); | 189 referrer = content::Referrer::SanitizeForRequest(url, referrer); |
175 render_view->Send( | 190 render_view->Send( |
176 new PDFHostMsg_PDFSaveURLAs(render_view->GetRoutingID(), url, referrer)); | 191 new PDFHostMsg_PDFSaveURLAs(render_view->GetRoutingID(), url, referrer)); |
177 return PP_OK; | 192 return PP_OK; |
178 } | 193 } |
179 | 194 |
180 int32_t PepperPDFHost::OnHostMsgSetSelectedText( | 195 int32_t PepperPDFHost::OnHostMsgSetSelectedText( |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
233 } | 248 } |
234 | 249 |
235 void PepperPDFHost::CreatePdfAccessibilityTreeIfNeeded() { | 250 void PepperPDFHost::CreatePdfAccessibilityTreeIfNeeded() { |
236 if (!pdf_accessibility_tree_) { | 251 if (!pdf_accessibility_tree_) { |
237 pdf_accessibility_tree_.reset(new PdfAccessibilityTree( | 252 pdf_accessibility_tree_.reset(new PdfAccessibilityTree( |
238 host_, pp_instance())); | 253 host_, pp_instance())); |
239 } | 254 } |
240 } | 255 } |
241 | 256 |
242 } // namespace pdf | 257 } // namespace pdf |
OLD | NEW |