Chromium Code Reviews| 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..d6a7f3c004b619be135609cba9500e66031bfdcd |
| --- /dev/null |
| +++ b/chrome/test/data/nacl/pnacl_url_loader/pnacl_url_loader.cc |
| @@ -0,0 +1,60 @@ |
| +// Copyright (c) 2016 The Chromium Authors. All rights reserved. |
|
nhiroki
2016/02/09 04:48:42
"(c)" is not necessary:
http://www.chromium.org/de
horo
2016/02/10 06:09:22
Done.
|
| +// 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) {} |
| + |
| + virtual void HandleMessage(const pp::Var& var_message) { |
|
nhiroki
2016/02/09 04:48:42
remove "virtual" and add "override" ?
horo
2016/02/10 06:09:22
Done.
|
| + 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 |