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

Side by Side Diff: chrome/browser/renderer_host/blob_dispatcher_host.cc

Issue 5698008: Switch a bunch of remaining filters to derive from BrowserMessageFilters so t... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years 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
OLDNEW
(Empty)
1 // Copyright (c) 2010 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/renderer_host/blob_dispatcher_host.h"
6
7 #include "chrome/browser/browser_thread.h"
8 #include "chrome/browser/child_process_security_policy.h"
9 #include "chrome/browser/chrome_blob_storage_context.h"
10 #include "chrome/common/render_messages.h"
11 #include "googleurl/src/gurl.h"
12 #include "ipc/ipc_message.h"
13 #include "webkit/blob/blob_data.h"
14 #include "webkit/blob/blob_storage_controller.h"
15
16 BlobDispatcherHost::BlobDispatcherHost(
17 int process_id,
18 ChromeBlobStorageContext* blob_storage_context)
19 : process_id_(process_id),
20 blob_storage_context_(blob_storage_context) {
21 }
22
23 BlobDispatcherHost::~BlobDispatcherHost() {
24 }
25
26 void BlobDispatcherHost::Shutdown() {
27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
28
29 // Unregister all the blob URLs that are previously registered in this
30 // process.
31 for (base::hash_set<std::string>::const_iterator iter = blob_urls_.begin();
32 iter != blob_urls_.end(); ++iter) {
33 blob_storage_context_->controller()->UnregisterBlobUrl(GURL(*iter));
34 }
35 }
36
37 bool BlobDispatcherHost::OnMessageReceived(const IPC::Message& message,
38 bool* msg_is_ok) {
39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
40
41 *msg_is_ok = true;
42 bool handled = true;
43 IPC_BEGIN_MESSAGE_MAP_EX(BlobDispatcherHost, message, *msg_is_ok)
44 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterBlobUrl, OnRegisterBlobUrl)
45 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterBlobUrlFrom, OnRegisterBlobUrlFrom)
46 IPC_MESSAGE_HANDLER(ViewHostMsg_UnregisterBlobUrl, OnUnregisterBlobUrl)
47 IPC_MESSAGE_UNHANDLED(handled = false)
48 IPC_END_MESSAGE_MAP()
49 return handled;
50 }
51
52 // Check if the child process has been granted permission to register the files.
53 bool BlobDispatcherHost::CheckPermission(
54 webkit_blob::BlobData* blob_data) const {
55 ChildProcessSecurityPolicy* policy =
56 ChildProcessSecurityPolicy::GetInstance();
57 for (std::vector<webkit_blob::BlobData::Item>::const_iterator iter =
58 blob_data->items().begin();
59 iter != blob_data->items().end(); ++iter) {
60 if (iter->type() == webkit_blob::BlobData::TYPE_FILE) {
61 if (!policy->CanReadFile(process_id_, iter->file_path()))
62 return false;
63 }
64 }
65 return true;
66 }
67
68 void BlobDispatcherHost::OnRegisterBlobUrl(
69 const GURL& url, const scoped_refptr<webkit_blob::BlobData>& blob_data) {
70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
71 if (!CheckPermission(blob_data.get()))
72 return;
73 blob_storage_context_->controller()->RegisterBlobUrl(url, blob_data);
74 blob_urls_.insert(url.spec());
75 }
76
77 void BlobDispatcherHost::OnRegisterBlobUrlFrom(
78 const GURL& url, const GURL& src_url) {
79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
80 blob_storage_context_->controller()->RegisterBlobUrlFrom(url, src_url);
81 blob_urls_.insert(url.spec());
82 }
83
84 void BlobDispatcherHost::OnUnregisterBlobUrl(const GURL& url) {
85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
86 blob_storage_context_->controller()->UnregisterBlobUrl(url);
87 blob_urls_.erase(url.spec());
88 }
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/blob_dispatcher_host.h ('k') | chrome/browser/renderer_host/blob_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698