OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" |
16 #include "webkit/plugins/ppapi/common.h" | 16 #include "webkit/plugins/ppapi/common.h" |
17 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 17 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
18 #include "webkit/plugins/ppapi/resource_tracker.h" | 18 #include "webkit/plugins/ppapi/resource_tracker.h" |
19 #include "webkit/plugins/ppapi/string.h" | 19 #include "webkit/plugins/ppapi/string.h" |
20 #include "webkit/plugins/ppapi/var.h" | 20 #include "webkit/plugins/ppapi/var.h" |
21 | 21 |
22 namespace webkit { | 22 namespace webkit { |
23 namespace ppapi { | 23 namespace ppapi { |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 void ConvertComponent(const url_parse::Component& input, | 27 void ConvertComponent(const url_parse::Component& input, |
28 PP_UrlComponent_Dev* output) { | 28 PP_URLComponent_Dev* output) { |
29 output->begin = input.begin; | 29 output->begin = input.begin; |
30 output->len = input.len; | 30 output->len = input.len; |
31 } | 31 } |
32 | 32 |
33 // Output can be NULL to specify "do nothing." This rule is followed by all the | 33 // Output can be NULL to specify "do nothing." This rule is followed by all the |
34 // url util functions, so we implement it once here. | 34 // url util functions, so we implement it once here. |
35 void ConvertComponents(const url_parse::Parsed& input, | 35 void ConvertComponents(const url_parse::Parsed& input, |
36 PP_UrlComponents_Dev* output) { | 36 PP_URLComponents_Dev* output) { |
37 if (!output) | 37 if (!output) |
38 return; | 38 return; |
39 | 39 |
40 ConvertComponent(input.scheme, &output->scheme); | 40 ConvertComponent(input.scheme, &output->scheme); |
41 ConvertComponent(input.username, &output->username); | 41 ConvertComponent(input.username, &output->username); |
42 ConvertComponent(input.password, &output->password); | 42 ConvertComponent(input.password, &output->password); |
43 ConvertComponent(input.host, &output->host); | 43 ConvertComponent(input.host, &output->host); |
44 ConvertComponent(input.port, &output->port); | 44 ConvertComponent(input.port, &output->port); |
45 ConvertComponent(input.path, &output->path); | 45 ConvertComponent(input.path, &output->path); |
46 ConvertComponent(input.query, &output->query); | 46 ConvertComponent(input.query, &output->query); |
47 ConvertComponent(input.ref, &output->ref); | 47 ConvertComponent(input.ref, &output->ref); |
48 } | 48 } |
49 | 49 |
50 // Used for returning the given GURL from a PPAPI function, with an optional | 50 // Used for returning the given GURL from a PPAPI function, with an optional |
51 // out param indicating the components. | 51 // out param indicating the components. |
52 PP_Var GenerateUrlReturn(PluginModule* module, const GURL& url, | 52 PP_Var GenerateURLReturn(PluginModule* module, const GURL& url, |
53 PP_UrlComponents_Dev* components) { | 53 PP_URLComponents_Dev* components) { |
54 if (!url.is_valid()) | 54 if (!url.is_valid()) |
55 return PP_MakeNull(); | 55 return PP_MakeNull(); |
56 ConvertComponents(url.parsed_for_possibly_invalid_spec(), components); | 56 ConvertComponents(url.parsed_for_possibly_invalid_spec(), components); |
57 return StringVar::StringToPPVar(module, url.possibly_invalid_spec()); | 57 return StringVar::StringToPPVar(module, url.possibly_invalid_spec()); |
58 } | 58 } |
59 | 59 |
60 // Sets |*security_origin| to be the WebKit security origin associated with the | 60 // Sets |*security_origin| to be the WebKit security origin associated with the |
61 // document containing the given plugin instance. On success, returns true. If | 61 // document containing the given plugin instance. On success, returns true. If |
62 // the instance is invalid, returns false and |*security_origin| will be | 62 // the instance is invalid, returns false and |*security_origin| will be |
63 // unchanged. | 63 // unchanged. |
64 bool SecurityOriginForInstance(PP_Instance instance_id, | 64 bool SecurityOriginForInstance(PP_Instance instance_id, |
65 WebKit::WebSecurityOrigin* security_origin) { | 65 WebKit::WebSecurityOrigin* security_origin) { |
66 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | 66 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); |
67 if (!instance) | 67 if (!instance) |
68 return false; | 68 return false; |
69 | 69 |
70 WebKit::WebElement plugin_element = instance->container()->element(); | 70 WebKit::WebElement plugin_element = instance->container()->element(); |
71 WebKit::WebFrame* plugin_frame = plugin_element.document().frame(); | 71 WebKit::WebFrame* plugin_frame = plugin_element.document().frame(); |
72 if (!plugin_frame) | 72 if (!plugin_frame) |
73 return false; | 73 return false; |
74 | 74 |
75 *security_origin = plugin_frame->securityOrigin(); | 75 *security_origin = plugin_frame->securityOrigin(); |
76 return true; | 76 return true; |
77 } | 77 } |
78 | 78 |
79 PP_Var Canonicalize(PP_Var url, PP_UrlComponents_Dev* components) { | 79 PP_Var Canonicalize(PP_Var url, PP_URLComponents_Dev* components) { |
80 scoped_refptr<StringVar> url_string(StringVar::FromPPVar(url)); | 80 scoped_refptr<StringVar> url_string(StringVar::FromPPVar(url)); |
81 if (!url_string) | 81 if (!url_string) |
82 return PP_MakeNull(); | 82 return PP_MakeNull(); |
83 return GenerateUrlReturn(url_string->module(), | 83 return GenerateURLReturn(url_string->module(), |
84 GURL(url_string->value()), components); | 84 GURL(url_string->value()), components); |
85 } | 85 } |
86 | 86 |
87 PP_Var ResolveRelativeToUrl(PP_Var base_url, | 87 PP_Var ResolveRelativeToURL(PP_Var base_url, |
88 PP_Var relative, | 88 PP_Var relative, |
89 PP_UrlComponents_Dev* components) { | 89 PP_URLComponents_Dev* components) { |
90 scoped_refptr<StringVar> base_url_string(StringVar::FromPPVar(base_url)); | 90 scoped_refptr<StringVar> base_url_string(StringVar::FromPPVar(base_url)); |
91 scoped_refptr<StringVar> relative_string(StringVar::FromPPVar(relative)); | 91 scoped_refptr<StringVar> relative_string(StringVar::FromPPVar(relative)); |
92 if (!base_url_string || !relative_string) | 92 if (!base_url_string || !relative_string) |
93 return PP_MakeNull(); | 93 return PP_MakeNull(); |
94 | 94 |
95 GURL base_gurl(base_url_string->value()); | 95 GURL base_gurl(base_url_string->value()); |
96 if (!base_gurl.is_valid()) | 96 if (!base_gurl.is_valid()) |
97 return PP_MakeNull(); | 97 return PP_MakeNull(); |
98 return GenerateUrlReturn(base_url_string->module(), | 98 return GenerateURLReturn(base_url_string->module(), |
99 base_gurl.Resolve(relative_string->value()), | 99 base_gurl.Resolve(relative_string->value()), |
100 components); | 100 components); |
101 } | 101 } |
102 | 102 |
103 PP_Var ResolveRelativeToDocument(PP_Instance instance_id, | 103 PP_Var ResolveRelativeToDocument(PP_Instance instance_id, |
104 PP_Var relative, | 104 PP_Var relative, |
105 PP_UrlComponents_Dev* components) { | 105 PP_URLComponents_Dev* components) { |
106 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | 106 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); |
107 if (!instance) | 107 if (!instance) |
108 return PP_MakeNull(); | 108 return PP_MakeNull(); |
109 | 109 |
110 scoped_refptr<StringVar> relative_string(StringVar::FromPPVar(relative)); | 110 scoped_refptr<StringVar> relative_string(StringVar::FromPPVar(relative)); |
111 if (!relative_string) | 111 if (!relative_string) |
112 return PP_MakeNull(); | 112 return PP_MakeNull(); |
113 | 113 |
114 WebKit::WebElement plugin_element = instance->container()->element(); | 114 WebKit::WebElement plugin_element = instance->container()->element(); |
115 GURL document_url = plugin_element.document().baseURL(); | 115 GURL document_url = plugin_element.document().baseURL(); |
116 return GenerateUrlReturn(instance->module(), | 116 return GenerateURLReturn(instance->module(), |
117 document_url.Resolve(relative_string->value()), | 117 document_url.Resolve(relative_string->value()), |
118 components); | 118 components); |
119 } | 119 } |
120 | 120 |
121 PP_Bool IsSameSecurityOrigin(PP_Var url_a, PP_Var url_b) { | 121 PP_Bool IsSameSecurityOrigin(PP_Var url_a, PP_Var url_b) { |
122 scoped_refptr<StringVar> url_a_string(StringVar::FromPPVar(url_a)); | 122 scoped_refptr<StringVar> url_a_string(StringVar::FromPPVar(url_a)); |
123 scoped_refptr<StringVar> url_b_string(StringVar::FromPPVar(url_b)); | 123 scoped_refptr<StringVar> url_b_string(StringVar::FromPPVar(url_b)); |
124 if (!url_a_string || !url_b_string) | 124 if (!url_a_string || !url_b_string) |
125 return PP_FALSE; | 125 return PP_FALSE; |
126 | 126 |
(...skipping 26 matching lines...) Expand all Loading... | |
153 if (!SecurityOriginForInstance(active, &active_origin)) | 153 if (!SecurityOriginForInstance(active, &active_origin)) |
154 return PP_FALSE; | 154 return PP_FALSE; |
155 | 155 |
156 WebKit::WebSecurityOrigin target_origin; | 156 WebKit::WebSecurityOrigin target_origin; |
157 if (!SecurityOriginForInstance(active, &target_origin)) | 157 if (!SecurityOriginForInstance(active, &target_origin)) |
158 return PP_FALSE; | 158 return PP_FALSE; |
159 | 159 |
160 return BoolToPPBool(active_origin.canAccess(target_origin)); | 160 return BoolToPPBool(active_origin.canAccess(target_origin)); |
161 } | 161 } |
162 | 162 |
163 } // namespace | 163 PP_Var GetDocumentURL(PP_Instance instance_id, |
164 PP_URLComponents_Dev* components) { | |
165 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | |
166 if (!instance) | |
167 return PP_MakeNull(); | |
164 | 168 |
165 const PPB_UrlUtil_Dev ppb_url_util = { | 169 WebKit::WebFrame* frame = instance->container()->element().document().frame(); |
170 if (!frame) | |
171 return PP_MakeNull(); | |
172 | |
173 return GenerateURLReturn(instance->module(), frame->url(), components); | |
viettrungluu
2011/03/02 21:00:54
This looks okay to me, though I'm not the expert..
| |
174 } | |
175 | |
176 const PPB_URLUtil_Dev ppb_url_util = { | |
166 &Canonicalize, | 177 &Canonicalize, |
167 &ResolveRelativeToUrl, | 178 &ResolveRelativeToURL, |
168 &ResolveRelativeToDocument, | 179 &ResolveRelativeToDocument, |
169 &IsSameSecurityOrigin, | 180 &IsSameSecurityOrigin, |
170 &DocumentCanRequest, | 181 &DocumentCanRequest, |
171 &DocumentCanAccessDocument | 182 &DocumentCanAccessDocument, |
183 &GetDocumentURL | |
172 }; | 184 }; |
173 | 185 |
186 } // namespace | |
187 | |
174 // static | 188 // static |
175 const PPB_UrlUtil_Dev* PPB_UrlUtil_Impl::GetInterface() { | 189 const PPB_URLUtil_Dev* PPB_URLUtil_Impl::GetInterface() { |
176 return &ppb_url_util; | 190 return &ppb_url_util; |
177 } | 191 } |
178 | 192 |
179 } // namespace ppapi | 193 } // namespace ppapi |
180 } // namespace webkit | 194 } // namespace webkit |
181 | 195 |
OLD | NEW |