<commit_before>// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "webkit/plugins/npapi/plugin_list.h"

#include <algorithm>

#include "base/command_line.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/string_split.h"
#include "base/string_util.h"
#include "base/sys_string_conversions.h"
#include "base/utf_string_conversions.h"
#include "googleurl/src/gurl.h"
#include "net/base/mime_util.h"
#include "webkit/glue/webkit_glue.h"
#include "webkit/plugins/npapi/plugin_constants_win.h"
#include "webkit/plugins/npapi/plugin_lib.h"
#include "webkit/plugins/plugin_switches.h"

namespace {

const char kApplicationOctetStream[] = "application/octet-stream";

base::LazyInstance<webkit::npapi::PluginList> g_singleton =
    LAZY_INSTANCE_INITIALIZER;

bool AllowMimeTypeMismatch(const std::string& orig_mime_type,
                           const std::string& actual_mime_type) {
  if (orig_mime_type == actual_mime_type) {
    NOTREACHED();
    return true;
  }

  // We do not permit URL-sniff based plug-in MIME type overrides aside from
  // the case where the "type" was initially missing or generic
  // (application/octet-stream).
  // We collected stats to determine this approach isn't a major compat issue,
  // and we defend against content confusion attacks in various cases, such
  // as when the user doesn't have the Flash plug-in enabled.
  bool allow = orig_mime_type.empty() ||
               orig_mime_type == kApplicationOctetStream;
  LOG_IF(INFO, !allow) << "Ignoring plugin with unexpected MIME type "
                       << actual_mime_type << " (expected " << orig_mime_type
                       << ")";
  return allow;
}

}

namespace webkit {
namespace npapi {

// Some version ranges can be shared across operating systems. This should be
// done where possible to avoid duplication.
static const VersionRangeDefinition kAllVersionsVersionRange[] = {
    { "", "", "", true }
};

// This is up to date with
// http://www.adobe.com/support/security/bulletins/apsb12-03.html
// NOTE: We would like to go to the 4th component value but we cannot because
// on some platforms, such as Linux, it is not available.
static const VersionRangeDefinition kFlashVersionRange[] = {
    { "", "", "11.1.102", false }
};
// This is up to date with
// http://www.adobe.com/support/security/bulletins/apsb12-02.html
static const VersionRangeDefinition kShockwaveVersionRange[] = {
    { "",  "", "11.6.4.634", true }
};
// This is up to date with
// http://support.microsoft.com/kb/2668562
// http://technet.microsoft.com/en-us/security/Bulletin/MS12-016
static const VersionRangeDefinition kSilverlightVersionRange[] = {
    { "0", "5", "4.1.10111.0", false },
    { "5", "6", "", false },
};

// Similarly, try and share the group definition for plug-ins that are
// very consistent across OS'es.
#define kFlashDefinition { \
    "adobe-flash-player", "Flash", "Shockwave Flash", kFlashVersionRange,\
    arraysize(kFlashVersionRange), "http://get.adobe.com/flashplayer/" }

#define kShockwaveDefinition { \
    "shockwave", PluginGroup::kShockwaveGroupName, "Shockwave for Director", \
    kShockwaveVersionRange, arraysize(kShockwaveVersionRange), \
    "http://www.adobe.com/shockwave/download/" }

#define kSilverlightDefinition { \
    "silverlight", PluginGroup::kSilverlightGroupName, "Silverlight", \
    kSilverlightVersionRange, arraysize(kSilverlightVersionRange), \
    "http://www.microsoft.com/getsilverlight/" }

#define kChromePdfDefinition { \
    "google-chrome-pdf", "Chrome PDF Viewer", "Chrome PDF Viewer", \
    kAllVersionsVersionRange, arraysize(kAllVersionsVersionRange), "" }

#define kGoogleTalkDefinition { \
    "google-talk", "Google Talk NPAPI Plugin", "Google Talk NPAPI Plugin", \
    kAllVersionsVersionRange, arraysize(kAllVersionsVersionRange), ""}

#if defined(OS_MACOSX)
// Plugin Groups for Mac.
// Plugins are listed here as soon as vulnerabilities and solutions
// (new versions) are published.
static const VersionRangeDefinition kQuicktimeVersionRange[] = {
    { "", "", "7.6.6", true }
};
static const VersionRangeDefinition kJavaVersionRange[] = {
    { "0", "13.0", "12.8.0", true },  // Leopard
    { "13.0", "14.0", "13.5.0", true },  // Snow Leopard
    { "14.0", "", "14.0.3", true }  // Lion
};
static const VersionRangeDefinition kFlip4MacVersionRange[] = {
    { "", "", "2.2.1", true }
};
static const VersionRangeDefinition kDivXVersionRange[] = {
    { "", "", "", true }
};
// Note: The Adobe Reader browser plug-in is not supported in Chrome.
// Note: The Real Player plugin for mac doesn't expose a version at all.
static const PluginGroupDefinition kGroupDefinitions[] = {
  kFlashDefinition,
  { "apple-quicktime", PluginGroup::kQuickTimeGroupName, "QuickTime Plug-in",
    kQuicktimeVersionRange, arraysize(kQuicktimeVersionRange),
    "http://www.apple.com/quicktime/download/" },
  { "java-runtime-environment", PluginGroup::kJavaGroupName, "Java",
    kJavaVersionRange, arraysize(kJavaVersionRange),
    "http://support.apple.com/kb/HT1338" },
  kSilverlightDefinition,
  { "flip4mac", "Flip4Mac", "Flip4Mac", kFlip4MacVersionRange,
    arraysize(kFlip4MacVersionRange),
    "http://www.telestream.net/flip4mac-wmv/overview.htm" },
  { "divx-player", "DivX Plus Web Player", "DivX Plus Web Player",
    kDivXVersionRange, arraysize(kDivXVersionRange),
    "http://www.divx.com/en/software/divx-plus/web-player" },
  kShockwaveDefinition,
  kChromePdfDefinition,
  kGoogleTalkDefinition,
};

#elif defined(OS_WIN)
// TODO(panayiotis): We should group "RealJukebox NS Plugin" with the rest of
// the RealPlayer files.
static const VersionRangeDefinition kQuicktimeVersionRange[] = {
    { "", "", "7.6.9", true }
};
static const VersionRangeDefinition kJavaVersionRange[] = {
    { "0", "7", "6.0.310", true },  // "310" is not a typo.
    { "7", "", "10.3", true }  // JDK7u3 identifies itself as 10.3
};
// This is up to date with
// http://www.adobe.com/support/security/bulletins/apsb12-01.html
static const VersionRangeDefinition kAdobeReaderVersionRange[] = {
    { "10", "11", "10.1.2", false },
    { "0", "10", "9.5", false }
};
static const VersionRangeDefinition kDivXVersionRange[] = {
    { "", "", "1.4.3.4", true }
};
// This is up to date with
// http://service.real.com/realplayer/security/02062012_player/en/
static const VersionRangeDefinition kRealPlayerVersionRange[] = {
    { "", "", "172.16.17.32", true }
};
static const PluginGroupDefinition kGroupDefinitions[] = {
  kFlashDefinition,
  { "apple-quicktime", PluginGroup::kQuickTimeGroupName, "QuickTime Plug-in",
    kQuicktimeVersionRange, arraysize(kQuicktimeVersionRange),
    "http://www.apple.com/quicktime/download/" },
  { "java-runtime-environment", PluginGroup::kJavaGroupName, "Java",
    kJavaVersionRange, arraysize(kJavaVersionRange),
    "http://www.java.com/download" },
  { "adobe-reader", PluginGroup::kAdobeReaderGroupName, "Adobe Acrobat",
    kAdobeReaderVersionRange, arraysize(kAdobeReaderVersionRange),
    "http://get.adobe.com/reader/" },
  kSilverlightDefinition,
  kShockwaveDefinition,
  { "divx-player", "DivX Player", "DivX Web Player", kDivXVersionRange,
    arraysize(kDivXVersionRange),
    "http://download.divx.com/divx/autoupdate/player/"
    "DivXWebPlayerInstaller.exe" },
  { "realplayer", PluginGroup::kRealPlayerGroupName, "RealPlayer",
    kRealPlayerVersionRange, arraysize(kRealPlayerVersionRange),
    "http://www.real.com/realplayer/download" },
  // These are here for grouping, no vulnerabilities known.
  { "windows-media-player", PluginGroup::kWindowsMediaPlayerGroupName,
    "Windows Media Player", kAllVersionsVersionRange,
    arraysize(kAllVersionsVersionRange), "" },
  { "microsoft-office", "Microsoft Office", "Microsoft Office",
    NULL, 0, "" },
  { "nvidia-3d", "NVIDIA 3D", "NVIDIA 3D", kAllVersionsVersionRange,
    arraysize(kAllVersionsVersionRange), "" },
  kChromePdfDefinition,
  kGoogleTalkDefinition,
};

#elif defined(OS_CHROMEOS)
// ChromeOS generally has (autoupdated) system plug-ins and no user-installable<commit_msg>Don't infobar pdf viewer and google talk plugin.<commit_after>// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "webkit/plugins/npapi/plugin_list.h"

#include <algorithm>

#include "base/command_line.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/string_split.h"
#include "base/string_util.h"
#include "base/sys_string_conversions.h"
#include "base/utf_string_conversions.h"
#include "googleurl/src/gurl.h"
#include "net/base/mime_util.h"
#include "webkit/glue/webkit_glue.h"
#include "webkit/plugins/npapi/plugin_constants_win.h"
#include "webkit/plugins/npapi/plugin_lib.h"
#include "webkit/plugins/plugin_switches.h"

namespace {

const char kApplicationOctetStream[] = "application/octet-stream";

base::LazyInstance<webkit::npapi::PluginList> g_singleton =
    LAZY_INSTANCE_INITIALIZER;

bool AllowMimeTypeMismatch(const std::string& orig_mime_type,
                           const std::string& actual_mime_type) {
  if (orig_mime_type == actual_mime_type) {
    NOTREACHED();
    return true;
  }

  // We do not permit URL-sniff based plug-in MIME type overrides aside from
  // the case where the "type" was initially missing or generic
  // (application/octet-stream).
  // We collected stats to determine this approach isn't a major compat issue,
  // and we defend against content confusion attacks in various cases, such
  // as when the user doesn't have the Flash plug-in enabled.
  bool allow = orig_mime_type.empty() ||
               orig_mime_type == kApplicationOctetStream;
  LOG_IF(INFO, !allow) << "Ignoring plugin with unexpected MIME type "
                       << actual_mime_type << " (expected " << orig_mime_type
                       << ")";
  return allow;
}

}

namespace webkit {
namespace npapi {

// Some version ranges can be shared across operating systems. This should be
// done where possible to avoid duplication.
// TODO(bauerb): The |requires_authorization| flag should be part of
// PluginGroupDefinition, not VersionRangeDefinition.
static const VersionRangeDefinition kAllVersionsInfobarVersionRange[] = {
    { "", "", "", true }
};

static const VersionRangeDefinition kAllVersionsNoInfobarVersionRange[] = {
    { "", "", "", false }
};

// This is up to date with
// http://www.adobe.com/support/security/bulletins/apsb12-03.html
// NOTE: We would like to go to the 4th component value but we cannot because
// on some platforms, such as Linux, it is not available.
static const VersionRangeDefinition kFlashVersionRange[] = {
    { "", "", "11.1.102", false }
};
// This is up to date with
// http://www.adobe.com/support/security/bulletins/apsb12-02.html
static const VersionRangeDefinition kShockwaveVersionRange[] = {
    { "",  "", "11.6.4.634", true }
};
// This is up to date with
// http://support.microsoft.com/kb/2668562
// http://technet.microsoft.com/en-us/security/Bulletin/MS12-016
static const VersionRangeDefinition kSilverlightVersionRange[] = {
    { "0", "5", "4.1.10111.0", false },
    { "5", "6", "", false },
};

// Similarly, try and share the group definition for plug-ins that are
// very consistent across OS'es.
#define kFlashDefinition { \
    "adobe-flash-player", "Flash", "Shockwave Flash", kFlashVersionRange,\
    arraysize(kFlashVersionRange), "http://get.adobe.com/flashplayer/" }

#define kShockwaveDefinition { \
    "shockwave", PluginGroup::kShockwaveGroupName, "Shockwave for Director", \
    kShockwaveVersionRange, arraysize(kShockwaveVersionRange), \
    "http://www.adobe.com/shockwave/download/" }

#define kSilverlightDefinition { \
    "silverlight", PluginGroup::kSilverlightGroupName, "Silverlight", \
    kSilverlightVersionRange, arraysize(kSilverlightVersionRange), \
    "http://www.microsoft.com/getsilverlight/" }

#define kChromePdfDefinition { \
    "google-chrome-pdf", "Chrome PDF Viewer", "Chrome PDF Viewer", \
    kAllVersionsNoInfobarVersionRange, \
    arraysize(kAllVersionsNoInfobarVersionRange), "" }

#define kGoogleTalkDefinition { \
    "google-talk", "Google Talk NPAPI Plugin", "Google Talk NPAPI Plugin", \
    kAllVersionsNoInfobarVersionRange, \
    arraysize(kAllVersionsNoInfobarVersionRange), ""}

#if defined(OS_MACOSX)
// Plugin Groups for Mac.
// Plugins are listed here as soon as vulnerabilities and solutions
// (new versions) are published.
static const VersionRangeDefinition kQuicktimeVersionRange[] = {
    { "", "", "7.6.6", true }
};
static const VersionRangeDefinition kJavaVersionRange[] = {
    { "0", "13.0", "12.8.0", true },  // Leopard
    { "13.0", "14.0", "13.5.0", true },  // Snow Leopard
    { "14.0", "", "14.0.3", true }  // Lion
};
static const VersionRangeDefinition kFlip4MacVersionRange[] = {
    { "", "", "2.2.1", true }
};
static const VersionRangeDefinition kDivXVersionRange[] = {
    { "", "", "", true }
};
// Note: The Adobe Reader browser plug-in is not supported in Chrome.
// Note: The Real Player plugin for mac doesn't expose a version at all.
static const PluginGroupDefinition kGroupDefinitions[] = {
  kFlashDefinition,
  { "apple-quicktime", PluginGroup::kQuickTimeGroupName, "QuickTime Plug-in",
    kQuicktimeVersionRange, arraysize(kQuicktimeVersionRange),
    "http://www.apple.com/quicktime/download/" },
  { "java-runtime-environment", PluginGroup::kJavaGroupName, "Java",
    kJavaVersionRange, arraysize(kJavaVersionRange),
    "http://support.apple.com/kb/HT1338" },
  kSilverlightDefinition,
  { "flip4mac", "Flip4Mac", "Flip4Mac", kFlip4MacVersionRange,
    arraysize(kFlip4MacVersionRange),
    "http://www.telestream.net/flip4mac-wmv/overview.htm" },
  { "divx-player", "DivX Plus Web Player", "DivX Plus Web Player",
    kDivXVersionRange, arraysize(kDivXVersionRange),
    "http://www.divx.com/en/software/divx-plus/web-player" },
  kShockwaveDefinition,
  kChromePdfDefinition,
  kGoogleTalkDefinition,
};

#elif defined(OS_WIN)
// TODO(panayiotis): We should group "RealJukebox NS Plugin" with the rest of
// the RealPlayer files.
static const VersionRangeDefinition kQuicktimeVersionRange[] = {
    { "", "", "7.6.9", true }
};
static const VersionRangeDefinition kJavaVersionRange[] = {
    { "0", "7", "6.0.310", true },  // "310" is not a typo.
    { "7", "", "10.3", true }  // JDK7u3 identifies itself as 10.3
};
// This is up to date with
// http://www.adobe.com/support/security/bulletins/apsb12-01.html
static const VersionRangeDefinition kAdobeReaderVersionRange[] = {
    { "10", "11", "10.1.2", false },
    { "0", "10", "9.5", false }
};
static const VersionRangeDefinition kDivXVersionRange[] = {
    { "", "", "1.4.3.4", true }
};
// This is up to date with
// http://service.real.com/realplayer/security/02062012_player/en/
static const VersionRangeDefinition kRealPlayerVersionRange[] = {
    { "", "", "172.16.17.32", true }
};
static const PluginGroupDefinition kGroupDefinitions[] = {
  kFlashDefinition,
  { "apple-quicktime", PluginGroup::kQuickTimeGroupName, "QuickTime Plug-in",
    kQuicktimeVersionRange, arraysize(kQuicktimeVersionRange),
    "http://www.apple.com/quicktime/download/" },
  { "java-runtime-environment", PluginGroup::kJavaGroupName, "Java",
    kJavaVersionRange, arraysize(kJavaVersionRange),
    "http://www.java.com/download" },
  { "adobe-reader", PluginGroup::kAdobeReaderGroupName, "Adobe Acrobat",
    kAdobeReaderVersionRange, arraysize(kAdobeReaderVersionRange),
    "http://get.adobe.com/reader/" },
  kSilverlightDefinition,
  kShockwaveDefinition,
  { "divx-player", "DivX Player", "DivX Web Player", kDivXVersionRange,
    arraysize(kDivXVersionRange),
    "http://download.divx.com/divx/autoupdate/player/"
    "DivXWebPlayerInstaller.exe" },
  { "realplayer", PluginGroup::kRealPlayerGroupName, "RealPlayer",
    kRealPlayerVersionRange, arraysize(kRealPlayerVersionRange),
    "http://www.real.com/realplayer/download" },
  // These are here for grouping, no vulnerabilities known.
  { "windows-media-player", PluginGroup::kWindowsMediaPlayerGroupName,
    "Windows Media Player", kAllVersionsInfobarVersionRange,
    arraysize(kAllVersionsInfobarVersionRange), "" },
  { "microsoft-office", "Microsoft Office", "Microsoft Office",
    NULL, 0, "" },
  { "nvidia-3d", "NVIDIA 3D", "NVIDIA 3D", kAllVersionsInfobarVersionRange,
    arraysize(kAllVersionsInfobarVersionRange), "" },
  kChromePdfDefinition,
  kGoogleTalkDefinition,
};

#elif defined(OS_CHROMEOS)
// ChromeOS generally has (autoupdated) system plug-ins and no user-installable
{'fraction_non_alphanumeric': 0.1381614269522162, 'fraction_numerical': 0.018612420211179384, 'mean_word_length': 4.220803488009966, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 22, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5090774', 'n_tokens_mistral': 5577, 'n_tokens_neox': 5273, 'n_words': 1230}