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

Side by Side Diff: ppapi/proxy/ppb_url_util_proxy.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/proxy/ppb_url_util_proxy.h"
6
7 #include "base/basictypes.h"
8 #include "ppapi/c/dev/ppb_url_util_dev.h"
9 #include "ppapi/c/dev/ppb_var_deprecated.h"
10 #include "ppapi/c/ppb_core.h"
11 #include "ppapi/proxy/plugin_dispatcher.h"
12 #include "ppapi/proxy/ppapi_messages.h"
13 #include "ppapi/proxy/serialized_var.h"
yzshen1 2011/03/16 21:19:23 It has been included by ppb_url_util_proxy.h.
14 #include "ppapi/shared_impl/url_util_impl.h"
15
16 namespace pp {
17 namespace proxy {
18
19 using pp::shared_impl::URLUtilImpl;
20
21 namespace {
22
23 URLUtilImpl::VarFromUtf8 GetVarFromUtf8() {
24 const PPB_Var_Deprecated* var_deprecated =
25 static_cast<const PPB_Var_Deprecated*>(
26 PluginDispatcher::GetInterfaceFromDispatcher(
27 PPB_VAR_DEPRECATED_INTERFACE));
28 return var_deprecated->VarFromUtf8;
29 }
30
31 const std::string* GetStringFromVar(PP_Var var) {
32 return PluginVarTracker::GetInstance()->GetExistingString(var);
33 }
34
35 PP_Var Canonicalize(PP_Var url,
36 PP_URLComponents_Dev* components) {
37 return URLUtilImpl::Canonicalize(&GetStringFromVar, GetVarFromUtf8(),
38 0, url, components);
39 }
40
41 // Helper function for the functions below that optionally take a components
42 // structure. It's annoying to serialze the large PP_URLComponents structure
43 // and this data often isn't needed.
44 //
45 // To avoid this, we instead just parse the result again in the plugin, which
46 // this function does if the given URL is valid and the components are
47 // non-NULL. The URL var will be returned.
48 PP_Var ConvertComponentsAndReturnURL(PP_Var url,
49 PP_URLComponents_Dev* components) {
50 if (!components)
51 return url; // Common case - plugin doesn't care about parsing.
52
53 const std::string* url_string = GetStringFromVar(url);
54 if (!url_string)
55 return url;
56
57 PP_Var result = Canonicalize(url, components);
58 PluginVarTracker::GetInstance()->Release(url);
59 return result;
60 }
61
62 PP_Var ResolveRelativeToURL(PP_Var base_url,
63 PP_Var relative,
64 PP_URLComponents_Dev* components) {
65 return URLUtilImpl::ResolveRelativeToURL(&GetStringFromVar, GetVarFromUtf8(),
66 0, base_url, relative, components);
67 }
68
69 PP_Var ResolveRelativeToDocument(PP_Instance instance,
70 PP_Var relative_string,
71 PP_URLComponents_Dev* components) {
72 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
73 if (!dispatcher)
74 return PP_MakeUndefined();
75
76 ReceiveSerializedVarReturnValue result;
77 dispatcher->Send(new PpapiHostMsg_PPBURLUtil_ResolveRelativeToDocument(
78 INTERFACE_ID_PPB_URL_UTIL, instance,
79 SerializedVarSendInput(dispatcher, relative_string),
80 &result));
81 return ConvertComponentsAndReturnURL(result.Return(dispatcher), components);
82 }
83
84 PP_Bool IsSameSecurityOrigin(PP_Var url_a, PP_Var url_b) {
85 return URLUtilImpl::IsSameSecurityOrigin(&GetStringFromVar, url_a, url_b);
86 }
87
88 PP_Bool DocumentCanRequest(PP_Instance instance, PP_Var url) {
89 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
90 if (!dispatcher)
91 return PP_FALSE;
92
93 PP_Bool result = PP_FALSE;
94 dispatcher->Send(new PpapiHostMsg_PPBURLUtil_DocumentCanRequest(
95 INTERFACE_ID_PPB_URL_UTIL, instance,
96 SerializedVarSendInput(dispatcher, url),
97 &result));
98 return result;
99 }
100
101 PP_Bool DocumentCanAccessDocument(PP_Instance active, PP_Instance target) {
102 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(active);
103 if (!dispatcher)
104 return PP_FALSE;
105
106 PP_Bool result = PP_FALSE;
107 dispatcher->Send(new PpapiHostMsg_PPBURLUtil_DocumentCanAccessDocument(
108 INTERFACE_ID_PPB_URL_UTIL, active, target, &result));
109 return result;
110 }
111
112 PP_Var GetDocumentURL(PP_Instance instance,
113 struct PP_URLComponents_Dev* components) {
114 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
115 if (!dispatcher)
116 return PP_MakeNull();
yzshen1 2011/03/16 21:19:23 Is it intended that line 74 & 116 return different
117
118 ReceiveSerializedVarReturnValue result;
119 dispatcher->Send(new PpapiHostMsg_PPBURLUtil_GetDocumentURL(
120 INTERFACE_ID_PPB_URL_UTIL, instance, &result));
121 return ConvertComponentsAndReturnURL(result.Return(dispatcher), components);
122 }
123
124 const PPB_URLUtil_Dev url_util_interface = {
125 &Canonicalize,
126 &ResolveRelativeToURL,
127 &ResolveRelativeToDocument,
128 &IsSameSecurityOrigin,
129 &DocumentCanRequest,
130 &DocumentCanAccessDocument,
131 &GetDocumentURL
132 };
133
134 InterfaceProxy* CreateURLUtilProxy(Dispatcher* dispatcher,
135 const void* target_interface) {
136 return new PPB_URLUtil_Proxy(dispatcher, target_interface);
137 }
138
139 } // namespace
140
141 PPB_URLUtil_Proxy::PPB_URLUtil_Proxy(Dispatcher* dispatcher,
142 const void* target_interface)
143 : InterfaceProxy(dispatcher, target_interface) {
144 }
145
146 PPB_URLUtil_Proxy::~PPB_URLUtil_Proxy() {
147 }
148
149 // static
150 const InterfaceProxy::Info* PPB_URLUtil_Proxy::GetInfo() {
151 static const Info info = {
152 &url_util_interface,
153 PPB_URLUTIL_DEV_INTERFACE,
154 INTERFACE_ID_PPB_URL_UTIL,
155 false,
156 &CreateURLUtilProxy,
157 };
158 return &info;
159 }
160
161 bool PPB_URLUtil_Proxy::OnMessageReceived(const IPC::Message& msg) {
162 bool handled = true;
163 IPC_BEGIN_MESSAGE_MAP(PPB_URLUtil_Proxy, msg)
164 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLUtil_ResolveRelativeToDocument,
165 OnMsgResolveRelativeToDocument)
166 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLUtil_DocumentCanRequest,
167 OnMsgDocumentCanRequest)
168 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLUtil_DocumentCanAccessDocument,
169 OnMsgDocumentCanAccessDocument)
170 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLUtil_GetDocumentURL,
171 OnMsgGetDocumentURL)
172 IPC_MESSAGE_UNHANDLED(handled = false)
173 IPC_END_MESSAGE_MAP()
174 return handled;
175 }
176
177 void PPB_URLUtil_Proxy::OnMsgResolveRelativeToDocument(
178 PP_Instance instance,
179 SerializedVarReceiveInput relative,
180 SerializedVarReturnValue result) {
181 result.Return(dispatcher(),
182 ppb_url_util_target()->ResolveRelativeToDocument(
183 instance, relative.Get(dispatcher()), NULL));
184 }
185
186 void PPB_URLUtil_Proxy::OnMsgDocumentCanRequest(PP_Instance instance,
187 SerializedVarReceiveInput url,
188 PP_Bool* result) {
189 *result = ppb_url_util_target()->DocumentCanRequest(instance,
190 url.Get(dispatcher()));
191 }
192
193 void PPB_URLUtil_Proxy::OnMsgDocumentCanAccessDocument(PP_Instance active,
194 PP_Instance target,
195 PP_Bool* result) {
196 *result = ppb_url_util_target()->DocumentCanAccessDocument(
197 active, target);
198 }
199
200 void PPB_URLUtil_Proxy::OnMsgGetDocumentURL(PP_Instance instance,
201 SerializedVarReturnValue result) {
202 result.Return(dispatcher(),
203 ppb_url_util_target()->GetDocumentURL(instance, NULL));
204 }
205
206 } // namespace proxy
207 } // namespace pp
208
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698