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

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

Issue 7578001: Unify var tracking between webkit and the proxy. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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
« no previous file with comments | « ppapi/shared_impl/url_util_impl.h ('k') | ppapi/shared_impl/var.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/shared_impl/url_util_impl.h" 5 #include "ppapi/shared_impl/url_util_impl.h"
6 6
7 #include "googleurl/src/gurl.h" 7 #include "googleurl/src/gurl.h"
8 #include "ppapi/shared_impl/var.h"
8 9
9 namespace ppapi { 10 namespace ppapi {
10 11
11 namespace { 12 namespace {
12 13
13 void ConvertComponent(const url_parse::Component& input, 14 void ConvertComponent(const url_parse::Component& input,
14 PP_URLComponent_Dev* output) { 15 PP_URLComponent_Dev* output) {
15 output->begin = input.begin; 16 output->begin = input.begin;
16 output->len = input.len; 17 output->len = input.len;
17 } 18 }
(...skipping 15 matching lines...) Expand all
33 ConvertComponent(input.host, &output->host); 34 ConvertComponent(input.host, &output->host);
34 ConvertComponent(input.port, &output->port); 35 ConvertComponent(input.port, &output->port);
35 ConvertComponent(input.path, &output->path); 36 ConvertComponent(input.path, &output->path);
36 ConvertComponent(input.query, &output->query); 37 ConvertComponent(input.query, &output->query);
37 ConvertComponent(input.ref, &output->ref); 38 ConvertComponent(input.ref, &output->ref);
38 } 39 }
39 40
40 } // namespace 41 } // namespace
41 42
42 // static 43 // static
43 PP_Var URLUtilImpl::Canonicalize(StringFromVar string_from_var, 44 PP_Var URLUtilImpl::Canonicalize(PP_Module pp_module,
44 VarFromUtf8 var_from_utf8,
45 PP_Module pp_module,
46 PP_Var url, 45 PP_Var url,
47 PP_URLComponents_Dev* components) { 46 PP_URLComponents_Dev* components) {
48 const std::string* url_string = string_from_var(url); 47 scoped_refptr<StringVar> url_string(StringVar::FromPPVar(url));
49 if (!url_string) 48 if (!url_string)
50 return PP_MakeNull(); 49 return PP_MakeNull();
51 return GenerateURLReturn(var_from_utf8, pp_module, 50 return GenerateURLReturn(pp_module, GURL(url_string->value()), components);
52 GURL(*url_string), components);
53 } 51 }
54 52
55 // static 53 // static
56 PP_Var URLUtilImpl::ResolveRelativeToURL(StringFromVar string_from_var, 54 PP_Var URLUtilImpl::ResolveRelativeToURL(PP_Module pp_module,
57 VarFromUtf8 var_from_utf8,
58 PP_Module pp_module,
59 PP_Var base_url, 55 PP_Var base_url,
60 PP_Var relative, 56 PP_Var relative,
61 PP_URLComponents_Dev* components) { 57 PP_URLComponents_Dev* components) {
62 const std::string* base_url_string = string_from_var(base_url); 58 scoped_refptr<StringVar> base_url_string(StringVar::FromPPVar(base_url));
63 const std::string* relative_string = string_from_var(relative); 59 scoped_refptr<StringVar> relative_string(StringVar::FromPPVar(relative));
64 if (!base_url_string || !relative_string) 60 if (!base_url_string || !relative_string)
65 return PP_MakeNull(); 61 return PP_MakeNull();
66 62
67 GURL base_gurl(*base_url_string); 63 GURL base_gurl(base_url_string->value());
68 if (!base_gurl.is_valid()) 64 if (!base_gurl.is_valid())
69 return PP_MakeNull(); 65 return PP_MakeNull();
70 return GenerateURLReturn(var_from_utf8, pp_module, 66 return GenerateURLReturn(pp_module,
71 base_gurl.Resolve(*relative_string), 67 base_gurl.Resolve(relative_string->value()),
72 components); 68 components);
73 } 69 }
74 70
75 // static 71 // static
76 PP_Bool URLUtilImpl::IsSameSecurityOrigin(StringFromVar string_from_var, 72 PP_Bool URLUtilImpl::IsSameSecurityOrigin(PP_Var url_a, PP_Var url_b) {
77 PP_Var url_a, PP_Var url_b) { 73 scoped_refptr<StringVar> url_a_string(StringVar::FromPPVar(url_a));
78 const std::string* url_a_string = string_from_var(url_a); 74 scoped_refptr<StringVar> url_b_string(StringVar::FromPPVar(url_b));
79 const std::string* url_b_string = string_from_var(url_b);
80 if (!url_a_string || !url_b_string) 75 if (!url_a_string || !url_b_string)
81 return PP_FALSE; 76 return PP_FALSE;
82 77
83 GURL gurl_a(*url_a_string); 78 GURL gurl_a(url_a_string->value());
84 GURL gurl_b(*url_b_string); 79 GURL gurl_b(url_b_string->value());
85 if (!gurl_a.is_valid() || !gurl_b.is_valid()) 80 if (!gurl_a.is_valid() || !gurl_b.is_valid())
86 return PP_FALSE; 81 return PP_FALSE;
87 82
88 return gurl_a.GetOrigin() == gurl_b.GetOrigin() ? PP_TRUE : PP_FALSE; 83 return gurl_a.GetOrigin() == gurl_b.GetOrigin() ? PP_TRUE : PP_FALSE;
89 } 84 }
90 85
91 // Used for returning the given GURL from a PPAPI function, with an optional 86 // Used for returning the given GURL from a PPAPI function, with an optional
92 // out param indicating the components. 87 // out param indicating the components.
93 PP_Var URLUtilImpl::GenerateURLReturn(VarFromUtf8 var_from_utf8, 88 PP_Var URLUtilImpl::GenerateURLReturn(PP_Module module,
94 PP_Module module,
95 const GURL& url, 89 const GURL& url,
96 PP_URLComponents_Dev* components) { 90 PP_URLComponents_Dev* components) {
97 if (!url.is_valid()) 91 if (!url.is_valid())
98 return PP_MakeNull(); 92 return PP_MakeNull();
99 ConvertComponents(url.parsed_for_possibly_invalid_spec(), components); 93 ConvertComponents(url.parsed_for_possibly_invalid_spec(), components);
100 return var_from_utf8(module, url.possibly_invalid_spec().c_str(), 94 return StringVar::StringToPPVar(module, url.possibly_invalid_spec());
101 static_cast<uint32_t>(url.possibly_invalid_spec().size()));
102 } 95 }
103 96
104 } // namespace ppapi 97 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/shared_impl/url_util_impl.h ('k') | ppapi/shared_impl/var.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698