Vectorize website settings icons in omnibox
[chromium-blink-merge.git] / ppapi / cpp / dev / url_util_dev.cc
blobb0eece6e21e073a119e0c1415781eb2279f6a001
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"
10 namespace pp {
12 namespace {
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;
22 } // namespace
24 // static
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;
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;
37 if (!interface_available)
38 return NULL;
39 return &util;
42 Var URLUtil_Dev::Canonicalize(const Var& url,
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));
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));
54 return 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>()) {
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));
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));
74 return 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>()) {
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));
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));
95 return 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>()) {
101 return PP_ToBool(
102 get_interface<PPB_URLUtil_Dev_0_7>()->IsSameSecurityOrigin(
103 url_a.pp_var(),
104 url_b.pp_var()));
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()));
112 return false;
115 bool URLUtil_Dev::DocumentCanRequest(const InstanceHandle& instance,
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()));
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()));
129 return false;
132 bool URLUtil_Dev::DocumentCanAccessDocument(
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()));
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()));
147 return false;
150 Var URLUtil_Dev::GetDocumentURL(const InstanceHandle& instance,
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));
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));
164 return Var();
167 Var URLUtil_Dev::GetPluginInstanceURL(const InstanceHandle& instance,
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));
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));
181 return Var();
184 Var URLUtil_Dev::GetPluginReferrerURL(const InstanceHandle& instance,
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));
192 return Var();
195 } // namespace pp