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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_PLUGINS_PLUGIN_INFO_MESSAGE_FILTER_H_ 6 #define CHROME_BROWSER_PLUGINS_PLUGIN_INFO_MESSAGE_FILTER_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "base/compiler_specific.h" 12 #include "base/memory/ref_counted.h" 13 #include "base/memory/weak_ptr.h" 14 #include "base/prefs/pref_member.h" 15 #include "base/sequenced_task_runner_helpers.h" 16 #include "chrome/browser/plugins/plugin_prefs.h" 17 #include "components/content_settings/core/common/content_settings.h" 18 #include "content/public/browser/browser_message_filter.h" 19 20 struct ChromeViewHostMsg_GetPluginInfo_Output; 21 struct ChromeViewHostMsg_GetPluginInfo_Status; 22 class GURL; 23 class HostContentSettingsMap; 24 class PluginFinder; 25 class PluginMetadata; 26 class Profile; 27 28 namespace content { 29 class ResourceContext; 30 struct WebPluginInfo; 31 } 32 33 // This class filters out incoming IPC messages requesting plug-in information. 34 class PluginInfoMessageFilter : public content::BrowserMessageFilter { 35 public: 36 struct GetPluginInfo_Params; 37 38 // Contains all the information needed by the PluginInfoMessageFilter. 39 class Context { 40 public: 41 Context(int render_process_id, Profile* profile); 42 43 ~Context(); 44 45 void DecidePluginStatus( 46 const GetPluginInfo_Params& params, 47 const content::WebPluginInfo& plugin, 48 const PluginMetadata* plugin_metadata, 49 ChromeViewHostMsg_GetPluginInfo_Status* status) const; 50 bool FindEnabledPlugin(int render_frame_id, 51 const GURL& url, 52 const GURL& top_origin_url, 53 const std::string& mime_type, 54 ChromeViewHostMsg_GetPluginInfo_Status* status, 55 content::WebPluginInfo* plugin, 56 std::string* actual_mime_type, 57 scoped_ptr<PluginMetadata>* plugin_metadata) const; 58 void GetPluginContentSetting(const content::WebPluginInfo& plugin, 59 const GURL& policy_url, 60 const GURL& plugin_url, 61 const std::string& resource, 62 ContentSetting* setting, 63 bool* is_default, 64 bool* is_managed) const; 65 void MaybeGrantAccess(const ChromeViewHostMsg_GetPluginInfo_Status& status, 66 const base::FilePath& path) const; 67 bool IsPluginEnabled(const content::WebPluginInfo& plugin) const; 68 69 private: 70 int render_process_id_; 71 content::ResourceContext* resource_context_; 72 const HostContentSettingsMap* host_content_settings_map_; 73 scoped_refptr<PluginPrefs> plugin_prefs_; 74 75 BooleanPrefMember allow_outdated_plugins_; 76 BooleanPrefMember always_authorize_plugins_; 77 }; 78 79 PluginInfoMessageFilter(int render_process_id, Profile* profile); 80 81 // content::BrowserMessageFilter methods: 82 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 83 virtual void OnDestruct() const OVERRIDE; 84 85 private: 86 friend struct content::BrowserThread::DeleteOnThread< 87 content::BrowserThread::UI>; 88 friend class base::DeleteHelper<PluginInfoMessageFilter>; 89 90 virtual ~PluginInfoMessageFilter(); 91 92 void OnGetPluginInfo(int render_frame_id, 93 const GURL& url, 94 const GURL& top_origin_url, 95 const std::string& mime_type, 96 IPC::Message* reply_msg); 97 98 // |params| wraps the parameters passed to |OnGetPluginInfo|, because 99 // |base::Bind| doesn't support the required arity <http://crbug.com/98542>. 100 void PluginsLoaded(const GetPluginInfo_Params& params, 101 IPC::Message* reply_msg, 102 const std::vector<content::WebPluginInfo>& plugins); 103 104 #if defined(ENABLE_PEPPER_CDMS) 105 // Returns whether any internal plugin supporting |mime_type| is registered 106 // and enabled. Does not determine whether the plugin can actually be 107 // instantiated (e.g. whether it has all its dependencies). 108 // When the returned *|is_available| is true, |additional_param_names| and 109 // |additional_param_values| contain the name-value pairs, if any, specified 110 // for the *first* non-disabled plugin found that is registered for 111 // |mime_type|. 112 void OnIsInternalPluginAvailableForMimeType( 113 const std::string& mime_type, 114 bool* is_available, 115 std::vector<base::string16>* additional_param_names, 116 std::vector<base::string16>* additional_param_values); 117 #endif 118 119 Context context_; 120 121 base::WeakPtrFactory<PluginInfoMessageFilter> weak_ptr_factory_; 122 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; 123 124 DISALLOW_COPY_AND_ASSIGN(PluginInfoMessageFilter); 125 }; 126 127 #endif // CHROME_BROWSER_PLUGINS_PLUGIN_INFO_MESSAGE_FILTER_H_ 128