OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_CHROME_PLUGIN_SERVICE_HELPER_H_ |
| 6 #define CHROME_BROWSER_CHROME_PLUGIN_SERVICE_HELPER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <vector> |
| 10 |
| 11 #include "base/hash_tables.h" |
| 12 #include "base/file_path.h" |
| 13 #include "base/memory/singleton.h" |
| 14 #include "base/synchronization/lock.h" |
| 15 #include "content/browser/plugin_service.h" |
| 16 #include "content/common/notification_observer.h" |
| 17 #include "content/common/notification_registrar.h" |
| 18 #include "googleurl/src/gurl.h" |
| 19 #include "webkit/plugins/npapi/webplugininfo.h" |
| 20 |
| 21 // This class must be created (by calling the |GetInstance| method) on the UI |
| 22 // thread, but is safe to use on any thread after that. |
| 23 class ChromePluginServiceHelper : public NotificationObserver { |
| 24 public: |
| 25 static ChromePluginServiceHelper* GetInstance(); |
| 26 |
| 27 // Overrides the plugin lookup mechanism for a given tab and object URL to use |
| 28 // a specifc plugin. |
| 29 void OverridePluginForTab(int render_process_id, |
| 30 int render_view_id, |
| 31 const GURL& url, |
| 32 const webkit::npapi::WebPluginInfo& plugin); |
| 33 |
| 34 // Finds the overridden plugin for a given tab and object URL and returns a |
| 35 // copy, or NULL if no overridden plugin was found. |
| 36 // Caller takes ownership. |
| 37 webkit::npapi::WebPluginInfo* FindOverriddenPluginForTab( |
| 38 int render_process_id, |
| 39 int render_view_id, |
| 40 const GURL& url); |
| 41 |
| 42 // Restricts the given plugin to the the scheme and host of the given url. |
| 43 // Call with an empty url to reset this. |
| 44 void RestrictPluginToUrl(const FilePath& plugin_path, const GURL& url); |
| 45 |
| 46 // Returns the URL a given plugin is restricted to, or an empty URL if it can |
| 47 // be used on all URLs. |
| 48 GURL FindRestrictedURLForPlugin(const FilePath& plugin_path); |
| 49 |
| 50 // Creates a new plugin filter. Caller takes ownership. |
| 51 // This method should only be called from the IO thread. |
| 52 PluginFilter* CreatePluginFilter( |
| 53 int render_process_id, |
| 54 int render_view_id, |
| 55 const content::ResourceContext& resource_context, |
| 56 const GURL& url, |
| 57 const GURL& policy_url); |
| 58 |
| 59 private: |
| 60 friend struct DefaultSingletonTraits<ChromePluginServiceHelper>; |
| 61 |
| 62 struct OverriddenPlugin { |
| 63 int render_process_id; |
| 64 int render_view_id; |
| 65 GURL url; |
| 66 webkit::npapi::WebPluginInfo plugin; |
| 67 }; |
| 68 |
| 69 ChromePluginServiceHelper(); |
| 70 virtual ~ChromePluginServiceHelper(); |
| 71 |
| 72 // NotificationObserver implementation: |
| 73 virtual void Observe(int type, |
| 74 const NotificationSource& source, |
| 75 const NotificationDetails& details); |
| 76 |
| 77 NotificationRegistrar registrar_; |
| 78 |
| 79 base::Lock lock_; // Guards access to member variables. |
| 80 // Map of plugin paths to the origin they are restricted to. |
| 81 typedef base::hash_map<FilePath, GURL> RestrictedPluginMap; |
| 82 RestrictedPluginMap restricted_plugins_; |
| 83 |
| 84 std::vector<OverriddenPlugin> overridden_plugins_; |
| 85 }; |
| 86 |
| 87 #endif // CHROME_BROWSER_CHROME_PLUGIN_SERVICE_HELPER_H_ |
OLD | NEW |