OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This example demonstrates how to load content of the page into NaCl module. | 5 // This example demonstrates how to load content of the page into NaCl module. |
6 | 6 |
7 #include <cstdio> | 7 #include <cstdio> |
8 #include <string> | 8 #include <string> |
9 #include "ppapi/cpp/instance.h" | 9 #include "ppapi/cpp/instance.h" |
10 #include "ppapi/cpp/module.h" | 10 #include "ppapi/cpp/module.h" |
11 #include "ppapi/cpp/url_loader.h" | 11 #include "ppapi/cpp/url_loader.h" |
12 #include "ppapi/cpp/var.h" | 12 #include "ppapi/cpp/var.h" |
13 | 13 |
14 #include "url_loader_handler.h" | 14 #include "url_loader_handler.h" |
15 | 15 |
16 // These are the method names as JavaScript sees them. | 16 // These are the method names as JavaScript sees them. |
17 namespace { | 17 namespace { |
18 const char* const kLoadUrlMethodId = "getUrl"; | 18 const char* const kLoadUrlMethodId = "getUrl"; |
19 static const char kMessageArgumentSeparator = ':'; | 19 static const char kMessageArgumentSeparator = ':'; |
20 | |
21 // Exception strings. These are passed back to the browser when errors | |
22 // happen during property accesses or method calls. | |
23 const char* const kExceptionStartFailed = "URLLoaderHandler::Start() failed"; | |
24 const char* const kExceptionURLNotAString = "URL is not a string"; | |
25 } // namespace | 20 } // namespace |
26 | 21 |
27 class URLLoaderInstance : public pp::Instance { | 22 class URLLoaderInstance : public pp::Instance { |
28 public: | 23 public: |
29 explicit URLLoaderInstance(PP_Instance instance) : pp::Instance(instance) {} | 24 explicit URLLoaderInstance(PP_Instance instance) : pp::Instance(instance) {} |
30 virtual ~URLLoaderInstance() {} | 25 virtual ~URLLoaderInstance() {} |
31 | 26 |
32 // Called by the browser to handle the postMessage() call in Javascript. | 27 // Called by the browser to handle the postMessage() call in Javascript. |
33 // The message in this case is expected to contain the string 'getUrl' | 28 // The message in this case is expected to contain the string 'getUrl' |
34 // followed by a ':' separator, then the URL to fetch. If a valid message | 29 // followed by a ':' separator, then the URL to fetch. If a valid message |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 65 |
71 // Create and return a URLLoaderInstance object. | 66 // Create and return a URLLoaderInstance object. |
72 virtual pp::Instance* CreateInstance(PP_Instance instance) { | 67 virtual pp::Instance* CreateInstance(PP_Instance instance) { |
73 return new URLLoaderInstance(instance); | 68 return new URLLoaderInstance(instance); |
74 } | 69 } |
75 }; | 70 }; |
76 | 71 |
77 namespace pp { | 72 namespace pp { |
78 Module* CreateModule() { return new URLLoaderModule(); } | 73 Module* CreateModule() { return new URLLoaderModule(); } |
79 } // namespace pp | 74 } // namespace pp |
OLD | NEW |