File: convert_web_app.h

package info (click to toggle)
chromium 73.0.3683.75-1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,792,156 kB
  • sloc: cpp: 13,473,466; ansic: 1,577,080; python: 898,539; javascript: 655,737; xml: 341,883; asm: 306,070; java: 289,969; perl: 80,911; objc: 67,198; sh: 43,184; cs: 27,853; makefile: 12,092; php: 11,064; yacc: 10,373; tcl: 8,875; ruby: 3,941; lex: 1,800; pascal: 1,473; lisp: 812; awk: 41; jsp: 39; sed: 19; sql: 3
file content (81 lines) | stat: -rw-r--r-- 3,310 bytes parent folder | download | duplicates (4)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (c) 2011 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.

#ifndef CHROME_BROWSER_EXTENSIONS_CONVERT_WEB_APP_H_
#define CHROME_BROWSER_EXTENSIONS_CONVERT_WEB_APP_H_

#include <string>

#include "base/memory/ref_counted.h"
#include "extensions/common/manifest.h"

namespace base {
class DictionaryValue;
class FilePath;
class Time;
}

class GURL;
struct WebApplicationInfo;

namespace extensions {
class Extension;

// Creates a DictionaryValue with a single URL handler for |scope_url| and
// |title|. |title| is meant to appear in relevant UI surfaces but it's not used
// anywhere yet. The resulting DictionaryValue can be used as the "url_handlers"
// field in a Chrome Apps manifest.
//
// To create a URL handler that will match the same URLs as the "within
// scope" algorithm of the Web Manifest spec, we remove everything
// but the origin and path and append a wildcard, i.e. "*", to the result.
// According to the Web Manifest spec, a URL |url| is within scope of
// |scope_url| if |url|'s origin is the same as |scope_url|'s origin and
// |url|'s path starts with |scope_url|'s path.
// Note that this results in some unexpected URLs being within scope
// according to the spec:
// Suppose |scope_url| is "https://example.com/foo" and |url| is
// "https://example.com/foobar.html", then according to the spec algorithm
// |url| is within scope.
// See https://github.com/w3c/manifest/issues/554 for details.
//
// GetScopeURLFromBookmarkApp() reverses this operation, i.e. removes
// the '*' from the scope URL handler, to retrieve the scope for a Bookmark App.
// So if you change this, you also have to change GetScopeURLFromBookmarkApp().
std::unique_ptr<base::DictionaryValue> CreateURLHandlersForBookmarkApp(
    const GURL& scope_url,
    const base::string16& title);

// Retrieves the scope URL from a Bookmark App's URL handlers.
GURL GetScopeURLFromBookmarkApp(const Extension* extension);

// Generates a version number for an extension from a time. The goal is to make
// use of the version number to communicate the date in a human readable form,
// while maintaining high enough resolution to change each time an app is
// reinstalled. The version that is returned has the format:
//
// <year>.<month>.<day>.<fraction>
//
// fraction is represented as a number between 0 and 2^16-1. Each unit is
// ~1.32 seconds.
std::string ConvertTimeToExtensionVersion(const base::Time& time);

// Wraps the specified web app in an extension. The extension is created
// unpacked in the system temp dir. Returns a valid extension that the caller
// should take ownership on success, or NULL and |error| on failure.
//
// NOTE: The app created is always marked as a bookmark app.
// NOTE: This function does file IO and should not be called on the UI thread.
// NOTE: The caller takes ownership of the directory at extension->path() on the
// returned object.
scoped_refptr<Extension> ConvertWebAppToExtension(
    const WebApplicationInfo& web_app_info,
    const base::Time& create_time,
    const base::FilePath& extensions_dir,
    int extra_creation_flags,
    Manifest::Location install_source);

}  // namespace extensions

#endif  // CHROME_BROWSER_EXTENSIONS_CONVERT_WEB_APP_H_