Index: chrome/test/data/nacl/pnacl_url_loader/pnacl_url_loader.cc |
diff --git a/chrome/test/data/nacl/pnacl_url_loader/pnacl_url_loader.cc b/chrome/test/data/nacl/pnacl_url_loader/pnacl_url_loader.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9ef656bf3ee492bd2f776fad4dd8705775fdf1bf |
--- /dev/null |
+++ b/chrome/test/data/nacl/pnacl_url_loader/pnacl_url_loader.cc |
@@ -0,0 +1,60 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include <string> |
+ |
+#include "ppapi/cpp/instance.h" |
+#include "ppapi/cpp/module.h" |
+#include "ppapi/cpp/url_loader.h" |
+#include "ppapi/cpp/url_request_info.h" |
+#include "ppapi/cpp/url_response_info.h" |
+#include "ppapi/cpp/var.h" |
+#include "ppapi/utility/completion_callback_factory.h" |
+ |
+class PnaclUrlLoaderInstance : public pp::Instance { |
+ public: |
+ explicit PnaclUrlLoaderInstance(PP_Instance instance) |
+ : pp::Instance(instance), loader_(this), factory_(this) {} |
+ |
+ void HandleMessage(const pp::Var& var_message) override { |
+ if (var_message.is_string()) { |
+ command_ = var_message.AsString(); |
+ pp::URLRequestInfo request(this); |
+ request.SetMethod("GET"); |
+ if (command_.find("Other") != std::string::npos) |
+ request.SetURL("https://www.example.com/echo"); |
+ else |
+ request.SetURL("/echo"); |
+ if (command_.find("CORS") != std::string::npos) |
+ request.SetAllowCrossOriginRequests(true); |
+ if (command_.find("Credentials") != std::string::npos) |
+ request.SetAllowCredentials(true); |
+ loader_.Open(request, |
+ factory_.NewCallback(&PnaclUrlLoaderInstance::OnOpen)); |
+ return; |
+ } |
+ } |
+ |
+ private: |
+ void OnOpen(int32_t result) { PostMessage(pp::Var("OnOpen" + command_)); } |
+ |
+ pp::URLLoader loader_; |
+ pp::CompletionCallbackFactory<PnaclUrlLoaderInstance> factory_; |
+ std::string command_; |
+}; |
+ |
+class PnaclUrlLoaderModule : public pp::Module { |
+ public: |
+ virtual pp::Instance* CreateInstance(PP_Instance instance) { |
+ return new PnaclUrlLoaderInstance(instance); |
+ } |
+}; |
+ |
+namespace pp { |
+ |
+__attribute__((visibility("default"))) Module* CreateModule() { |
+ return new PnaclUrlLoaderModule(); |
+} |
+ |
+} // namespace pp |