OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef PPAPI_SHARED_IMPL_URL_UTIL_IMPL_H_ | 5 #ifndef PPAPI_SHARED_IMPL_URL_UTIL_IMPL_H_ |
6 #define PPAPI_SHARED_IMPL_URL_UTIL_IMPL_H_ | 6 #define PPAPI_SHARED_IMPL_URL_UTIL_IMPL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "googleurl/src/url_parse.h" | 11 #include "googleurl/src/url_parse.h" |
12 #include "ppapi/c/dev/ppb_url_util_dev.h" | 12 #include "ppapi/c/dev/ppb_url_util_dev.h" |
13 #include "ppapi/c/pp_module.h" | 13 #include "ppapi/c/pp_module.h" |
14 #include "ppapi/c/pp_var.h" | 14 #include "ppapi/c/pp_var.h" |
15 | 15 |
16 class GURL; | 16 class GURL; |
17 | 17 |
18 namespace ppapi { | 18 namespace ppapi { |
19 | 19 |
20 // Contains the implementation of PPB_URLUtil that is shared between the proxy | 20 // Contains the implementation of PPB_URLUtil that is shared between the proxy |
21 // and the renderer. | 21 // and the renderer. |
22 class URLUtilImpl { | 22 class URLUtilImpl { |
23 public: | 23 public: |
24 // The functions here would normally take the var interface for constructing | |
25 // return strings. However, at the current time there's some mixup between | |
26 // using Var and VarDeprecated. To resolve this, we instead pass the pointer | |
27 // to the string creation function so can be used independently of this. | |
28 typedef PP_Var (*VarFromUtf8)(PP_Module, const char*, uint32_t); | |
29 | |
30 // Function that converts the given var to a std::string or NULL if the | |
31 // var is not a string or is invalid. | |
32 // | |
33 // We could use PPB_Var for this, but that interface requires an additional | |
34 // string conversion. Both the proxy and the host side maintain the strings | |
35 // in a std::string, and the form we want for passing to GURL is also a | |
36 // std::string. Parameterizing this separately saves this, and also solves | |
37 // the same problem that VarFromUtf8 does. | |
38 typedef const std::string* (*StringFromVar)(PP_Var var); | |
39 | |
40 // PPB_URLUtil shared functions. | 24 // PPB_URLUtil shared functions. |
41 static PP_Var Canonicalize(StringFromVar string_from_var, | 25 static PP_Var Canonicalize(PP_Module pp_module, |
42 VarFromUtf8 var_from_utf8, | |
43 PP_Module pp_module, | |
44 PP_Var url, | 26 PP_Var url, |
45 PP_URLComponents_Dev* components); | 27 PP_URLComponents_Dev* components); |
46 static PP_Var ResolveRelativeToURL(StringFromVar string_from_var, | 28 static PP_Var ResolveRelativeToURL(PP_Module pp_module, |
47 VarFromUtf8 var_from_utf8, | |
48 PP_Module pp_module, | |
49 PP_Var base_url, | 29 PP_Var base_url, |
50 PP_Var relative, | 30 PP_Var relative, |
51 PP_URLComponents_Dev* components); | 31 PP_URLComponents_Dev* components); |
52 static PP_Bool IsSameSecurityOrigin(StringFromVar string_from_var, | 32 static PP_Bool IsSameSecurityOrigin(PP_Var url_a, PP_Var url_b); |
53 PP_Var url_a, PP_Var url_b); | |
54 | 33 |
55 // Used for returning the given GURL from a PPAPI function, with an optional | 34 // Used for returning the given GURL from a PPAPI function, with an optional |
56 // out param indicating the components. | 35 // out param indicating the components. |
57 static PP_Var GenerateURLReturn(VarFromUtf8 var_from_utf8, | 36 static PP_Var GenerateURLReturn(PP_Module pp_module, |
58 PP_Module pp_module, | |
59 const GURL& url, | 37 const GURL& url, |
60 PP_URLComponents_Dev* components); | 38 PP_URLComponents_Dev* components); |
61 }; | 39 }; |
62 | 40 |
63 } // namespace ppapi | 41 } // namespace ppapi |
64 | 42 |
65 #endif | 43 #endif |
OLD | NEW |