OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef EXTENSIONS_COMMON_MANIFEST_HANDLERS_BACKGROUND_INFO_H_ | 5 #ifndef EXTENSIONS_COMMON_MANIFEST_HANDLERS_BACKGROUND_INFO_H_ |
6 #define EXTENSIONS_COMMON_MANIFEST_HANDLERS_BACKGROUND_INFO_H_ | 6 #define EXTENSIONS_COMMON_MANIFEST_HANDLERS_BACKGROUND_INFO_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "extensions/common/extension.h" | 12 #include "extensions/common/extension.h" |
13 #include "extensions/common/manifest_handler.h" | 13 #include "extensions/common/manifest_handler.h" |
14 #include "url/gurl.h" | 14 #include "url/gurl.h" |
15 | 15 |
16 namespace extensions { | 16 namespace extensions { |
17 | 17 |
18 class BackgroundInfo : public Extension::ManifestData { | 18 class BackgroundInfo : public Extension::ManifestData { |
19 public: | 19 public: |
20 BackgroundInfo(); | 20 BackgroundInfo(); |
21 virtual ~BackgroundInfo(); | 21 virtual ~BackgroundInfo(); |
22 | 22 |
23 static GURL GetBackgroundURL(const Extension* extension); | 23 static GURL GetBackgroundURL(const Extension* extension); |
24 static const std::vector<std::string>& GetBackgroundScripts( | 24 static const std::vector<std::string>& GetBackgroundScripts( |
25 const Extension* extension); | 25 const Extension* extension); |
26 static const std::string& GetServiceWorkerScript(const Extension* extension); | |
27 static bool HasBackgroundPage(const Extension* extension); | 26 static bool HasBackgroundPage(const Extension* extension); |
28 static bool HasPersistentBackgroundPage(const Extension* extension); | 27 static bool HasPersistentBackgroundPage(const Extension* extension); |
29 static bool HasLazyBackgroundPage(const Extension* extension); | 28 static bool HasLazyBackgroundPage(const Extension* extension); |
30 static bool HasGeneratedBackgroundPage(const Extension* extension); | 29 static bool HasGeneratedBackgroundPage(const Extension* extension); |
31 static bool HasServiceWorker(const Extension* extension); | |
32 static bool AllowJSAccess(const Extension* extension); | 30 static bool AllowJSAccess(const Extension* extension); |
33 | 31 |
34 bool has_background_page() const { | 32 bool has_background_page() const { |
35 return background_url_.is_valid() || !background_scripts_.empty(); | 33 return background_url_.is_valid() || !background_scripts_.empty(); |
36 } | 34 } |
37 | 35 |
38 bool has_persistent_background_page() const { | 36 bool has_persistent_background_page() const { |
39 return has_background_page() && is_persistent_; | 37 return has_background_page() && is_persistent_; |
40 } | 38 } |
41 | 39 |
42 bool has_lazy_background_page() const { | 40 bool has_lazy_background_page() const { |
43 return has_background_page() && !is_persistent_; | 41 return has_background_page() && !is_persistent_; |
44 } | 42 } |
45 | 43 |
46 bool has_service_worker() const { return !service_worker_script_.empty(); } | |
47 | |
48 bool Parse(const Extension* extension, base::string16* error); | 44 bool Parse(const Extension* extension, base::string16* error); |
49 | 45 |
50 private: | 46 private: |
51 bool LoadServiceWorkerScript(const Extension* extension, | |
52 const std::string& key, | |
53 base::string16* error); | |
54 bool LoadBackgroundScripts(const Extension* extension, | 47 bool LoadBackgroundScripts(const Extension* extension, |
55 const std::string& key, | 48 const std::string& key, |
56 base::string16* error); | 49 base::string16* error); |
57 bool LoadBackgroundPage(const Extension* extension, | 50 bool LoadBackgroundPage(const Extension* extension, |
58 const std::string& key, | 51 const std::string& key, |
59 base::string16* error); | 52 base::string16* error); |
60 bool LoadBackgroundPage(const Extension* extension, base::string16* error); | 53 bool LoadBackgroundPage(const Extension* extension, base::string16* error); |
61 bool LoadBackgroundPersistent(const Extension* extension, | 54 bool LoadBackgroundPersistent(const Extension* extension, |
62 base::string16* error); | 55 base::string16* error); |
63 bool LoadAllowJSAccess(const Extension* extension, base::string16* error); | 56 bool LoadAllowJSAccess(const Extension* extension, base::string16* error); |
64 | 57 |
65 // Optional URL to a master page of which a single instance should be always | 58 // Optional URL to a master page of which a single instance should be always |
66 // loaded in the background. | 59 // loaded in the background. |
67 GURL background_url_; | 60 GURL background_url_; |
68 | 61 |
69 // Optional list of scripts to use to generate a background page. If this is | 62 // Optional list of scripts to use to generate a background page. If this is |
70 // present, background_url_ will be empty and generated by GetBackgroundURL(). | 63 // present, background_url_ will be empty and generated by GetBackgroundURL(). |
71 std::vector<std::string> background_scripts_; | 64 std::vector<std::string> background_scripts_; |
72 | 65 |
73 // True if the background page should stay loaded forever; false if it should | 66 // True if the background page should stay loaded forever; false if it should |
74 // load on-demand (when it needs to handle an event). Defaults to true. | 67 // load on-demand (when it needs to handle an event). Defaults to true. |
75 bool is_persistent_; | 68 bool is_persistent_; |
76 | 69 |
77 // Optional script to register as a service worker. This is mutually exclusive | |
78 // to the use of background_url_ or background_scripts_. | |
79 std::string service_worker_script_; | |
80 | |
81 // True if the background page can be scripted by pages of the app or | 70 // True if the background page can be scripted by pages of the app or |
82 // extension, in which case all such pages must run in the same process. | 71 // extension, in which case all such pages must run in the same process. |
83 // False if such pages are not permitted to script the background page, | 72 // False if such pages are not permitted to script the background page, |
84 // allowing them to run in different processes. | 73 // allowing them to run in different processes. |
85 // Defaults to true. | 74 // Defaults to true. |
86 bool allow_js_access_; | 75 bool allow_js_access_; |
87 | 76 |
88 DISALLOW_COPY_AND_ASSIGN(BackgroundInfo); | 77 DISALLOW_COPY_AND_ASSIGN(BackgroundInfo); |
89 }; | 78 }; |
90 | 79 |
(...skipping 11 matching lines...) Expand all Loading... |
102 | 91 |
103 private: | 92 private: |
104 virtual const std::vector<std::string> Keys() const OVERRIDE; | 93 virtual const std::vector<std::string> Keys() const OVERRIDE; |
105 | 94 |
106 DISALLOW_COPY_AND_ASSIGN(BackgroundManifestHandler); | 95 DISALLOW_COPY_AND_ASSIGN(BackgroundManifestHandler); |
107 }; | 96 }; |
108 | 97 |
109 } // namespace extensions | 98 } // namespace extensions |
110 | 99 |
111 #endif // EXTENSIONS_COMMON_MANIFEST_HANDLERS_BACKGROUND_INFO_H_ | 100 #endif // EXTENSIONS_COMMON_MANIFEST_HANDLERS_BACKGROUND_INFO_H_ |
OLD | NEW |