Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: chrome/common/extensions/extension_set.h

Issue 16625012: Remove ExtensionURLInfo, make security decisions in render process (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address feedback Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_COMMON_EXTENSIONS_EXTENSION_SET_H_ 5 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_SET_H_
6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_SET_H_ 6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_SET_H_
7 7
8 #include <iterator> 8 #include <iterator>
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 11
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "chrome/common/extensions/extension.h" 14 #include "chrome/common/extensions/extension.h"
15 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
16 #include "url/gurl.h" 15 #include "url/gurl.h"
17 16
18 class ExtensionURLInfo {
19 public:
20 // The extension system uses both a document's origin and its URL to
21 // grant permissions. Ideally, we would use only the origin, but because
22 // the web extent of a hosted app can be less than an entire origin, we
23 // take the URL into account as well
24 ExtensionURLInfo(WebKit::WebSecurityOrigin origin, const GURL& url);
25
26 // WARNING! Using this constructor can miss important security checks if
27 // you're trying to find a running extension. For example, if the
28 // URL in question is being rendered inside an iframe sandbox, then
29 // we might incorrectly grant it access to powerful extension APIs.
30 explicit ExtensionURLInfo(const GURL& url);
31
32 const WebKit::WebSecurityOrigin& origin() const { return origin_; }
33 const GURL& url() const { return url_; }
34
35 private:
36 WebKit::WebSecurityOrigin origin_;
37 GURL url_;
38 };
39
40 // The one true extension container. Extensions are identified by their id. 17 // The one true extension container. Extensions are identified by their id.
41 // Only one extension can be in the set with a given ID. 18 // Only one extension can be in the set with a given ID.
42 class ExtensionSet { 19 class ExtensionSet {
43 public: 20 public:
44 typedef std::pair<base::FilePath, std::string> ExtensionPathAndDefaultLocale; 21 typedef std::pair<base::FilePath, std::string> ExtensionPathAndDefaultLocale;
45 typedef std::map<std::string, scoped_refptr<const extensions::Extension> > 22 typedef std::map<std::string, scoped_refptr<const extensions::Extension> >
46 ExtensionMap; 23 ExtensionMap;
47 24
48 // Iteration over the values of the map (given that it's an ExtensionSet, 25 // Iteration over the values of the map (given that it's an ExtensionSet,
49 // it should iterate like a set iterator). 26 // it should iterate like a set iterator).
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 72
96 // Removes the specified extension. 73 // Removes the specified extension.
97 // Returns true if the set contained the specified extnesion. 74 // Returns true if the set contained the specified extnesion.
98 bool Remove(const std::string& id); 75 bool Remove(const std::string& id);
99 76
100 // Removes all extensions. 77 // Removes all extensions.
101 void Clear(); 78 void Clear();
102 79
103 // Returns the extension ID, or empty if none. This includes web URLs that 80 // Returns the extension ID, or empty if none. This includes web URLs that
104 // are part of an extension's web extent. 81 // are part of an extension's web extent.
105 std::string GetExtensionOrAppIDByURL(const ExtensionURLInfo& info) const; 82 std::string GetExtensionOrAppIDByURL(const GURL& url) const;
106 83
107 // Returns the Extension, or NULL if none. This includes web URLs that are 84 // Returns the Extension, or NULL if none. This includes web URLs that are
108 // part of an extension's web extent. 85 // part of an extension's web extent.
109 // NOTE: This can return NULL if called before UpdateExtensions receives 86 // NOTE: This can return NULL if called before UpdateExtensions receives
110 // bulk extension data (e.g. if called from 87 // bulk extension data (e.g. if called from
111 // EventBindings::HandleContextCreated) 88 // EventBindings::HandleContextCreated)
112 const extensions::Extension* GetExtensionOrAppByURL( 89 const extensions::Extension* GetExtensionOrAppByURL(const GURL& url) const;
113 const ExtensionURLInfo& info) const;
114 90
115 // Returns the hosted app whose web extent contains the URL. 91 // Returns the hosted app whose web extent contains the URL.
116 const extensions::Extension* GetHostedAppByURL( 92 const extensions::Extension* GetHostedAppByURL(const GURL& url) const;
117 const ExtensionURLInfo& info) const;
118 93
119 // Returns a hosted app that contains any URL that overlaps with the given 94 // Returns a hosted app that contains any URL that overlaps with the given
120 // extent, if one exists. 95 // extent, if one exists.
121 const extensions::Extension* GetHostedAppByOverlappingWebExtent( 96 const extensions::Extension* GetHostedAppByOverlappingWebExtent(
122 const extensions::URLPatternSet& extent) const; 97 const extensions::URLPatternSet& extent) const;
123 98
124 // Returns true if |new_url| is in the extent of the same extension as 99 // Returns true if |new_url| is in the extent of the same extension as
125 // |old_url|. Also returns true if neither URL is in an app. 100 // |old_url|. Also returns true if neither URL is in an app.
126 bool InSameExtent(const GURL& old_url, const GURL& new_url) const; 101 bool InSameExtent(const GURL& old_url, const GURL& new_url) const;
127 102
128 // Look up an Extension object by id. 103 // Look up an Extension object by id.
129 const extensions::Extension* GetByID(const std::string& id) const; 104 const extensions::Extension* GetByID(const std::string& id) const;
130 105
131 // Gets the IDs of all extensions in the set. 106 // Gets the IDs of all extensions in the set.
132 std::set<std::string> GetIDs() const; 107 std::set<std::string> GetIDs() const;
133 108
134 // Returns true if |info| should get extension api bindings and be permitted 109 // Returns true if |info| should get extension api bindings and be permitted
135 // to make api calls. Note that this is independent of what extension 110 // to make api calls. Note that this is independent of what extension
136 // permissions the given extension has been granted. 111 // permissions the given extension has been granted.
137 bool ExtensionBindingsAllowed(const ExtensionURLInfo& info) const; 112 bool ExtensionBindingsAllowed(const GURL& url) const;
138
139 // Returns true if |info| is an extension page that is to be served in a
140 // unique sandboxed origin.
141 bool IsSandboxedPage(const ExtensionURLInfo& info) const;
142 113
143 private: 114 private:
144 FRIEND_TEST_ALL_PREFIXES(ExtensionSetTest, ExtensionSet); 115 FRIEND_TEST_ALL_PREFIXES(ExtensionSetTest, ExtensionSet);
145 116
146 ExtensionMap extensions_; 117 ExtensionMap extensions_;
147 118
148 DISALLOW_COPY_AND_ASSIGN(ExtensionSet); 119 DISALLOW_COPY_AND_ASSIGN(ExtensionSet);
149 }; 120 };
150 121
151 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_SET_H_ 122 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_SET_H_
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_process_policy.cc ('k') | chrome/common/extensions/extension_set.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698