blob: e6a2ca85b266a3844a2e5d7d9fe00c4653a35081 [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"
[email protected]eab9b452009-01-23 20:48:5914#include "chrome/browser/extensions/user_script_master.h"
15#include "googleurl/src/gurl.h"
16
17// The URL schemes Chromium extensions and user scripts are served from. These
18// really should be in extension_protocols.h, but that causes link errors on
19// linux because extension_protocols.cc refers to undefined symbols.
20// TODO(aa): Move these back to extension_protocols.h when more of Linux and
21// Mac are up and running.
22extern const char kExtensionURLScheme[];
23extern const char kUserScriptURLScheme[];
[email protected]7713d632008-12-02 07:52:3324
25// Represents a Chromium extension.
26class Extension {
27 public:
[email protected]eab9b452009-01-23 20:48:5928 Extension(const FilePath& path);
[email protected]7713d632008-12-02 07:52:3329
30 // The format for extension manifests that this code understands.
31 static const int kExpectedFormatVersion = 1;
32
[email protected]6014d672008-12-05 00:38:2533 // The name of the manifest inside an extension.
[email protected]0e292232009-01-22 15:23:3434 static const char kManifestFilename[];
[email protected]6014d672008-12-05 00:38:2535
[email protected]7713d632008-12-02 07:52:3336 // Keys used in JSON representation of extensions.
[email protected]eab9b452009-01-23 20:48:5937 static const wchar_t* kDescriptionKey;
38 static const wchar_t* kFilesKey;
[email protected]17122322009-01-22 20:03:3039 static const wchar_t* kFormatVersionKey;
40 static const wchar_t* kIdKey;
[email protected]eab9b452009-01-23 20:48:5941 static const wchar_t* kMatchesKey;
[email protected]17122322009-01-22 20:03:3042 static const wchar_t* kNameKey;
[email protected]eab9b452009-01-23 20:48:5943 static const wchar_t* kUserScriptsKey;
[email protected]17122322009-01-22 20:03:3044 static const wchar_t* kVersionKey;
[email protected]7713d632008-12-02 07:52:3345
46 // Error messages returned from InitFromValue().
[email protected]17122322009-01-22 20:03:3047 static const char* kInvalidDescriptionError;
[email protected]eab9b452009-01-23 20:48:5948 static const char* kInvalidFileCountError;
49 static const char* kInvalidFileError;
50 static const char* kInvalidFilesError;
51 static const char* kInvalidFormatVersionError;
52 static const char* kInvalidIdError;
53 static const char* kInvalidManifestError;
54 static const char* kInvalidMatchCountError;
55 static const char* kInvalidMatchError;
56 static const char* kInvalidMatchesError;
57 static const char* kInvalidNameError;
58 static const char* kInvalidUserScriptError;
59 static const char* kInvalidUserScriptsListError;
[email protected]17122322009-01-22 20:03:3060 static const char* kInvalidVersionError;
[email protected]7713d632008-12-02 07:52:3361
[email protected]eab9b452009-01-23 20:48:5962 // Creates an absolute url to a resource inside an extension. The
63 // |extension_url| argument should be the url() from an Extension object. The
64 // |relative_path| can be untrusted user input. The returned URL will either
65 // be invalid() or a child of |extension_url|.
66 // NOTE: Static so that it can be used from multiple threads.
67 static GURL GetResourceURL(const GURL& extension_url,
68 const std::string& relative_path);
69
70 // Creates an absolute path to a resource inside an extension. The
71 // |extension_path| argument should be the path() from an Extension object.
72 // The |relative_path| can be untrusted user input. The returned path will
73 // either be empty or a child of extension_path.
74 // NOTE: Static so that it can be used from multiple threads.
75 static FilePath GetResourcePath(const FilePath& extension_path,
76 const std::string& relative_path);
77
[email protected]82891262008-12-24 00:21:2678 // The path to the folder the extension is stored in.
79 const FilePath& path() const { return path_; }
80
[email protected]eab9b452009-01-23 20:48:5981 // The base URL for the extension.
82 const GURL& url() const { return extension_url_; }
83
[email protected]7713d632008-12-02 07:52:3384 // A human-readable ID for the extension. The convention is to use something
85 // like 'com.example.myextension', but this is not currently enforced. An
86 // extension's ID is used in things like directory structures and URLs, and
87 // is expected to not change across versions. In the case of conflicts,
88 // updates will only be allowed if the extension can be validated using the
89 // previous version's update key.
[email protected]e1cec06c2008-12-18 01:22:2390 const std::string& id() const { return id_; }
[email protected]7713d632008-12-02 07:52:3391
[email protected]64a02b802009-01-12 19:36:4292 // The version number for the extension.
93 const std::string& version() const { return version_; }
94
[email protected]7713d632008-12-02 07:52:3395 // A human-readable name of the extension.
[email protected]e1cec06c2008-12-18 01:22:2396 const std::string& name() const { return name_; }
[email protected]7713d632008-12-02 07:52:3397
98 // An optional longer description of the extension.
[email protected]e1cec06c2008-12-18 01:22:2399 const std::string& description() const { return description_; }
[email protected]7713d632008-12-02 07:52:33100
101 // Paths to the content scripts that the extension contains.
[email protected]eab9b452009-01-23 20:48:59102 const UserScriptList& user_scripts() const {
103 return user_scripts_;
[email protected]7713d632008-12-02 07:52:33104 }
105
106 // Initialize the extension from a parsed manifest.
[email protected]3acbd422008-12-08 18:25:00107 bool InitFromValue(const DictionaryValue& value, std::string* error);
[email protected]7713d632008-12-02 07:52:33108
[email protected]7713d632008-12-02 07:52:33109 private:
[email protected]82891262008-12-24 00:21:26110 // The path to the directory the extension is stored in.
111 FilePath path_;
112
[email protected]eab9b452009-01-23 20:48:59113 // The base extension url for the extension.
114 GURL extension_url_;
115
[email protected]82891262008-12-24 00:21:26116 // The extension's ID.
[email protected]e1cec06c2008-12-18 01:22:23117 std::string id_;
[email protected]82891262008-12-24 00:21:26118
[email protected]64a02b802009-01-12 19:36:42119 // The extension's version.
120 std::string version_;
121
[email protected]82891262008-12-24 00:21:26122 // The extension's human-readable name.
[email protected]e1cec06c2008-12-18 01:22:23123 std::string name_;
[email protected]82891262008-12-24 00:21:26124
125 // An optional description for the extension.
[email protected]e1cec06c2008-12-18 01:22:23126 std::string description_;
[email protected]82891262008-12-24 00:21:26127
128 // Paths to the content scripts the extension contains.
[email protected]eab9b452009-01-23 20:48:59129 UserScriptList user_scripts_;
[email protected]7713d632008-12-02 07:52:33130
131 DISALLOW_COPY_AND_ASSIGN(Extension);
132};
133
[email protected]6014d672008-12-05 00:38:25134#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_H_