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

Side by Side Diff: chrome/browser/extensions/blob_holder.cc

Issue 280393003: Blobs: Catching browser-process created Blobs in extension code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/blob_holder.h ('k') | chrome/chrome_browser_extensions.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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()));
Tom Sepez 2014/05/19 23:41:37 How do we ensure the UUID isn't duplicated?
tommycli 2014/05/20 00:04:11 Currently we don't. We just assumed that they're u
tommycli 2014/05/20 18:22:42 Done.
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: "
Tom Sepez 2014/05/19 23:41:37 probably want to kill the renderer here via BadMes
tommycli 2014/05/20 00:04:11 Since this isn't a BrowserMessageFilter, I don't h
tommycli 2014/05/20 18:22:42 Done.
67 << uuid;
68 }
69
70 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/blob_holder.h ('k') | chrome/chrome_browser_extensions.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698