blob: 8a825477ce45ab892c10990be883f7545676ec80 [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:
[email protected]17122322009-01-22 20:03:3018 Extension(){};
19 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.
[email protected]0e292232009-01-22 15:23:3425 static const char kManifestFilename[];
[email protected]6014d672008-12-05 00:38:2526
[email protected]7713d632008-12-02 07:52:3327 // Keys used in JSON representation of extensions.
[email protected]17122322009-01-22 20:03:3028 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;
33 static const wchar_t* kVersionKey;
[email protected]7713d632008-12-02 07:52:3334
35 // Error messages returned from InitFromValue().
[email protected]17122322009-01-22 20:03:3036 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;
43 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]17122322009-01-22 20:03:3066 const std::vector<std::string>& content_scripts() const {
67 return content_scripts_;
[email protected]7713d632008-12-02 07:52:3368 }
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
[email protected]17122322009-01-22 20:03:3073 // Serialize the extension to a DictionaryValue.
74 void CopyToValue(DictionaryValue* value);
75
[email protected]7713d632008-12-02 07:52:3376 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]17122322009-01-22 20:03:3093 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_