| 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 "webkit/plugins/ppapi/ppb_broker_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_broker_impl.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ppapi/shared_impl/platform_file.h" | 8 #include "ppapi/shared_impl/platform_file.h" |
| 9 #include "third_party/WebKit/public/web/WebDocument.h" | 9 #include "third_party/WebKit/public/web/WebDocument.h" |
| 10 #include "third_party/WebKit/public/web/WebElement.h" | 10 #include "third_party/WebKit/public/web/WebElement.h" |
| 11 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 11 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
| 12 #include "webkit/plugins/ppapi/common.h" | 12 #include "webkit/plugins/ppapi/common.h" |
| 13 #include "webkit/plugins/ppapi/plugin_module.h" | 13 #include "webkit/plugins/ppapi/plugin_module.h" |
| 14 #include "webkit/plugins/ppapi/ppapi_plugin_instance_impl.h" |
| 14 #include "webkit/plugins/ppapi/resource_helper.h" | 15 #include "webkit/plugins/ppapi/resource_helper.h" |
| 15 | 16 |
| 16 using ppapi::PlatformFileToInt; | 17 using ppapi::PlatformFileToInt; |
| 17 using ppapi::thunk::PPB_Broker_API; | 18 using ppapi::thunk::PPB_Broker_API; |
| 18 using ppapi::TrackedCallback; | 19 using ppapi::TrackedCallback; |
| 19 | 20 |
| 20 namespace webkit { | 21 namespace webkit { |
| 21 namespace ppapi { | 22 namespace ppapi { |
| 22 | 23 |
| 23 // PPB_Broker_Impl ------------------------------------------------------ | 24 // PPB_Broker_Impl ------------------------------------------------------ |
| (...skipping 21 matching lines...) Expand all Loading... |
| 45 | 46 |
| 46 int32_t PPB_Broker_Impl::Connect( | 47 int32_t PPB_Broker_Impl::Connect( |
| 47 scoped_refptr<TrackedCallback> connect_callback) { | 48 scoped_refptr<TrackedCallback> connect_callback) { |
| 48 // TODO(ddorwin): Return PP_ERROR_FAILED if plugin is in-process. | 49 // TODO(ddorwin): Return PP_ERROR_FAILED if plugin is in-process. |
| 49 | 50 |
| 50 if (broker_) { | 51 if (broker_) { |
| 51 // May only be called once. | 52 // May only be called once. |
| 52 return PP_ERROR_FAILED; | 53 return PP_ERROR_FAILED; |
| 53 } | 54 } |
| 54 | 55 |
| 55 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 56 PluginInstanceImpl* plugin_instance = ResourceHelper::GetPluginInstance(this); |
| 56 if (!plugin_instance) | 57 if (!plugin_instance) |
| 57 return PP_ERROR_FAILED; | 58 return PP_ERROR_FAILED; |
| 58 | 59 |
| 59 // The callback must be populated now in case we are connected to the broker | 60 // The callback must be populated now in case we are connected to the broker |
| 60 // and BrokerConnected is called before ConnectToBroker returns. | 61 // and BrokerConnected is called before ConnectToBroker returns. |
| 61 // Because it must be created now, it must be aborted and cleared if | 62 // Because it must be created now, it must be aborted and cleared if |
| 62 // ConnectToBroker fails. | 63 // ConnectToBroker fails. |
| 63 connect_callback_ = connect_callback; | 64 connect_callback_ = connect_callback; |
| 64 | 65 |
| 65 broker_ = plugin_instance->delegate()->ConnectToBroker(this); | 66 broker_ = plugin_instance->delegate()->ConnectToBroker(this); |
| 66 if (!broker_) { | 67 if (!broker_) { |
| 67 connect_callback_->Abort(); | 68 connect_callback_->Abort(); |
| 68 return PP_ERROR_FAILED; | 69 return PP_ERROR_FAILED; |
| 69 } | 70 } |
| 70 | 71 |
| 71 return PP_OK_COMPLETIONPENDING; | 72 return PP_OK_COMPLETIONPENDING; |
| 72 } | 73 } |
| 73 | 74 |
| 74 int32_t PPB_Broker_Impl::GetHandle(int32_t* handle) { | 75 int32_t PPB_Broker_Impl::GetHandle(int32_t* handle) { |
| 75 if (pipe_handle_ == PlatformFileToInt(base::kInvalidPlatformFileValue)) | 76 if (pipe_handle_ == PlatformFileToInt(base::kInvalidPlatformFileValue)) |
| 76 return PP_ERROR_FAILED; // Handle not set yet. | 77 return PP_ERROR_FAILED; // Handle not set yet. |
| 77 *handle = pipe_handle_; | 78 *handle = pipe_handle_; |
| 78 return PP_OK; | 79 return PP_OK; |
| 79 } | 80 } |
| 80 | 81 |
| 81 GURL PPB_Broker_Impl::GetDocumentUrl() { | 82 GURL PPB_Broker_Impl::GetDocumentUrl() { |
| 82 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 83 PluginInstanceImpl* plugin_instance = ResourceHelper::GetPluginInstance(this); |
| 83 return plugin_instance->container()->element().document().url(); | 84 return plugin_instance->container()->element().document().url(); |
| 84 } | 85 } |
| 85 | 86 |
| 86 // Transfers ownership of the handle to the plugin. | 87 // Transfers ownership of the handle to the plugin. |
| 87 void PPB_Broker_Impl::BrokerConnected(int32_t handle, int32_t result) { | 88 void PPB_Broker_Impl::BrokerConnected(int32_t handle, int32_t result) { |
| 88 DCHECK(pipe_handle_ == | 89 DCHECK(pipe_handle_ == |
| 89 PlatformFileToInt(base::kInvalidPlatformFileValue)); | 90 PlatformFileToInt(base::kInvalidPlatformFileValue)); |
| 90 DCHECK(result == PP_OK || | 91 DCHECK(result == PP_OK || |
| 91 handle == PlatformFileToInt(base::kInvalidPlatformFileValue)); | 92 handle == PlatformFileToInt(base::kInvalidPlatformFileValue)); |
| 92 | 93 |
| 93 pipe_handle_ = handle; | 94 pipe_handle_ = handle; |
| 94 | 95 |
| 95 // Synchronous calls are not supported. | 96 // Synchronous calls are not supported. |
| 96 DCHECK(TrackedCallback::IsPending(connect_callback_)); | 97 DCHECK(TrackedCallback::IsPending(connect_callback_)); |
| 97 | 98 |
| 98 connect_callback_->Run(result); | 99 connect_callback_->Run(result); |
| 99 } | 100 } |
| 100 | 101 |
| 101 } // namespace ppapi | 102 } // namespace ppapi |
| 102 } // namespace webkit | 103 } // namespace webkit |
| OLD | NEW |