Pepper_47_C++_interfaces
url_util_dev.cc
Go to the documentation of this file.
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 
6 
9 
10 namespace pp {
11 
12 namespace {
13 
14 template <> const char* interface_name<PPB_URLUtil_Dev_0_6>() {
15  return PPB_URLUTIL_DEV_INTERFACE_0_6;
16 }
17 
18 template <> const char* interface_name<PPB_URLUtil_Dev_0_7>() {
19  return PPB_URLUTIL_DEV_INTERFACE_0_7;
20 }
21 
22 } // namespace
23 
24 // static
26  static URLUtil_Dev util;
27  static bool tried_to_init = false;
28  static bool interface_available = false;
29 
30  if (!tried_to_init) {
31  tried_to_init = true;
32  if (has_interface<PPB_URLUtil_Dev_0_7>() ||
33  has_interface<PPB_URLUtil_Dev_0_6>())
34  interface_available = true;
35  }
36 
37  if (!interface_available)
38  return NULL;
39  return &util;
40 }
41 
43  PP_URLComponents_Dev* components) const {
44  if (has_interface<PPB_URLUtil_Dev_0_7>()) {
45  return Var(PASS_REF,
46  get_interface<PPB_URLUtil_Dev_0_7>()->Canonicalize(url.pp_var(),
47  components));
48  }
49  if (has_interface<PPB_URLUtil_Dev_0_6>()) {
50  return Var(PASS_REF,
51  get_interface<PPB_URLUtil_Dev_0_6>()->Canonicalize(url.pp_var(),
52  components));
53  }
54  return Var();
55 }
56 
58  const Var& relative_string,
59  PP_URLComponents_Dev* components) const {
60  if (has_interface<PPB_URLUtil_Dev_0_7>()) {
61  return Var(PASS_REF,
62  get_interface<PPB_URLUtil_Dev_0_7>()->ResolveRelativeToURL(
63  base_url.pp_var(),
64  relative_string.pp_var(),
65  components));
66  }
67  if (has_interface<PPB_URLUtil_Dev_0_6>()) {
68  return Var(PASS_REF,
69  get_interface<PPB_URLUtil_Dev_0_6>()->ResolveRelativeToURL(
70  base_url.pp_var(),
71  relative_string.pp_var(),
72  components));
73  }
74  return Var();
75 }
76 
78  const InstanceHandle& instance,
79  const Var& relative_string,
80  PP_URLComponents_Dev* components) const {
81  if (has_interface<PPB_URLUtil_Dev_0_7>()) {
82  return Var(PASS_REF,
83  get_interface<PPB_URLUtil_Dev_0_7>()->ResolveRelativeToDocument(
84  instance.pp_instance(),
85  relative_string.pp_var(),
86  components));
87  }
88  if (has_interface<PPB_URLUtil_Dev_0_6>()) {
89  return Var(PASS_REF,
90  get_interface<PPB_URLUtil_Dev_0_6>()->ResolveRelativeToDocument(
91  instance.pp_instance(),
92  relative_string.pp_var(),
93  components));
94  }
95  return Var();
96 }
97 
99  const Var& url_b) const {
100  if (has_interface<PPB_URLUtil_Dev_0_7>()) {
101  return PP_ToBool(
102  get_interface<PPB_URLUtil_Dev_0_7>()->IsSameSecurityOrigin(
103  url_a.pp_var(),
104  url_b.pp_var()));
105  }
106  if (has_interface<PPB_URLUtil_Dev_0_6>()) {
107  return PP_ToBool(
108  get_interface<PPB_URLUtil_Dev_0_6>()->IsSameSecurityOrigin(
109  url_a.pp_var(),
110  url_b.pp_var()));
111  }
112  return false;
113 }
114 
116  const Var& url) const {
117  if (has_interface<PPB_URLUtil_Dev_0_7>()) {
118  return PP_ToBool(
119  get_interface<PPB_URLUtil_Dev_0_7>()->DocumentCanRequest(
120  instance.pp_instance(),
121  url.pp_var()));
122  }
123  if (has_interface<PPB_URLUtil_Dev_0_6>()) {
124  return PP_ToBool(
125  get_interface<PPB_URLUtil_Dev_0_6>()->DocumentCanRequest(
126  instance.pp_instance(),
127  url.pp_var()));
128  }
129  return false;
130 }
131 
133  const InstanceHandle& active,
134  const InstanceHandle& target) const {
135  if (has_interface<PPB_URLUtil_Dev_0_7>()) {
136  return PP_ToBool(
137  get_interface<PPB_URLUtil_Dev_0_7>()->DocumentCanAccessDocument(
138  active.pp_instance(),
139  target.pp_instance()));
140  }
141  if (has_interface<PPB_URLUtil_Dev_0_6>()) {
142  return PP_ToBool(
143  get_interface<PPB_URLUtil_Dev_0_6>()->DocumentCanAccessDocument(
144  active.pp_instance(),
145  target.pp_instance()));
146  }
147  return false;
148 }
149 
151  PP_URLComponents_Dev* components) const {
152  if (has_interface<PPB_URLUtil_Dev_0_7>()) {
153  return Var(PASS_REF,
154  get_interface<PPB_URLUtil_Dev_0_7>()->GetDocumentURL(
155  instance.pp_instance(),
156  components));
157  }
158  if (has_interface<PPB_URLUtil_Dev_0_6>()) {
159  return Var(PASS_REF,
160  get_interface<PPB_URLUtil_Dev_0_6>()->GetDocumentURL(
161  instance.pp_instance(),
162  components));
163  }
164  return Var();
165 }
166 
168  PP_URLComponents_Dev* components) const {
169  if (has_interface<PPB_URLUtil_Dev_0_7>()) {
170  return Var(PASS_REF,
171  get_interface<PPB_URLUtil_Dev_0_7>()->GetPluginInstanceURL(
172  instance.pp_instance(),
173  components));
174  }
175  if (has_interface<PPB_URLUtil_Dev_0_6>()) {
176  return Var(PASS_REF,
177  get_interface<PPB_URLUtil_Dev_0_6>()->GetPluginInstanceURL(
178  instance.pp_instance(),
179  components));
180  }
181  return Var();
182 }
183 
185  PP_URLComponents_Dev* components) const {
186  if (has_interface<PPB_URLUtil_Dev_0_7>()) {
187  return Var(PASS_REF,
188  get_interface<PPB_URLUtil_Dev_0_7>()->GetPluginReferrerURL(
189  instance.pp_instance(),
190  components));
191  }
192  return Var();
193 }
194 
195 } // namespace pp
bool DocumentCanRequest(const InstanceHandle &instance, const Var &url) const
Var GetDocumentURL(const InstanceHandle &instance, PP_URLComponents_Dev *components=NULL) const
Var GetPluginReferrerURL(const InstanceHandle &instance, PP_URLComponents_Dev *components=NULL) const
Var Canonicalize(const Var &url, PP_URLComponents_Dev *components=NULL) const
Definition: url_util_dev.cc:42
static const URLUtil_Dev * Get()
Definition: url_util_dev.cc:25
const PP_Var & pp_var() const
Definition: var.h:226
Var ResolveRelativeToDocument(const InstanceHandle &instance, const Var &relative_string, PP_URLComponents_Dev *components=NULL) const
Definition: url_util_dev.cc:77
bool DocumentCanAccessDocument(const InstanceHandle &active, const InstanceHandle &target) const
Var ResolveRelativeToURL(const Var &base_url, const Var &relative_string, PP_URLComponents_Dev *components=NULL) const
Definition: url_util_dev.cc:57
A generic type used for passing data types between the module and the page.
Definition: var.h:21
PP_Instance pp_instance() const
Var GetPluginInstanceURL(const InstanceHandle &instance, PP_URLComponents_Dev *components=NULL) const
bool IsSameSecurityOrigin(const Var &url_a, const Var &url_b) const
Definition: url_util_dev.cc:98