summaryrefslogtreecommitdiffstats
path: root/ios/web/url_scheme_util.mm
blob: 945a09a54f79d92fbddd1f75c110fcba27e8df58 (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
// Copyright 2014 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.

#import "ios/web/public/url_scheme_util.h"

#import <Foundation/Foundation.h>

#include "url/gurl.h"

namespace web {

bool UrlHasWebScheme(const GURL& url) {
  return url.SchemeIs(url::kHttpScheme) ||
         url.SchemeIs(url::kHttpsScheme) ||
         url.SchemeIs(url::kDataScheme);
}

bool UrlHasWebScheme(NSURL* url) {
  NSString* scheme = [url scheme];
  if (![scheme length])
    return false;

  // Use the GURL implementation, but with a scheme-only URL to avoid
  // unnecessary parsing in GURL construction.
  NSString* schemeURLString = [scheme stringByAppendingString:@":"];
  GURL gurl([schemeURLString UTF8String]);
  return UrlHasWebScheme(gurl);
}

}  // namespace web