Home | History | Annotate | Download | only in plugins
      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 
     42     ~Context();
     43 
     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,
     50                            const GURL& url,
     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,
     62                                  bool* is_default,
     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;
     67 
     68    private:
     69     int render_process_id_;
     70     content::ResourceContext* resource_context_;
     71     const HostContentSettingsMap* host_content_settings_map_;
     72     scoped_refptr<PluginPrefs> plugin_prefs_;
     73 
     74     BooleanPrefMember allow_outdated_plugins_;
     75     BooleanPrefMember always_authorize_plugins_;
     76   };
     77 
     78   PluginInfoMessageFilter(int render_process_id, Profile* profile);
     79 
     80   // content::BrowserMessageFilter methods:
     81   virtual bool OnMessageReceived(const IPC::Message& message) 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 #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
    110   // |mime_type|.
    111   void OnIsInternalPluginAvailableForMimeType(
    112       const std::string& mime_type,
    113       bool* is_available,
    114       std::vector<base::string16>* additional_param_names,
    115       std::vector<base::string16>* additional_param_values);
    116 #endif
    117 
    118   Context context_;
    119 
    120   base::WeakPtrFactory<PluginInfoMessageFilter> weak_ptr_factory_;
    121 
    122   DISALLOW_COPY_AND_ASSIGN(PluginInfoMessageFilter);
    123 };
    124 
    125 #endif  // CHROME_BROWSER_PLUGINS_PLUGIN_INFO_MESSAGE_FILTER_H_
    126