Chromium Code Reviews| 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 struct BlobHolder::BlobHolderData { | |
| 17 // Takes ownership of |blob_handle|. | |
| 18 BlobHolderData(content::RenderViewHost* render_view_host, | |
| 19 content::BlobHandle* blob_handle) | |
| 20 : render_view_host(render_view_host), | |
| 21 blob_handle(blob_handle) { | |
| 22 } | |
| 23 | |
| 24 content::RenderViewHost* render_view_host; | |
| 25 scoped_ptr<content::BlobHandle> blob_handle; | |
| 26 }; | |
| 27 | |
| 28 BlobHolder::~BlobHolder() { | |
| 29 } | |
| 30 | |
| 31 void BlobHolder::HoldBlobReference(content::RenderViewHost* render_view_host, | |
| 32 scoped_ptr<content::BlobHandle> blob) { | |
| 33 DCHECK(!ContainsUUID(blob->GetUUID())); | |
|
michaeln
2014/05/20 19:08:19
wait, this isn't correct. there can be multiple ha
tommycli
2014/05/20 19:49:06
Done.
| |
| 34 held_blobs_.push_back(new BlobHolderData(render_view_host, blob.release())); | |
| 35 } | |
| 36 | |
| 37 BlobHolder::BlobHolder(content::WebContents* web_contents) | |
| 38 : content::WebContentsObserver(web_contents) { | |
| 39 } | |
| 40 | |
| 41 bool BlobHolder::ContainsUUID(const std::string& uuid) const { | |
| 42 for (ScopedVector<BlobHolderData>::const_iterator it = held_blobs_.begin(); | |
| 43 it != held_blobs_.end(); ++it) { | |
| 44 if ((*it)->blob_handle->GetUUID() == uuid) | |
| 45 return true; | |
| 46 } | |
| 47 | |
| 48 return false; | |
| 49 } | |
| 50 | |
| 51 void BlobHolder::RenderViewDeleted(content::RenderViewHost* render_view_host) { | |
| 52 for (ScopedVector<BlobHolderData>::iterator it = held_blobs_.begin(); | |
| 53 it != held_blobs_.end(); ++it) { | |
| 54 if ((*it)->render_view_host == render_view_host) | |
| 55 it = held_blobs_.erase(it); | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 bool BlobHolder::OnMessageReceived(const IPC::Message& message) { | |
| 60 bool handled = true; | |
| 61 IPC_BEGIN_MESSAGE_MAP(BlobHolder, message) | |
| 62 IPC_MESSAGE_HANDLER(ExtensionHostMsg_BlobOwnershipTaken, | |
| 63 OnBlobOwnershipTaken) | |
| 64 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 65 IPC_END_MESSAGE_MAP() | |
| 66 return handled; | |
| 67 } | |
| 68 | |
| 69 void BlobHolder::OnBlobOwnershipTaken(const std::string& uuid) { | |
| 70 for (ScopedVector<BlobHolderData>::iterator it = held_blobs_.begin(); | |
| 71 it != held_blobs_.end(); ++it) { | |
| 72 if ((*it)->blob_handle->GetUUID() == uuid) { | |
| 73 it = held_blobs_.erase(it); | |
| 74 return; | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 DLOG(ERROR) << "Tried to release a Blob we don't have ownership to. UUID: " | |
| 79 << uuid; | |
| 80 web_contents()->GetRenderProcessHost()->ReceivedBadMessage(); | |
| 81 } | |
| 82 | |
| 83 } // namespace extensions | |
| OLD | NEW |