Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Side by Side Diff: components/nacl/renderer/ppb_nacl_private_impl.cc

Issue 287153006: Pepper: Manifest refactoring in trusted plugin. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ppapi/api/private/ppb_nacl_private.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "components/nacl/renderer/ppb_nacl_private_impl.h" 5 #include "components/nacl/renderer/ppb_nacl_private_impl.h"
6 6
7 #include <numeric> 7 #include <numeric>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 812
813 int64_t GetNexeSize(PP_Instance instance) { 813 int64_t GetNexeSize(PP_Instance instance) {
814 NexeLoadManager* load_manager = GetNexeLoadManager(instance); 814 NexeLoadManager* load_manager = GetNexeLoadManager(instance);
815 DCHECK(load_manager); 815 DCHECK(load_manager);
816 if (load_manager) 816 if (load_manager)
817 return load_manager->nexe_size(); 817 return load_manager->nexe_size();
818 return 0; 818 return 0;
819 } 819 }
820 820
821 void DownloadManifestToBuffer(PP_Instance instance, 821 void DownloadManifestToBuffer(PP_Instance instance,
822 struct PP_Var* out_data, 822 int32_t* out_manifest_id,
823 struct PP_CompletionCallback callback); 823 struct PP_CompletionCallback callback);
824 824
825 int32_t CreateJsonManifest(PP_Instance instance,
826 const std::string& manifest_url,
827 const std::string& manifest_data);
828
825 void RequestNaClManifest(PP_Instance instance, 829 void RequestNaClManifest(PP_Instance instance,
826 const char* url, 830 const char* url,
827 PP_Var* out_data, 831 int32_t* out_manifest_id,
828 PP_CompletionCallback callback) { 832 PP_CompletionCallback callback) {
829 NexeLoadManager* load_manager = GetNexeLoadManager(instance); 833 NexeLoadManager* load_manager = GetNexeLoadManager(instance);
830 DCHECK(load_manager); 834 DCHECK(load_manager);
831 if (!load_manager) { 835 if (!load_manager) {
832 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( 836 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
833 FROM_HERE, 837 FROM_HERE,
834 base::Bind(callback.func, callback.user_data, 838 base::Bind(callback.func, callback.user_data,
835 static_cast<int32_t>(PP_ERROR_FAILED))); 839 static_cast<int32_t>(PP_ERROR_FAILED)));
836 return; 840 return;
837 } 841 }
838 842
839 if (!load_manager->RequestNaClManifest(url)) { 843 if (!load_manager->RequestNaClManifest(url)) {
840 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( 844 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
841 FROM_HERE, 845 FROM_HERE,
842 base::Bind(callback.func, callback.user_data, 846 base::Bind(callback.func, callback.user_data,
843 static_cast<int32_t>(PP_ERROR_FAILED))); 847 static_cast<int32_t>(PP_ERROR_FAILED)));
844 return; 848 return;
845 } 849 }
846 850
847 const GURL& base_url = load_manager->manifest_base_url(); 851 const GURL& base_url = load_manager->manifest_base_url();
848 if (base_url.SchemeIs("data")) { 852 if (base_url.SchemeIs("data")) {
849 GURL gurl(base_url); 853 GURL gurl(base_url);
850 std::string mime_type; 854 std::string mime_type;
851 std::string charset; 855 std::string charset;
852 std::string data; 856 std::string data;
853 int32_t error = PP_ERROR_FAILED; 857 int32_t error = PP_ERROR_FAILED;
854 if (net::DataURL::Parse(gurl, &mime_type, &charset, &data)) { 858 if (net::DataURL::Parse(gurl, &mime_type, &charset, &data)) {
855 if (data.size() <= ManifestDownloader::kNaClManifestMaxFileBytes) { 859 if (data.size() <= ManifestDownloader::kNaClManifestMaxFileBytes) {
856 error = PP_OK; 860 error = PP_OK;
857 *out_data = ppapi::StringVar::StringToPPVar(data); 861 *out_manifest_id = CreateJsonManifest(instance, base_url.spec(), data);
858 } else { 862 } else {
859 load_manager->ReportLoadError(PP_NACL_ERROR_MANIFEST_TOO_LARGE, 863 load_manager->ReportLoadError(PP_NACL_ERROR_MANIFEST_TOO_LARGE,
860 "manifest file too large."); 864 "manifest file too large.");
861 } 865 }
862 } else { 866 } else {
863 load_manager->ReportLoadError(PP_NACL_ERROR_MANIFEST_LOAD_URL, 867 load_manager->ReportLoadError(PP_NACL_ERROR_MANIFEST_LOAD_URL,
864 "could not load manifest url."); 868 "could not load manifest url.");
865 } 869 }
866 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( 870 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
867 FROM_HERE, 871 FROM_HERE,
868 base::Bind(callback.func, callback.user_data, error)); 872 base::Bind(callback.func, callback.user_data, error));
869 } else { 873 } else {
870 DownloadManifestToBuffer(instance, out_data, callback); 874 DownloadManifestToBuffer(instance, out_manifest_id, callback);
871 } 875 }
872 } 876 }
873 877
874 PP_Var GetManifestBaseURL(PP_Instance instance) { 878 PP_Var GetManifestBaseURL(PP_Instance instance) {
875 NexeLoadManager* load_manager = GetNexeLoadManager(instance); 879 NexeLoadManager* load_manager = GetNexeLoadManager(instance);
876 DCHECK(load_manager); 880 DCHECK(load_manager);
877 if (!load_manager) 881 if (!load_manager)
878 return PP_MakeUndefined(); 882 return PP_MakeUndefined();
879 const GURL& gurl = load_manager->manifest_base_url(); 883 const GURL& gurl = load_manager->manifest_base_url();
880 if (!gurl.is_valid()) 884 if (!gurl.is_valid())
(...skipping 30 matching lines...) Expand all
911 915
912 PP_Bool DevInterfacesEnabled(PP_Instance instance) { 916 PP_Bool DevInterfacesEnabled(PP_Instance instance) {
913 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); 917 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance);
914 if (load_manager) 918 if (load_manager)
915 return PP_FromBool(load_manager->DevInterfacesEnabled()); 919 return PP_FromBool(load_manager->DevInterfacesEnabled());
916 return PP_FALSE; 920 return PP_FALSE;
917 } 921 }
918 922
919 void DownloadManifestToBufferCompletion(PP_Instance instance, 923 void DownloadManifestToBufferCompletion(PP_Instance instance,
920 struct PP_CompletionCallback callback, 924 struct PP_CompletionCallback callback,
921 struct PP_Var* out_data, 925 int32_t* out_manifest_id,
922 base::Time start_time, 926 base::Time start_time,
923 PP_NaClError pp_nacl_error, 927 PP_NaClError pp_nacl_error,
924 const std::string& data); 928 const std::string& data);
925 929
926 void DownloadManifestToBuffer(PP_Instance instance, 930 void DownloadManifestToBuffer(PP_Instance instance,
927 struct PP_Var* out_data, 931 int32_t* out_manifest_id,
928 struct PP_CompletionCallback callback) { 932 struct PP_CompletionCallback callback) {
929 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); 933 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance);
930 DCHECK(load_manager); 934 DCHECK(load_manager);
931 content::PepperPluginInstance* plugin_instance = 935 content::PepperPluginInstance* plugin_instance =
932 content::PepperPluginInstance::Get(instance); 936 content::PepperPluginInstance::Get(instance);
933 if (!load_manager || !plugin_instance) { 937 if (!load_manager || !plugin_instance) {
934 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( 938 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
935 FROM_HERE, 939 FROM_HERE,
936 base::Bind(callback.func, callback.user_data, 940 base::Bind(callback.func, callback.user_data,
937 static_cast<int32_t>(PP_ERROR_FAILED))); 941 static_cast<int32_t>(PP_ERROR_FAILED)));
938 } 942 }
939 const blink::WebDocument& document = 943 const blink::WebDocument& document =
940 plugin_instance->GetContainer()->element().document(); 944 plugin_instance->GetContainer()->element().document();
941 945
942 const GURL& gurl = load_manager->manifest_base_url(); 946 const GURL& gurl = load_manager->manifest_base_url();
943 scoped_ptr<blink::WebURLLoader> url_loader( 947 scoped_ptr<blink::WebURLLoader> url_loader(
944 CreateWebURLLoader(document, gurl)); 948 CreateWebURLLoader(document, gurl));
945 blink::WebURLRequest request = CreateWebURLRequest(document, gurl); 949 blink::WebURLRequest request = CreateWebURLRequest(document, gurl);
946 950
947 // ManifestDownloader deletes itself after invoking the callback. 951 // ManifestDownloader deletes itself after invoking the callback.
948 ManifestDownloader* manifest_downloader = new ManifestDownloader( 952 ManifestDownloader* manifest_downloader = new ManifestDownloader(
949 url_loader.Pass(), 953 url_loader.Pass(),
950 load_manager->is_installed(), 954 load_manager->is_installed(),
951 base::Bind(DownloadManifestToBufferCompletion, 955 base::Bind(DownloadManifestToBufferCompletion,
952 instance, callback, out_data, base::Time::Now())); 956 instance, callback, out_manifest_id, base::Time::Now()));
953 manifest_downloader->Load(request); 957 manifest_downloader->Load(request);
954 } 958 }
955 959
956 void DownloadManifestToBufferCompletion(PP_Instance instance, 960 void DownloadManifestToBufferCompletion(PP_Instance instance,
957 struct PP_CompletionCallback callback, 961 struct PP_CompletionCallback callback,
958 struct PP_Var* out_data, 962 int32_t* out_manifest_id,
959 base::Time start_time, 963 base::Time start_time,
960 PP_NaClError pp_nacl_error, 964 PP_NaClError pp_nacl_error,
961 const std::string& data) { 965 const std::string& data) {
962 base::TimeDelta download_time = base::Time::Now() - start_time; 966 base::TimeDelta download_time = base::Time::Now() - start_time;
963 HistogramTimeSmall("NaCl.Perf.StartupTime.ManifestDownload", 967 HistogramTimeSmall("NaCl.Perf.StartupTime.ManifestDownload",
964 download_time.InMilliseconds()); 968 download_time.InMilliseconds());
965 969
966 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); 970 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance);
967 if (!load_manager) { 971 if (!load_manager) {
968 callback.func(callback.user_data, PP_ERROR_ABORTED); 972 callback.func(callback.user_data, PP_ERROR_ABORTED);
(...skipping 21 matching lines...) Expand all
990 "access to manifest url was denied."); 994 "access to manifest url was denied.");
991 break; 995 break;
992 default: 996 default:
993 NOTREACHED(); 997 NOTREACHED();
994 pp_error = PP_ERROR_FAILED; 998 pp_error = PP_ERROR_FAILED;
995 load_manager->ReportLoadError(PP_NACL_ERROR_MANIFEST_LOAD_URL, 999 load_manager->ReportLoadError(PP_NACL_ERROR_MANIFEST_LOAD_URL,
996 "could not load manifest url."); 1000 "could not load manifest url.");
997 } 1001 }
998 1002
999 if (pp_error == PP_OK) { 1003 if (pp_error == PP_OK) {
1000 std::string contents; 1004 std::string base_url = load_manager->manifest_base_url().spec();
1001 *out_data = ppapi::StringVar::StringToPPVar(data); 1005 *out_manifest_id = CreateJsonManifest(instance, base_url, data);
1002 } 1006 }
1003 callback.func(callback.user_data, pp_error); 1007 callback.func(callback.user_data, pp_error);
1004 } 1008 }
1005 1009
1006 int32_t CreatePNaClManifest(PP_Instance /* instance */) { 1010 int32_t CreatePNaClManifest(PP_Instance /* instance */) {
1007 return GetPNaClManifestId(); 1011 return GetPNaClManifestId();
1008 } 1012 }
1009 1013
1010 int32_t CreateJsonManifest(PP_Instance instance, 1014 int32_t CreateJsonManifest(PP_Instance instance,
1011 const char* manifest_url, 1015 const std::string& manifest_url,
1012 const char* manifest_data) { 1016 const std::string& manifest_data) {
1017 HistogramSizeKB("NaCl.Perf.Size.Manifest",
1018 static_cast<int32_t>(manifest_data.length() / 1024));
1019
1013 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); 1020 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance);
1014 if (!load_manager) 1021 if (!load_manager)
1015 return -1; 1022 return -1;
1016 int32_t manifest_id = g_next_manifest_id.Get(); 1023 int32_t manifest_id = g_next_manifest_id.Get();
1017 g_next_manifest_id.Get()++; 1024 g_next_manifest_id.Get()++;
1018 1025
1019 const char* isa_type; 1026 const char* isa_type;
1020 if (load_manager->IsPNaCl()) 1027 if (load_manager->IsPNaCl())
1021 isa_type = kPortableArch; 1028 isa_type = kPortableArch;
1022 else 1029 else
1023 isa_type = GetSandboxArch(); 1030 isa_type = GetSandboxArch();
1024 1031
1025 scoped_ptr<nacl::JsonManifest> j( 1032 scoped_ptr<nacl::JsonManifest> j(
1026 new nacl::JsonManifest( 1033 new nacl::JsonManifest(
1027 manifest_url, 1034 manifest_url.c_str(),
1028 isa_type, 1035 isa_type,
1029 IsNonSFIModeEnabled(), 1036 IsNonSFIModeEnabled(),
1030 PP_ToBool(NaClDebugEnabledForURL(manifest_url)))); 1037 PP_ToBool(NaClDebugEnabledForURL(manifest_url.c_str()))));
1031 JsonManifest::ErrorInfo error_info; 1038 JsonManifest::ErrorInfo error_info;
1032 if (j->Init(manifest_data, &error_info)) { 1039 if (j->Init(manifest_data.c_str(), &error_info)) {
1033 g_manifest_map.Get().add(manifest_id, j.Pass()); 1040 g_manifest_map.Get().add(manifest_id, j.Pass());
1034 return manifest_id; 1041 return manifest_id;
1035 } 1042 }
1036 load_manager->ReportLoadError(error_info.error, error_info.string); 1043 load_manager->ReportLoadError(error_info.error, error_info.string);
1037 return -1; 1044 return -1;
1038 } 1045 }
1039 1046
1040 void DestroyManifest(PP_Instance /* instance */, 1047 void DestroyManifest(PP_Instance /* instance */,
1041 int32_t manifest_id) { 1048 int32_t manifest_id) {
1042 if (manifest_id == GetPNaClManifestId()) 1049 if (manifest_id == GetPNaClManifestId())
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
1454 &Vlog, 1461 &Vlog,
1455 &InitializePlugin, 1462 &InitializePlugin,
1456 &GetNexeSize, 1463 &GetNexeSize,
1457 &RequestNaClManifest, 1464 &RequestNaClManifest,
1458 &GetManifestBaseURL, 1465 &GetManifestBaseURL,
1459 &ResolvesRelativeToPluginBaseURL, 1466 &ResolvesRelativeToPluginBaseURL,
1460 &ProcessNaClManifest, 1467 &ProcessNaClManifest,
1461 &GetManifestURLArgument, 1468 &GetManifestURLArgument,
1462 &DevInterfacesEnabled, 1469 &DevInterfacesEnabled,
1463 &CreatePNaClManifest, 1470 &CreatePNaClManifest,
1464 &CreateJsonManifest,
1465 &DestroyManifest, 1471 &DestroyManifest,
1466 &ManifestGetProgramURL, 1472 &ManifestGetProgramURL,
1467 &ManifestResolveKey, 1473 &ManifestResolveKey,
1468 &GetPNaClResourceInfo, 1474 &GetPNaClResourceInfo,
1469 &GetCpuFeatureAttrs, 1475 &GetCpuFeatureAttrs,
1470 &PostMessageToJavaScript, 1476 &PostMessageToJavaScript,
1471 &DownloadNexe 1477 &DownloadNexe
1472 }; 1478 };
1473 1479
1474 } // namespace 1480 } // namespace
1475 1481
1476 const PPB_NaCl_Private* GetNaClPrivateInterface() { 1482 const PPB_NaCl_Private* GetNaClPrivateInterface() {
1477 return &nacl_interface; 1483 return &nacl_interface;
1478 } 1484 }
1479 1485
1480 } // namespace nacl 1486 } // namespace nacl
OLDNEW
« no previous file with comments | « no previous file | ppapi/api/private/ppb_nacl_private.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698