summaryrefslogtreecommitdiffstats
path: root/chrome/common/content_settings_helper.cc
blob: e553eabd9d4fa5a3d96e903869bac99f84a443af (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
// Copyright (c) 2012 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 "chrome/common/content_settings_helper.h"

#include "base/strings/string_piece.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/common/url_constants.h"
#include "url/gurl.h"

namespace content_settings_helper {

std::string OriginToString(const GURL& origin) {
  std::string port_component(origin.IntPort() != url::PORT_UNSPECIFIED
                                 ? ":" + origin.port()
                                 : std::string());
  std::string scheme_component(!origin.SchemeIs(url::kHttpScheme)
                                   ? origin.scheme() +
                                     content::kStandardSchemeSeparator
                                   : std::string());
   return scheme_component + origin.host() + port_component;
}

base::string16 OriginToString16(const GURL& origin) {
  return base::UTF8ToUTF16(OriginToString(origin));
}

}  // namespace content_settings_helper