1 // Copyright 2016 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_UTILS_H_ 6 #define CHROME_BROWSER_PLUGINS_PLUGIN_UTILS_H_ 7 8 #include <string> 9 10 #include "base/containers/flat_map.h" 11 #include "base/macros.h" 12 #include "components/content_settings/core/common/content_settings.h" 13 14 class GURL; 15 class HostContentSettingsMap; 16 17 namespace content { 18 class BrowserContext; 19 struct WebPluginInfo; 20 } 21 22 namespace url { 23 class Origin; 24 } 25 26 class PluginUtils { 27 public: 28 // |is_default| and |is_managed| may be nullptr. In that case, they aren't 29 // set. 30 static void GetPluginContentSetting( 31 const HostContentSettingsMap* host_content_settings_map, 32 const content::WebPluginInfo& plugin, 33 const url::Origin& main_frame_origin, 34 const GURL& plugin_url, 35 const std::string& resource, 36 ContentSetting* setting, 37 bool* is_default, 38 bool* is_managed); 39 40 // Returns the content setting for Flash. This is the same as 41 // |GetPluginContentSetting| but flash-specific. 42 static ContentSetting GetFlashPluginContentSetting( 43 const HostContentSettingsMap* host_content_settings_map, 44 const url::Origin& main_frame_origin, 45 const GURL& plugin_url, 46 bool* is_managed); 47 48 // Returns the raw default content setting for Flash. This should not be used 49 // to actually run Flash, as it bypasses the origin scheme filter, legacy 50 // guardrails, and plugin-specific content settings. Hence "unsafe". 51 // It's used only for displaying Flash deprecation advisories. 52 static ContentSetting UnsafeGetRawDefaultFlashContentSetting( 53 const HostContentSettingsMap* host_content_settings_map, 54 bool* is_managed); 55 56 // If there's an extension that is allowed to handle |mime_type|, returns its 57 // ID. Otherwise returns an empty string. 58 static std::string GetExtensionIdForMimeType( 59 content::BrowserContext* browser_context, 60 const std::string& mime_type); 61 62 // Returns a map populated with MIME types that are handled by an extension as 63 // keys and the corresponding extensions Ids as values. 64 static base::flat_map<std::string, std::string> GetMimeTypeToExtensionIdMap( 65 content::BrowserContext* browser_context); 66 67 private: 68 DISALLOW_IMPLICIT_CONSTRUCTORS(PluginUtils); 69 }; 70 71 #endif // CHROME_BROWSER_PLUGINS_PLUGIN_UTILS_H_ 72