OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 CHROME_RENDERER_EXTENSIONS_EXTENSION_RENDERER_INFO_H_ | 5 #ifndef CHROME_RENDERER_EXTENSIONS_EXTENSION_RENDERER_INFO_H_ |
6 #define CHROME_RENDERER_EXTENSIONS_EXTENSION_RENDERER_INFO_H_ | 6 #define CHROME_RENDERER_EXTENSIONS_EXTENSION_RENDERER_INFO_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/ref_counted.h" |
13 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
14 #include "chrome/common/extensions/extension_extent.h" | |
15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
16 | 16 |
17 struct ViewMsg_ExtensionsUpdated_Params; | 17 // ExtensionRendererInfo is a convenience wrapper around a map of extension |
18 struct ViewMsg_ExtensionRendererInfo; | 18 // objects. It is used by renderers to maintain information about currently |
19 | 19 // loaded extensions. |
20 // Extension information needed in the renderer process along with static | |
21 // methods to look up information about the currently loaded extensions. | |
22 class ExtensionRendererInfo { | 20 class ExtensionRendererInfo { |
23 public: | 21 public: |
24 ExtensionRendererInfo(); | 22 ExtensionRendererInfo(); |
25 ExtensionRendererInfo(const ExtensionRendererInfo& that); | |
26 ~ExtensionRendererInfo(); | |
27 | 23 |
28 const std::string& id() const { return id_; } | 24 // Gets the number of extensions contained. |
29 const ExtensionExtent& web_extent() const { return web_extent_; } | 25 size_t size() const; |
30 const std::string& name() const { return name_; } | |
31 const GURL& icon_url() const { return icon_url_; } | |
32 bool allowed_to_execute_script_everywhere() const { | |
33 return allowed_to_execute_script_everywhere_; | |
34 } | |
35 const std::vector<URLPattern>& host_permissions() const { | |
36 return host_permissions_; | |
37 } | |
38 | 26 |
39 // Replace the list of extensions with those provided in |params|. | 27 // Updates the specified extension. |
40 static void UpdateExtensions(const ViewMsg_ExtensionsUpdated_Params& params); | 28 void Update(const scoped_refptr<const Extension>& extension); |
| 29 |
| 30 // Removes the specified extension. |
| 31 void Remove(const std::string& id); |
41 | 32 |
42 // Returns the extension ID that the given URL is a part of, or empty if | 33 // Returns the extension ID that the given URL is a part of, or empty if |
43 // none. This includes web URLs that are part of an extension's web extent. | 34 // none. This includes web URLs that are part of an extension's web extent. |
44 static std::string GetIdByURL(const GURL& url); | 35 std::string GetIdByURL(const GURL& url) const; |
45 | 36 |
46 // Returns the ExtensionRendererInfo that the given URL is a part of, or NULL | 37 // Returns the Extension that the given URL is a part of, or NULL if none. |
47 // if none. This includes web URLs that are part of an extension's web extent. | 38 // This includes web URLs that are part of an extension's web extent. |
48 // NOTE: This can return NULL if called before UpdateExtensions receives | 39 // NOTE: This can return NULL if called before UpdateExtensions receives |
49 // bulk extension data (e.g. if called from | 40 // bulk extension data (e.g. if called from |
50 // EventBindings::HandleContextCreated) | 41 // EventBindings::HandleContextCreated) |
51 static ExtensionRendererInfo* GetByURL(const GURL& url); | 42 const Extension* GetByURL(const GURL& url) const; |
52 | 43 |
53 // Returns true if |new_url| is in the extent of the same extension as | 44 // Returns true if |new_url| is in the extent of the same extension as |
54 // |old_url|. Also returns true if neither URL is in an app. | 45 // |old_url|. Also returns true if neither URL is in an app. |
55 static bool InSameExtent(const GURL& old_url, const GURL& new_url); | 46 bool InSameExtent(const GURL& old_url, const GURL& new_url) const; |
56 | 47 |
57 // Look up an ExtensionInfo object by id. | 48 // Look up an Extension object by id. |
58 static ExtensionRendererInfo* GetByID(const std::string& id); | 49 const Extension* GetByID(const std::string& id) const; |
59 | 50 |
60 // Returns true if |url| should get extension api bindings and be permitted | 51 // Returns true if |url| should get extension api bindings and be permitted |
61 // to make api calls. Note that this is independent of what extension | 52 // to make api calls. Note that this is independent of what extension |
62 // permissions the given extension has been granted. | 53 // permissions the given extension has been granted. |
63 static bool ExtensionBindingsAllowed(const GURL& url); | 54 bool ExtensionBindingsAllowed(const GURL& url) const; |
64 | 55 |
65 private: | 56 private: |
66 void Update(const ViewMsg_ExtensionRendererInfo& info); | |
67 | |
68 FRIEND_TEST_ALL_PREFIXES(ExtensionRendererInfoTest, ExtensionRendererInfo); | 57 FRIEND_TEST_ALL_PREFIXES(ExtensionRendererInfoTest, ExtensionRendererInfo); |
69 | 58 |
70 std::string id_; | 59 // static |
71 ExtensionExtent web_extent_; | 60 typedef std::map<std::string, scoped_refptr<const Extension> > ExtensionMap; |
72 std::string name_; | 61 ExtensionMap extensions_; |
73 Extension::Location location_; | |
74 GURL icon_url_; | |
75 | 62 |
76 // Some internal extensions, such as accessibility extensions, should be able | 63 DISALLOW_COPY_AND_ASSIGN(ExtensionRendererInfo); |
77 // to execute scripts everywhere. | |
78 bool allowed_to_execute_script_everywhere_; | |
79 | |
80 // The list of host permissions, that the extension is allowed to run scripts | |
81 // on. | |
82 std::vector<URLPattern> host_permissions_; | |
83 | |
84 // static | |
85 static std::vector<ExtensionRendererInfo>* extensions_; | |
86 }; | 64 }; |
87 | 65 |
88 #endif // CHROME_RENDERER_EXTENSIONS_EXTENSION_RENDERER_INFO_H_ | 66 #endif // CHROME_RENDERER_EXTENSIONS_EXTENSION_RENDERER_INFO_H_ |
OLD | NEW |