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 "chrome/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);
41 // Dummy constructor for tests.
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_view_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,
63 bool* is_default) const;
64 void MaybeGrantAccess(const ChromeViewHostMsg_GetPluginInfo_Status& status,
65 const base::FilePath& path) const;
68 int render_process_id_;
69 content::ResourceContext* resource_context_;
70 const HostContentSettingsMap* host_content_settings_map_;
71 scoped_refptr<PluginPrefs> plugin_prefs_;
73 BooleanPrefMember allow_outdated_plugins_;
74 BooleanPrefMember always_authorize_plugins_;
77 PluginInfoMessageFilter(int render_process_id, Profile* profile);
79 // content::BrowserMessageFilter methods:
80 virtual bool OnMessageReceived(const IPC::Message& message,
81 bool* message_was_ok) 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_view_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 // 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,
112 std::vector<base::string16>* additional_param_names,
113 std::vector<base::string16>* additional_param_values);
117 base::WeakPtrFactory<PluginInfoMessageFilter> weak_ptr_factory_;
119 DISALLOW_COPY_AND_ASSIGN(PluginInfoMessageFilter);
122 #endif // CHROME_BROWSER_PLUGINS_PLUGIN_INFO_MESSAGE_FILTER_H_