| OLD | NEW |
| 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_BROWSER_CHROME_PLUGIN_SERVICE_FILTER_H_ | 5 #ifndef CHROME_BROWSER_CHROME_PLUGIN_SERVICE_FILTER_H_ |
| 6 #define CHROME_BROWSER_CHROME_PLUGIN_SERVICE_FILTER_H_ | 6 #define CHROME_BROWSER_CHROME_PLUGIN_SERVICE_FILTER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 12 #include "base/hash_tables.h" | 13 #include "base/hash_tables.h" |
| 13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
| 15 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 16 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
| 17 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
| 18 #include "content/public/browser/plugin_service_filter.h" | 19 #include "content/public/browser/plugin_service_filter.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 43 | 44 |
| 44 // Restricts the given plugin to the given profile and origin of the given | 45 // Restricts the given plugin to the given profile and origin of the given |
| 45 // URL. | 46 // URL. |
| 46 void RestrictPluginToProfileAndOrigin(const FilePath& plugin_path, | 47 void RestrictPluginToProfileAndOrigin(const FilePath& plugin_path, |
| 47 Profile* profile, | 48 Profile* profile, |
| 48 const GURL& url); | 49 const GURL& url); |
| 49 | 50 |
| 50 // Lifts a restriction on a plug-in. | 51 // Lifts a restriction on a plug-in. |
| 51 void UnrestrictPlugin(const FilePath& plugin_path); | 52 void UnrestrictPlugin(const FilePath& plugin_path); |
| 52 | 53 |
| 54 // Authorizes a given plug-in for a given process. |
| 55 void AuthorizePlugin(int render_process_id, const FilePath& plugin_path); |
| 56 |
| 57 // Authorizes all plug-ins for a given process. |
| 58 void AuthorizeAllPlugins(int render_process_id); |
| 59 |
| 53 // PluginServiceFilter implementation: | 60 // PluginServiceFilter implementation: |
| 54 virtual bool ShouldUsePlugin( | 61 virtual bool IsPluginEnabled( |
| 55 int render_process_id, | 62 int render_process_id, |
| 56 int render_view_id, | 63 int render_view_id, |
| 57 const void* context, | 64 const void* context, |
| 58 const GURL& url, | 65 const GURL& url, |
| 59 const GURL& policy_url, | 66 const GURL& policy_url, |
| 60 webkit::WebPluginInfo* plugin) OVERRIDE; | 67 webkit::WebPluginInfo* plugin) OVERRIDE; |
| 61 | 68 |
| 69 // CanLoadPlugin always grants permission to the browser |
| 70 // (render_process_id == 0) |
| 71 virtual bool CanLoadPlugin( |
| 72 int render_process_id, |
| 73 const FilePath& path) OVERRIDE; |
| 74 |
| 62 private: | 75 private: |
| 63 friend struct DefaultSingletonTraits<ChromePluginServiceFilter>; | 76 friend struct DefaultSingletonTraits<ChromePluginServiceFilter>; |
| 64 | 77 |
| 65 struct OverriddenPlugin { | 78 struct OverriddenPlugin { |
| 66 int render_process_id; | 79 OverriddenPlugin(); |
| 80 ~OverriddenPlugin(); |
| 81 |
| 67 int render_view_id; | 82 int render_view_id; |
| 68 GURL url; // If empty, the override applies to all urls in render_view. | 83 GURL url; // If empty, the override applies to all urls in render_view. |
| 69 webkit::WebPluginInfo plugin; | 84 webkit::WebPluginInfo plugin; |
| 70 }; | 85 }; |
| 71 | 86 |
| 87 struct ProcessDetails { |
| 88 ProcessDetails(); |
| 89 ~ProcessDetails(); |
| 90 |
| 91 std::vector<OverriddenPlugin> overridden_plugins; |
| 92 std::set<FilePath> authorized_plugins; |
| 93 }; |
| 94 |
| 72 ChromePluginServiceFilter(); | 95 ChromePluginServiceFilter(); |
| 73 virtual ~ChromePluginServiceFilter(); | 96 virtual ~ChromePluginServiceFilter(); |
| 74 | 97 |
| 75 // content::NotificationObserver implementation: | 98 // content::NotificationObserver implementation: |
| 76 virtual void Observe(int type, | 99 virtual void Observe(int type, |
| 77 const content::NotificationSource& source, | 100 const content::NotificationSource& source, |
| 78 const content::NotificationDetails& details) OVERRIDE; | 101 const content::NotificationDetails& details) OVERRIDE; |
| 79 | 102 |
| 103 ProcessDetails* GetOrRegisterProcess(int render_process_id); |
| 104 const ProcessDetails* GetProcess(int render_process_id) const; |
| 105 |
| 80 content::NotificationRegistrar registrar_; | 106 content::NotificationRegistrar registrar_; |
| 81 | 107 |
| 82 base::Lock lock_; // Guards access to member variables. | 108 base::Lock lock_; // Guards access to member variables. |
| 83 // Map of plugin paths to the origin they are restricted to. | 109 // Map of plugin paths to the origin they are restricted to. |
| 84 typedef std::pair<const void*, GURL> RestrictedPluginPair; | 110 typedef std::pair<const void*, GURL> RestrictedPluginPair; |
| 85 typedef base::hash_map<FilePath, RestrictedPluginPair> RestrictedPluginMap; | 111 typedef base::hash_map<FilePath, RestrictedPluginPair> RestrictedPluginMap; |
| 86 RestrictedPluginMap restricted_plugins_; | 112 RestrictedPluginMap restricted_plugins_; |
| 87 typedef std::map<const void*, scoped_refptr<PluginPrefs> > ResourceContextMap; | 113 typedef std::map<const void*, scoped_refptr<PluginPrefs> > ResourceContextMap; |
| 88 ResourceContextMap resource_context_map_; | 114 ResourceContextMap resource_context_map_; |
| 89 | 115 |
| 90 std::vector<OverriddenPlugin> overridden_plugins_; | 116 std::map<int, ProcessDetails> plugin_details_; |
| 91 }; | 117 }; |
| 92 | 118 |
| 93 #endif // CHROME_BROWSER_CHROME_PLUGIN_SERVICE_FILTER_H_ | 119 #endif // CHROME_BROWSER_CHROME_PLUGIN_SERVICE_FILTER_H_ |
| OLD | NEW |