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 "content/public/browser/render_process_host.h" |
| 10 #include "extensions/common/extension_messages.h" |
| 11 |
| 12 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::BlobHolder); |
| 13 |
| 14 namespace extensions { |
| 15 |
| 16 BlobHolder::~BlobHolder() {} |
| 17 |
| 18 void BlobHolder::HoldBlobReference(scoped_ptr<content::BlobHandle> blob) { |
| 19 DCHECK(!ContainsBlobHandle(blob.get())); |
| 20 held_blobs_.push_back(blob.release()); |
| 21 } |
| 22 |
| 23 BlobHolder::BlobHolder(content::WebContents* web_contents) |
| 24 : content::WebContentsObserver(web_contents) { |
| 25 } |
| 26 |
| 27 bool BlobHolder::ContainsBlobHandle(content::BlobHandle* handle) const { |
| 28 for (BlobHandleVector::const_iterator it = held_blobs_.begin(); |
| 29 it != held_blobs_.end(); ++it) { |
| 30 if (*it == handle) |
| 31 return true; |
| 32 } |
| 33 |
| 34 return false; |
| 35 } |
| 36 |
| 37 bool BlobHolder::OnMessageReceived(const IPC::Message& message) { |
| 38 bool handled = true; |
| 39 IPC_BEGIN_MESSAGE_MAP(BlobHolder, message) |
| 40 IPC_MESSAGE_HANDLER(ExtensionHostMsg_TransferBlobsAck, OnTransferBlobsAck) |
| 41 IPC_MESSAGE_UNHANDLED(handled = false) |
| 42 IPC_END_MESSAGE_MAP() |
| 43 return handled; |
| 44 } |
| 45 |
| 46 void BlobHolder::OnTransferBlobsAck( |
| 47 const std::vector<std::string>& blob_uuids) { |
| 48 for (std::vector<std::string>::const_iterator uuid_it = blob_uuids.begin(); |
| 49 uuid_it != blob_uuids.end(); ++uuid_it) { |
| 50 bool found = false; |
| 51 for (BlobHandleVector::iterator blob_handle_it = held_blobs_.begin(); |
| 52 blob_handle_it != held_blobs_.end(); ++blob_handle_it) { |
| 53 if ((*blob_handle_it)->GetUUID() == *uuid_it) { |
| 54 held_blobs_.erase(blob_handle_it); |
| 55 found = true; |
| 56 break; |
| 57 } |
| 58 } |
| 59 |
| 60 if (!found) { |
| 61 DLOG(ERROR) << "Tried to release a Blob we don't have ownership to." |
| 62 << "UUID: " << *uuid_it; |
| 63 web_contents()->GetRenderProcessHost()->ReceivedBadMessage(); |
| 64 } |
| 65 } |
| 66 } |
| 67 |
| 68 } // namespace extensions |
OLD | NEW |