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

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: Created 7 years, 6 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 "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
17
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 16
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,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 69
93 // Removes the specified extension. 70 // Removes the specified extension.
94 // Returns true if the set contained the specified extnesion. 71 // Returns true if the set contained the specified extnesion.
95 bool Remove(const std::string& id); 72 bool Remove(const std::string& id);
96 73
97 // Removes all extensions. 74 // Removes all extensions.
98 void Clear(); 75 void Clear();
99 76
100 // Returns the extension ID, or empty if none. This includes web URLs that 77 // Returns the extension ID, or empty if none. This includes web URLs that
101 // are part of an extension's web extent. 78 // are part of an extension's web extent.
102 std::string GetExtensionOrAppIDByURL(const ExtensionURLInfo& info) const; 79 std::string GetExtensionOrAppIDByURL(const GURL& url) const;
103 80
104 // Returns the Extension, or NULL if none. This includes web URLs that are 81 // Returns the Extension, or NULL if none. This includes web URLs that are
105 // part of an extension's web extent. 82 // part of an extension's web extent.
106 // NOTE: This can return NULL if called before UpdateExtensions receives 83 // NOTE: This can return NULL if called before UpdateExtensions receives
107 // bulk extension data (e.g. if called from 84 // bulk extension data (e.g. if called from
108 // EventBindings::HandleContextCreated) 85 // EventBindings::HandleContextCreated)
109 const extensions::Extension* GetExtensionOrAppByURL( 86 const extensions::Extension* GetExtensionOrAppByURL(const GURL& url) const;
110 const ExtensionURLInfo& info) const;
111 87
112 // Returns the hosted app whose web extent contains the URL. 88 // Returns the hosted app whose web extent contains the URL.
113 const extensions::Extension* GetHostedAppByURL( 89 const extensions::Extension* GetHostedAppByURL(const GURL& url) const;
114 const ExtensionURLInfo& info) const;
115 90
116 // Returns a hosted app that contains any URL that overlaps with the given 91 // Returns a hosted app that contains any URL that overlaps with the given
117 // extent, if one exists. 92 // extent, if one exists.
118 const extensions::Extension* GetHostedAppByOverlappingWebExtent( 93 const extensions::Extension* GetHostedAppByOverlappingWebExtent(
119 const extensions::URLPatternSet& extent) const; 94 const extensions::URLPatternSet& extent) const;
120 95
121 // Returns true if |new_url| is in the extent of the same extension as 96 // Returns true if |new_url| is in the extent of the same extension as
122 // |old_url|. Also returns true if neither URL is in an app. 97 // |old_url|. Also returns true if neither URL is in an app.
123 bool InSameExtent(const GURL& old_url, const GURL& new_url) const; 98 bool InSameExtent(const GURL& old_url, const GURL& new_url) const;
124 99
125 // Look up an Extension object by id. 100 // Look up an Extension object by id.
126 const extensions::Extension* GetByID(const std::string& id) const; 101 const extensions::Extension* GetByID(const std::string& id) const;
127 102
128 // Gets the IDs of all extensions in the set. 103 // Gets the IDs of all extensions in the set.
129 std::set<std::string> GetIDs() const; 104 std::set<std::string> GetIDs() const;
130 105
131 // Returns true if |info| should get extension api bindings and be permitted 106 // Returns true if |info| should get extension api bindings and be permitted
132 // to make api calls. Note that this is independent of what extension 107 // to make api calls. Note that this is independent of what extension
133 // permissions the given extension has been granted. 108 // permissions the given extension has been granted.
134 bool ExtensionBindingsAllowed(const ExtensionURLInfo& info) const; 109 bool ExtensionBindingsAllowed(const GURL& url) const;
135 110
136 // Returns true if |info| is an extension page that is to be served in a 111 // Returns true if |info| is an extension page that is to be served in a
137 // unique sandboxed origin. 112 // unique sandboxed origin.
138 bool IsSandboxedPage(const ExtensionURLInfo& info) const; 113 bool IsSandboxedPage(const GURL& url) const;
139 114
140 private: 115 private:
141 FRIEND_TEST_ALL_PREFIXES(ExtensionSetTest, ExtensionSet); 116 FRIEND_TEST_ALL_PREFIXES(ExtensionSetTest, ExtensionSet);
142 117
143 ExtensionMap extensions_; 118 ExtensionMap extensions_;
144 119
145 DISALLOW_COPY_AND_ASSIGN(ExtensionSet); 120 DISALLOW_COPY_AND_ASSIGN(ExtensionSet);
146 }; 121 };
147 122
148 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_SET_H_ 123 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_SET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698