OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Native Client Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "native_client/tests/fake_browser_ppapi/fake_url_util.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "native_client/src/include/nacl_macros.h" | |
10 #include "native_client/src/include/portability.h" | |
11 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_var.h" | |
12 #include "native_client/tests/fake_browser_ppapi/fake_url_loader.h" | |
13 #include "native_client/tests/fake_browser_ppapi/utility.h" | |
14 | |
15 #include "ppapi/c/pp_errors.h" | |
16 | |
17 using fake_browser_ppapi::DebugPrintf; | |
18 using ppapi_proxy::PluginVar; | |
19 | |
20 namespace fake_browser_ppapi { | |
21 | |
22 namespace { | |
23 | |
24 struct PP_Var Canonicalize(struct PP_Var url, | |
25 struct PP_URLComponents_Dev* components) { | |
26 // Return values as if none of these components exist, the ppapi plugin | |
27 // doesn't require any of these normally, but needs valid values. | |
28 if (components) { | |
29 components->scheme.begin = 0; | |
30 components->scheme.len = -1; | |
31 components->username.begin = 0; | |
32 components->username.len = -1; | |
33 components->password.begin = 0; | |
34 components->password.len = -1; | |
35 components->host.begin = 0; | |
36 components->host.len = -1; | |
37 components->port.begin = 0; | |
38 components->port.len = -1; | |
39 components->path.begin = 0; | |
40 components->path.len = -1; | |
41 components->query.begin = 0; | |
42 components->query.len = -1; | |
43 components->ref.begin = 0; | |
44 components->ref.len = -1; | |
45 } | |
46 // TODO(sehr,polina) This could easily be 'return url;' but refcounting | |
47 // in fake_browser_ppapi is broken. | |
48 std::string url_str = PluginVar::PPVarToString(url); | |
49 return PluginVar::StringToPPVar(0, url_str); | |
50 } | |
51 | |
52 | |
53 struct PP_Var ResolveRelativeToURL(struct PP_Var base_url, | |
54 struct PP_Var relative_string, | |
55 struct PP_URLComponents_Dev* components) { | |
56 std::string base_url_str = PluginVar::PPVarToString(base_url); | |
57 std::string relative_string_str = PluginVar::PPVarToString(relative_string); | |
58 std::string resolved_str; | |
59 UNREFERENCED_PARAMETER(components); | |
60 // This is a very limited version of canonical URL matching. It's just | |
61 // enough for simple testing. | |
62 DebugPrintf("ResolveRelativeToURL: %s %s\n", | |
63 base_url_str.c_str(), relative_string_str.c_str()); | |
64 size_t last_slash = base_url_str.rfind("/"); | |
65 // If there's no slash in the url, it doesn't even have a scheme, which | |
66 // is clearly an error. | |
67 if (last_slash == std::string::npos || last_slash == 0) { | |
68 return PP_MakeNull(); | |
69 } | |
70 if (base_url_str[last_slash - 1] == '/' && | |
71 base_url_str.substr(last_slash).find(".") == std::string::npos) { | |
72 // If the last slash is part of the // before the host and the last slash | |
73 // does not precede "foo.bar", then it is a hostname/path, so just append. | |
74 resolved_str = base_url_str + "/" + relative_string_str; | |
75 } else { | |
76 // Otherwise, the last slash precedes a file name, which we strip off. | |
77 resolved_str = base_url_str.substr(0, last_slash + 1) + relative_string_str; | |
78 } | |
79 return PluginVar::StringToPPVar(0, resolved_str); | |
80 } | |
81 | |
82 struct PP_Var ResolveRelativeToDocument( | |
83 PP_Instance instance, | |
84 struct PP_Var relative_string, | |
85 struct PP_URLComponents_Dev* components) { | |
86 UNREFERENCED_PARAMETER(instance); | |
87 UNREFERENCED_PARAMETER(relative_string); | |
88 UNREFERENCED_PARAMETER(components); | |
89 NACL_UNIMPLEMENTED(); | |
90 return PP_MakeNull(); | |
91 } | |
92 | |
93 PP_Bool IsSameSecurityOrigin(struct PP_Var url_a, struct PP_Var url_b) { | |
94 UNREFERENCED_PARAMETER(url_a); | |
95 UNREFERENCED_PARAMETER(url_b); | |
96 NACL_UNIMPLEMENTED(); | |
97 return PP_FALSE; | |
98 } | |
99 | |
100 PP_Bool DocumentCanRequest(PP_Instance instance, struct PP_Var url) { | |
101 UNREFERENCED_PARAMETER(instance); | |
102 UNREFERENCED_PARAMETER(url); | |
103 NACL_UNIMPLEMENTED(); | |
104 return PP_FALSE; | |
105 } | |
106 | |
107 PP_Bool DocumentCanAccessDocument(PP_Instance active, PP_Instance target) { | |
108 UNREFERENCED_PARAMETER(active); | |
109 UNREFERENCED_PARAMETER(target); | |
110 NACL_UNIMPLEMENTED(); | |
111 return PP_FALSE; | |
112 } | |
113 | |
114 struct PP_Var GetDocumentURL(PP_Instance instance, | |
115 struct PP_URLComponents_Dev* components) { | |
116 UNREFERENCED_PARAMETER(components); | |
117 return PluginVar::StringToPPVar( | |
118 instance, fake_browser_ppapi::g_nacl_ppapi_url_path); | |
119 } | |
120 | |
121 struct PP_Var GetPluginInstanceURL(PP_Instance instance, | |
122 struct PP_URLComponents_Dev* components) { | |
123 UNREFERENCED_PARAMETER(instance); | |
124 UNREFERENCED_PARAMETER(components); | |
125 return PluginVar::StringToPPVar( | |
126 instance, fake_browser_ppapi::g_nacl_ppapi_url_path); | |
127 } | |
128 | |
129 } // namespace | |
130 | |
131 | |
132 const struct PPB_URLUtil_Dev* URLUtil_Dev::GetInterface() { | |
133 static const PPB_URLUtil_Dev url_util_interface = { | |
134 Canonicalize, | |
135 ResolveRelativeToURL, | |
136 ResolveRelativeToDocument, | |
137 IsSameSecurityOrigin , | |
138 DocumentCanRequest, | |
139 DocumentCanAccessDocument, | |
140 GetDocumentURL, | |
141 GetPluginInstanceURL | |
142 }; | |
143 return &url_util_interface; | |
144 } | |
145 | |
146 } // namespace fake_browser_ppapi | |
OLD | NEW |