OLD | NEW |
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 "content/browser/renderer_host/pepper/browser_ppapi_host_impl.h" | 5 #include "content/browser/renderer_host/pepper/browser_ppapi_host_impl.h" |
6 | 6 |
7 #include "content/browser/renderer_host/pepper/pepper_message_filter.h" | 7 #include "content/browser/renderer_host/pepper/pepper_message_filter.h" |
8 #include "content/browser/trace_message_filter.h" | 8 #include "content/browser/trace_message_filter.h" |
| 9 #include "content/common/pepper_renderer_instance_data.h" |
9 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
10 #include "content/public/browser/render_view_host.h" | 11 #include "content/public/browser/render_view_host.h" |
11 #include "ipc/ipc_message_macros.h" | 12 #include "ipc/ipc_message_macros.h" |
12 | 13 |
13 namespace content { | 14 namespace content { |
14 | 15 |
15 // static | 16 // static |
16 BrowserPpapiHost* BrowserPpapiHost::CreateExternalPluginProcess( | 17 BrowserPpapiHost* BrowserPpapiHost::CreateExternalPluginProcess( |
17 IPC::Sender* sender, | 18 IPC::Sender* sender, |
18 ppapi::PpapiPermissions permissions, | 19 ppapi::PpapiPermissions permissions, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 return &ppapi_host_; | 67 return &ppapi_host_; |
67 } | 68 } |
68 | 69 |
69 base::ProcessHandle BrowserPpapiHostImpl::GetPluginProcessHandle() const { | 70 base::ProcessHandle BrowserPpapiHostImpl::GetPluginProcessHandle() const { |
70 // Handle should previously have been set before use. | 71 // Handle should previously have been set before use. |
71 DCHECK(plugin_process_handle_ != base::kNullProcessHandle); | 72 DCHECK(plugin_process_handle_ != base::kNullProcessHandle); |
72 return plugin_process_handle_; | 73 return plugin_process_handle_; |
73 } | 74 } |
74 | 75 |
75 bool BrowserPpapiHostImpl::IsValidInstance(PP_Instance instance) const { | 76 bool BrowserPpapiHostImpl::IsValidInstance(PP_Instance instance) const { |
76 return instance_to_view_.find(instance) != instance_to_view_.end(); | 77 return instance_map_.find(instance) != instance_map_.end(); |
77 } | 78 } |
78 | 79 |
79 bool BrowserPpapiHostImpl::GetRenderViewIDsForInstance( | 80 bool BrowserPpapiHostImpl::GetRenderViewIDsForInstance( |
80 PP_Instance instance, | 81 PP_Instance instance, |
81 int* render_process_id, | 82 int* render_process_id, |
82 int* render_view_id) const { | 83 int* render_view_id) const { |
83 InstanceToViewMap::const_iterator found = instance_to_view_.find(instance); | 84 InstanceMap::const_iterator found = instance_map_.find(instance); |
84 if (found == instance_to_view_.end()) { | 85 if (found == instance_map_.end()) { |
85 *render_process_id = 0; | 86 *render_process_id = 0; |
86 *render_view_id = 0; | 87 *render_view_id = 0; |
87 return false; | 88 return false; |
88 } | 89 } |
89 | 90 |
90 *render_process_id = found->second.process_id; | 91 *render_process_id = found->second.render_process_id; |
91 *render_view_id = found->second.view_id; | 92 *render_view_id = found->second.render_view_id; |
92 return true; | 93 return true; |
93 } | 94 } |
94 | 95 |
95 const std::string& BrowserPpapiHostImpl::GetPluginName() { | 96 const std::string& BrowserPpapiHostImpl::GetPluginName() { |
96 return plugin_name_; | 97 return plugin_name_; |
97 } | 98 } |
98 | 99 |
99 const FilePath& BrowserPpapiHostImpl::GetProfileDataDirectory() { | 100 const FilePath& BrowserPpapiHostImpl::GetProfileDataDirectory() { |
100 return profile_data_directory_; | 101 return profile_data_directory_; |
101 } | 102 } |
102 | 103 |
103 void BrowserPpapiHostImpl::AddInstanceForView(PP_Instance instance, | 104 GURL BrowserPpapiHostImpl::GetDocumentURLForInstance(PP_Instance instance) { |
104 int render_process_id, | 105 InstanceMap::const_iterator found = instance_map_.find(instance); |
105 int render_view_id) { | 106 if (found == instance_map_.end()) |
106 DCHECK(instance_to_view_.find(instance) == instance_to_view_.end()); | 107 return GURL(); |
107 | 108 return found->second.document_url; |
108 RenderViewIDs ids; | |
109 ids.process_id = render_process_id; | |
110 ids.view_id = render_view_id; | |
111 instance_to_view_[instance] = ids; | |
112 } | 109 } |
113 | 110 |
114 void BrowserPpapiHostImpl::DeleteInstanceForView(PP_Instance instance) { | 111 GURL BrowserPpapiHostImpl::GetPluginURLForInstance(PP_Instance instance) { |
115 InstanceToViewMap::iterator found = instance_to_view_.find(instance); | 112 InstanceMap::const_iterator found = instance_map_.find(instance); |
116 if (found == instance_to_view_.end()) { | 113 if (found == instance_map_.end()) |
| 114 return GURL(); |
| 115 return found->second.plugin_url; |
| 116 } |
| 117 |
| 118 void BrowserPpapiHostImpl::AddInstance( |
| 119 PP_Instance instance, |
| 120 const PepperRendererInstanceData& instance_data) { |
| 121 DCHECK(instance_map_.find(instance) == instance_map_.end()); |
| 122 instance_map_[instance] = instance_data; |
| 123 } |
| 124 |
| 125 void BrowserPpapiHostImpl::DeleteInstance(PP_Instance instance) { |
| 126 InstanceMap::iterator found = instance_map_.find(instance); |
| 127 if (found == instance_map_.end()) { |
117 NOTREACHED(); | 128 NOTREACHED(); |
118 return; | 129 return; |
119 } | 130 } |
120 instance_to_view_.erase(found); | 131 instance_map_.erase(found); |
121 } | 132 } |
122 | 133 |
123 bool BrowserPpapiHostImpl::HostMessageFilter::OnMessageReceived( | 134 bool BrowserPpapiHostImpl::HostMessageFilter::OnMessageReceived( |
124 const IPC::Message& msg) { | 135 const IPC::Message& msg) { |
125 // Don't forward messages if our owner object has been destroyed. | 136 // Don't forward messages if our owner object has been destroyed. |
126 if (!ppapi_host_) | 137 if (!ppapi_host_) |
127 return false; | 138 return false; |
128 | 139 |
129 /* TODO(brettw) when we add messages, here, the code should look like this: | 140 /* TODO(brettw) when we add messages, here, the code should look like this: |
130 bool handled = true; | 141 bool handled = true; |
131 IPC_BEGIN_MESSAGE_MAP(BrowserPpapiHostImpl, msg) | 142 IPC_BEGIN_MESSAGE_MAP(BrowserPpapiHostImpl, msg) |
132 // Add necessary message handlers here. | 143 // Add necessary message handlers here. |
133 IPC_MESSAGE_UNHANDLED(handled = ppapi_host_->OnMessageReceived(msg)) | 144 IPC_MESSAGE_UNHANDLED(handled = ppapi_host_->OnMessageReceived(msg)) |
134 IPC_END_MESSAGE_MAP(); | 145 IPC_END_MESSAGE_MAP(); |
135 return handled; | 146 return handled; |
136 */ | 147 */ |
137 return ppapi_host_->OnMessageReceived(msg); | 148 return ppapi_host_->OnMessageReceived(msg); |
138 } | 149 } |
139 | 150 |
140 void BrowserPpapiHostImpl::HostMessageFilter::OnHostDestroyed() { | 151 void BrowserPpapiHostImpl::HostMessageFilter::OnHostDestroyed() { |
141 DCHECK(ppapi_host_); | 152 DCHECK(ppapi_host_); |
142 ppapi_host_ = NULL; | 153 ppapi_host_ = NULL; |
143 } | 154 } |
144 | 155 |
145 } // namespace content | 156 } // namespace content |
OLD | NEW |