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/weak_ptr.h" 13 #include "base/prefs/pref_member.h" 14 #include "base/sequenced_task_runner_helpers.h" 15 #include "chrome/browser/plugins/plugin_prefs.h" 16 #include "chrome/common/content_settings.h" 17 #include "content/public/browser/browser_message_filter.h" 18 19 struct ChromeViewHostMsg_GetPluginInfo_Output; 20 struct ChromeViewHostMsg_GetPluginInfo_Status; 21 class GURL; 22 class HostContentSettingsMap; 23 class PluginFinder; 24 class PluginMetadata; 25 class Profile; 26 27 namespace content { 28 class ResourceContext; 29 struct WebPluginInfo; 30 } 31 32 // This class filters out incoming IPC messages requesting plug-in information. 33 class PluginInfoMessageFilter : public content::BrowserMessageFilter { 34 public: 35 struct GetPluginInfo_Params; 36 37 // Contains all the information needed by the PluginInfoMessageFilter. 38 class Context { 39 public: 40 Context(int render_process_id, Profile* profile); 41 // Dummy constructor for tests. 42 Context(); 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) const; 64 void MaybeGrantAccess(const ChromeViewHostMsg_GetPluginInfo_Status& status, 65 const base::FilePath& path) const; 66 67 private: 68 int render_process_id_; 69 content::ResourceContext* resource_context_; 70 const HostContentSettingsMap* host_content_settings_map_; 71 scoped_refptr<PluginPrefs> plugin_prefs_; 72 73 BooleanPrefMember allow_outdated_plugins_; 74 BooleanPrefMember always_authorize_plugins_; 75 }; 76 77 PluginInfoMessageFilter(int render_process_id, Profile* profile); 78 79 // content::BrowserMessageFilter methods: 80 virtual bool OnMessageReceived(const IPC::Message& message, 81 bool* message_was_ok) OVERRIDE; 82 virtual void OnDestruct() const OVERRIDE; 83 84 private: 85 friend struct content::BrowserThread::DeleteOnThread< 86 content::BrowserThread::UI>; 87 friend class base::DeleteHelper<PluginInfoMessageFilter>; 88 89 virtual ~PluginInfoMessageFilter(); 90 91 void OnGetPluginInfo(int render_frame_id, 92 const GURL& url, 93 const GURL& top_origin_url, 94 const std::string& mime_type, 95 IPC::Message* reply_msg); 96 97 // |params| wraps the parameters passed to |OnGetPluginInfo|, because 98 // |base::Bind| doesn't support the required arity <http://crbug.com/98542>. 99 void PluginsLoaded(const GetPluginInfo_Params& params, 100 IPC::Message* reply_msg, 101 const std::vector<content::WebPluginInfo>& plugins); 102 103 // Returns whether any internal plugin supporting |mime_type| is registered. 104 // Does not determine whether the plugin can actually be instantiated 105 // (e.g. whether it is allowed or has all its dependencies). 106 // When the returned *|is_registered| is true, |additional_param_names| and 107 // |additional_param_values| contain the name-value pairs, if any, specified 108 // for the *first* plugin found that is registered for |mime_type|. 109 void OnIsInternalPluginRegisteredForMimeType( 110 const std::string& mime_type, 111 bool* is_registered, 112 std::vector<base::string16>* additional_param_names, 113 std::vector<base::string16>* additional_param_values); 114 115 Context context_; 116 117 base::WeakPtrFactory<PluginInfoMessageFilter> weak_ptr_factory_; 118 119 DISALLOW_COPY_AND_ASSIGN(PluginInfoMessageFilter); 120 }; 121 122 #endif // CHROME_BROWSER_PLUGINS_PLUGIN_INFO_MESSAGE_FILTER_H_ 123