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 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
657 uint32_t value; | 662 uint32_t value; |
658 if (!m->ReadString(iter, &key)) | 663 if (!m->ReadString(iter, &key)) |
659 return false; | 664 return false; |
660 if (!m->ReadUInt32(iter, &value)) | 665 if (!m->ReadUInt32(iter, &value)) |
661 return false; | 666 return false; |
662 children_.push_back(make_pair(key, value)); | 667 children_.push_back(make_pair(key, value)); |
663 } | 668 } |
664 return true; | 669 return true; |
665 } | 670 } |
666 | 671 |
672 // ResourceDispatcher ---------------------------------------------------------- | |
673 // Used by the plugin side to dispatch resource creation messages. | |
674 // This allows messages from the host side with pending resources to be made | |
675 // into actual plugin-side resources. | |
676 // Must only be created on the plugin side. | |
677 class ResourceDispatcher { | |
raymes
2013/10/11 04:02:24
This class seems like a little overkill for what's
Matt Giuca
2013/10/15 00:25:16
The reason I needed a class (instead of just funct
raymes
2013/10/16 00:45:14
My suggestion is to not use IPC_BEGIN_MESSAGE_MAP
Matt Giuca
2013/10/21 05:20:03
OK DONE! You were right, this is much simpler. Loo
| |
678 public: | |
679 // The |pp_resource| argument will be written with the real resource ID once | |
680 // one of the dispatch methods is called. | |
681 ResourceDispatcher(PP_Instance instance, int pending_renderer_id, | |
raymes
2013/10/11 04:02:24
nit: one line per argument
Matt Giuca
2013/10/15 00:25:16
Done.
| |
682 int pending_browser_id, PP_Resource* pp_resource); | |
683 | |
684 // Execute an IPC message that creates a plugin-side resource. | |
685 void ExecuteCreationMessage(const IPC::Message& creation_message); | |
686 | |
687 void OnMsgFileSystem_CreateFromPendingHost( | |
688 PP_FileSystemType file_system_type); | |
689 | |
690 private: | |
691 Connection GetConnection(); | |
692 | |
693 PP_Instance instance_; | |
694 int pending_renderer_id_; | |
695 int pending_browser_id_; | |
696 PP_Resource* pp_resource_; | |
697 PluginDispatcher* dispatcher_; | |
698 }; | |
699 | |
700 ResourceDispatcher::ResourceDispatcher( | |
701 PP_Instance instance, | |
702 int pending_renderer_id, | |
703 int pending_browser_id, | |
704 PP_Resource* pp_resource) | |
705 : instance_(instance), | |
706 pending_renderer_id_(pending_renderer_id), | |
707 pending_browser_id_(pending_browser_id), | |
708 pp_resource_(pp_resource), | |
709 dispatcher_(NULL) { | |
710 // Check that this is on the plugin side. | |
711 DCHECK(PpapiGlobals::Get()->IsPluginGlobals()); | |
yzshen1
2013/10/11 17:45:45
Please see my comment on line 779.
| |
712 dispatcher_ = PluginDispatcher::GetForInstance(instance); | |
713 } | |
714 | |
715 void ResourceDispatcher::ExecuteCreationMessage( | |
716 const IPC::Message& creation_message) { | |
717 bool handled = true; | |
718 bool msg_is_good = false; | |
719 IPC_BEGIN_MESSAGE_MAP_EX(ResourceDispatcher, creation_message, msg_is_good) | |
720 IPC_MESSAGE_HANDLER( | |
721 PpapiPluginMsg_FileSystem_CreateFromPendingHost, | |
722 OnMsgFileSystem_CreateFromPendingHost); | |
723 IPC_MESSAGE_UNHANDLED_ERROR() | |
724 IPC_END_MESSAGE_MAP() | |
725 DCHECK(handled); | |
726 DCHECK(msg_is_good); | |
727 } | |
728 | |
729 void ResourceDispatcher::OnMsgFileSystem_CreateFromPendingHost( | |
730 PP_FileSystemType file_system_type) { | |
731 DCHECK(pending_renderer_id_); | |
732 DCHECK(pending_browser_id_); | |
733 // Create a plugin-side resource and attach it to the host resource. | |
734 ResourceCreationProxy proxy(dispatcher_); | |
yzshen1
2013/10/11 17:45:45
Can we just EnterResourceCreationNoLock without ex
Matt Giuca
2013/10/17 09:17:58
It looks as though the ResourceCreationProxy is no
yzshen1
2013/10/23 18:29:23
ResourceCreationProxy is what we use for most reso
Matt Giuca
2013/10/24 03:15:26
OK, this seems like a complicated change (touching
| |
735 *pp_resource_ = (new FileSystemResource(GetConnection(), | |
736 instance_, | |
737 pending_renderer_id_, | |
738 pending_browser_id_, | |
739 file_system_type))->GetReference(); | |
740 } | |
741 | |
742 Connection ResourceDispatcher::GetConnection() { | |
743 return Connection(PluginGlobals::Get()->GetBrowserSender(), dispatcher_); | |
744 } | |
745 | |
667 // ResourceRawVarData ---------------------------------------------------------- | 746 // ResourceRawVarData ---------------------------------------------------------- |
668 ResourceRawVarData::ResourceRawVarData() | 747 ResourceRawVarData::ResourceRawVarData() |
669 : pp_resource_(0), | 748 : pp_resource_(0), |
670 pending_renderer_host_id_(0), | 749 pending_renderer_host_id_(0), |
671 pending_browser_host_id_(0) {} | 750 pending_browser_host_id_(0) {} |
672 | 751 |
673 ResourceRawVarData::~ResourceRawVarData() { | 752 ResourceRawVarData::~ResourceRawVarData() { |
674 } | 753 } |
675 | 754 |
676 PP_VarType ResourceRawVarData::Type() { | 755 PP_VarType ResourceRawVarData::Type() { |
(...skipping 11 matching lines...) Expand all Loading... | |
688 creation_message_.reset(new IPC::Message(*message)); | 767 creation_message_.reset(new IPC::Message(*message)); |
689 else | 768 else |
690 creation_message_.reset(); | 769 creation_message_.reset(); |
691 pending_renderer_host_id_ = resource_var->GetPendingRendererHostId(); | 770 pending_renderer_host_id_ = resource_var->GetPendingRendererHostId(); |
692 pending_browser_host_id_ = resource_var->GetPendingBrowserHostId(); | 771 pending_browser_host_id_ = resource_var->GetPendingBrowserHostId(); |
693 initialized_ = true; | 772 initialized_ = true; |
694 return true; | 773 return true; |
695 } | 774 } |
696 | 775 |
697 PP_Var ResourceRawVarData::CreatePPVar(PP_Instance instance) { | 776 PP_Var ResourceRawVarData::CreatePPVar(PP_Instance instance) { |
698 // If pp_resource_ is NULL, it could be because we are on the plugin side and | 777 // If the var is a pending resource host, and we are on the plugin side, |
699 // there is a pending resource host on the renderer. | 778 // create a plugin-side resource. |
700 // TODO(mgiuca): Create a plugin-side resource in this case. | 779 if (PpapiGlobals::Get()->IsPluginGlobals()) { |
yzshen1
2013/10/11 17:45:45
If a plugin is run "in-process", the plugin side o
Matt Giuca
2013/10/17 09:17:58
Hmm, I'm actually really confused about how this w
dmichael (off chromium)
2013/10/17 17:36:11
The Var proxies aren't "refactored" to use the in-
Matt Giuca
2013/10/18 00:00:53
So (I'm obviously going to have to run the in-proc
Matt Giuca
2013/10/18 07:09:30
OK I just wrote browser tests with the help of Ray
Matt Giuca
2013/10/21 05:20:03
Actually, ignore the previous comment. The in-proc
| |
701 // Currently, this should never occur. This will be needed when passing a | 780 if (!pp_resource_) { |
702 // resource from the renderer to the plugin (http://crbug.com/177017). | 781 // If this check fails, then it is a null resource (not pending). |
703 DCHECK(pp_resource_); | 782 DCHECK(creation_message_); |
783 ResourceDispatcher dispatcher(instance, pending_renderer_host_id_, | |
784 pending_browser_host_id_, &pp_resource_); | |
785 dispatcher.ExecuteCreationMessage(*creation_message_); | |
786 DCHECK(pp_resource_); | |
787 } | |
788 } else { | |
789 DCHECK(pp_resource_); | |
790 } | |
raymes
2013/10/11 04:02:24
Have you considered whether all these DCHECKs shou
Matt Giuca
2013/10/17 09:17:58
I just realised that the recent changes we made to
Matt Giuca
2013/10/21 05:20:03
Done.
| |
704 | 791 |
705 return PpapiGlobals::Get()->GetVarTracker()->MakeResourcePPVar(pp_resource_); | 792 return PpapiGlobals::Get()->GetVarTracker()->MakeResourcePPVar(pp_resource_); |
706 } | 793 } |
707 | 794 |
708 void ResourceRawVarData::PopulatePPVar(const PP_Var& var, | 795 void ResourceRawVarData::PopulatePPVar(const PP_Var& var, |
709 const std::vector<PP_Var>& graph) { | 796 const std::vector<PP_Var>& graph) { |
710 } | 797 } |
711 | 798 |
712 void ResourceRawVarData::Write(IPC::Message* m, | 799 void ResourceRawVarData::Write(IPC::Message* m, |
713 const HandleWriter& handle_writer) { | 800 const HandleWriter& handle_writer) { |
(...skipping 24 matching lines...) Expand all Loading... | |
738 if (!IPC::ParamTraits<IPC::Message>::Read(m, iter, creation_message_.get())) | 825 if (!IPC::ParamTraits<IPC::Message>::Read(m, iter, creation_message_.get())) |
739 return false; | 826 return false; |
740 } else { | 827 } else { |
741 creation_message_.reset(); | 828 creation_message_.reset(); |
742 } | 829 } |
743 return true; | 830 return true; |
744 } | 831 } |
745 | 832 |
746 } // namespace proxy | 833 } // namespace proxy |
747 } // namespace ppapi | 834 } // namespace ppapi |
OLD | NEW |