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 "webkit/plugins/ppapi/ppb_url_util_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_url_util_impl.h" |
6 | 6 |
7 #include "googleurl/src/gurl.h" | 7 #include "googleurl/src/gurl.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/ppb_var.h" | 9 #include "ppapi/c/ppb_var.h" |
10 #include "ppapi/shared_impl/url_util_impl.h" | 10 #include "ppapi/shared_impl/url_util_impl.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 namespace { | 32 namespace { |
33 | 33 |
34 // Returns the PP_Module associated with the given string, or 0 on failure. | 34 // Returns the PP_Module associated with the given string, or 0 on failure. |
35 PP_Module GetModuleFromVar(PP_Var string_var) { | 35 PP_Module GetModuleFromVar(PP_Var string_var) { |
36 scoped_refptr<StringVar> str(StringVar::FromPPVar(string_var)); | 36 scoped_refptr<StringVar> str(StringVar::FromPPVar(string_var)); |
37 if (!str) | 37 if (!str) |
38 return 0; | 38 return 0; |
39 return str->pp_module(); | 39 return str->pp_module(); |
40 } | 40 } |
41 | 41 |
42 const std::string* StringFromVar(PP_Var var) { | |
43 scoped_refptr<StringVar> string(StringVar::FromPPVar(var)); | |
44 if (!string) | |
45 return NULL; | |
46 return &string->value(); | |
47 } | |
48 | |
49 // Sets |*security_origin| to be the WebKit security origin associated with the | 42 // Sets |*security_origin| to be the WebKit security origin associated with the |
50 // document containing the given plugin instance. On success, returns true. If | 43 // document containing the given plugin instance. On success, returns true. If |
51 // the instance is invalid, returns false and |*security_origin| will be | 44 // the instance is invalid, returns false and |*security_origin| will be |
52 // unchanged. | 45 // unchanged. |
53 bool SecurityOriginForInstance(PP_Instance instance_id, | 46 bool SecurityOriginForInstance(PP_Instance instance_id, |
54 WebKit::WebSecurityOrigin* security_origin) { | 47 WebKit::WebSecurityOrigin* security_origin) { |
55 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | 48 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); |
56 if (!instance) | 49 if (!instance) |
57 return false; | 50 return false; |
58 | 51 |
59 WebKit::WebElement plugin_element = instance->container()->element(); | 52 WebKit::WebElement plugin_element = instance->container()->element(); |
60 *security_origin = plugin_element.document().securityOrigin(); | 53 *security_origin = plugin_element.document().securityOrigin(); |
61 return true; | 54 return true; |
62 } | 55 } |
63 | 56 |
64 PP_Var Canonicalize(PP_Var url, PP_URLComponents_Dev* components) { | 57 PP_Var Canonicalize(PP_Var url, PP_URLComponents_Dev* components) { |
65 return URLUtilImpl::Canonicalize(&StringFromVar, | 58 return URLUtilImpl::Canonicalize(GetModuleFromVar(url), url, components); |
66 PPB_Var_Impl::GetVarInterface()->VarFromUtf8, | |
67 GetModuleFromVar(url), | |
68 url, components); | |
69 } | 59 } |
70 | 60 |
71 PP_Var ResolveRelativeToURL(PP_Var base_url, | 61 PP_Var ResolveRelativeToURL(PP_Var base_url, |
72 PP_Var relative, | 62 PP_Var relative, |
73 PP_URLComponents_Dev* components) { | 63 PP_URLComponents_Dev* components) { |
74 return URLUtilImpl::ResolveRelativeToURL( | 64 return URLUtilImpl::ResolveRelativeToURL(GetModuleFromVar(base_url), |
75 &StringFromVar, | 65 base_url, relative, components); |
76 PPB_Var_Impl::GetVarInterface()->VarFromUtf8, | |
77 GetModuleFromVar(base_url), | |
78 base_url, relative, components); | |
79 } | 66 } |
80 | 67 |
81 PP_Var ResolveRelativeToDocument(PP_Instance instance_id, | 68 PP_Var ResolveRelativeToDocument(PP_Instance instance_id, |
82 PP_Var relative, | 69 PP_Var relative, |
83 PP_URLComponents_Dev* components) { | 70 PP_URLComponents_Dev* components) { |
84 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | 71 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); |
85 if (!instance) | 72 if (!instance) |
86 return PP_MakeNull(); | 73 return PP_MakeNull(); |
87 | 74 |
88 scoped_refptr<StringVar> relative_string(StringVar::FromPPVar(relative)); | 75 scoped_refptr<StringVar> relative_string(StringVar::FromPPVar(relative)); |
89 if (!relative_string) | 76 if (!relative_string) |
90 return PP_MakeNull(); | 77 return PP_MakeNull(); |
91 | 78 |
92 WebKit::WebElement plugin_element = instance->container()->element(); | 79 WebKit::WebElement plugin_element = instance->container()->element(); |
93 GURL document_url = plugin_element.document().baseURL(); | 80 GURL document_url = plugin_element.document().baseURL(); |
94 return URLUtilImpl::GenerateURLReturn( | 81 return URLUtilImpl::GenerateURLReturn( |
95 PPB_Var_Impl::GetVarInterface()->VarFromUtf8, | |
96 instance->module()->pp_module(), | 82 instance->module()->pp_module(), |
97 document_url.Resolve(relative_string->value()), | 83 document_url.Resolve(relative_string->value()), |
98 components); | 84 components); |
99 } | 85 } |
100 | 86 |
101 PP_Bool IsSameSecurityOrigin(PP_Var url_a, PP_Var url_b) { | 87 PP_Bool IsSameSecurityOrigin(PP_Var url_a, PP_Var url_b) { |
102 return URLUtilImpl::IsSameSecurityOrigin(&StringFromVar, url_a, url_b); | 88 return URLUtilImpl::IsSameSecurityOrigin(url_a, url_b); |
103 } | 89 } |
104 | 90 |
105 PP_Bool DocumentCanRequest(PP_Instance instance, PP_Var url) { | 91 PP_Bool DocumentCanRequest(PP_Instance instance, PP_Var url) { |
106 scoped_refptr<StringVar> url_string(StringVar::FromPPVar(url)); | 92 scoped_refptr<StringVar> url_string(StringVar::FromPPVar(url)); |
107 if (!url_string) | 93 if (!url_string) |
108 return PP_FALSE; | 94 return PP_FALSE; |
109 | 95 |
110 WebKit::WebSecurityOrigin security_origin; | 96 WebKit::WebSecurityOrigin security_origin; |
111 if (!SecurityOriginForInstance(instance, &security_origin)) | 97 if (!SecurityOriginForInstance(instance, &security_origin)) |
112 return PP_FALSE; | 98 return PP_FALSE; |
(...skipping 17 matching lines...) Expand all Loading... |
130 return BoolToPPBool(active_origin.canAccess(target_origin)); | 116 return BoolToPPBool(active_origin.canAccess(target_origin)); |
131 } | 117 } |
132 | 118 |
133 PP_Var GetDocumentURL(PP_Instance instance_id, | 119 PP_Var GetDocumentURL(PP_Instance instance_id, |
134 PP_URLComponents_Dev* components) { | 120 PP_URLComponents_Dev* components) { |
135 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | 121 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); |
136 if (!instance) | 122 if (!instance) |
137 return PP_MakeNull(); | 123 return PP_MakeNull(); |
138 | 124 |
139 WebKit::WebDocument document = instance->container()->element().document(); | 125 WebKit::WebDocument document = instance->container()->element().document(); |
140 return URLUtilImpl::GenerateURLReturn( | 126 return URLUtilImpl::GenerateURLReturn(instance->module()->pp_module(), |
141 PPB_Var_Impl::GetVarInterface()->VarFromUtf8, | 127 document.url(), components); |
142 instance->module()->pp_module(), | |
143 document.url(), components); | |
144 } | 128 } |
145 | 129 |
146 PP_Var GetPluginInstanceURL(PP_Instance instance_id, | 130 PP_Var GetPluginInstanceURL(PP_Instance instance_id, |
147 PP_URLComponents_Dev* components) { | 131 PP_URLComponents_Dev* components) { |
148 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | 132 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); |
149 if (!instance) | 133 if (!instance) |
150 return PP_MakeNull(); | 134 return PP_MakeNull(); |
151 | 135 |
152 const GURL& url = instance->plugin_url(); | 136 const GURL& url = instance->plugin_url(); |
153 return URLUtilImpl::GenerateURLReturn( | 137 return URLUtilImpl::GenerateURLReturn(instance->module()->pp_module(), |
154 PPB_Var_Impl::GetVarInterface()->VarFromUtf8, | 138 url, components); |
155 instance->module()->pp_module(), | |
156 url, components); | |
157 } | 139 } |
158 | 140 |
159 const PPB_URLUtil_Dev ppb_url_util = { | 141 const PPB_URLUtil_Dev ppb_url_util = { |
160 &Canonicalize, | 142 &Canonicalize, |
161 &ResolveRelativeToURL, | 143 &ResolveRelativeToURL, |
162 &ResolveRelativeToDocument, | 144 &ResolveRelativeToDocument, |
163 &IsSameSecurityOrigin, | 145 &IsSameSecurityOrigin, |
164 &DocumentCanRequest, | 146 &DocumentCanRequest, |
165 &DocumentCanAccessDocument, | 147 &DocumentCanAccessDocument, |
166 &GetDocumentURL, | 148 &GetDocumentURL, |
167 &GetPluginInstanceURL | 149 &GetPluginInstanceURL |
168 }; | 150 }; |
169 | 151 |
170 } // namespace | 152 } // namespace |
171 | 153 |
172 // static | 154 // static |
173 const PPB_URLUtil_Dev* PPB_URLUtil_Impl::GetInterface() { | 155 const PPB_URLUtil_Dev* PPB_URLUtil_Impl::GetInterface() { |
174 return &ppb_url_util; | 156 return &ppb_url_util; |
175 } | 157 } |
176 | 158 |
177 } // namespace ppapi | 159 } // namespace ppapi |
178 } // namespace webkit | 160 } // namespace webkit |
179 | 161 |
OLD | NEW |