Fix sort order of unlaunched apps on app list start page.
[chromium-blink-merge.git] / extensions / common / manifest_handlers / background_info.h
blob87c2f1218d5f7918a5fe5e179649e78c43448734
1 // Copyright 2013 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 #ifndef EXTENSIONS_COMMON_MANIFEST_HANDLERS_BACKGROUND_INFO_H_
6 #define EXTENSIONS_COMMON_MANIFEST_HANDLERS_BACKGROUND_INFO_H_
8 #include <string>
9 #include <vector>
11 #include "base/values.h"
12 #include "extensions/common/extension.h"
13 #include "extensions/common/manifest_handler.h"
14 #include "url/gurl.h"
16 namespace extensions {
18 class BackgroundInfo : public Extension::ManifestData {
19 public:
20 BackgroundInfo();
21 ~BackgroundInfo() override;
23 static GURL GetBackgroundURL(const Extension* extension);
24 static const std::vector<std::string>& GetBackgroundScripts(
25 const Extension* extension);
26 static bool HasBackgroundPage(const Extension* extension);
27 static bool HasPersistentBackgroundPage(const Extension* extension);
28 static bool HasLazyBackgroundPage(const Extension* extension);
29 static bool HasGeneratedBackgroundPage(const Extension* extension);
30 static bool AllowJSAccess(const Extension* extension);
32 bool has_background_page() const {
33 return background_url_.is_valid() || !background_scripts_.empty();
36 bool has_persistent_background_page() const {
37 return has_background_page() && is_persistent_;
40 bool has_lazy_background_page() const {
41 return has_background_page() && !is_persistent_;
44 bool Parse(const Extension* extension, base::string16* error);
46 private:
47 bool LoadBackgroundScripts(const Extension* extension,
48 const std::string& key,
49 base::string16* error);
50 bool LoadBackgroundPage(const Extension* extension,
51 const std::string& key,
52 base::string16* error);
53 bool LoadBackgroundPage(const Extension* extension, base::string16* error);
54 bool LoadBackgroundPersistent(const Extension* extension,
55 base::string16* error);
56 bool LoadAllowJSAccess(const Extension* extension, base::string16* error);
58 // Optional URL to a master page of which a single instance should be always
59 // loaded in the background.
60 GURL background_url_;
62 // Optional list of scripts to use to generate a background page. If this is
63 // present, background_url_ will be empty and generated by GetBackgroundURL().
64 std::vector<std::string> background_scripts_;
66 // True if the background page should stay loaded forever; false if it should
67 // load on-demand (when it needs to handle an event). Defaults to true.
68 bool is_persistent_;
70 // True if the background page can be scripted by pages of the app or
71 // extension, in which case all such pages must run in the same process.
72 // False if such pages are not permitted to script the background page,
73 // allowing them to run in different processes.
74 // Defaults to true.
75 bool allow_js_access_;
77 DISALLOW_COPY_AND_ASSIGN(BackgroundInfo);
80 // Parses all background/event page-related keys in the manifest.
81 class BackgroundManifestHandler : public ManifestHandler {
82 public:
83 BackgroundManifestHandler();
84 ~BackgroundManifestHandler() override;
86 bool Parse(Extension* extension, base::string16* error) override;
87 bool Validate(const Extension* extension,
88 std::string* error,
89 std::vector<InstallWarning>* warnings) const override;
90 bool AlwaysParseForType(Manifest::Type type) const override;
92 private:
93 const std::vector<std::string> Keys() const override;
95 DISALLOW_COPY_AND_ASSIGN(BackgroundManifestHandler);
98 } // namespace extensions
100 #endif // EXTENSIONS_COMMON_MANIFEST_HANDLERS_BACKGROUND_INFO_H_