blob: 2b2f775851552f7f3c7b41d7a3d1f67710b27c5a [file] [log] [blame]
[email protected]7713d632008-12-02 07:52:331// Copyright (c) 2006-2008 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.
4
[email protected]6014d672008-12-05 00:38:255#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_H_
6#define CHROME_BROWSER_EXTENSIONS_EXTENSION_H_
[email protected]7713d632008-12-02 07:52:337
8#include <string>
9#include <vector>
10
[email protected]6014d672008-12-05 00:38:2511#include "base/file_path.h"
[email protected]7713d632008-12-02 07:52:3312#include "base/string16.h"
13#include "base/values.h"
14
15// Represents a Chromium extension.
16class Extension {
17 public:
18 Extension(){};
[email protected]82891262008-12-24 00:21:2619 Extension(const FilePath& path) : path_(path) {};
[email protected]7713d632008-12-02 07:52:3320
21 // The format for extension manifests that this code understands.
22 static const int kExpectedFormatVersion = 1;
23
[email protected]6014d672008-12-05 00:38:2524 // The name of the manifest inside an extension.
25 static const FilePath::CharType* kManifestFilename;
26
[email protected]7713d632008-12-02 07:52:3327 // Keys used in JSON representation of extensions.
[email protected]6014d672008-12-05 00:38:2528 static const wchar_t* kFormatVersionKey;
29 static const wchar_t* kIdKey;
30 static const wchar_t* kNameKey;
31 static const wchar_t* kDescriptionKey;
32 static const wchar_t* kContentScriptsKey;
[email protected]64a02b802009-01-12 19:36:4233 static const wchar_t* kVersionKey;
[email protected]7713d632008-12-02 07:52:3334
35 // Error messages returned from InitFromValue().
[email protected]3acbd422008-12-08 18:25:0036 static const char* kInvalidFormatVersionError;
37 static const char* kInvalidManifestError;
38 static const char* kInvalidIdError;
39 static const char* kInvalidNameError;
40 static const char* kInvalidDescriptionError;
41 static const char* kInvalidContentScriptsListError;
42 static const char* kInvalidContentScriptError;
[email protected]64a02b802009-01-12 19:36:4243 static const char* kInvalidVersionError;
[email protected]7713d632008-12-02 07:52:3344
[email protected]82891262008-12-24 00:21:2645 // The path to the folder the extension is stored in.
46 const FilePath& path() const { return path_; }
47
[email protected]7713d632008-12-02 07:52:3348 // A human-readable ID for the extension. The convention is to use something
49 // like 'com.example.myextension', but this is not currently enforced. An
50 // extension's ID is used in things like directory structures and URLs, and
51 // is expected to not change across versions. In the case of conflicts,
52 // updates will only be allowed if the extension can be validated using the
53 // previous version's update key.
[email protected]e1cec06c2008-12-18 01:22:2354 const std::string& id() const { return id_; }
[email protected]7713d632008-12-02 07:52:3355
[email protected]64a02b802009-01-12 19:36:4256 // The version number for the extension.
57 const std::string& version() const { return version_; }
58
[email protected]7713d632008-12-02 07:52:3359 // A human-readable name of the extension.
[email protected]e1cec06c2008-12-18 01:22:2360 const std::string& name() const { return name_; }
[email protected]7713d632008-12-02 07:52:3361
62 // An optional longer description of the extension.
[email protected]e1cec06c2008-12-18 01:22:2363 const std::string& description() const { return description_; }
[email protected]7713d632008-12-02 07:52:3364
65 // Paths to the content scripts that the extension contains.
[email protected]e1cec06c2008-12-18 01:22:2366 const std::vector<std::string>& content_scripts() const {
[email protected]7713d632008-12-02 07:52:3367 return content_scripts_;
68 }
69
70 // Initialize the extension from a parsed manifest.
[email protected]3acbd422008-12-08 18:25:0071 bool InitFromValue(const DictionaryValue& value, std::string* error);
[email protected]7713d632008-12-02 07:52:3372
73 // Serialize the extension to a DictionaryValue.
74 void CopyToValue(DictionaryValue* value);
75
76 private:
[email protected]82891262008-12-24 00:21:2677 // The path to the directory the extension is stored in.
78 FilePath path_;
79
80 // The extension's ID.
[email protected]e1cec06c2008-12-18 01:22:2381 std::string id_;
[email protected]82891262008-12-24 00:21:2682
[email protected]64a02b802009-01-12 19:36:4283 // The extension's version.
84 std::string version_;
85
[email protected]82891262008-12-24 00:21:2686 // The extension's human-readable name.
[email protected]e1cec06c2008-12-18 01:22:2387 std::string name_;
[email protected]82891262008-12-24 00:21:2688
89 // An optional description for the extension.
[email protected]e1cec06c2008-12-18 01:22:2390 std::string description_;
[email protected]82891262008-12-24 00:21:2691
92 // Paths to the content scripts the extension contains.
[email protected]e1cec06c2008-12-18 01:22:2393 std::vector<std::string> content_scripts_;
[email protected]7713d632008-12-02 07:52:3394
95 DISALLOW_COPY_AND_ASSIGN(Extension);
96};
97
[email protected]6014d672008-12-05 00:38:2598#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_H_