Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
| 16 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | |
| 17 | 18 |
| 18 // The one true extension container. Extensions are identified by their id. | 19 // The one true extension container. Extensions are identified by their id. |
| 19 // Only one extension can be in the set with a given ID. | 20 // Only one extension can be in the set with a given ID. |
| 20 class ExtensionSet { | 21 class ExtensionSet { |
| 21 public: | 22 public: |
| 22 typedef std::pair<FilePath, std::string> ExtensionPathAndDefaultLocale; | 23 typedef std::pair<FilePath, std::string> ExtensionPathAndDefaultLocale; |
| 23 typedef std::map<std::string, scoped_refptr<const Extension> > ExtensionMap; | 24 typedef std::map<std::string, scoped_refptr<const Extension> > ExtensionMap; |
| 24 typedef ExtensionMap::const_iterator const_iterator; | 25 typedef ExtensionMap::const_iterator const_iterator; |
| 25 | 26 |
| 26 ExtensionSet(); | 27 ExtensionSet(); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 38 | 39 |
| 39 // Adds the specified extension to the set. The set becomes an owner. Any | 40 // Adds the specified extension to the set. The set becomes an owner. Any |
| 40 // previous extension with the same ID is removed. | 41 // previous extension with the same ID is removed. |
| 41 void Insert(const scoped_refptr<const Extension>& extension); | 42 void Insert(const scoped_refptr<const Extension>& extension); |
| 42 | 43 |
| 43 // Removes the specified extension. | 44 // Removes the specified extension. |
| 44 void Remove(const std::string& id); | 45 void Remove(const std::string& id); |
| 45 | 46 |
| 46 // Returns the extension ID that the given URL is a part of, or empty if | 47 // Returns the extension ID that the given URL is a part of, or empty if |
| 47 // none. This includes web URLs that are part of an extension's web extent. | 48 // none. This includes web URLs that are part of an extension's web extent. |
| 48 std::string GetIdByURL(const GURL& url) const; | 49 std::string GetIdByURL(WebKit::WebSecurityOrigin origin, |
|
Aaron Boodman
2011/11/30 02:01:31
What about defining an ExtensionURLInfo struct or
Aaron Boodman
2011/11/30 02:04:45
And would at least ensure people think twice when
abarth-chromium
2011/11/30 02:04:49
Will do.
| |
| 50 const GURL& url) const; | |
| 49 | 51 |
| 50 // Returns the Extension that the given URL is a part of, or NULL if none. | 52 // Returns the Extension that the given URL is a part of, or NULL if none. |
| 51 // This includes web URLs that are part of an extension's web extent. | 53 // This includes web URLs that are part of an extension's web extent. |
| 52 // NOTE: This can return NULL if called before UpdateExtensions receives | 54 // NOTE: This can return NULL if called before UpdateExtensions receives |
| 53 // bulk extension data (e.g. if called from | 55 // bulk extension data (e.g. if called from |
| 54 // EventBindings::HandleContextCreated) | 56 // EventBindings::HandleContextCreated) |
| 55 const Extension* GetByURL(const GURL& url) const; | 57 const Extension* GetByURL(WebKit::WebSecurityOrigin origin, |
| 58 const GURL& url) const; | |
| 59 | |
| 60 const Extension* GetByURLWithoutSecurityCheck(const GURL& url) const; | |
|
Aaron Boodman
2011/11/30 02:01:31
ExtensionURLInfo could have a constructor that jus
| |
| 56 | 61 |
| 57 // Returns true if |new_url| is in the extent of the same extension as | 62 // Returns true if |new_url| is in the extent of the same extension as |
| 58 // |old_url|. Also returns true if neither URL is in an app. | 63 // |old_url|. Also returns true if neither URL is in an app. |
| 59 bool InSameExtent(const GURL& old_url, const GURL& new_url) const; | 64 bool InSameExtent(const GURL& old_url, const GURL& new_url) const; |
| 60 | 65 |
| 61 // Look up an Extension object by id. | 66 // Look up an Extension object by id. |
| 62 const Extension* GetByID(const std::string& id) const; | 67 const Extension* GetByID(const std::string& id) const; |
| 63 | 68 |
| 64 // Returns true if |url| should get extension api bindings and be permitted | 69 // Returns true if |url| should get extension api bindings and be permitted |
| 65 // to make api calls. Note that this is independent of what extension | 70 // to make api calls. Note that this is independent of what extension |
| 66 // permissions the given extension has been granted. | 71 // permissions the given extension has been granted. |
| 67 bool ExtensionBindingsAllowed(const GURL& url) const; | 72 bool ExtensionBindingsAllowed(WebKit::WebSecurityOrigin origin, |
| 73 const GURL& url) const; | |
| 68 | 74 |
| 69 private: | 75 private: |
| 70 FRIEND_TEST_ALL_PREFIXES(ExtensionSetTest, ExtensionSet); | 76 FRIEND_TEST_ALL_PREFIXES(ExtensionSetTest, ExtensionSet); |
| 71 | 77 |
| 72 ExtensionMap extensions_; | 78 ExtensionMap extensions_; |
| 73 | 79 |
| 74 DISALLOW_COPY_AND_ASSIGN(ExtensionSet); | 80 DISALLOW_COPY_AND_ASSIGN(ExtensionSet); |
| 75 }; | 81 }; |
| 76 | 82 |
| 77 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_SET_H_ | 83 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_SET_H_ |
| OLD | NEW |