15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2011 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/dev/url_util_dev.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/instance_handle.h" 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/module.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace pp { 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const URLUtil_Dev* URLUtil_Dev::Get() { 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool tried_to_init = false; 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static URLUtil_Dev util; 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!tried_to_init) { 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) tried_to_init = true; 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) util.interface_ = static_cast<const PPB_URLUtil_Dev*>( 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Module::Get()->GetBrowserInterface(PPB_URLUTIL_DEV_INTERFACE)); 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!util.interface_) 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return NULL; 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return &util; 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Var URLUtil_Dev::Canonicalize(const Var& url, 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PP_URLComponents_Dev* components) const { 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return Var(PASS_REF, interface_->Canonicalize(url.pp_var(), components)); 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Var URLUtil_Dev::ResolveRelativeToURL(const Var& base_url, 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Var& relative_string, 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PP_URLComponents_Dev* components) const { 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return Var(PASS_REF, 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) interface_->ResolveRelativeToURL(base_url.pp_var(), 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) relative_string.pp_var(), 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) components)); 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Var URLUtil_Dev::ResolveRelativeToDocument( 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const InstanceHandle& instance, 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Var& relative_string, 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PP_URLComponents_Dev* components) const { 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return Var(PASS_REF, 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) interface_->ResolveRelativeToDocument(instance.pp_instance(), 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) relative_string.pp_var(), 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) components)); 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool URLUtil_Dev::IsSameSecurityOrigin(const Var& url_a, 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Var& url_b) const { 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return PP_ToBool(interface_->IsSameSecurityOrigin(url_a.pp_var(), 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) url_b.pp_var())); 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool URLUtil_Dev::DocumentCanRequest(const InstanceHandle& instance, 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Var& url) const { 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return PP_ToBool(interface_->DocumentCanRequest(instance.pp_instance(), 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) url.pp_var())); 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool URLUtil_Dev::DocumentCanAccessDocument( 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const InstanceHandle& active, 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const InstanceHandle& target) const { 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return PP_ToBool( 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) interface_->DocumentCanAccessDocument(active.pp_instance(), 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) target.pp_instance())); 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Var URLUtil_Dev::GetDocumentURL(const InstanceHandle& instance, 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PP_URLComponents_Dev* components) const { 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return Var(PASS_REF, 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) interface_->GetDocumentURL(instance.pp_instance(), components)); 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Var URLUtil_Dev::GetPluginInstanceURL(const InstanceHandle& instance, 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PP_URLComponents_Dev* components) const { 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return Var(PASS_REF, 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) interface_->GetPluginInstanceURL(instance.pp_instance(), 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) components)); 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace pp 86