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_context.h" |
| 9 #include "extensions/common/extension_messages.h" |
| 10 |
| 11 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::BlobHolder); |
| 12 |
| 13 namespace extensions { |
| 14 |
| 15 BlobHolder::~BlobHolder() { |
| 16 } |
| 17 |
| 18 void BlobHolder::HoldBlobReference(scoped_ptr<content::BlobHandle> blob) { |
| 19 held_blobs_.push_back(blob.release()); |
| 20 } |
| 21 |
| 22 BlobHolder::BlobHolder(content::WebContents* web_contents) |
| 23 : content::WebContentsObserver(web_contents) { |
| 24 } |
| 25 |
| 26 bool BlobHolder::OnMessageReceived(const IPC::Message& message) { |
| 27 bool handled = true; |
| 28 IPC_BEGIN_MESSAGE_MAP(BlobHolder, message) |
| 29 IPC_MESSAGE_HANDLER(ExtensionHostMsg_BlobOwnershipTaken, |
| 30 OnBlobOwnershipTaken) |
| 31 IPC_MESSAGE_UNHANDLED(handled = false) |
| 32 IPC_END_MESSAGE_MAP() |
| 33 return handled; |
| 34 } |
| 35 |
| 36 void BlobHolder::OnBlobOwnershipTaken(const std::string& uuid) { |
| 37 for (ScopedVector<content::BlobHandle>::iterator it = held_blobs_.begin(); |
| 38 it != held_blobs_.end(); ++it) { |
| 39 if ((*it)->uuid() == uuid) { |
| 40 it = held_blobs_.erase(it); |
| 41 return; |
| 42 } |
| 43 } |
| 44 DLOG(ERROR) << "Tried to release a Blob we don't have ownership to. UUID: " |
| 45 << uuid; |
| 46 } |
| 47 |
| 48 } // namespace extensions |
OLD | NEW |