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

Side by Side Diff: ppapi/host/ppapi_host.cc

Issue 10803050: Hook up the PPB_Flash_Print interface to new host system. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: with deps Created 8 years, 4 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 | « ppapi/host/ppapi_host.h ('k') | ppapi/ppapi_host.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/host/ppapi_host.h" 5 #include "ppapi/host/ppapi_host.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ppapi/c/pp_errors.h" 8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/host/host_factory.h" 9 #include "ppapi/host/host_factory.h"
10 #include "ppapi/host/host_message_context.h" 10 #include "ppapi/host/host_message_context.h"
11 #include "ppapi/host/instance_message_filter.h"
11 #include "ppapi/host/resource_host.h" 12 #include "ppapi/host/resource_host.h"
12 #include "ppapi/proxy/ppapi_messages.h" 13 #include "ppapi/proxy/ppapi_messages.h"
13 #include "ppapi/proxy/resource_message_params.h" 14 #include "ppapi/proxy/resource_message_params.h"
14 #include "ppapi/shared_impl/host_resource.h" 15 #include "ppapi/shared_impl/host_resource.h"
15 16
16 namespace ppapi { 17 namespace ppapi {
17 namespace host { 18 namespace host {
18 19
19 namespace { 20 namespace {
20 21
21 // Put a cap on the maximum number of resources so we don't explode if the 22 // Put a cap on the maximum number of resources so we don't explode if the
22 // renderer starts spamming us. 23 // renderer starts spamming us.
23 const size_t kMaxResourcesPerPlugin = 1 << 14; 24 const size_t kMaxResourcesPerPlugin = 1 << 14;
24 25
25 } // namespace 26 } // namespace
26 27
27 PpapiHost::PpapiHost(IPC::Sender* sender, 28 PpapiHost::PpapiHost(IPC::Sender* sender,
28 HostFactory* host_factory, 29 HostFactory* host_factory,
29 const PpapiPermissions& perms) 30 const PpapiPermissions& perms)
30 : sender_(sender), 31 : sender_(sender),
31 host_factory_(host_factory), 32 host_factory_(host_factory),
32 permissions_(perms) { 33 permissions_(perms) {
33 } 34 }
34 35
35 PpapiHost::~PpapiHost() { 36 PpapiHost::~PpapiHost() {
37 // Delete these explicitly before destruction since then the host is still
38 // technically alive in case one of the filters accesses us from the
39 // destructor.
40 instance_message_filters_.clear();
36 } 41 }
37 42
38 bool PpapiHost::Send(IPC::Message* msg) { 43 bool PpapiHost::Send(IPC::Message* msg) {
39 return sender_->Send(msg); 44 return sender_->Send(msg);
40 } 45 }
41 46
42 bool PpapiHost::OnMessageReceived(const IPC::Message& msg) { 47 bool PpapiHost::OnMessageReceived(const IPC::Message& msg) {
43 bool handled = true; 48 bool handled = true;
44 IPC_BEGIN_MESSAGE_MAP(PpapiHost, msg) 49 IPC_BEGIN_MESSAGE_MAP(PpapiHost, msg)
45 IPC_MESSAGE_HANDLER(PpapiHostMsg_ResourceCall, 50 IPC_MESSAGE_HANDLER(PpapiHostMsg_ResourceCall,
46 OnHostMsgResourceCall) 51 OnHostMsgResourceCall)
47 IPC_MESSAGE_HANDLER(PpapiHostMsg_ResourceCreated, 52 IPC_MESSAGE_HANDLER(PpapiHostMsg_ResourceCreated,
48 OnHostMsgResourceCreated) 53 OnHostMsgResourceCreated)
49 IPC_MESSAGE_HANDLER(PpapiHostMsg_ResourceDestroyed, 54 IPC_MESSAGE_HANDLER(PpapiHostMsg_ResourceDestroyed,
50 OnHostMsgResourceDestroyed) 55 OnHostMsgResourceDestroyed)
51 IPC_MESSAGE_UNHANDLED(handled = false) 56 IPC_MESSAGE_UNHANDLED(handled = false)
52 IPC_END_MESSAGE_MAP() 57 IPC_END_MESSAGE_MAP()
58
59 if (!handled) {
60 for (size_t i = 0; i < instance_message_filters_.size(); i++) {
61 if (instance_message_filters_[i]->OnInstanceMessageReceived(msg)) {
62 handled = true;
63 break;
64 }
65 }
66 }
67
53 return handled; 68 return handled;
54 } 69 }
55 70
56 void PpapiHost::SendReply(const proxy::ResourceMessageReplyParams& params, 71 void PpapiHost::SendReply(const proxy::ResourceMessageReplyParams& params,
57 const IPC::Message& msg) { 72 const IPC::Message& msg) {
58 Send(new PpapiPluginMsg_ResourceReply(params, msg)); 73 Send(new PpapiPluginMsg_ResourceReply(params, msg));
59 } 74 }
60 75
76
77 void PpapiHost::AddInstanceMessageFilter(
78 scoped_ptr<InstanceMessageFilter> filter) {
79 instance_message_filters_.push_back(filter.release());
80 }
81
61 void PpapiHost::OnHostMsgResourceCall( 82 void PpapiHost::OnHostMsgResourceCall(
62 const proxy::ResourceMessageCallParams& params, 83 const proxy::ResourceMessageCallParams& params,
63 const IPC::Message& nested_msg) { 84 const IPC::Message& nested_msg) {
64 HostMessageContext context(params); 85 HostMessageContext context(params);
65 proxy::ResourceMessageReplyParams reply_params(params.pp_resource(), 86 proxy::ResourceMessageReplyParams reply_params(params.pp_resource(),
66 params.sequence()); 87 params.sequence());
67 88
68 ResourceHost* resource_host = GetResourceHost(params.pp_resource()); 89 ResourceHost* resource_host = GetResourceHost(params.pp_resource());
69 if (resource_host) { 90 if (resource_host) {
70 reply_params.set_result(resource_host->OnResourceMessageReceived( 91 reply_params.set_result(resource_host->OnResourceMessageReceived(
(...skipping 22 matching lines...) Expand all
93 } 114 }
94 115
95 void PpapiHost::OnHostMsgResourceCreated( 116 void PpapiHost::OnHostMsgResourceCreated(
96 const proxy::ResourceMessageCallParams& params, 117 const proxy::ResourceMessageCallParams& params,
97 PP_Instance instance, 118 PP_Instance instance,
98 const IPC::Message& nested_msg) { 119 const IPC::Message& nested_msg) {
99 if (resources_.size() >= kMaxResourcesPerPlugin) 120 if (resources_.size() >= kMaxResourcesPerPlugin)
100 return; 121 return;
101 122
102 scoped_ptr<ResourceHost> resource_host( 123 scoped_ptr<ResourceHost> resource_host(
103 host_factory_->CreateResourceHost(this, params, instance, 124 host_factory_->CreateResourceHost(this, params, instance, nested_msg));
104 nested_msg));
105 if (!resource_host.get()) { 125 if (!resource_host.get()) {
106 NOTREACHED(); 126 NOTREACHED();
107 return; 127 return;
108 } 128 }
109 129
110 resources_[params.pp_resource()] = 130 resources_[params.pp_resource()] =
111 linked_ptr<ResourceHost>(resource_host.release()); 131 linked_ptr<ResourceHost>(resource_host.release());
112 } 132 }
113 133
114 void PpapiHost::OnHostMsgResourceDestroyed(PP_Resource resource) { 134 void PpapiHost::OnHostMsgResourceDestroyed(PP_Resource resource) {
115 ResourceMap::iterator found = resources_.find(resource); 135 ResourceMap::iterator found = resources_.find(resource);
116 if (found == resources_.end()) { 136 if (found == resources_.end()) {
117 NOTREACHED(); 137 NOTREACHED();
118 return; 138 return;
119 } 139 }
120 resources_.erase(found); 140 resources_.erase(found);
121 } 141 }
122 142
123 ResourceHost* PpapiHost::GetResourceHost(PP_Resource resource) { 143 ResourceHost* PpapiHost::GetResourceHost(PP_Resource resource) {
124 ResourceMap::iterator found = resources_.find(resource); 144 ResourceMap::iterator found = resources_.find(resource);
125 return found == resources_.end() ? NULL : found->second.get(); 145 return found == resources_.end() ? NULL : found->second.get();
126 } 146 }
127 147
128 } // namespace host 148 } // namespace host
129 } // namespace ppapi 149 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/host/ppapi_host.h ('k') | ppapi/ppapi_host.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698