| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/pepper/pepper_webplugin_impl.h" | 5 #include "content/renderer/pepper/pepper_webplugin_impl.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/debug/crash_logging.h" | 9 #include "base/debug/crash_logging.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 namespace content { | 47 namespace content { |
| 48 | 48 |
| 49 struct PepperWebPluginImpl::InitData { | 49 struct PepperWebPluginImpl::InitData { |
| 50 scoped_refptr<PluginModule> module; | 50 scoped_refptr<PluginModule> module; |
| 51 RenderFrameImpl* render_frame; | 51 RenderFrameImpl* render_frame; |
| 52 std::vector<std::string> arg_names; | 52 std::vector<std::string> arg_names; |
| 53 std::vector<std::string> arg_values; | 53 std::vector<std::string> arg_values; |
| 54 GURL url; | 54 GURL url; |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 PepperWebPluginImpl::PepperWebPluginImpl( | 57 PepperWebPluginImpl::PepperWebPluginImpl(PluginModule* plugin_module, |
| 58 PluginModule* plugin_module, | 58 const WebPluginParams& params, |
| 59 const WebPluginParams& params, | 59 RenderFrameImpl* render_frame) |
| 60 RenderFrameImpl* render_frame) | |
| 61 : init_data_(new InitData()), | 60 : init_data_(new InitData()), |
| 62 full_frame_(params.loadManually), | 61 full_frame_(params.loadManually), |
| 63 instance_object_(PP_MakeUndefined()), | 62 instance_object_(PP_MakeUndefined()), |
| 64 container_(NULL) { | 63 container_(NULL) { |
| 65 DCHECK(plugin_module); | 64 DCHECK(plugin_module); |
| 66 init_data_->module = plugin_module; | 65 init_data_->module = plugin_module; |
| 67 init_data_->render_frame = render_frame; | 66 init_data_->render_frame = render_frame; |
| 68 for (size_t i = 0; i < params.attributeNames.size(); ++i) { | 67 for (size_t i = 0; i < params.attributeNames.size(); ++i) { |
| 69 init_data_->arg_names.push_back(params.attributeNames[i].utf8()); | 68 init_data_->arg_names.push_back(params.attributeNames[i].utf8()); |
| 70 init_data_->arg_values.push_back(params.attributeValues[i].utf8()); | 69 init_data_->arg_values.push_back(params.attributeValues[i].utf8()); |
| 71 } | 70 } |
| 72 init_data_->url = params.url; | 71 init_data_->url = params.url; |
| 73 | 72 |
| 74 // Set subresource URL for crash reporting. | 73 // Set subresource URL for crash reporting. |
| 75 base::debug::SetCrashKeyValue("subresource_url", init_data_->url.spec()); | 74 base::debug::SetCrashKeyValue("subresource_url", init_data_->url.spec()); |
| 76 } | 75 } |
| 77 | 76 |
| 78 PepperWebPluginImpl::~PepperWebPluginImpl() { | 77 PepperWebPluginImpl::~PepperWebPluginImpl() {} |
| 79 } | |
| 80 | 78 |
| 81 blink::WebPluginContainer* PepperWebPluginImpl::container() const { | 79 blink::WebPluginContainer* PepperWebPluginImpl::container() const { |
| 82 return container_; | 80 return container_; |
| 83 } | 81 } |
| 84 | 82 |
| 85 bool PepperWebPluginImpl::initialize(WebPluginContainer* container) { | 83 bool PepperWebPluginImpl::initialize(WebPluginContainer* container) { |
| 86 // The plugin delegate may have gone away. | 84 // The plugin delegate may have gone away. |
| 87 instance_ = init_data_->module->CreateInstance( | 85 instance_ = init_data_->module->CreateInstance( |
| 88 init_data_->render_frame, container, init_data_->url); | 86 init_data_->render_frame, container, init_data_->url); |
| 89 if (!instance_.get()) | 87 if (!instance_.get()) |
| 90 return false; | 88 return false; |
| 91 | 89 |
| 92 // Enable script objects for this plugin. | 90 // Enable script objects for this plugin. |
| 93 container->allowScriptObjects(); | 91 container->allowScriptObjects(); |
| 94 | 92 |
| 95 bool success = instance_->Initialize(init_data_->arg_names, | 93 bool success = instance_->Initialize( |
| 96 init_data_->arg_values, | 94 init_data_->arg_names, init_data_->arg_values, full_frame_); |
| 97 full_frame_); | |
| 98 if (!success) { | 95 if (!success) { |
| 99 instance_->Delete(); | 96 instance_->Delete(); |
| 100 instance_ = NULL; | 97 instance_ = NULL; |
| 101 | 98 |
| 102 blink::WebPlugin* replacement_plugin = | 99 blink::WebPlugin* replacement_plugin = |
| 103 GetContentClient()->renderer()->CreatePluginReplacement( | 100 GetContentClient()->renderer()->CreatePluginReplacement( |
| 104 init_data_->render_frame, init_data_->module->path()); | 101 init_data_->render_frame, init_data_->module->path()); |
| 105 if (!replacement_plugin || !replacement_plugin->initialize(container)) | 102 if (!replacement_plugin || !replacement_plugin->initialize(container)) |
| 106 return false; | 103 return false; |
| 107 | 104 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 // any non-postMessage calls to it. | 141 // any non-postMessage calls to it. |
| 145 if (object.get()) { | 142 if (object.get()) { |
| 146 instance_->message_channel().SetPassthroughObject(object->np_object()); | 143 instance_->message_channel().SetPassthroughObject(object->np_object()); |
| 147 } | 144 } |
| 148 NPObject* message_channel_np_object(instance_->message_channel().np_object()); | 145 NPObject* message_channel_np_object(instance_->message_channel().np_object()); |
| 149 // The object is expected to be retained before it is returned. | 146 // The object is expected to be retained before it is returned. |
| 150 blink::WebBindings::retainObject(message_channel_np_object); | 147 blink::WebBindings::retainObject(message_channel_np_object); |
| 151 return message_channel_np_object; | 148 return message_channel_np_object; |
| 152 } | 149 } |
| 153 | 150 |
| 154 NPP PepperWebPluginImpl::pluginNPP() { | 151 NPP PepperWebPluginImpl::pluginNPP() { return instance_->instanceNPP(); } |
| 155 return instance_->instanceNPP(); | |
| 156 } | |
| 157 | 152 |
| 158 bool PepperWebPluginImpl::getFormValue(WebString& value) { | 153 bool PepperWebPluginImpl::getFormValue(WebString& value) { return false; } |
| 159 return false; | |
| 160 } | |
| 161 | 154 |
| 162 void PepperWebPluginImpl::paint(WebCanvas* canvas, const WebRect& rect) { | 155 void PepperWebPluginImpl::paint(WebCanvas* canvas, const WebRect& rect) { |
| 163 if (!instance_->FlashIsFullscreenOrPending()) | 156 if (!instance_->FlashIsFullscreenOrPending()) |
| 164 instance_->Paint(canvas, plugin_rect_, rect); | 157 instance_->Paint(canvas, plugin_rect_, rect); |
| 165 } | 158 } |
| 166 | 159 |
| 167 void PepperWebPluginImpl::updateGeometry( | 160 void PepperWebPluginImpl::updateGeometry( |
| 168 const WebRect& window_rect, | 161 const WebRect& window_rect, |
| 169 const WebRect& clip_rect, | 162 const WebRect& clip_rect, |
| 170 const WebVector<WebRect>& cut_outs_rects, | 163 const WebVector<WebRect>& cut_outs_rects, |
| 171 bool is_visible) { | 164 bool is_visible) { |
| 172 plugin_rect_ = window_rect; | 165 plugin_rect_ = window_rect; |
| 173 if (!instance_->FlashIsFullscreenOrPending()) { | 166 if (!instance_->FlashIsFullscreenOrPending()) { |
| 174 std::vector<gfx::Rect> cut_outs; | 167 std::vector<gfx::Rect> cut_outs; |
| 175 for (size_t i = 0; i < cut_outs_rects.size(); ++i) | 168 for (size_t i = 0; i < cut_outs_rects.size(); ++i) |
| 176 cut_outs.push_back(cut_outs_rects[i]); | 169 cut_outs.push_back(cut_outs_rects[i]); |
| 177 instance_->ViewChanged(plugin_rect_, clip_rect, cut_outs); | 170 instance_->ViewChanged(plugin_rect_, clip_rect, cut_outs); |
| 178 } | 171 } |
| 179 } | 172 } |
| 180 | 173 |
| 181 void PepperWebPluginImpl::updateFocus(bool focused) { | 174 void PepperWebPluginImpl::updateFocus(bool focused) { |
| 182 instance_->SetWebKitFocus(focused); | 175 instance_->SetWebKitFocus(focused); |
| 183 } | 176 } |
| 184 | 177 |
| 185 void PepperWebPluginImpl::updateVisibility(bool visible) { | 178 void PepperWebPluginImpl::updateVisibility(bool visible) {} |
| 186 } | |
| 187 | 179 |
| 188 bool PepperWebPluginImpl::acceptsInputEvents() { | 180 bool PepperWebPluginImpl::acceptsInputEvents() { return true; } |
| 189 return true; | |
| 190 } | |
| 191 | 181 |
| 192 bool PepperWebPluginImpl::handleInputEvent(const blink::WebInputEvent& event, | 182 bool PepperWebPluginImpl::handleInputEvent(const blink::WebInputEvent& event, |
| 193 blink::WebCursorInfo& cursor_info) { | 183 blink::WebCursorInfo& cursor_info) { |
| 194 if (instance_->FlashIsFullscreenOrPending()) | 184 if (instance_->FlashIsFullscreenOrPending()) |
| 195 return false; | 185 return false; |
| 196 return instance_->HandleInputEvent(event, &cursor_info); | 186 return instance_->HandleInputEvent(event, &cursor_info); |
| 197 } | 187 } |
| 198 | 188 |
| 199 void PepperWebPluginImpl::didReceiveResponse( | 189 void PepperWebPluginImpl::didReceiveResponse( |
| 200 const blink::WebURLResponse& response) { | 190 const blink::WebURLResponse& response) { |
| 201 DCHECK(!instance_->document_loader()); | 191 DCHECK(!instance_->document_loader()); |
| 202 instance_->HandleDocumentLoad(response); | 192 instance_->HandleDocumentLoad(response); |
| 203 } | 193 } |
| 204 | 194 |
| 205 void PepperWebPluginImpl::didReceiveData(const char* data, int data_length) { | 195 void PepperWebPluginImpl::didReceiveData(const char* data, int data_length) { |
| 206 blink::WebURLLoaderClient* document_loader = instance_->document_loader(); | 196 blink::WebURLLoaderClient* document_loader = instance_->document_loader(); |
| 207 if (document_loader) | 197 if (document_loader) |
| 208 document_loader->didReceiveData(NULL, data, data_length, 0); | 198 document_loader->didReceiveData(NULL, data, data_length, 0); |
| 209 } | 199 } |
| 210 | 200 |
| 211 void PepperWebPluginImpl::didFinishLoading() { | 201 void PepperWebPluginImpl::didFinishLoading() { |
| 212 blink::WebURLLoaderClient* document_loader = instance_->document_loader(); | 202 blink::WebURLLoaderClient* document_loader = instance_->document_loader(); |
| 213 if (document_loader) | 203 if (document_loader) |
| 214 document_loader->didFinishLoading(NULL, 0.0, | 204 document_loader->didFinishLoading( |
| 215 blink::WebURLLoaderClient::kUnknownEncodedDataLength); | 205 NULL, 0.0, blink::WebURLLoaderClient::kUnknownEncodedDataLength); |
| 216 } | 206 } |
| 217 | 207 |
| 218 void PepperWebPluginImpl::didFailLoading(const blink::WebURLError& error) { | 208 void PepperWebPluginImpl::didFailLoading(const blink::WebURLError& error) { |
| 219 blink::WebURLLoaderClient* document_loader = instance_->document_loader(); | 209 blink::WebURLLoaderClient* document_loader = instance_->document_loader(); |
| 220 if (document_loader) | 210 if (document_loader) |
| 221 document_loader->didFail(NULL, error); | 211 document_loader->didFail(NULL, error); |
| 222 } | 212 } |
| 223 | 213 |
| 224 void PepperWebPluginImpl::didFinishLoadingFrameRequest( | 214 void PepperWebPluginImpl::didFinishLoadingFrameRequest(const blink::WebURL& url, |
| 225 const blink::WebURL& url, | 215 void* notify_data) {} |
| 226 void* notify_data) { | |
| 227 } | |
| 228 | 216 |
| 229 void PepperWebPluginImpl::didFailLoadingFrameRequest( | 217 void PepperWebPluginImpl::didFailLoadingFrameRequest( |
| 230 const blink::WebURL& url, | 218 const blink::WebURL& url, |
| 231 void* notify_data, | 219 void* notify_data, |
| 232 const blink::WebURLError& error) { | 220 const blink::WebURLError& error) {} |
| 233 } | |
| 234 | 221 |
| 235 bool PepperWebPluginImpl::hasSelection() const { | 222 bool PepperWebPluginImpl::hasSelection() const { |
| 236 return !selectionAsText().isEmpty(); | 223 return !selectionAsText().isEmpty(); |
| 237 } | 224 } |
| 238 | 225 |
| 239 WebString PepperWebPluginImpl::selectionAsText() const { | 226 WebString PepperWebPluginImpl::selectionAsText() const { |
| 240 return instance_->GetSelectedText(false); | 227 return instance_->GetSelectedText(false); |
| 241 } | 228 } |
| 242 | 229 |
| 243 WebString PepperWebPluginImpl::selectionAsMarkup() const { | 230 WebString PepperWebPluginImpl::selectionAsMarkup() const { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 255 bool PepperWebPluginImpl::startFind(const blink::WebString& search_text, | 242 bool PepperWebPluginImpl::startFind(const blink::WebString& search_text, |
| 256 bool case_sensitive, | 243 bool case_sensitive, |
| 257 int identifier) { | 244 int identifier) { |
| 258 return instance_->StartFind(search_text, case_sensitive, identifier); | 245 return instance_->StartFind(search_text, case_sensitive, identifier); |
| 259 } | 246 } |
| 260 | 247 |
| 261 void PepperWebPluginImpl::selectFindResult(bool forward) { | 248 void PepperWebPluginImpl::selectFindResult(bool forward) { |
| 262 instance_->SelectFindResult(forward); | 249 instance_->SelectFindResult(forward); |
| 263 } | 250 } |
| 264 | 251 |
| 265 void PepperWebPluginImpl::stopFind() { | 252 void PepperWebPluginImpl::stopFind() { instance_->StopFind(); } |
| 266 instance_->StopFind(); | |
| 267 } | |
| 268 | 253 |
| 269 bool PepperWebPluginImpl::supportsPaginatedPrint() { | 254 bool PepperWebPluginImpl::supportsPaginatedPrint() { |
| 270 return instance_->SupportsPrintInterface(); | 255 return instance_->SupportsPrintInterface(); |
| 271 } | 256 } |
| 272 | 257 |
| 273 bool PepperWebPluginImpl::isPrintScalingDisabled() { | 258 bool PepperWebPluginImpl::isPrintScalingDisabled() { |
| 274 return instance_->IsPrintScalingDisabled(); | 259 return instance_->IsPrintScalingDisabled(); |
| 275 } | 260 } |
| 276 | 261 |
| 277 int PepperWebPluginImpl::printBegin(const WebPrintParams& print_params) { | 262 int PepperWebPluginImpl::printBegin(const WebPrintParams& print_params) { |
| 278 return instance_->PrintBegin(print_params); | 263 return instance_->PrintBegin(print_params); |
| 279 } | 264 } |
| 280 | 265 |
| 281 bool PepperWebPluginImpl::printPage(int page_number, | 266 bool PepperWebPluginImpl::printPage(int page_number, blink::WebCanvas* canvas) { |
| 282 blink::WebCanvas* canvas) { | |
| 283 return instance_->PrintPage(page_number, canvas); | 267 return instance_->PrintPage(page_number, canvas); |
| 284 } | 268 } |
| 285 | 269 |
| 286 void PepperWebPluginImpl::printEnd() { | 270 void PepperWebPluginImpl::printEnd() { return instance_->PrintEnd(); } |
| 287 return instance_->PrintEnd(); | |
| 288 } | |
| 289 | 271 |
| 290 bool PepperWebPluginImpl::canRotateView() { | 272 bool PepperWebPluginImpl::canRotateView() { return instance_->CanRotateView(); } |
| 291 return instance_->CanRotateView(); | |
| 292 } | |
| 293 | 273 |
| 294 void PepperWebPluginImpl::rotateView(RotationType type) { | 274 void PepperWebPluginImpl::rotateView(RotationType type) { |
| 295 instance_->RotateView(type); | 275 instance_->RotateView(type); |
| 296 } | 276 } |
| 297 | 277 |
| 298 bool PepperWebPluginImpl::isPlaceholder() { | 278 bool PepperWebPluginImpl::isPlaceholder() { return false; } |
| 299 return false; | |
| 300 } | |
| 301 | 279 |
| 302 } // namespace content | 280 } // namespace content |
| OLD | NEW |