Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Side by Side Diff: ppapi/shared_impl/url_util_impl.cc

Issue 6676045: Implement a proxy for URL util. Some of the implementation that doesn't need ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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 #include "ppapi/shared_impl/url_util_impl.h"
6
7 #include "googleurl/src/gurl.h"
8
9 namespace pp {
10 namespace shared_impl {
11
12 namespace {
13
14 void ConvertComponent(const url_parse::Component& input,
15 PP_URLComponent_Dev* output) {
16 output->begin = input.begin;
17 output->len = input.len;
18 }
19
20 } // namespace
21
22 // static
23 PP_Var URLUtilImpl::Canonicalize(StringFromVar string_from_var,
24 VarFromUtf8 var_from_utf8,
25 PP_Module pp_module,
26 PP_Var url,
27 PP_URLComponents_Dev* components) {
28 const std::string* url_string = string_from_var(url);
29 if (!url_string)
30 return PP_MakeNull();
31 return GenerateURLReturn(var_from_utf8, pp_module,
32 GURL(*url_string), components);
33 }
34
35 // static
36 PP_Var URLUtilImpl::ResolveRelativeToURL(StringFromVar string_from_var,
37 VarFromUtf8 var_from_utf8,
38 PP_Module pp_module,
39 PP_Var base_url,
40 PP_Var relative,
yzshen1 2011/03/16 21:19:23 Please use the same name as the one in the .h file
41 PP_URLComponents_Dev* components) {
42 const std::string* base_url_string = string_from_var(base_url);
43 const std::string* relative_string = string_from_var(relative);
44 if (!base_url_string || !relative_string)
45 return PP_MakeNull();
46
47 GURL base_gurl(*base_url_string);
48 if (!base_gurl.is_valid())
49 return PP_MakeNull();
50 return GenerateURLReturn(var_from_utf8, pp_module,
51 base_gurl.Resolve(*relative_string),
52 components);
53 }
54
55 // static
56 PP_Bool URLUtilImpl::IsSameSecurityOrigin(StringFromVar string_from_var,
57 PP_Var url_a, PP_Var url_b) {
58 const std::string* url_a_string = string_from_var(url_a);
59 const std::string* url_b_string = string_from_var(url_b);
60 if (!url_a_string || !url_b_string)
61 return PP_FALSE;
62
63 GURL gurl_a(*url_a_string);
64 GURL gurl_b(*url_b_string);
65 if (!gurl_a.is_valid() || !gurl_b.is_valid())
66 return PP_FALSE;
67
68 return gurl_a.GetOrigin() == gurl_b.GetOrigin() ? PP_TRUE : PP_FALSE;
69 }
70
71 // Output can be NULL to specify "do nothing." This rule is followed by all the
72 // url util functions, so we implement it once here.
73 void URLUtilImpl::ConvertComponents(const url_parse::Parsed& input,
yzshen1 2011/03/16 21:19:23 It seems this one is not used by anyone other than
74 PP_URLComponents_Dev* output) {
75 if (!output)
76 return;
77
78 ConvertComponent(input.scheme, &output->scheme);
79 ConvertComponent(input.username, &output->username);
80 ConvertComponent(input.password, &output->password);
81 ConvertComponent(input.host, &output->host);
82 ConvertComponent(input.port, &output->port);
83 ConvertComponent(input.path, &output->path);
84 ConvertComponent(input.query, &output->query);
85 ConvertComponent(input.ref, &output->ref);
86 }
87
88 // Used for returning the given GURL from a PPAPI function, with an optional
89 // out param indicating the components.
90 PP_Var URLUtilImpl::GenerateURLReturn(VarFromUtf8 var_from_utf8,
91 PP_Module module,
92 const GURL& url,
93 PP_URLComponents_Dev* components) {
94 if (!url.is_valid())
95 return PP_MakeNull();
96 ConvertComponents(url.parsed_for_possibly_invalid_spec(), components);
97 return var_from_utf8(module, url.possibly_invalid_spec().c_str(),
98 static_cast<uint32_t>(url.possibly_invalid_spec().size()));
99 }
100
101 } // namespace shared_impl
102 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698