Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1799)

Unified Diff: sky/engine/core/loader/CanvasImageDecoder.cpp

Issue 1213313002: Don't crash when decoding an invalid handle (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/engine/core/loader/CanvasImageDecoder.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/engine/core/loader/CanvasImageDecoder.cpp
diff --git a/sky/engine/core/loader/CanvasImageDecoder.cpp b/sky/engine/core/loader/CanvasImageDecoder.cpp
index 8f29408c1fc2b62d4730d0bef53486f9fe80f087..084d21e017339f3f22ba01d7d37edd32d8893ceb 100644
--- a/sky/engine/core/loader/CanvasImageDecoder.cpp
+++ b/sky/engine/core/loader/CanvasImageDecoder.cpp
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/bind.h"
+#include "base/message_loop/message_loop.h"
#include "sky/engine/core/loader/CanvasImageDecoder.h"
#include "sky/engine/core/painting/CanvasImage.h"
#include "sky/engine/platform/SharedBuffer.h"
@@ -10,17 +12,23 @@
namespace blink {
PassRefPtr<CanvasImageDecoder> CanvasImageDecoder::create(
- mojo::ScopedDataPipeConsumerHandle handle,
- PassOwnPtr<ImageDecoderCallback> callback)
-{
+ mojo::ScopedDataPipeConsumerHandle handle,
+ PassOwnPtr<ImageDecoderCallback> callback) {
return adoptRef(new CanvasImageDecoder(handle.Pass(), callback));
}
CanvasImageDecoder::CanvasImageDecoder(
mojo::ScopedDataPipeConsumerHandle handle,
PassOwnPtr<ImageDecoderCallback> callback)
- : callback_(callback) {
+ : callback_(callback), weak_factory_(this) {
CHECK(callback_);
+ if (!handle.is_valid()) {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&CanvasImageDecoder::RejectCallback,
+ weak_factory_.GetWeakPtr()));
+ return;
+ }
+
buffer_ = SharedBuffer::create();
drainer_ = adoptPtr(new mojo::common::DataPipeDrainer(this, handle.Pass()));
}
@@ -53,4 +61,8 @@ void CanvasImageDecoder::OnDataComplete() {
callback_->handleEvent(resultImage.get());
}
-} // namespace blink
+void CanvasImageDecoder::RejectCallback() {
+ callback_->handleEvent(nullptr);
+}
+
+} // namespace blink
« no previous file with comments | « sky/engine/core/loader/CanvasImageDecoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698