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.
5 #ifndef CHROME_BROWSER_PLUGINS_PLUGIN_INFO_MESSAGE_FILTER_H_
6 #define CHROME_BROWSER_PLUGINS_PLUGIN_INFO_MESSAGE_FILTER_H_
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 "components/content_settings/core/common/content_settings.h"
17 #include "content/public/browser/browser_message_filter.h"
19 struct ChromeViewHostMsg_GetPluginInfo_Output;
20 struct ChromeViewHostMsg_GetPluginInfo_Status;
22 class HostContentSettingsMap;
28 class ResourceContext;
32 // This class filters out incoming IPC messages requesting plug-in information.
33 class PluginInfoMessageFilter : public content::BrowserMessageFilter {
35 struct GetPluginInfo_Params;
37 // Contains all the information needed by the PluginInfoMessageFilter.
40 Context(int render_process_id, Profile* profile);
44 void DecidePluginStatus(
45 const GetPluginInfo_Params& params,
46 const content::WebPluginInfo& plugin,
47 const PluginMetadata* plugin_metadata,
48 ChromeViewHostMsg_GetPluginInfo_Status* status) const;
49 bool FindEnabledPlugin(int render_frame_id,
51 const GURL& top_origin_url,
52 const std::string& mime_type,
53 ChromeViewHostMsg_GetPluginInfo_Status* status,
54 content::WebPluginInfo* plugin,
55 std::string* actual_mime_type,
56 scoped_ptr<PluginMetadata>* plugin_metadata) const;
57 void GetPluginContentSetting(const content::WebPluginInfo& plugin,
58 const GURL& policy_url,
59 const GURL& plugin_url,
60 const std::string& resource,
61 ContentSetting* setting,
63 bool* is_managed) const;
64 void MaybeGrantAccess(const ChromeViewHostMsg_GetPluginInfo_Status& status,
65 const base::FilePath& path) const;
66 bool IsPluginEnabled(const content::WebPluginInfo& plugin) const;
69 int render_process_id_;
70 content::ResourceContext* resource_context_;
71 const HostContentSettingsMap* host_content_settings_map_;
72 scoped_refptr<PluginPrefs> plugin_prefs_;
74 BooleanPrefMember allow_outdated_plugins_;
75 BooleanPrefMember always_authorize_plugins_;
78 PluginInfoMessageFilter(int render_process_id, Profile* profile);
80 // content::BrowserMessageFilter methods:
81 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
82 virtual void OnDestruct() const OVERRIDE;
85 friend struct content::BrowserThread::DeleteOnThread<
86 content::BrowserThread::UI>;
87 friend class base::DeleteHelper<PluginInfoMessageFilter>;
89 virtual ~PluginInfoMessageFilter();
91 void OnGetPluginInfo(int render_frame_id,
93 const GURL& top_origin_url,
94 const std::string& mime_type,
95 IPC::Message* reply_msg);
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);
103 #if defined(ENABLE_PEPPER_CDMS)
104 // Returns whether any internal plugin supporting |mime_type| is registered
105 // and enabled. Does not determine whether the plugin can actually be
106 // instantiated (e.g. whether it has all its dependencies).
107 // When the returned *|is_available| is true, |additional_param_names| and
108 // |additional_param_values| contain the name-value pairs, if any, specified
109 // for the *first* non-disabled plugin found that is registered for
111 void OnIsInternalPluginAvailableForMimeType(
112 const std::string& mime_type,
114 std::vector<base::string16>* additional_param_names,
115 std::vector<base::string16>* additional_param_values);
120 base::WeakPtrFactory<PluginInfoMessageFilter> weak_ptr_factory_;
122 DISALLOW_COPY_AND_ASSIGN(PluginInfoMessageFilter);
125 #endif // CHROME_BROWSER_PLUGINS_PLUGIN_INFO_MESSAGE_FILTER_H_