blob: 8a123eb3316e1d301769772900a0dcf0a999feaa [file] [log] [blame]
droger9baf2a72015-01-22 14:44:401// Copyright 2012 The Chromium Authors. All rights reserved.
[email protected]2366a3a2012-10-02 20:41:142// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]97eddfe2013-02-12 19:16:305#include "chrome/browser/plugins/plugins_resource_service.h"
[email protected]2366a3a2012-10-02 20:41:146
droger73a60702015-08-25 08:45:207#include "base/bind.h"
[email protected]2366a3a2012-10-02 20:41:148#include "base/command_line.h"
avib896c712015-12-26 02:10:439#include "build/build_config.h"
droger73a60702015-08-25 08:45:2010#include "chrome/browser/browser_process.h"
Mark Pilgrimf6332242018-05-31 21:15:4511#include "chrome/browser/net/system_network_context_manager.h"
[email protected]2366a3a2012-10-02 20:41:1412#include "chrome/browser/plugins/plugin_finder.h"
[email protected]2366a3a2012-10-02 20:41:1413#include "chrome/common/chrome_switches.h"
14#include "chrome/common/pref_names.h"
brettwb1fc1b82016-02-02 00:19:0815#include "components/prefs/pref_registry_simple.h"
16#include "components/prefs/pref_service.h"
Clark DuVall5bf72b12018-08-31 19:53:3017#include "content/public/browser/network_service_instance.h"
Mark Pilgrimf6332242018-05-31 21:15:4518#include "services/network/public/cpp/shared_url_loader_factory.h"
[email protected]761fa4702013-07-02 15:25:1519#include "url/gurl.h"
[email protected]2366a3a2012-10-02 20:41:1420
21namespace {
Daniel Bratell9e1ad2a72018-02-01 09:25:2122constexpr net::NetworkTrafficAnnotationTag
23 kPluginResourceServiceTrafficAnnotation =
24 net::DefineNetworkTrafficAnnotation("plugins_resource_service", R"(
rhalavati24b32ef2017-04-05 10:26:5325 semantics {
26 sender: "Plugins Resource Service"
27 description:
28 "Fetches updates to the list of plugins known to Chromium. For a "
29 "given plugin, this list contains the minimum version not "
30 "containing known security vulnerabilities, and can be used to "
31 "inform the user that their plugins need to be updated."
32 trigger: "Triggered at regular intervals (once per day)."
33 data: "None"
34 destination: GOOGLE_OWNED_SERVICE
35 }
36 policy {
Ramin Halavati3b979782017-07-21 11:40:2637 cookies_allowed: NO
rhalavati24b32ef2017-04-05 10:26:5338 setting: "This feature cannot be disabled in settings."
39 policy_exception_justification:
40 "Not implemented. AllowOutdatedPlugins policy silences local "
41 "warnings, but network request to update the list of plugins are "
42 "still sent."
43 })");
44
45} // namespace
46
47namespace {
[email protected]2366a3a2012-10-02 20:41:1448
49// Delay on first fetch so we don't interfere with startup.
50const int kStartResourceFetchDelayMs = 60 * 1000;
51
52// Delay between calls to update the cache 1 day and 2 minutes in testing mode.
53const int kCacheUpdateDelayMs = 24 * 60 * 60 * 1000;
[email protected]2366a3a2012-10-02 20:41:1454
[email protected]8c3042c72012-11-24 08:38:1555const char kPluginsServerUrl[] =
Will Harris9f2b8a02017-10-27 16:31:4056 "https://www.gstatic.com/chrome/config/plugins_3/";
[email protected]2366a3a2012-10-02 20:41:1457
[email protected]2366a3a2012-10-02 20:41:1458GURL GetPluginsServerURL() {
59 std::string filename;
60#if defined(OS_WIN)
61 filename = "plugins_win.json";
bauerbecab4f52017-03-13 20:16:4162#elif defined(OS_CHROMEOS)
63 filename = "plugins_chromeos.json";
[email protected]2366a3a2012-10-02 20:41:1464#elif defined(OS_LINUX)
65 filename = "plugins_linux.json";
Avi Drissman2e458df2020-07-29 16:24:3166#elif defined(OS_MAC)
[email protected]2366a3a2012-10-02 20:41:1467 filename = "plugins_mac.json";
68#else
[email protected]97eddfe2013-02-12 19:16:3069#error Unknown platform
[email protected]2366a3a2012-10-02 20:41:1470#endif
71
mohan.reddy43ed0892015-01-06 14:25:1572 return GURL(kPluginsServerUrl + filename);
[email protected]2366a3a2012-10-02 20:41:1473}
74
75} // namespace
76
77PluginsResourceService::PluginsResourceService(PrefService* local_state)
droger73a60702015-08-25 08:45:2078 : web_resource::WebResourceService(
79 local_state,
80 GetPluginsServerURL(),
81 std::string(),
82 prefs::kPluginsResourceCacheUpdate,
83 kStartResourceFetchDelayMs,
84 kCacheUpdateDelayMs,
Mark Pilgrimf6332242018-05-31 21:15:4585 g_browser_process->system_network_context_manager()
86 ->GetSharedURLLoaderFactory(),
droger73a60702015-08-25 08:45:2087 switches::kDisableBackgroundNetworking,
Clark DuVall5bf72b12018-08-31 19:53:3088 kPluginResourceServiceTrafficAnnotation,
89 base::BindOnce(&content::GetNetworkConnectionTracker)) {}
[email protected]2366a3a2012-10-02 20:41:1490
[email protected]97eddfe2013-02-12 19:16:3091void PluginsResourceService::Init() {
92 const base::DictionaryValue* metadata =
93 prefs_->GetDictionary(prefs::kPluginsMetadata);
94 PluginFinder::GetInstance()->ReinitializePlugins(metadata);
95 StartAfterDelay();
96}
97
[email protected]2366a3a2012-10-02 20:41:1498PluginsResourceService::~PluginsResourceService() {
99}
100
101// static
[email protected]b1de2c72013-02-06 02:45:47102void PluginsResourceService::RegisterPrefs(PrefRegistrySimple* registry) {
Sylvain Defresne4363df4f2019-02-05 16:41:51103 registry->RegisterDictionaryPref(prefs::kPluginsMetadata);
[email protected]b1de2c72013-02-06 02:45:47104 registry->RegisterStringPref(prefs::kPluginsResourceCacheUpdate, "0");
[email protected]2366a3a2012-10-02 20:41:14105}
106
[email protected]cb1078de2013-12-23 20:04:22107void PluginsResourceService::Unpack(const base::DictionaryValue& parsed_json) {
[email protected]2366a3a2012-10-02 20:41:14108 prefs_->Set(prefs::kPluginsMetadata, parsed_json);
[email protected]97eddfe2013-02-12 19:16:30109 PluginFinder::GetInstance()->ReinitializePlugins(&parsed_json);
[email protected]2366a3a2012-10-02 20:41:14110}