summaryrefslogtreecommitdiffstats
path: root/ppapi/cpp/dev/url_util_dev.cc
blob: 3d07cb4d03e7cf9e73ef09ba1f0f8d1859259570 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ppapi/cpp/dev/url_util_dev.h"

#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"

namespace pp {

// static
const URLUtil_Dev* URLUtil_Dev::Get() {
  static bool tried_to_init = false;
  static URLUtil_Dev util;

  if (!tried_to_init) {
    tried_to_init = true;
    util.interface_ = static_cast<const PPB_URLUtil_Dev*>(
        Module::Get()->GetBrowserInterface(PPB_URLUTIL_DEV_INTERFACE));
  }

  if (!util.interface_)
    return NULL;
  return &util;
}

Var URLUtil_Dev::Canonicalize(const Var& url,
                              PP_URLComponents_Dev* components) const {
  return Var(Var::PassRef(),
             interface_->Canonicalize(url.pp_var(), components));
}

Var URLUtil_Dev::ResolveRelativeToURL(const Var& base_url,
                                      const Var& relative_string,
                                      PP_URLComponents_Dev* components) const {
  return Var(Var::PassRef(),
             interface_->ResolveRelativeToURL(base_url.pp_var(),
                                              relative_string.pp_var(),
                                              components));
}

Var URLUtil_Dev::ResolveRelativeToDocument(
    const Instance& instance,
    const Var& relative_string,
    PP_URLComponents_Dev* components) const {
  return Var(Var::PassRef(),
             interface_->ResolveRelativeToDocument(instance.pp_instance(),
                                                   relative_string.pp_var(),
                                                   components));
}

bool URLUtil_Dev::IsSameSecurityOrigin(const Var& url_a,
                                       const Var& url_b) const {
  return PP_ToBool(interface_->IsSameSecurityOrigin(url_a.pp_var(),
                                                    url_b.pp_var()));
}

bool URLUtil_Dev::DocumentCanRequest(const Instance& instance,
                                     const Var& url) const {
  return PP_ToBool(interface_->DocumentCanRequest(instance.pp_instance(),
                                                  url.pp_var()));
}

bool URLUtil_Dev::DocumentCanAccessDocument(const Instance& active,
                                            const Instance& target) const {
  return PP_ToBool(
      interface_->DocumentCanAccessDocument(active.pp_instance(),
                                            target.pp_instance()));
}

Var URLUtil_Dev::GetDocumentURL(const Instance& instance,
                                PP_URLComponents_Dev* components) const {
  return Var(Var::PassRef(),
             interface_->GetDocumentURL(instance.pp_instance(), components));
}

Var URLUtil_Dev::GetPluginInstanceURL(const Instance& instance,
                                      PP_URLComponents_Dev* components) const {
  return Var(Var::PassRef(),
             interface_->GetPluginInstanceURL(instance.pp_instance(),
                                              components));
}

}  // namespace pp