summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authoryzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-26 03:39:13 +0000
committeryzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-26 03:39:13 +0000
commit98b1462d9778f3554bfd70c9ad730b9a1bf1c402 (patch)
tree3ee479e938e46c212db0fa6369a3bdf739cde769 /ppapi
parent2ce42c602bf3574bd7c257ef6928c32d486ae1f3 (diff)
downloadchromium_src-98b1462d9778f3554bfd70c9ad730b9a1bf1c402.zip
chromium_src-98b1462d9778f3554bfd70c9ad730b9a1bf1c402.tar.gz
chromium_src-98b1462d9778f3554bfd70c9ad730b9a1bf1c402.tar.bz2
Make PPB_URLUtil_Dev interface backward compatible
Commit on behalf of xzhang@adobe.com The original code review issue is: https://codereview.chromium.org/59243002/ BUG=None TEST=None Review URL: https://codereview.chromium.org/86483003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@237244 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/cpp/dev/url_util_dev.cc161
-rw-r--r--ppapi/cpp/dev/url_util_dev.h11
2 files changed, 136 insertions, 36 deletions
diff --git a/ppapi/cpp/dev/url_util_dev.cc b/ppapi/cpp/dev/url_util_dev.cc
index 5029a45..b0eece6 100644
--- a/ppapi/cpp/dev/url_util_dev.cc
+++ b/ppapi/cpp/dev/url_util_dev.cc
@@ -5,88 +5,191 @@
#include "ppapi/cpp/dev/url_util_dev.h"
#include "ppapi/cpp/instance_handle.h"
-#include "ppapi/cpp/module.h"
+#include "ppapi/cpp/module_impl.h"
namespace pp {
+namespace {
+
+template <> const char* interface_name<PPB_URLUtil_Dev_0_6>() {
+ return PPB_URLUTIL_DEV_INTERFACE_0_6;
+}
+
+template <> const char* interface_name<PPB_URLUtil_Dev_0_7>() {
+ return PPB_URLUTIL_DEV_INTERFACE_0_7;
+}
+
+} // namespace
+
// static
const URLUtil_Dev* URLUtil_Dev::Get() {
- static bool tried_to_init = false;
static URLUtil_Dev util;
+ static bool tried_to_init = false;
+ static bool interface_available = false;
if (!tried_to_init) {
tried_to_init = true;
- util.interface_ = static_cast<const PPB_URLUtil_Dev*>(
- Module::Get()->GetBrowserInterface(PPB_URLUTIL_DEV_INTERFACE));
+ if (has_interface<PPB_URLUtil_Dev_0_7>() ||
+ has_interface<PPB_URLUtil_Dev_0_6>())
+ interface_available = true;
}
- if (!util.interface_)
+ if (!interface_available)
return NULL;
return &util;
}
Var URLUtil_Dev::Canonicalize(const Var& url,
PP_URLComponents_Dev* components) const {
- return Var(PASS_REF, interface_->Canonicalize(url.pp_var(), components));
+ if (has_interface<PPB_URLUtil_Dev_0_7>()) {
+ return Var(PASS_REF,
+ get_interface<PPB_URLUtil_Dev_0_7>()->Canonicalize(url.pp_var(),
+ components));
+ }
+ if (has_interface<PPB_URLUtil_Dev_0_6>()) {
+ return Var(PASS_REF,
+ get_interface<PPB_URLUtil_Dev_0_6>()->Canonicalize(url.pp_var(),
+ components));
+ }
+ return Var();
}
Var URLUtil_Dev::ResolveRelativeToURL(const Var& base_url,
const Var& relative_string,
PP_URLComponents_Dev* components) const {
- return Var(PASS_REF,
- interface_->ResolveRelativeToURL(base_url.pp_var(),
- relative_string.pp_var(),
- components));
+ if (has_interface<PPB_URLUtil_Dev_0_7>()) {
+ return Var(PASS_REF,
+ get_interface<PPB_URLUtil_Dev_0_7>()->ResolveRelativeToURL(
+ base_url.pp_var(),
+ relative_string.pp_var(),
+ components));
+ }
+ if (has_interface<PPB_URLUtil_Dev_0_6>()) {
+ return Var(PASS_REF,
+ get_interface<PPB_URLUtil_Dev_0_6>()->ResolveRelativeToURL(
+ base_url.pp_var(),
+ relative_string.pp_var(),
+ components));
+ }
+ return Var();
}
Var URLUtil_Dev::ResolveRelativeToDocument(
const InstanceHandle& instance,
const Var& relative_string,
PP_URLComponents_Dev* components) const {
- return Var(PASS_REF,
- interface_->ResolveRelativeToDocument(instance.pp_instance(),
- relative_string.pp_var(),
- components));
+ if (has_interface<PPB_URLUtil_Dev_0_7>()) {
+ return Var(PASS_REF,
+ get_interface<PPB_URLUtil_Dev_0_7>()->ResolveRelativeToDocument(
+ instance.pp_instance(),
+ relative_string.pp_var(),
+ components));
+ }
+ if (has_interface<PPB_URLUtil_Dev_0_6>()) {
+ return Var(PASS_REF,
+ get_interface<PPB_URLUtil_Dev_0_6>()->ResolveRelativeToDocument(
+ instance.pp_instance(),
+ relative_string.pp_var(),
+ components));
+ }
+ return Var();
}
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()));
+ if (has_interface<PPB_URLUtil_Dev_0_7>()) {
+ return PP_ToBool(
+ get_interface<PPB_URLUtil_Dev_0_7>()->IsSameSecurityOrigin(
+ url_a.pp_var(),
+ url_b.pp_var()));
+ }
+ if (has_interface<PPB_URLUtil_Dev_0_6>()) {
+ return PP_ToBool(
+ get_interface<PPB_URLUtil_Dev_0_6>()->IsSameSecurityOrigin(
+ url_a.pp_var(),
+ url_b.pp_var()));
+ }
+ return false;
}
bool URLUtil_Dev::DocumentCanRequest(const InstanceHandle& instance,
const Var& url) const {
- return PP_ToBool(interface_->DocumentCanRequest(instance.pp_instance(),
- url.pp_var()));
+ if (has_interface<PPB_URLUtil_Dev_0_7>()) {
+ return PP_ToBool(
+ get_interface<PPB_URLUtil_Dev_0_7>()->DocumentCanRequest(
+ instance.pp_instance(),
+ url.pp_var()));
+ }
+ if (has_interface<PPB_URLUtil_Dev_0_6>()) {
+ return PP_ToBool(
+ get_interface<PPB_URLUtil_Dev_0_6>()->DocumentCanRequest(
+ instance.pp_instance(),
+ url.pp_var()));
+ }
+ return false;
}
bool URLUtil_Dev::DocumentCanAccessDocument(
const InstanceHandle& active,
const InstanceHandle& target) const {
- return PP_ToBool(
- interface_->DocumentCanAccessDocument(active.pp_instance(),
- target.pp_instance()));
+ if (has_interface<PPB_URLUtil_Dev_0_7>()) {
+ return PP_ToBool(
+ get_interface<PPB_URLUtil_Dev_0_7>()->DocumentCanAccessDocument(
+ active.pp_instance(),
+ target.pp_instance()));
+ }
+ if (has_interface<PPB_URLUtil_Dev_0_6>()) {
+ return PP_ToBool(
+ get_interface<PPB_URLUtil_Dev_0_6>()->DocumentCanAccessDocument(
+ active.pp_instance(),
+ target.pp_instance()));
+ }
+ return false;
}
Var URLUtil_Dev::GetDocumentURL(const InstanceHandle& instance,
PP_URLComponents_Dev* components) const {
- return Var(PASS_REF,
- interface_->GetDocumentURL(instance.pp_instance(), components));
+ if (has_interface<PPB_URLUtil_Dev_0_7>()) {
+ return Var(PASS_REF,
+ get_interface<PPB_URLUtil_Dev_0_7>()->GetDocumentURL(
+ instance.pp_instance(),
+ components));
+ }
+ if (has_interface<PPB_URLUtil_Dev_0_6>()) {
+ return Var(PASS_REF,
+ get_interface<PPB_URLUtil_Dev_0_6>()->GetDocumentURL(
+ instance.pp_instance(),
+ components));
+ }
+ return Var();
}
Var URLUtil_Dev::GetPluginInstanceURL(const InstanceHandle& instance,
PP_URLComponents_Dev* components) const {
- return Var(PASS_REF,
- interface_->GetPluginInstanceURL(instance.pp_instance(),
- components));
+ if (has_interface<PPB_URLUtil_Dev_0_7>()) {
+ return Var(PASS_REF,
+ get_interface<PPB_URLUtil_Dev_0_7>()->GetPluginInstanceURL(
+ instance.pp_instance(),
+ components));
+ }
+ if (has_interface<PPB_URLUtil_Dev_0_6>()) {
+ return Var(PASS_REF,
+ get_interface<PPB_URLUtil_Dev_0_6>()->GetPluginInstanceURL(
+ instance.pp_instance(),
+ components));
+ }
+ return Var();
}
Var URLUtil_Dev::GetPluginReferrerURL(const InstanceHandle& instance,
PP_URLComponents_Dev* components) const {
- return Var(PASS_REF,
- interface_->GetPluginReferrerURL(instance.pp_instance(),
- components));
+ if (has_interface<PPB_URLUtil_Dev_0_7>()) {
+ return Var(PASS_REF,
+ get_interface<PPB_URLUtil_Dev_0_7>()->GetPluginReferrerURL(
+ instance.pp_instance(),
+ components));
+ }
+ return Var();
}
} // namespace pp
diff --git a/ppapi/cpp/dev/url_util_dev.h b/ppapi/cpp/dev/url_util_dev.h
index 9399752..db63e7a 100644
--- a/ppapi/cpp/dev/url_util_dev.h
+++ b/ppapi/cpp/dev/url_util_dev.h
@@ -16,10 +16,9 @@ class InstanceHandle;
class URLUtil_Dev {
public:
// This class is just a collection of random functions that aren't
- // particularly attached to anything. So this getter returns a cached
- // instance of this interface. This may return NULL if the browser doesn't
- // support the URLUtil interface. Since this is a singleton, don't delete the
- // pointer.
+ // particularly attached to anything. This may return NULL if the
+ // browser doesn't support the URLUtil interface. Since this is a
+ // singleton, don't delete the pointer.
static const URLUtil_Dev* Get();
Var Canonicalize(const Var& url,
@@ -45,13 +44,11 @@ class URLUtil_Dev {
PP_URLComponents_Dev* components = NULL) const;
private:
- URLUtil_Dev() : interface_(NULL) {}
+ URLUtil_Dev() {}
// Copy and assignment are disallowed.
URLUtil_Dev(const URLUtil_Dev& other);
URLUtil_Dev& operator=(const URLUtil_Dev& other);
-
- const PPB_URLUtil_Dev* interface_;
};
} // namespace pp