15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/plugins/plugin_info_message_filter.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/bind.h"
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/metrics/histogram.h"
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/prefs/pref_service.h"
11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h"
12e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch#include "base/thread_task_runner_handle.h"
13e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch#include "chrome/browser/browser_process.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/content_settings/content_settings_utils.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/content_settings/host_content_settings_map.h"
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/plugins/chrome_plugin_service_filter.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/plugins/plugin_finder.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/plugins/plugin_metadata.h"
194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/plugins/plugin_prefs.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/profiles/profile.h"
21e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch#include "chrome/browser/ui/browser_otr_state.h"
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/pref_names.h"
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/render_messages.h"
241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "components/content_settings/core/common/content_settings.h"
25e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch#include "components/rappor/rappor_service.h"
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/browser_thread.h"
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/plugin_service.h"
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/plugin_service_filter.h"
29e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch#include "content/public/common/content_constants.h"
30e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
31eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "url/gurl.h"
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "widevine_cdm_version.h"  // In SHARED_INTERMEDIATE_DIR.
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
35116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#if defined(ENABLE_EXTENSIONS)
361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
37116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#endif
38116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN)
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/win/metro.h"
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#if !defined(DISABLE_NACL)
4403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "components/nacl/common/nacl_constants.h"
4503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#endif
4603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::PluginService;
48ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdochusing content::WebPluginInfo;
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace {
512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// For certain sandboxed Pepper plugins, use the JavaScript Content Settings.
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool ShouldUseJavaScriptSettingForPlugin(const WebPluginInfo& plugin) {
542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (plugin.type != WebPluginInfo::PLUGIN_TYPE_PEPPER_IN_PROCESS &&
552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      plugin.type != WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS) {
562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return false;
572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#if !defined(DISABLE_NACL)
602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Treat Native Client invocations like JavaScript.
6103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  if (plugin.name == base::ASCIIToUTF16(nacl::kNaClPluginName))
622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return true;
6303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#endif
642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
65eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#if defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS)
662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Treat CDM invocations like JavaScript.
675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (plugin.name == base::ASCIIToUTF16(kWidevineCdmDisplayName)) {
682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    DCHECK(plugin.type == WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS);
692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return true;
702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
71eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#endif  // defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS)
722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return false;
742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#if defined(ENABLE_PEPPER_CDMS)
775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)enum PluginAvailabilityStatusForUMA {
795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  PLUGIN_NOT_REGISTERED,
805f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  PLUGIN_AVAILABLE,
815f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  PLUGIN_DISABLED,
825f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  PLUGIN_AVAILABILITY_STATUS_MAX
835f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)};
845f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
855f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)static void SendPluginAvailabilityUMA(const std::string& mime_type,
865f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                      PluginAvailabilityStatusForUMA status) {
875f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#if defined(WIDEVINE_CDM_AVAILABLE)
885f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Only report results for Widevine CDM.
895f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  if (mime_type != kWidevineCdmPluginMimeType)
905f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    return;
915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
925f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  UMA_HISTOGRAM_ENUMERATION("Plugin.AvailabilityStatus.WidevineCdm",
935f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                            status, PLUGIN_AVAILABILITY_STATUS_MAX);
945f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#endif  // defined(WIDEVINE_CDM_AVAILABLE)
955f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)}
965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
975f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#endif  // defined(ENABLE_PEPPER_CDMS)
985f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
99e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch// Report usage metrics for Silverlight and Flash plugin instantiations to the
100e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch// RAPPOR service.
101e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdochvoid ReportMetrics(const std::string& mime_type,
102e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch                   const GURL& url,
103e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch                   const GURL& origin_url) {
104e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch  DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
105e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch
106e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch  if (chrome::IsOffTheRecordSessionActive())
107e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch    return;
108e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch  rappor::RapporService* rappor_service = g_browser_process->rappor_service();
109e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch  if (!rappor_service)
110e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch    return;
111e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch
112e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch  if (StartsWithASCII(mime_type, content::kSilverlightPluginMimeTypePrefix,
113e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch                      false)) {
114e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch    rappor_service->RecordSample(
115e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch        "Plugins.SilverlightOriginUrl", rappor::ETLD_PLUS_ONE_RAPPOR_TYPE,
116e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch        net::registry_controlled_domains::GetDomainAndRegistry(
117e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch            origin_url,
118e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch            net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES));
119e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch  } else if (mime_type == content::kFlashPluginSwfMimeType ||
120e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch             mime_type == content::kFlashPluginSplMimeType) {
121e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch    rappor_service->RecordSample(
122e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch        "Plugins.FlashOriginUrl", rappor::ETLD_PLUS_ONE_RAPPOR_TYPE,
123e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch        net::registry_controlled_domains::GetDomainAndRegistry(
124e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch            origin_url,
125e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch            net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES));
126e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch    rappor_service->RecordSample(
127e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch        "Plugins.FlashUrl", rappor::ETLD_PLUS_ONE_RAPPOR_TYPE,
128e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch        net::registry_controlled_domains::GetDomainAndRegistry(
129e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch            url,
130e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch            net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES));
131e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch  }
132e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch}
133e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch
1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace
1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)PluginInfoMessageFilter::Context::Context(int render_process_id,
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                          Profile* profile)
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : render_process_id_(render_process_id),
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      resource_context_(profile->GetResourceContext()),
1404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      host_content_settings_map_(profile->GetHostContentSettingsMap()),
1414e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      plugin_prefs_(PluginPrefs::GetForProfile(profile)) {
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  allow_outdated_plugins_.Init(prefs::kPluginsAllowOutdated,
1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                               profile->GetPrefs());
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  allow_outdated_plugins_.MoveToThread(
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      content::BrowserThread::GetMessageLoopProxyForThread(
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          content::BrowserThread::IO));
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  always_authorize_plugins_.Init(prefs::kPluginsAlwaysAuthorize,
1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                 profile->GetPrefs());
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  always_authorize_plugins_.MoveToThread(
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      content::BrowserThread::GetMessageLoopProxyForThread(
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          content::BrowserThread::IO));
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)PluginInfoMessageFilter::Context::~Context() {
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
157e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben MurdochPluginInfoMessageFilter::PluginInfoMessageFilter(int render_process_id,
158e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch                                                 Profile* profile)
1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    : BrowserMessageFilter(ChromeMsgStart),
1605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      context_(render_process_id, profile),
161e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch      weak_ptr_factory_(this),
162e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch      main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()) {
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
165cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)bool PluginInfoMessageFilter::OnMessageReceived(const IPC::Message& message) {
166cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  IPC_BEGIN_MESSAGE_MAP(PluginInfoMessageFilter, message)
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    IPC_MESSAGE_HANDLER_DELAY_REPLY(ChromeViewHostMsg_GetPluginInfo,
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    OnGetPluginInfo)
169116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#if defined(ENABLE_PEPPER_CDMS)
170d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    IPC_MESSAGE_HANDLER(
1715f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        ChromeViewHostMsg_IsInternalPluginAvailableForMimeType,
1725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        OnIsInternalPluginAvailableForMimeType)
173116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#endif
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    IPC_MESSAGE_UNHANDLED(return false)
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  IPC_END_MESSAGE_MAP()
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void PluginInfoMessageFilter::OnDestruct() const {
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const_cast<PluginInfoMessageFilter*>(this)->
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      weak_ptr_factory_.InvalidateWeakPtrs();
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Destroy on the UI thread because we contain a |PrefMember|.
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::BrowserThread::DeleteOnUIThread::Destruct(this);
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)PluginInfoMessageFilter::~PluginInfoMessageFilter() {}
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct PluginInfoMessageFilter::GetPluginInfo_Params {
190a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  int render_frame_id;
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL url;
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL top_origin_url;
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string mime_type;
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void PluginInfoMessageFilter::OnGetPluginInfo(
197a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    int render_frame_id,
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const GURL& url,
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const GURL& top_origin_url,
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const std::string& mime_type,
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    IPC::Message* reply_msg) {
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GetPluginInfo_Params params = {
203a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    render_frame_id,
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    url,
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    top_origin_url,
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    mime_type
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  PluginService::GetInstance()->GetPlugins(
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::Bind(&PluginInfoMessageFilter::PluginsLoaded,
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                 weak_ptr_factory_.GetWeakPtr(),
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                 params, reply_msg));
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void PluginInfoMessageFilter::PluginsLoaded(
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const GetPluginInfo_Params& params,
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    IPC::Message* reply_msg,
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const std::vector<WebPluginInfo>& plugins) {
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ChromeViewHostMsg_GetPluginInfo_Output output;
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This also fills in |actual_mime_type|.
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<PluginMetadata> plugin_metadata;
221a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (context_.FindEnabledPlugin(params.render_frame_id, params.url,
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 params.top_origin_url, params.mime_type,
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 &output.status, &output.plugin,
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 &output.actual_mime_type,
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 &plugin_metadata)) {
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    context_.DecidePluginStatus(params, output.plugin, plugin_metadata.get(),
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                &output.status);
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (plugin_metadata) {
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    output.group_identifier = plugin_metadata->identifier();
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    output.group_name = plugin_metadata->name();
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  context_.MaybeGrantAccess(output.status, output.plugin.path);
2362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ChromeViewHostMsg_GetPluginInfo::WriteReplyParams(reply_msg, output);
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Send(reply_msg);
239e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch  if (output.status.value !=
240e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch      ChromeViewHostMsg_GetPluginInfo_Status::kNotFound) {
241e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch    main_thread_task_runner_->PostTask(
242e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch        FROM_HERE, base::Bind(&ReportMetrics, output.actual_mime_type,
243e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch                              params.url, params.top_origin_url));
244e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch  }
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
247116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#if defined(ENABLE_PEPPER_CDMS)
2485f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)void PluginInfoMessageFilter::OnIsInternalPluginAvailableForMimeType(
250d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    const std::string& mime_type,
2515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    bool* is_available,
2521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    std::vector<base::string16>* additional_param_names,
2531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    std::vector<base::string16>* additional_param_values) {
2541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  std::vector<WebPluginInfo> plugins;
2551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  PluginService::GetInstance()->GetInternalPlugins(&plugins);
2565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  bool is_plugin_disabled = false;
2581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  for (size_t i = 0; i < plugins.size(); ++i) {
2595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    const WebPluginInfo& plugin = plugins[i];
2601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    const std::vector<content::WebPluginMimeType>& mime_types =
2615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        plugin.mime_types;
2621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    for (size_t j = 0; j < mime_types.size(); ++j) {
2631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      if (mime_types[j].mime_type == mime_type) {
2645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        if (!context_.IsPluginEnabled(plugin)) {
2655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)          is_plugin_disabled = true;
2665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)          break;
2675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        }
2685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        *is_available = true;
2701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        *additional_param_names = mime_types[j].additional_param_names;
2711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        *additional_param_values = mime_types[j].additional_param_values;
2725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        SendPluginAvailabilityUMA(mime_type, PLUGIN_AVAILABLE);
2731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        return;
2741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      }
2751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    }
2761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
2771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  *is_available = false;
2795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  SendPluginAvailabilityUMA(
2805f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      mime_type, is_plugin_disabled ? PLUGIN_DISABLED : PLUGIN_NOT_REGISTERED);
281d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
2825f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2835f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#endif // defined(ENABLE_PEPPER_CDMS)
284d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void PluginInfoMessageFilter::Context::DecidePluginStatus(
2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const GetPluginInfo_Params& params,
2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const WebPluginInfo& plugin,
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const PluginMetadata* plugin_metadata,
2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ChromeViewHostMsg_GetPluginInfo_Status* status) const {
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN)
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (plugin.type == WebPluginInfo::PLUGIN_TYPE_NPAPI &&
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::win::IsMetroProcess()) {
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    status->value =
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        ChromeViewHostMsg_GetPluginInfo_Status::kNPAPINotSupported;
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
2984e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  if (plugin.type == WebPluginInfo::PLUGIN_TYPE_NPAPI) {
2994e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
3004e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    // NPAPI plugins are not supported inside <webview> guests.
301116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#if defined(ENABLE_EXTENSIONS)
3026e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    if (extensions::WebViewRendererState::GetInstance()->IsGuest(
3036e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)        render_process_id_)) {
3044e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      status->value =
3054e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)          ChromeViewHostMsg_GetPluginInfo_Status::kNPAPINotSupported;
3064e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      return;
3074e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    }
308116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#endif
3094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  }
3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ContentSetting plugin_setting = CONTENT_SETTING_DEFAULT;
3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool uses_default_content_setting = true;
3135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool is_managed = false;
3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Check plug-in content settings. The primary URL is the top origin URL and
3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the secondary URL is the plug-in URL.
3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GetPluginContentSetting(plugin, params.top_origin_url, params.url,
3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          plugin_metadata->identifier(), &plugin_setting,
3185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                          &uses_default_content_setting, &is_managed);
3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(plugin_setting != CONTENT_SETTING_DEFAULT);
3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  PluginMetadata::SecurityStatus plugin_status =
3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      plugin_metadata->GetSecurityStatus(plugin);
3232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(ENABLE_PLUGIN_INSTALLATION)
3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Check if the plug-in is outdated.
3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (plugin_status == PluginMetadata::SECURITY_STATUS_OUT_OF_DATE &&
3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      !allow_outdated_plugins_.GetValue()) {
3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (allow_outdated_plugins_.IsManaged()) {
3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      status->value =
3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedDisallowed;
3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    } else {
3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      status->value = ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedBlocked;
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
3364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Check if the plug-in or its group is enabled by policy.
3374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  PluginPrefs::PolicyStatus plugin_policy =
3384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      plugin_prefs_->PolicyStatusForPlugin(plugin.name);
3394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  PluginPrefs::PolicyStatus group_policy =
3404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      plugin_prefs_->PolicyStatusForPlugin(plugin_metadata->name());
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Check if the plug-in requires authorization.
3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (plugin_status ==
3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          PluginMetadata::SECURITY_STATUS_REQUIRES_AUTHORIZATION &&
3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      plugin.type != WebPluginInfo::PLUGIN_TYPE_PEPPER_IN_PROCESS &&
3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      plugin.type != WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS &&
3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      !always_authorize_plugins_.GetValue() &&
3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      plugin_setting != CONTENT_SETTING_BLOCK &&
3494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      uses_default_content_setting &&
3504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      plugin_policy != PluginPrefs::POLICY_ENABLED &&
3518bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      group_policy != PluginPrefs::POLICY_ENABLED &&
3528bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      !ChromePluginServiceFilter::GetInstance()->IsPluginRestricted(
3538bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)          plugin.path)) {
354f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    status->value = ChromeViewHostMsg_GetPluginInfo_Status::kUnauthorized;
3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Check if the plug-in is crashing too much.
3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (PluginService::GetInstance()->IsPluginUnstable(plugin.path) &&
3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      !always_authorize_plugins_.GetValue() &&
3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      plugin_setting != CONTENT_SETTING_BLOCK &&
3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      uses_default_content_setting) {
3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    status->value = ChromeViewHostMsg_GetPluginInfo_Status::kUnauthorized;
3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (plugin_setting == CONTENT_SETTING_ASK) {
3685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      status->value = ChromeViewHostMsg_GetPluginInfo_Status::kClickToPlay;
3695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  } else if (plugin_setting == CONTENT_SETTING_BLOCK) {
3705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    status->value =
3715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        is_managed ? ChromeViewHostMsg_GetPluginInfo_Status::kBlockedByPolicy
3725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                   : ChromeViewHostMsg_GetPluginInfo_Status::kBlocked;
3735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
3744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
3754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  if (status->value == ChromeViewHostMsg_GetPluginInfo_Status::kAllowed) {
3764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    // Allow an embedder of <webview> to block a plugin from being loaded inside
3774e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    // the guest. In order to do this, set the status to 'Unauthorized' here,
3784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    // and update the status as appropriate depending on the response from the
3794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    // embedder.
380116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#if defined(ENABLE_EXTENSIONS)
3816e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    if (extensions::WebViewRendererState::GetInstance()->IsGuest(
3826e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)        render_process_id_))
383a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      status->value = ChromeViewHostMsg_GetPluginInfo_Status::kUnauthorized;
384116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
385116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#endif
3864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  }
3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool PluginInfoMessageFilter::Context::FindEnabledPlugin(
390a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    int render_frame_id,
3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const GURL& url,
3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const GURL& top_origin_url,
3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const std::string& mime_type,
3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ChromeViewHostMsg_GetPluginInfo_Status* status,
3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    WebPluginInfo* plugin,
3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    std::string* actual_mime_type,
3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    scoped_ptr<PluginMetadata>* plugin_metadata) const {
3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool allow_wildcard = true;
3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::vector<WebPluginInfo> matching_plugins;
4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::vector<std::string> mime_types;
4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  PluginService::GetInstance()->GetPluginInfoArray(
4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      url, mime_type, allow_wildcard, &matching_plugins, &mime_types);
4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (matching_plugins.empty()) {
4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    status->value = ChromeViewHostMsg_GetPluginInfo_Status::kNotFound;
4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return false;
4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::PluginServiceFilter* filter =
4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      PluginService::GetInstance()->GetFilter();
4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  size_t i = 0;
4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (; i < matching_plugins.size(); ++i) {
4122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    if (!filter || filter->IsPluginAvailable(render_process_id_,
413a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                             render_frame_id,
4142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                             resource_context_,
4152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                             url,
4162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                             top_origin_url,
4172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                             &matching_plugins[i])) {
4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      break;
4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If we broke out of the loop, we have found an enabled plug-in.
4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool enabled = i < matching_plugins.size();
4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!enabled) {
4255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Otherwise, we only found disabled plug-ins, so we take the first one.
4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    i = 0;
4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    status->value = ChromeViewHostMsg_GetPluginInfo_Status::kDisabled;
4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  *plugin = matching_plugins[i];
4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  *actual_mime_type = mime_types[i];
4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (plugin_metadata)
4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    *plugin_metadata = PluginFinder::GetInstance()->GetPluginMetadata(*plugin);
4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return enabled;
4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void PluginInfoMessageFilter::Context::GetPluginContentSetting(
4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const WebPluginInfo& plugin,
4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const GURL& policy_url,
4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const GURL& plugin_url,
4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const std::string& resource,
4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ContentSetting* setting,
4445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    bool* uses_default_content_setting,
4455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    bool* is_managed) const {
4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<base::Value> value;
4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content_settings::SettingInfo info;
4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool uses_plugin_specific_setting = false;
4492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (ShouldUseJavaScriptSettingForPlugin(plugin)) {
4501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    value = host_content_settings_map_->GetWebsiteSetting(
4511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci        policy_url,
4521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci        policy_url,
4531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci        CONTENT_SETTINGS_TYPE_JAVASCRIPT,
4541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci        std::string(),
4551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci        &info);
4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  } else {
457cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    content_settings::SettingInfo specific_info;
4581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    scoped_ptr<base::Value> specific_setting =
4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        host_content_settings_map_->GetWebsiteSetting(
4601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci            policy_url,
4611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci            plugin_url,
4621320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci            CONTENT_SETTINGS_TYPE_PLUGINS,
4631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci            resource,
4641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci            &specific_info);
465cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    content_settings::SettingInfo general_info;
4661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    scoped_ptr<base::Value> general_setting =
467cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)        host_content_settings_map_->GetWebsiteSetting(
4681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci            policy_url,
4691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci            plugin_url,
4701320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci            CONTENT_SETTINGS_TYPE_PLUGINS,
4711320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci            std::string(),
4721320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci            &general_info);
473cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
474cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    // If there is a plugin-specific setting, we use it, unless the general
475cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    // setting was set by policy, in which case it takes precedence.
476cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    uses_plugin_specific_setting = specific_setting &&
477cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)        (general_info.source != content_settings::SETTING_SOURCE_POLICY);
478cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    if (uses_plugin_specific_setting) {
479cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      value = specific_setting.Pass();
480cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      info = specific_info;
4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    } else {
482cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      value = general_setting.Pass();
483cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      info = general_info;
4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  *setting = content_settings::ValueToContentSetting(value.get());
4875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  *uses_default_content_setting =
4885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      !uses_plugin_specific_setting &&
4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      info.primary_pattern == ContentSettingsPattern::Wildcard() &&
4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      info.secondary_pattern == ContentSettingsPattern::Wildcard();
4915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  *is_managed = info.source == content_settings::SETTING_SOURCE_POLICY;
4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void PluginInfoMessageFilter::Context::MaybeGrantAccess(
4952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const ChromeViewHostMsg_GetPluginInfo_Status& status,
4962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const base::FilePath& path) const {
4972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (status.value == ChromeViewHostMsg_GetPluginInfo_Status::kAllowed ||
4982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      status.value == ChromeViewHostMsg_GetPluginInfo_Status::kClickToPlay) {
4992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ChromePluginServiceFilter::GetInstance()->AuthorizePlugin(
5002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        render_process_id_, path);
5012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
5022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
5032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5045f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)bool PluginInfoMessageFilter::Context::IsPluginEnabled(
5055f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    const content::WebPluginInfo& plugin) const {
5065f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  return plugin_prefs_->IsPluginEnabled(plugin);
5075f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)}
508