OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/extensions/blob_holder.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "content/public/browser/blob_handle.h" |
| 9 #include "extensions/common/extension_messages.h" |
| 10 |
| 11 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::BlobHolder); |
| 12 |
| 13 namespace extensions { |
| 14 |
| 15 struct BlobHolder::BlobHolderData { |
| 16 // Takes ownership of |blob_handle|. |
| 17 BlobHolderData(content::RenderViewHost* render_view_host, |
| 18 content::BlobHandle* blob_handle) |
| 19 : render_view_host(render_view_host), |
| 20 blob_handle(blob_handle) { |
| 21 } |
| 22 |
| 23 content::RenderViewHost* render_view_host; |
| 24 scoped_ptr<content::BlobHandle> blob_handle; |
| 25 }; |
| 26 |
| 27 BlobHolder::~BlobHolder() { |
| 28 } |
| 29 |
| 30 void BlobHolder::HoldBlobReference(content::RenderViewHost* render_view_host, |
| 31 scoped_ptr<content::BlobHandle> blob) { |
| 32 held_blobs_.push_back(new BlobHolderData(render_view_host, blob.release())); |
| 33 } |
| 34 |
| 35 BlobHolder::BlobHolder(content::WebContents* web_contents) |
| 36 : content::WebContentsObserver(web_contents) { |
| 37 } |
| 38 |
| 39 void BlobHolder::RenderViewDeleted(content::RenderViewHost* render_view_host) { |
| 40 for (ScopedVector<BlobHolderData>::iterator it = held_blobs_.begin(); |
| 41 it != held_blobs_.end(); ++it) { |
| 42 if ((*it)->render_view_host == render_view_host) |
| 43 it = held_blobs_.erase(it); |
| 44 } |
| 45 } |
| 46 |
| 47 bool BlobHolder::OnMessageReceived(const IPC::Message& message) { |
| 48 bool handled = true; |
| 49 IPC_BEGIN_MESSAGE_MAP(BlobHolder, message) |
| 50 IPC_MESSAGE_HANDLER(ExtensionHostMsg_BlobOwnershipTaken, |
| 51 OnBlobOwnershipTaken) |
| 52 IPC_MESSAGE_UNHANDLED(handled = false) |
| 53 IPC_END_MESSAGE_MAP() |
| 54 return handled; |
| 55 } |
| 56 |
| 57 void BlobHolder::OnBlobOwnershipTaken(const std::string& uuid) { |
| 58 for (ScopedVector<BlobHolderData>::iterator it = held_blobs_.begin(); |
| 59 it != held_blobs_.end(); ++it) { |
| 60 if ((*it)->blob_handle->GetUUID() == uuid) { |
| 61 it = held_blobs_.erase(it); |
| 62 return; |
| 63 } |
| 64 } |
| 65 |
| 66 DLOG(ERROR) << "Tried to release a Blob we don't have ownership to. UUID: " |
| 67 << uuid; |
| 68 } |
| 69 |
| 70 } // namespace extensions |
OLD | NEW |