OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/proxy/raw_var_data.h" | 5 #include "ppapi/proxy/raw_var_data.h" |
6 | 6 |
7 #include <stack> | 7 #include <stack> |
8 | 8 |
9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "ipc/ipc_message.h" | 11 #include "ipc/ipc_message.h" |
| 12 #include "ppapi/proxy/file_system_resource.h" |
| 13 #include "ppapi/proxy/plugin_dispatcher.h" |
| 14 #include "ppapi/proxy/plugin_globals.h" |
| 15 #include "ppapi/proxy/ppapi_messages.h" |
12 #include "ppapi/proxy/ppapi_param_traits.h" | 16 #include "ppapi/proxy/ppapi_param_traits.h" |
| 17 #include "ppapi/proxy/resource_creation_proxy.h" |
13 #include "ppapi/shared_impl/array_var.h" | 18 #include "ppapi/shared_impl/array_var.h" |
14 #include "ppapi/shared_impl/dictionary_var.h" | 19 #include "ppapi/shared_impl/dictionary_var.h" |
15 #include "ppapi/shared_impl/ppapi_globals.h" | 20 #include "ppapi/shared_impl/ppapi_globals.h" |
16 #include "ppapi/shared_impl/resource_var.h" | 21 #include "ppapi/shared_impl/resource_var.h" |
17 #include "ppapi/shared_impl/scoped_pp_var.h" | 22 #include "ppapi/shared_impl/scoped_pp_var.h" |
18 #include "ppapi/shared_impl/var.h" | 23 #include "ppapi/shared_impl/var.h" |
19 #include "ppapi/shared_impl/var_tracker.h" | 24 #include "ppapi/shared_impl/var_tracker.h" |
20 | 25 |
21 using std::make_pair; | 26 using std::make_pair; |
22 | 27 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 } else { | 62 } else { |
58 data->push_back(RawVarData::Create(var.type)); | 63 data->push_back(RawVarData::Create(var.type)); |
59 } | 64 } |
60 return data->size() - 1; | 65 return data->size() - 1; |
61 } | 66 } |
62 | 67 |
63 bool CanHaveChildren(PP_Var var) { | 68 bool CanHaveChildren(PP_Var var) { |
64 return var.type == PP_VARTYPE_ARRAY || var.type == PP_VARTYPE_DICTIONARY; | 69 return var.type == PP_VARTYPE_ARRAY || var.type == PP_VARTYPE_DICTIONARY; |
65 } | 70 } |
66 | 71 |
| 72 // Should only be called when the Pepper plugin is out of process. |
| 73 Connection GetConnectionForInstance(PP_Instance instance) { |
| 74 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 75 // GetForInstance returns NULL in the in-process case. |
| 76 DCHECK(dispatcher); |
| 77 return Connection(PluginGlobals::Get()->GetBrowserSender(), dispatcher); |
| 78 } |
| 79 |
67 } // namespace | 80 } // namespace |
68 | 81 |
69 // RawVarDataGraph ------------------------------------------------------------ | 82 // RawVarDataGraph ------------------------------------------------------------ |
70 RawVarDataGraph::RawVarDataGraph() { | 83 RawVarDataGraph::RawVarDataGraph() { |
71 } | 84 } |
72 | 85 |
73 RawVarDataGraph::~RawVarDataGraph() { | 86 RawVarDataGraph::~RawVarDataGraph() { |
74 } | 87 } |
75 | 88 |
76 // This function uses a stack-based DFS search to traverse the var graph. Each | 89 // This function uses a stack-based DFS search to traverse the var graph. Each |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 creation_message_.reset(new IPC::Message(*message)); | 701 creation_message_.reset(new IPC::Message(*message)); |
689 else | 702 else |
690 creation_message_.reset(); | 703 creation_message_.reset(); |
691 pending_renderer_host_id_ = resource_var->GetPendingRendererHostId(); | 704 pending_renderer_host_id_ = resource_var->GetPendingRendererHostId(); |
692 pending_browser_host_id_ = resource_var->GetPendingBrowserHostId(); | 705 pending_browser_host_id_ = resource_var->GetPendingBrowserHostId(); |
693 initialized_ = true; | 706 initialized_ = true; |
694 return true; | 707 return true; |
695 } | 708 } |
696 | 709 |
697 PP_Var ResourceRawVarData::CreatePPVar(PP_Instance instance) { | 710 PP_Var ResourceRawVarData::CreatePPVar(PP_Instance instance) { |
698 // If pp_resource_ is NULL, it could be because we are on the plugin side and | 711 // If we are on the plugin side, and the var is a pending resource host, |
699 // there is a pending resource host on the renderer. | 712 // create a plugin-side resource. A var is a pending resource host if it has a |
700 // TODO(mgiuca): Create a plugin-side resource in this case. | 713 // pp_resource of 0, and a non-null creation message. |
701 // Currently, this should never occur. This will be needed when passing a | 714 if (PpapiGlobals::Get()->IsPluginGlobals() && !pp_resource_ && |
702 // resource from the renderer to the plugin (http://crbug.com/177017). | 715 creation_message_) { |
703 DCHECK(pp_resource_); | 716 DCHECK(pending_renderer_host_id_); |
| 717 DCHECK(pending_browser_host_id_); |
| 718 switch (creation_message_->type()) { |
| 719 case PpapiPluginMsg_FileSystem_CreateFromPendingHost::ID: { |
| 720 PP_FileSystemType file_system_type; |
| 721 if (!UnpackMessage<PpapiPluginMsg_FileSystem_CreateFromPendingHost>( |
| 722 *creation_message_, &file_system_type)) { |
| 723 NOTREACHED() << "Invalid message of type " |
| 724 "PpapiPluginMsg_FileSystem_CreateFromPendingHost"; |
| 725 return PP_MakeNull(); |
| 726 } |
| 727 // Create a plugin-side resource and attach it to the host resource. |
| 728 // Note: This only makes sense when the plugin is out of process (which |
| 729 // should always be true when passing resource vars). |
| 730 pp_resource_ = |
| 731 (new FileSystemResource(GetConnectionForInstance(instance), |
| 732 instance, |
| 733 pending_renderer_host_id_, |
| 734 pending_browser_host_id_, |
| 735 file_system_type))->GetReference(); |
| 736 break; |
| 737 } |
| 738 default: { |
| 739 NOTREACHED() << "Creation message has unexpected type " |
| 740 << creation_message_->type(); |
| 741 return PP_MakeNull(); |
| 742 } |
| 743 } |
| 744 } |
704 | 745 |
705 return PpapiGlobals::Get()->GetVarTracker()->MakeResourcePPVar(pp_resource_); | 746 return PpapiGlobals::Get()->GetVarTracker()->MakeResourcePPVar(pp_resource_); |
706 } | 747 } |
707 | 748 |
708 void ResourceRawVarData::PopulatePPVar(const PP_Var& var, | 749 void ResourceRawVarData::PopulatePPVar(const PP_Var& var, |
709 const std::vector<PP_Var>& graph) { | 750 const std::vector<PP_Var>& graph) { |
710 } | 751 } |
711 | 752 |
712 void ResourceRawVarData::Write(IPC::Message* m, | 753 void ResourceRawVarData::Write(IPC::Message* m, |
713 const HandleWriter& handle_writer) { | 754 const HandleWriter& handle_writer) { |
(...skipping 24 matching lines...) Expand all Loading... |
738 if (!IPC::ParamTraits<IPC::Message>::Read(m, iter, creation_message_.get())) | 779 if (!IPC::ParamTraits<IPC::Message>::Read(m, iter, creation_message_.get())) |
739 return false; | 780 return false; |
740 } else { | 781 } else { |
741 creation_message_.reset(); | 782 creation_message_.reset(); |
742 } | 783 } |
743 return true; | 784 return true; |
744 } | 785 } |
745 | 786 |
746 } // namespace proxy | 787 } // namespace proxy |
747 } // namespace ppapi | 788 } // namespace ppapi |
OLD | NEW |