1 // Copyright (c) 2012 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.
5 #include "google_apis/drive/gdata_wapi_url_generator.h"
7 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/stringprintf.h"
10 #include "net/base/escape.h"
11 #include "net/base/url_util.h"
14 namespace google_apis
{
17 // URL requesting single resource entry whose resource id is followed by this
19 const char kGetEditURLPrefix
[] = "/feeds/default/private/full/";
23 const char GDataWapiUrlGenerator::kBaseUrlForProduction
[] =
24 "https://docs.google.com/";
27 GURL
GDataWapiUrlGenerator::AddStandardUrlParams(const GURL
& url
) {
28 GURL result
= net::AppendOrReplaceQueryParameter(url
, "v", "3");
29 result
= net::AppendOrReplaceQueryParameter(result
, "alt", "json");
30 result
= net::AppendOrReplaceQueryParameter(result
, "showroot", "true");
34 GDataWapiUrlGenerator::GDataWapiUrlGenerator(const GURL
& base_url
)
35 : base_url_(base_url
) {
38 GDataWapiUrlGenerator::~GDataWapiUrlGenerator() {
41 GURL
GDataWapiUrlGenerator::GenerateEditUrl(
42 const std::string
& resource_id
) const {
43 return AddStandardUrlParams(GenerateEditUrlWithoutParams(resource_id
));
46 GURL
GDataWapiUrlGenerator::GenerateEditUrlWithoutParams(
47 const std::string
& resource_id
) const {
48 return base_url_
.Resolve(kGetEditURLPrefix
+ net::EscapePath(resource_id
));
51 GURL
GDataWapiUrlGenerator::GenerateEditUrlWithEmbedOrigin(
52 const std::string
& resource_id
, const GURL
& embed_origin
) const {
53 GURL url
= GenerateEditUrl(resource_id
);
54 if (!embed_origin
.is_empty()) {
55 // Construct a valid serialized embed origin from an url, according to
56 // WD-html5-20110525. Such string has to be built manually, since
57 // GURL::spec() always adds the trailing slash. Moreover, ports are
58 // currently not supported.
59 DCHECK(!embed_origin
.has_port());
60 DCHECK(!embed_origin
.has_path() || embed_origin
.path() == "/");
61 const std::string serialized_embed_origin
=
62 embed_origin
.scheme() + "://" + embed_origin
.host();
63 url
= net::AppendOrReplaceQueryParameter(
64 url
, "embedOrigin", serialized_embed_origin
);
69 } // namespace google_apis