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.
5 #include "ppapi/cpp/dev/url_util_dev.h"
7 #include "ppapi/cpp/instance_handle.h"
8 #include "ppapi/cpp/module_impl.h"
14 template <> const char* interface_name
<PPB_URLUtil_Dev_0_6
>() {
15 return PPB_URLUTIL_DEV_INTERFACE_0_6
;
18 template <> const char* interface_name
<PPB_URLUtil_Dev_0_7
>() {
19 return PPB_URLUTIL_DEV_INTERFACE_0_7
;
25 const URLUtil_Dev
* URLUtil_Dev::Get() {
26 static URLUtil_Dev util
;
27 static bool tried_to_init
= false;
28 static bool interface_available
= false;
32 if (has_interface
<PPB_URLUtil_Dev_0_7
>() ||
33 has_interface
<PPB_URLUtil_Dev_0_6
>())
34 interface_available
= true;
37 if (!interface_available
)
42 Var
URLUtil_Dev::Canonicalize(const Var
& url
,
43 PP_URLComponents_Dev
* components
) const {
44 if (has_interface
<PPB_URLUtil_Dev_0_7
>()) {
46 get_interface
<PPB_URLUtil_Dev_0_7
>()->Canonicalize(url
.pp_var(),
49 if (has_interface
<PPB_URLUtil_Dev_0_6
>()) {
51 get_interface
<PPB_URLUtil_Dev_0_6
>()->Canonicalize(url
.pp_var(),
57 Var
URLUtil_Dev::ResolveRelativeToURL(const Var
& base_url
,
58 const Var
& relative_string
,
59 PP_URLComponents_Dev
* components
) const {
60 if (has_interface
<PPB_URLUtil_Dev_0_7
>()) {
62 get_interface
<PPB_URLUtil_Dev_0_7
>()->ResolveRelativeToURL(
64 relative_string
.pp_var(),
67 if (has_interface
<PPB_URLUtil_Dev_0_6
>()) {
69 get_interface
<PPB_URLUtil_Dev_0_6
>()->ResolveRelativeToURL(
71 relative_string
.pp_var(),
77 Var
URLUtil_Dev::ResolveRelativeToDocument(
78 const InstanceHandle
& instance
,
79 const Var
& relative_string
,
80 PP_URLComponents_Dev
* components
) const {
81 if (has_interface
<PPB_URLUtil_Dev_0_7
>()) {
83 get_interface
<PPB_URLUtil_Dev_0_7
>()->ResolveRelativeToDocument(
84 instance
.pp_instance(),
85 relative_string
.pp_var(),
88 if (has_interface
<PPB_URLUtil_Dev_0_6
>()) {
90 get_interface
<PPB_URLUtil_Dev_0_6
>()->ResolveRelativeToDocument(
91 instance
.pp_instance(),
92 relative_string
.pp_var(),
98 bool URLUtil_Dev::IsSameSecurityOrigin(const Var
& url_a
,
99 const Var
& url_b
) const {
100 if (has_interface
<PPB_URLUtil_Dev_0_7
>()) {
102 get_interface
<PPB_URLUtil_Dev_0_7
>()->IsSameSecurityOrigin(
106 if (has_interface
<PPB_URLUtil_Dev_0_6
>()) {
108 get_interface
<PPB_URLUtil_Dev_0_6
>()->IsSameSecurityOrigin(
115 bool URLUtil_Dev::DocumentCanRequest(const InstanceHandle
& instance
,
116 const Var
& url
) const {
117 if (has_interface
<PPB_URLUtil_Dev_0_7
>()) {
119 get_interface
<PPB_URLUtil_Dev_0_7
>()->DocumentCanRequest(
120 instance
.pp_instance(),
123 if (has_interface
<PPB_URLUtil_Dev_0_6
>()) {
125 get_interface
<PPB_URLUtil_Dev_0_6
>()->DocumentCanRequest(
126 instance
.pp_instance(),
132 bool URLUtil_Dev::DocumentCanAccessDocument(
133 const InstanceHandle
& active
,
134 const InstanceHandle
& target
) const {
135 if (has_interface
<PPB_URLUtil_Dev_0_7
>()) {
137 get_interface
<PPB_URLUtil_Dev_0_7
>()->DocumentCanAccessDocument(
138 active
.pp_instance(),
139 target
.pp_instance()));
141 if (has_interface
<PPB_URLUtil_Dev_0_6
>()) {
143 get_interface
<PPB_URLUtil_Dev_0_6
>()->DocumentCanAccessDocument(
144 active
.pp_instance(),
145 target
.pp_instance()));
150 Var
URLUtil_Dev::GetDocumentURL(const InstanceHandle
& instance
,
151 PP_URLComponents_Dev
* components
) const {
152 if (has_interface
<PPB_URLUtil_Dev_0_7
>()) {
154 get_interface
<PPB_URLUtil_Dev_0_7
>()->GetDocumentURL(
155 instance
.pp_instance(),
158 if (has_interface
<PPB_URLUtil_Dev_0_6
>()) {
160 get_interface
<PPB_URLUtil_Dev_0_6
>()->GetDocumentURL(
161 instance
.pp_instance(),
167 Var
URLUtil_Dev::GetPluginInstanceURL(const InstanceHandle
& instance
,
168 PP_URLComponents_Dev
* components
) const {
169 if (has_interface
<PPB_URLUtil_Dev_0_7
>()) {
171 get_interface
<PPB_URLUtil_Dev_0_7
>()->GetPluginInstanceURL(
172 instance
.pp_instance(),
175 if (has_interface
<PPB_URLUtil_Dev_0_6
>()) {
177 get_interface
<PPB_URLUtil_Dev_0_6
>()->GetPluginInstanceURL(
178 instance
.pp_instance(),
184 Var
URLUtil_Dev::GetPluginReferrerURL(const InstanceHandle
& instance
,
185 PP_URLComponents_Dev
* components
) const {
186 if (has_interface
<PPB_URLUtil_Dev_0_7
>()) {
188 get_interface
<PPB_URLUtil_Dev_0_7
>()->GetPluginReferrerURL(
189 instance
.pp_instance(),