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