diff options
author | lambroslambrou@chromium.org <lambroslambrou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-12 05:39:02 +0000 |
---|---|---|
committer | lambroslambrou@chromium.org <lambroslambrou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-12 05:39:02 +0000 |
commit | cb959349f7e2d506d32acde7cc664854c42eff76 (patch) | |
tree | 7c00aab7d1495b0afbeb2e4292acd73a91d9e295 /remoting | |
parent | 41f38c3b1775a30f02f91df1689e28afd3e46376 (diff) | |
download | chromium_src-cb959349f7e2d506d32acde7cc664854c42eff76.zip chromium_src-cb959349f7e2d506d32acde7cc664854c42eff76.tar.gz chromium_src-cb959349f7e2d506d32acde7cc664854c42eff76.tar.bz2 |
Move cursor-shape validation into remoting/protocol
The same validation code will be needed for drawing the cursor in the
Android client.
BUG=177559,270347
Review URL: https://chromiumcodereview.appspot.com/23571010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222717 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/client/plugin/chromoting_instance.cc | 33 | ||||
-rw-r--r-- | remoting/protocol/client_control_dispatcher.cc | 43 |
2 files changed, 47 insertions, 29 deletions
diff --git a/remoting/client/plugin/chromoting_instance.cc b/remoting/client/plugin/chromoting_instance.cc index 3532b9a..066d132 100644 --- a/remoting/client/plugin/chromoting_instance.cc +++ b/remoting/client/plugin/chromoting_instance.cc @@ -491,40 +491,17 @@ void ChromotingInstance::SetCursorShape( const protocol::CursorShapeInfo& cursor_shape) { COMPILE_ASSERT(sizeof(uint32_t) == kBytesPerPixel, rgba_pixels_are_32bit); - if (!cursor_shape.has_data() || - !cursor_shape.has_width() || - !cursor_shape.has_height() || - !cursor_shape.has_hotspot_x() || - !cursor_shape.has_hotspot_y()) { + // pp::MouseCursor requires image to be in the native format. + if (pp::ImageData::GetNativeImageDataFormat() != + PP_IMAGEDATAFORMAT_BGRA_PREMUL) { + LOG(WARNING) << "Unable to set cursor shape - native image format is not" + " premultiplied BGRA"; return; } int width = cursor_shape.width(); int height = cursor_shape.height(); - // Verify that |width| and |height| are within sane limits. Otherwise integer - // overflow can occur while calculating |cursor_total_bytes| below. - if (width <= 0 || width > (SHRT_MAX / 2) || - height <= 0 || height > (SHRT_MAX / 2)) { - VLOG(2) << "Cursor dimensions are out of bounds for SetCursor: " - << width << "x" << height; - return; - } - - uint32 cursor_total_bytes = width * height * kBytesPerPixel; - if (cursor_shape.data().size() < cursor_total_bytes) { - VLOG(2) << "Expected " << cursor_total_bytes << " bytes for a " - << width << "x" << height << " cursor. Only received " - << cursor_shape.data().size() << " bytes"; - return; - } - - if (pp::ImageData::GetNativeImageDataFormat() != - PP_IMAGEDATAFORMAT_BGRA_PREMUL) { - VLOG(2) << "Unable to set cursor shape - non-native image format"; - return; - } - int hotspot_x = cursor_shape.hotspot_x(); int hotspot_y = cursor_shape.hotspot_y(); int bytes_per_row = width * kBytesPerPixel; diff --git a/remoting/protocol/client_control_dispatcher.cc b/remoting/protocol/client_control_dispatcher.cc index 76376e2..ec77037 100644 --- a/remoting/protocol/client_control_dispatcher.cc +++ b/remoting/protocol/client_control_dispatcher.cc @@ -18,6 +18,46 @@ namespace remoting { namespace protocol { +namespace { + +// 32-bit BGRA is 4 bytes per pixel. +const int kBytesPerPixel = 4; + +bool CursorShapeIsValid(const CursorShapeInfo& cursor_shape) { + if (!cursor_shape.has_data() || + !cursor_shape.has_width() || + !cursor_shape.has_height() || + !cursor_shape.has_hotspot_x() || + !cursor_shape.has_hotspot_y()) { + LOG(ERROR) << "Cursor shape is missing required fields."; + return false; + } + + int width = cursor_shape.width(); + int height = cursor_shape.height(); + + // Verify that |width| and |height| are within sane limits. Otherwise integer + // overflow can occur while calculating |cursor_total_bytes| below. + if (width <= 0 || width > (SHRT_MAX / 2) || + height <= 0 || height > (SHRT_MAX / 2)) { + LOG(ERROR) << "Cursor dimensions are out of bounds for SetCursor: " + << width << "x" << height; + return false; + } + + uint32 cursor_total_bytes = width * height * kBytesPerPixel; + if (cursor_shape.data().size() < cursor_total_bytes) { + LOG(ERROR) << "Expected " << cursor_total_bytes << " bytes for a " + << width << "x" << height << " cursor. Only received " + << cursor_shape.data().size() << " bytes"; + return false; + } + + return true; +} + +} // namespace + ClientControlDispatcher::ClientControlDispatcher() : ChannelDispatcherBase(kControlChannelName), client_stub_(NULL), @@ -93,7 +133,8 @@ void ClientControlDispatcher::OnMessageReceived( } else if (message->has_capabilities()) { client_stub_->SetCapabilities(message->capabilities()); } else if (message->has_cursor_shape()) { - client_stub_->SetCursorShape(message->cursor_shape()); + if (CursorShapeIsValid(message->cursor_shape())) + client_stub_->SetCursorShape(message->cursor_shape()); } else if (message->has_pairing_response()) { client_stub_->SetPairingResponse(message->pairing_response()); } else if (message->has_extension_message()) { |