#ifndef EXTENSIONS_COMMON_MANIFEST_HANDLERS_BACKGROUND_INFO_H_
#define EXTENSIONS_COMMON_MANIFEST_HANDLERS_BACKGROUND_INFO_H_
#include <string>
#include <vector>
#include "base/values.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest_handler.h"
#include "url/gurl.h"
namespace extensions {
class BackgroundInfo : public Extension::ManifestData {
public:
BackgroundInfo();
virtual ~BackgroundInfo();
static GURL GetBackgroundURL(const Extension* extension);
static const std::vector<std::string>& GetBackgroundScripts(
const Extension* extension);
static const std::string& GetServiceWorkerScript(const Extension* extension);
static bool HasBackgroundPage(const Extension* extension);
static bool HasPersistentBackgroundPage(const Extension* extension);
static bool HasLazyBackgroundPage(const Extension* extension);
static bool HasGeneratedBackgroundPage(const Extension* extension);
static bool HasServiceWorker(const Extension* extension);
static bool AllowJSAccess(const Extension* extension);
bool has_background_page() const {
return background_url_.is_valid() || !background_scripts_.empty();
}
bool has_persistent_background_page() const {
return has_background_page() && is_persistent_;
}
bool has_lazy_background_page() const {
return has_background_page() && !is_persistent_;
}
bool has_service_worker() const { return !service_worker_script_.empty(); }
bool Parse(const Extension* extension, base::string16* error);
private:
bool LoadServiceWorkerScript(const Extension* extension,
const std::string& key,
base::string16* error);
bool LoadBackgroundScripts(const Extension* extension,
const std::string& key,
base::string16* error);
bool LoadBackgroundPage(const Extension* extension,
const std::string& key,
base::string16* error);
bool LoadBackgroundPage(const Extension* extension, base::string16* error);
bool LoadBackgroundPersistent(const Extension* extension,
base::string16* error);
bool LoadAllowJSAccess(const Extension* extension, base::string16* error);
GURL background_url_;
std::vector<std::string> background_scripts_;
bool is_persistent_;
std::string service_worker_script_;
bool allow_js_access_;
DISALLOW_COPY_AND_ASSIGN(BackgroundInfo);
};
class BackgroundManifestHandler : public ManifestHandler {
public:
BackgroundManifestHandler();
virtual ~BackgroundManifestHandler();
virtual bool Parse(Extension* extension, base::string16* error) OVERRIDE;
virtual bool Validate(const Extension* extension,
std::string* error,
std::vector<InstallWarning>* warnings) const OVERRIDE;
virtual bool AlwaysParseForType(Manifest::Type type) const OVERRIDE;
private:
virtual const std::vector<std::string> Keys() const OVERRIDE;
DISALLOW_COPY_AND_ASSIGN(BackgroundManifestHandler);
};
}
#endif