url_scheme_util.mm 1009 B

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright 2014 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. #import "ios/web/common/url_scheme_util.h"
  5. #import <Foundation/Foundation.h>
  6. #import "base/strings/sys_string_conversions.h"
  7. #include "url/gurl.h"
  8. #if !defined(__has_feature) || !__has_feature(objc_arc)
  9. #error "This file requires ARC support."
  10. #endif
  11. namespace web {
  12. bool UrlHasWebScheme(const GURL& url) {
  13. return url.SchemeIs(url::kHttpScheme) || url.SchemeIs(url::kHttpsScheme) ||
  14. url.SchemeIs(url::kDataScheme);
  15. }
  16. bool UrlHasWebScheme(NSURL* url) {
  17. NSString* scheme = [url scheme];
  18. if (![scheme length])
  19. return false;
  20. // Use the GURL implementation, but with a scheme-only URL to avoid
  21. // unnecessary parsing in GURL construction.
  22. NSString* schemeURLString = [scheme stringByAppendingString:@":"];
  23. GURL gurl(base::SysNSStringToUTF8(schemeURLString));
  24. return UrlHasWebScheme(gurl);
  25. }
  26. } // namespace web