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/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"
20 struct ChromeViewHostMsg_GetPluginInfo_Output;
21 struct ChromeViewHostMsg_GetPluginInfo_Status;
23 class HostContentSettingsMap;
29 class ResourceContext;
33 // This class filters out incoming IPC messages requesting plug-in information.
34 class PluginInfoMessageFilter : public content::BrowserMessageFilter {
36 struct GetPluginInfo_Params;
38 // Contains all the information needed by the PluginInfoMessageFilter.
41 Context(int render_process_id, Profile* profile);
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,
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,
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;
70 int render_process_id_;
71 content::ResourceContext* resource_context_;
72 const HostContentSettingsMap* host_content_settings_map_;
73 scoped_refptr<PluginPrefs> plugin_prefs_;
75 BooleanPrefMember allow_outdated_plugins_;
76 BooleanPrefMember always_authorize_plugins_;
79 PluginInfoMessageFilter(int render_process_id, Profile* profile);
81 // content::BrowserMessageFilter methods:
82 bool OnMessageReceived(const IPC::Message& message) override;
83 void OnDestruct() const override;
86 friend struct content::BrowserThread::DeleteOnThread<
87 content::BrowserThread::UI>;
88 friend class base::DeleteHelper<PluginInfoMessageFilter>;
90 ~PluginInfoMessageFilter() override;
92 void OnGetPluginInfo(int render_frame_id,
94 const GURL& top_origin_url,
95 const std::string& mime_type,
96 IPC::Message* reply_msg);
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);
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
112 void OnIsInternalPluginAvailableForMimeType(
113 const std::string& mime_type,
115 std::vector<base::string16>* additional_param_names,
116 std::vector<base::string16>* additional_param_values);
121 base::WeakPtrFactory<PluginInfoMessageFilter> weak_ptr_factory_;
122 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
124 DISALLOW_COPY_AND_ASSIGN(PluginInfoMessageFilter);
127 #endif // CHROME_BROWSER_PLUGINS_PLUGIN_INFO_MESSAGE_FILTER_H_