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