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 #include "ppapi/proxy/ppb_url_util_proxy.h" | 5 #include "ppapi/proxy/ppb_url_util_proxy.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "ppapi/c/dev/ppb_url_util_dev.h" | 8 #include "ppapi/c/dev/ppb_url_util_dev.h" |
9 #include "ppapi/c/dev/ppb_var_deprecated.h" | 9 #include "ppapi/c/dev/ppb_var_deprecated.h" |
10 #include "ppapi/c/ppb_core.h" | 10 #include "ppapi/c/ppb_core.h" |
11 #include "ppapi/proxy/plugin_dispatcher.h" | 11 #include "ppapi/proxy/plugin_dispatcher.h" |
| 12 #include "ppapi/proxy/plugin_resource_tracker.h" |
12 #include "ppapi/proxy/ppapi_messages.h" | 13 #include "ppapi/proxy/ppapi_messages.h" |
13 #include "ppapi/shared_impl/url_util_impl.h" | 14 #include "ppapi/shared_impl/url_util_impl.h" |
| 15 #include "ppapi/shared_impl/var.h" |
| 16 |
| 17 using ppapi::StringVar; |
| 18 using ppapi::URLUtilImpl; |
14 | 19 |
15 namespace pp { | 20 namespace pp { |
16 namespace proxy { | 21 namespace proxy { |
17 | 22 |
18 using ppapi::URLUtilImpl; | |
19 | |
20 namespace { | 23 namespace { |
21 | 24 |
22 URLUtilImpl::VarFromUtf8 GetVarFromUtf8() { | |
23 const PPB_Var_Deprecated* var_deprecated = | |
24 static_cast<const PPB_Var_Deprecated*>( | |
25 PluginDispatcher::GetInterfaceFromDispatcher( | |
26 PPB_VAR_DEPRECATED_INTERFACE)); | |
27 return var_deprecated->VarFromUtf8; | |
28 } | |
29 | |
30 const std::string* GetStringFromVar(PP_Var var) { | |
31 return PluginVarTracker::GetInstance()->GetExistingString(var); | |
32 } | |
33 | |
34 PP_Var Canonicalize(PP_Var url, | 25 PP_Var Canonicalize(PP_Var url, |
35 PP_URLComponents_Dev* components) { | 26 PP_URLComponents_Dev* components) { |
36 return URLUtilImpl::Canonicalize(&GetStringFromVar, GetVarFromUtf8(), | 27 return URLUtilImpl::Canonicalize(0, url, components); |
37 0, url, components); | |
38 } | 28 } |
39 | 29 |
40 // Helper function for the functions below that optionally take a components | 30 // Helper function for the functions below that optionally take a components |
41 // structure. It's annoying to serialze the large PP_URLComponents structure | 31 // structure. It's annoying to serialze the large PP_URLComponents structure |
42 // and this data often isn't needed. | 32 // and this data often isn't needed. |
43 // | 33 // |
44 // To avoid this, we instead just parse the result again in the plugin, which | 34 // To avoid this, we instead just parse the result again in the plugin, which |
45 // this function does if the given URL is valid and the components are | 35 // this function does if the given URL is valid and the components are |
46 // non-NULL. The URL var will be returned. | 36 // non-NULL. The URL var will be returned. |
47 PP_Var ConvertComponentsAndReturnURL(PP_Var url, | 37 PP_Var ConvertComponentsAndReturnURL(PP_Var url, |
48 PP_URLComponents_Dev* components) { | 38 PP_URLComponents_Dev* components) { |
49 if (!components) | 39 if (!components) |
50 return url; // Common case - plugin doesn't care about parsing. | 40 return url; // Common case - plugin doesn't care about parsing. |
51 | 41 |
52 const std::string* url_string = GetStringFromVar(url); | 42 scoped_refptr<StringVar> url_string(StringVar::FromPPVar(url)); |
53 if (!url_string) | 43 if (!url_string) |
54 return url; | 44 return url; |
55 | 45 |
56 PP_Var result = Canonicalize(url, components); | 46 PP_Var result = Canonicalize(url, components); |
57 PluginVarTracker::GetInstance()->Release(url); | 47 PluginResourceTracker::GetInstance()->var_tracker().ReleaseVar(url); |
58 return result; | 48 return result; |
59 } | 49 } |
60 | 50 |
61 PP_Var ResolveRelativeToURL(PP_Var base_url, | 51 PP_Var ResolveRelativeToURL(PP_Var base_url, |
62 PP_Var relative, | 52 PP_Var relative, |
63 PP_URLComponents_Dev* components) { | 53 PP_URLComponents_Dev* components) { |
64 return URLUtilImpl::ResolveRelativeToURL(&GetStringFromVar, GetVarFromUtf8(), | 54 return URLUtilImpl::ResolveRelativeToURL(0, base_url, relative, components); |
65 0, base_url, relative, components); | |
66 } | 55 } |
67 | 56 |
68 PP_Var ResolveRelativeToDocument(PP_Instance instance, | 57 PP_Var ResolveRelativeToDocument(PP_Instance instance, |
69 PP_Var relative_string, | 58 PP_Var relative_string, |
70 PP_URLComponents_Dev* components) { | 59 PP_URLComponents_Dev* components) { |
71 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 60 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
72 if (!dispatcher) | 61 if (!dispatcher) |
73 return PP_MakeNull(); | 62 return PP_MakeNull(); |
74 | 63 |
75 ReceiveSerializedVarReturnValue result; | 64 ReceiveSerializedVarReturnValue result; |
76 dispatcher->Send(new PpapiHostMsg_PPBURLUtil_ResolveRelativeToDocument( | 65 dispatcher->Send(new PpapiHostMsg_PPBURLUtil_ResolveRelativeToDocument( |
77 INTERFACE_ID_PPB_URL_UTIL, instance, | 66 INTERFACE_ID_PPB_URL_UTIL, instance, |
78 SerializedVarSendInput(dispatcher, relative_string), | 67 SerializedVarSendInput(dispatcher, relative_string), |
79 &result)); | 68 &result)); |
80 return ConvertComponentsAndReturnURL(result.Return(dispatcher), components); | 69 return ConvertComponentsAndReturnURL(result.Return(dispatcher), components); |
81 } | 70 } |
82 | 71 |
83 PP_Bool IsSameSecurityOrigin(PP_Var url_a, PP_Var url_b) { | 72 PP_Bool IsSameSecurityOrigin(PP_Var url_a, PP_Var url_b) { |
84 return URLUtilImpl::IsSameSecurityOrigin(&GetStringFromVar, url_a, url_b); | 73 return URLUtilImpl::IsSameSecurityOrigin(url_a, url_b); |
85 } | 74 } |
86 | 75 |
87 PP_Bool DocumentCanRequest(PP_Instance instance, PP_Var url) { | 76 PP_Bool DocumentCanRequest(PP_Instance instance, PP_Var url) { |
88 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 77 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
89 if (!dispatcher) | 78 if (!dispatcher) |
90 return PP_FALSE; | 79 return PP_FALSE; |
91 | 80 |
92 PP_Bool result = PP_FALSE; | 81 PP_Bool result = PP_FALSE; |
93 dispatcher->Send(new PpapiHostMsg_PPBURLUtil_DocumentCanRequest( | 82 dispatcher->Send(new PpapiHostMsg_PPBURLUtil_DocumentCanRequest( |
94 INTERFACE_ID_PPB_URL_UTIL, instance, | 83 INTERFACE_ID_PPB_URL_UTIL, instance, |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 | 208 |
220 void PPB_URLUtil_Proxy::OnMsgGetPluginInstanceURL( | 209 void PPB_URLUtil_Proxy::OnMsgGetPluginInstanceURL( |
221 PP_Instance instance, SerializedVarReturnValue result) { | 210 PP_Instance instance, SerializedVarReturnValue result) { |
222 result.Return(dispatcher(), | 211 result.Return(dispatcher(), |
223 ppb_url_util_target()->GetPluginInstanceURL(instance, NULL)); | 212 ppb_url_util_target()->GetPluginInstanceURL(instance, NULL)); |
224 } | 213 } |
225 | 214 |
226 } // namespace proxy | 215 } // namespace proxy |
227 } // namespace pp | 216 } // namespace pp |
228 | 217 |
OLD | NEW |