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/npapi/webplugin_delegate_proxy.h" | 5 #include "content/renderer/npapi/webplugin_delegate_proxy.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 |
7 #include <algorithm> | 9 #include <algorithm> |
8 | 10 |
9 #include "base/auto_reset.h" | 11 #include "base/auto_reset.h" |
10 #include "base/basictypes.h" | |
11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
12 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
16 #include "base/process/process.h" | 18 #include "base/process/process.h" |
17 #include "base/strings/string_split.h" | 19 #include "base/strings/string_split.h" |
18 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
19 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
20 #include "base/version.h" | 22 #include "base/version.h" |
| 23 #include "build/build_config.h" |
21 #include "cc/resources/shared_bitmap.h" | 24 #include "cc/resources/shared_bitmap.h" |
22 #include "content/child/child_process.h" | 25 #include "content/child/child_process.h" |
23 #include "content/child/child_shared_bitmap_manager.h" | 26 #include "content/child/child_shared_bitmap_manager.h" |
24 #include "content/child/npapi/npobject_proxy.h" | 27 #include "content/child/npapi/npobject_proxy.h" |
25 #include "content/child/npapi/npobject_stub.h" | 28 #include "content/child/npapi/npobject_stub.h" |
26 #include "content/child/npapi/npobject_util.h" | 29 #include "content/child/npapi/npobject_util.h" |
27 #include "content/child/npapi/webplugin_resource_client.h" | 30 #include "content/child/npapi/webplugin_resource_client.h" |
28 #include "content/child/plugin_messages.h" | 31 #include "content/child/plugin_messages.h" |
29 #include "content/common/content_constants_internal.h" | 32 #include "content/common/content_constants_internal.h" |
30 #include "content/common/cursors/webcursor.h" | 33 #include "content/common/cursors/webcursor.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 106 |
104 // PluginResourceClient implementation: | 107 // PluginResourceClient implementation: |
105 void WillSendRequest(const GURL& url, int http_status_code) override { | 108 void WillSendRequest(const GURL& url, int http_status_code) override { |
106 DCHECK(channel_.get() != NULL); | 109 DCHECK(channel_.get() != NULL); |
107 channel_->Send(new PluginMsg_WillSendRequest( | 110 channel_->Send(new PluginMsg_WillSendRequest( |
108 instance_id_, resource_id_, url, http_status_code)); | 111 instance_id_, resource_id_, url, http_status_code)); |
109 } | 112 } |
110 | 113 |
111 void DidReceiveResponse(const std::string& mime_type, | 114 void DidReceiveResponse(const std::string& mime_type, |
112 const std::string& headers, | 115 const std::string& headers, |
113 uint32 expected_length, | 116 uint32_t expected_length, |
114 uint32 last_modified, | 117 uint32_t last_modified, |
115 bool request_is_seekable) override { | 118 bool request_is_seekable) override { |
116 DCHECK(channel_.get() != NULL); | 119 DCHECK(channel_.get() != NULL); |
117 PluginMsg_DidReceiveResponseParams params; | 120 PluginMsg_DidReceiveResponseParams params; |
118 params.id = resource_id_; | 121 params.id = resource_id_; |
119 params.mime_type = mime_type; | 122 params.mime_type = mime_type; |
120 params.headers = headers; | 123 params.headers = headers; |
121 params.expected_length = expected_length; | 124 params.expected_length = expected_length; |
122 params.last_modified = last_modified; | 125 params.last_modified = last_modified; |
123 params.request_is_seekable = request_is_seekable; | 126 params.request_is_seekable = request_is_seekable; |
124 // Grab a reference on the underlying channel so it does not get | 127 // Grab a reference on the underlying channel so it does not get |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 } | 489 } |
487 | 490 |
488 Send(msg); | 491 Send(msg); |
489 } | 492 } |
490 | 493 |
491 void WebPluginDelegateProxy::UpdateGeometry(const gfx::Rect& window_rect, | 494 void WebPluginDelegateProxy::UpdateGeometry(const gfx::Rect& window_rect, |
492 const gfx::Rect& clip_rect) { | 495 const gfx::Rect& clip_rect) { |
493 // window_rect becomes either a window in native windowing system | 496 // window_rect becomes either a window in native windowing system |
494 // coords, or a backing buffer. In either case things will go bad | 497 // coords, or a backing buffer. In either case things will go bad |
495 // if the rectangle is very large. | 498 // if the rectangle is very large. |
496 if (window_rect.width() < 0 || window_rect.width() > kMaxPluginSideLength || | 499 if (window_rect.width() < 0 || window_rect.width() > kMaxPluginSideLength || |
497 window_rect.height() < 0 || window_rect.height() > kMaxPluginSideLength || | 500 window_rect.height() < 0 || window_rect.height() > kMaxPluginSideLength || |
498 // We know this won't overflow due to above checks. | 501 // We know this won't overflow due to above checks. |
499 static_cast<uint32>(window_rect.width()) * | 502 static_cast<uint32_t>(window_rect.width()) * |
500 static_cast<uint32>(window_rect.height()) > kMaxPluginSize) { | 503 static_cast<uint32_t>(window_rect.height()) > |
| 504 kMaxPluginSize) { |
501 return; | 505 return; |
502 } | 506 } |
503 | 507 |
504 plugin_rect_ = window_rect; | 508 plugin_rect_ = window_rect; |
505 clip_rect_ = clip_rect; | 509 clip_rect_ = clip_rect; |
506 | 510 |
507 bool bitmaps_changed = false; | 511 bool bitmaps_changed = false; |
508 | 512 |
509 if (uses_shared_bitmaps_) { | 513 if (uses_shared_bitmaps_) { |
510 if (!front_buffer_canvas() || | 514 if (!front_buffer_canvas() || |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 } | 549 } |
546 | 550 |
547 #if !defined(OS_WIN) | 551 #if !defined(OS_WIN) |
548 static size_t BitmapSizeForPluginRect(const gfx::Rect& plugin_rect) { | 552 static size_t BitmapSizeForPluginRect(const gfx::Rect& plugin_rect) { |
549 const size_t stride = | 553 const size_t stride = |
550 skia::PlatformCanvasStrideForWidth(plugin_rect.width()); | 554 skia::PlatformCanvasStrideForWidth(plugin_rect.width()); |
551 return stride * plugin_rect.height(); | 555 return stride * plugin_rect.height(); |
552 } | 556 } |
553 | 557 |
554 bool WebPluginDelegateProxy::CreateLocalBitmap( | 558 bool WebPluginDelegateProxy::CreateLocalBitmap( |
555 std::vector<uint8>* memory, | 559 std::vector<uint8_t>* memory, |
556 scoped_ptr<skia::PlatformCanvas>* canvas) { | 560 scoped_ptr<skia::PlatformCanvas>* canvas) { |
557 const size_t size = BitmapSizeForPluginRect(plugin_rect_); | 561 const size_t size = BitmapSizeForPluginRect(plugin_rect_); |
558 memory->resize(size); | 562 memory->resize(size); |
559 if (memory->size() != size) | 563 if (memory->size() != size) |
560 return false; | 564 return false; |
561 canvas->reset(skia::CreatePlatformCanvas( | 565 canvas->reset(skia::CreatePlatformCanvas( |
562 plugin_rect_.width(), plugin_rect_.height(), true, &((*memory)[0]), | 566 plugin_rect_.width(), plugin_rect_.height(), true, &((*memory)[0]), |
563 skia::CRASH_ON_FAILURE)); | 567 skia::CRASH_ON_FAILURE)); |
564 return true; | 568 return true; |
565 } | 569 } |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 void WebPluginDelegateProxy::CopyFromBackBufferToFrontBuffer( | 939 void WebPluginDelegateProxy::CopyFromBackBufferToFrontBuffer( |
936 const gfx::Rect& rect) { | 940 const gfx::Rect& rect) { |
937 #if defined(OS_MACOSX) | 941 #if defined(OS_MACOSX) |
938 // Blitting the bits directly is much faster than going through CG, and since | 942 // Blitting the bits directly is much faster than going through CG, and since |
939 // the goal is just to move the raw pixels between two bitmaps with the same | 943 // the goal is just to move the raw pixels between two bitmaps with the same |
940 // pixel format (no compositing, color correction, etc.), it's safe. | 944 // pixel format (no compositing, color correction, etc.), it's safe. |
941 const size_t stride = | 945 const size_t stride = |
942 skia::PlatformCanvasStrideForWidth(plugin_rect_.width()); | 946 skia::PlatformCanvasStrideForWidth(plugin_rect_.width()); |
943 const size_t chunk_size = 4 * rect.width(); | 947 const size_t chunk_size = 4 * rect.width(); |
944 DCHECK(back_buffer_bitmap() != NULL); | 948 DCHECK(back_buffer_bitmap() != NULL); |
945 uint8* source_data = | 949 uint8_t* source_data = |
946 back_buffer_bitmap()->pixels() + rect.y() * stride + 4 * rect.x(); | 950 back_buffer_bitmap()->pixels() + rect.y() * stride + 4 * rect.x(); |
947 DCHECK(front_buffer_bitmap() != NULL); | 951 DCHECK(front_buffer_bitmap() != NULL); |
948 uint8* target_data = | 952 uint8_t* target_data = |
949 front_buffer_bitmap()->pixels() + rect.y() * stride + 4 * rect.x(); | 953 front_buffer_bitmap()->pixels() + rect.y() * stride + 4 * rect.x(); |
950 for (int row = 0; row < rect.height(); ++row) { | 954 for (int row = 0; row < rect.height(); ++row) { |
951 memcpy(target_data, source_data, chunk_size); | 955 memcpy(target_data, source_data, chunk_size); |
952 source_data += stride; | 956 source_data += stride; |
953 target_data += stride; | 957 target_data += stride; |
954 } | 958 } |
955 #else | 959 #else |
956 BlitCanvasToCanvas(front_buffer_canvas(), | 960 BlitCanvasToCanvas(front_buffer_canvas(), |
957 rect, | 961 rect, |
958 back_buffer_canvas(), | 962 back_buffer_canvas(), |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 plugin_->SetDeferResourceLoading(resource_id, defer); | 1034 plugin_->SetDeferResourceLoading(resource_id, defer); |
1031 } | 1035 } |
1032 | 1036 |
1033 #if defined(OS_MACOSX) | 1037 #if defined(OS_MACOSX) |
1034 void WebPluginDelegateProxy::OnAcceleratedPluginEnabledRendering() { | 1038 void WebPluginDelegateProxy::OnAcceleratedPluginEnabledRendering() { |
1035 uses_compositor_ = true; | 1039 uses_compositor_ = true; |
1036 OnSetWindow(gfx::kNullPluginWindow); | 1040 OnSetWindow(gfx::kNullPluginWindow); |
1037 } | 1041 } |
1038 | 1042 |
1039 void WebPluginDelegateProxy::OnAcceleratedPluginAllocatedIOSurface( | 1043 void WebPluginDelegateProxy::OnAcceleratedPluginAllocatedIOSurface( |
1040 int32 width, | 1044 int32_t width, |
1041 int32 height, | 1045 int32_t height, |
1042 uint32 surface_id) { | 1046 uint32_t surface_id) { |
1043 if (plugin_) | 1047 if (plugin_) |
1044 plugin_->AcceleratedPluginAllocatedIOSurface(width, height, surface_id); | 1048 plugin_->AcceleratedPluginAllocatedIOSurface(width, height, surface_id); |
1045 } | 1049 } |
1046 | 1050 |
1047 void WebPluginDelegateProxy::OnAcceleratedPluginSwappedIOSurface() { | 1051 void WebPluginDelegateProxy::OnAcceleratedPluginSwappedIOSurface() { |
1048 if (plugin_) | 1052 if (plugin_) |
1049 plugin_->AcceleratedPluginSwappedIOSurface(); | 1053 plugin_->AcceleratedPluginSwappedIOSurface(); |
1050 } | 1054 } |
1051 #endif | 1055 #endif |
1052 | 1056 |
(...skipping 29 matching lines...) Expand all Loading... |
1082 | 1086 |
1083 plugin_->URLRedirectResponse(allow, resource_id); | 1087 plugin_->URLRedirectResponse(allow, resource_id); |
1084 } | 1088 } |
1085 | 1089 |
1086 void WebPluginDelegateProxy::OnCheckIfRunInsecureContent(const GURL& url, | 1090 void WebPluginDelegateProxy::OnCheckIfRunInsecureContent(const GURL& url, |
1087 bool* result) { | 1091 bool* result) { |
1088 *result = plugin_->CheckIfRunInsecureContent(url); | 1092 *result = plugin_->CheckIfRunInsecureContent(url); |
1089 } | 1093 } |
1090 | 1094 |
1091 } // namespace content | 1095 } // namespace content |
OLD | NEW |