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_HOST_IMPL_H_
6 #define CHROME_BROWSER_PLUGINS_PLUGIN_INFO_HOST_IMPL_H_
7 
8 #include <memory>
9 #include <string>
10 #include <vector>
11 
12 #include "base/compiler_specific.h"
13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/sequenced_task_runner_helpers.h"
16 #include "base/strings/string_piece.h"
17 #include "chrome/browser/plugins/plugin_metadata.h"
18 #include "chrome/browser/plugins/plugin_prefs.h"
19 #include "chrome/common/plugin.mojom.h"
20 #include "components/content_settings/core/common/content_settings.h"
21 #include "components/keyed_service/core/keyed_service_shutdown_notifier.h"
22 #include "components/prefs/pref_member.h"
23 #include "content/public/browser/browser_message_filter.h"
24 #include "content/public/browser/browser_thread.h"
25 #include "extensions/buildflags/buildflags.h"
26 #include "media/media_buildflags.h"
27 
28 class GURL;
29 class HostContentSettingsMap;
30 class Profile;
31 
32 namespace component_updater {
33 struct ComponentInfo;
34 }
35 
36 namespace content {
37 struct WebPluginInfo;
38 }  // namespace content
39 
40 namespace extensions {
41 class ExtensionRegistry;
42 }
43 
44 namespace user_prefs {
45 class PrefRegistrySyncable;
46 }
47 
48 namespace url {
49 class Origin;
50 }
51 
52 // Implements PluginInfoHost interface.
53 class PluginInfoHostImpl : public chrome::mojom::PluginInfoHost {
54  public:
55   struct GetPluginInfo_Params;
56 
57   // Contains all the information needed by the PluginInfoHostImpl.
58   class Context {
59    public:
60     Context(int render_process_id, Profile* profile);
61 
62     ~Context();
63 
render_process_id()64     int render_process_id() { return render_process_id_; }
65 
66     void DecidePluginStatus(const GURL& url,
67                             const url::Origin& main_frame_origin,
68                             const content::WebPluginInfo& plugin,
69                             PluginMetadata::SecurityStatus security_status,
70                             const std::string& plugin_identifier,
71                             chrome::mojom::PluginStatus* status) const;
72     bool FindEnabledPlugin(
73         int render_frame_id,
74         const GURL& url,
75         const url::Origin& main_frame_origin,
76         const std::string& mime_type,
77         chrome::mojom::PluginStatus* status,
78         content::WebPluginInfo* plugin,
79         std::string* actual_mime_type,
80         std::unique_ptr<PluginMetadata>* plugin_metadata) const;
81     void MaybeGrantAccess(chrome::mojom::PluginStatus status,
82                           const base::FilePath& path) const;
83     bool IsPluginEnabled(const content::WebPluginInfo& plugin) const;
84 
85     void ShutdownOnUIThread();
86 
87    private:
88     int render_process_id_;
89 #if BUILDFLAG(ENABLE_EXTENSIONS)
90     extensions::ExtensionRegistry* extension_registry_;
91 #endif
92     const HostContentSettingsMap* host_content_settings_map_;
93     scoped_refptr<PluginPrefs> plugin_prefs_;
94 
95     BooleanPrefMember allow_outdated_plugins_;
96     BooleanPrefMember run_all_flash_in_allow_mode_;
97   };
98 
99   PluginInfoHostImpl(int render_process_id, Profile* profile);
100   ~PluginInfoHostImpl() override;
101 
102   static void RegisterUserPrefs(user_prefs::PrefRegistrySyncable* registry);
103 
104  private:
105   void ShutdownOnUIThread();
106 
107   // chrome::mojom::PluginInfoHost
108   void GetPluginInfo(int32_t render_frame_id,
109                      const GURL& url,
110                      const url::Origin& origin,
111                      const std::string& mime_type,
112                      GetPluginInfoCallback callback) override;
113 
114   // |params| wraps the parameters passed to |OnGetPluginInfo|, because
115   // |base::Bind| doesn't support the required arity <http://crbug.com/98542>.
116   void PluginsLoaded(const GetPluginInfo_Params& params,
117                      GetPluginInfoCallback callback,
118                      const std::vector<content::WebPluginInfo>& plugins);
119 
120   void ComponentPluginLookupDone(
121       const GetPluginInfo_Params& params,
122       chrome::mojom::PluginInfoPtr output,
123       GetPluginInfoCallback callback,
124       std::unique_ptr<PluginMetadata> plugin_metadata,
125       std::unique_ptr<component_updater::ComponentInfo> cus_plugin_info);
126 
127   void GetPluginInfoFinish(const GetPluginInfo_Params& params,
128                            chrome::mojom::PluginInfoPtr output,
129                            GetPluginInfoCallback callback,
130                            std::unique_ptr<PluginMetadata> plugin_metadata);
131 
132   Context context_;
133   std::unique_ptr<KeyedServiceShutdownNotifier::Subscription>
134       shutdown_notifier_;
135 
136   base::WeakPtrFactory<PluginInfoHostImpl> weak_factory_{this};
137 
138   DISALLOW_COPY_AND_ASSIGN(PluginInfoHostImpl);
139 };
140 
141 #endif  // CHROME_BROWSER_PLUGINS_PLUGIN_INFO_HOST_IMPL_H_
142