droger | 9baf2a7 | 2015-01-22 14:44:40 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors. All rights reserved. |
[email protected] | 2366a3a | 2012-10-02 20:41:14 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 97eddfe | 2013-02-12 19:16:30 | [diff] [blame] | 5 | #include "chrome/browser/plugins/plugins_resource_service.h" |
[email protected] | 2366a3a | 2012-10-02 20:41:14 | [diff] [blame] | 6 | |
droger | 73a6070 | 2015-08-25 08:45:20 | [diff] [blame] | 7 | #include "base/bind.h" |
[email protected] | 2366a3a | 2012-10-02 20:41:14 | [diff] [blame] | 8 | #include "base/command_line.h" |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 9 | #include "build/build_config.h" |
droger | 73a6070 | 2015-08-25 08:45:20 | [diff] [blame] | 10 | #include "chrome/browser/browser_process.h" |
Mark Pilgrim | f633224 | 2018-05-31 21:15:45 | [diff] [blame] | 11 | #include "chrome/browser/net/system_network_context_manager.h" |
[email protected] | 2366a3a | 2012-10-02 20:41:14 | [diff] [blame] | 12 | #include "chrome/browser/plugins/plugin_finder.h" |
[email protected] | 2366a3a | 2012-10-02 20:41:14 | [diff] [blame] | 13 | #include "chrome/common/chrome_switches.h" |
| 14 | #include "chrome/common/pref_names.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 15 | #include "components/prefs/pref_registry_simple.h" |
| 16 | #include "components/prefs/pref_service.h" |
Clark DuVall | 5bf72b1 | 2018-08-31 19:53:30 | [diff] [blame] | 17 | #include "content/public/browser/network_service_instance.h" |
Mark Pilgrim | f633224 | 2018-05-31 21:15:45 | [diff] [blame] | 18 | #include "services/network/public/cpp/shared_url_loader_factory.h" |
[email protected] | 761fa470 | 2013-07-02 15:25:15 | [diff] [blame] | 19 | #include "url/gurl.h" |
[email protected] | 2366a3a | 2012-10-02 20:41:14 | [diff] [blame] | 20 | |
| 21 | namespace { |
Daniel Bratell | 9e1ad2a7 | 2018-02-01 09:25:21 | [diff] [blame] | 22 | constexpr net::NetworkTrafficAnnotationTag |
| 23 | kPluginResourceServiceTrafficAnnotation = |
| 24 | net::DefineNetworkTrafficAnnotation("plugins_resource_service", R"( |
rhalavati | 24b32ef | 2017-04-05 10:26:53 | [diff] [blame] | 25 | 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 Halavati | 3b97978 | 2017-07-21 11:40:26 | [diff] [blame] | 37 | cookies_allowed: NO |
rhalavati | 24b32ef | 2017-04-05 10:26:53 | [diff] [blame] | 38 | 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 | |
| 47 | namespace { |
[email protected] | 2366a3a | 2012-10-02 20:41:14 | [diff] [blame] | 48 | |
| 49 | // Delay on first fetch so we don't interfere with startup. |
| 50 | const int kStartResourceFetchDelayMs = 60 * 1000; |
| 51 | |
| 52 | // Delay between calls to update the cache 1 day and 2 minutes in testing mode. |
| 53 | const int kCacheUpdateDelayMs = 24 * 60 * 60 * 1000; |
[email protected] | 2366a3a | 2012-10-02 20:41:14 | [diff] [blame] | 54 | |
[email protected] | 8c3042c7 | 2012-11-24 08:38:15 | [diff] [blame] | 55 | const char kPluginsServerUrl[] = |
Will Harris | 9f2b8a0 | 2017-10-27 16:31:40 | [diff] [blame] | 56 | "https://www.gstatic.com/chrome/config/plugins_3/"; |
[email protected] | 2366a3a | 2012-10-02 20:41:14 | [diff] [blame] | 57 | |
[email protected] | 2366a3a | 2012-10-02 20:41:14 | [diff] [blame] | 58 | GURL GetPluginsServerURL() { |
| 59 | std::string filename; |
| 60 | #if defined(OS_WIN) |
| 61 | filename = "plugins_win.json"; |
bauerb | ecab4f5 | 2017-03-13 20:16:41 | [diff] [blame] | 62 | #elif defined(OS_CHROMEOS) |
| 63 | filename = "plugins_chromeos.json"; |
[email protected] | 2366a3a | 2012-10-02 20:41:14 | [diff] [blame] | 64 | #elif defined(OS_LINUX) |
| 65 | filename = "plugins_linux.json"; |
Avi Drissman | 2e458df | 2020-07-29 16:24:31 | [diff] [blame] | 66 | #elif defined(OS_MAC) |
[email protected] | 2366a3a | 2012-10-02 20:41:14 | [diff] [blame] | 67 | filename = "plugins_mac.json"; |
| 68 | #else |
[email protected] | 97eddfe | 2013-02-12 19:16:30 | [diff] [blame] | 69 | #error Unknown platform |
[email protected] | 2366a3a | 2012-10-02 20:41:14 | [diff] [blame] | 70 | #endif |
| 71 | |
mohan.reddy | 43ed089 | 2015-01-06 14:25:15 | [diff] [blame] | 72 | return GURL(kPluginsServerUrl + filename); |
[email protected] | 2366a3a | 2012-10-02 20:41:14 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | } // namespace |
| 76 | |
| 77 | PluginsResourceService::PluginsResourceService(PrefService* local_state) |
droger | 73a6070 | 2015-08-25 08:45:20 | [diff] [blame] | 78 | : web_resource::WebResourceService( |
| 79 | local_state, |
| 80 | GetPluginsServerURL(), |
| 81 | std::string(), |
| 82 | prefs::kPluginsResourceCacheUpdate, |
| 83 | kStartResourceFetchDelayMs, |
| 84 | kCacheUpdateDelayMs, |
Mark Pilgrim | f633224 | 2018-05-31 21:15:45 | [diff] [blame] | 85 | g_browser_process->system_network_context_manager() |
| 86 | ->GetSharedURLLoaderFactory(), |
droger | 73a6070 | 2015-08-25 08:45:20 | [diff] [blame] | 87 | switches::kDisableBackgroundNetworking, |
Clark DuVall | 5bf72b1 | 2018-08-31 19:53:30 | [diff] [blame] | 88 | kPluginResourceServiceTrafficAnnotation, |
| 89 | base::BindOnce(&content::GetNetworkConnectionTracker)) {} |
[email protected] | 2366a3a | 2012-10-02 20:41:14 | [diff] [blame] | 90 | |
[email protected] | 97eddfe | 2013-02-12 19:16:30 | [diff] [blame] | 91 | void PluginsResourceService::Init() { |
| 92 | const base::DictionaryValue* metadata = |
| 93 | prefs_->GetDictionary(prefs::kPluginsMetadata); |
| 94 | PluginFinder::GetInstance()->ReinitializePlugins(metadata); |
| 95 | StartAfterDelay(); |
| 96 | } |
| 97 | |
[email protected] | 2366a3a | 2012-10-02 20:41:14 | [diff] [blame] | 98 | PluginsResourceService::~PluginsResourceService() { |
| 99 | } |
| 100 | |
| 101 | // static |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 102 | void PluginsResourceService::RegisterPrefs(PrefRegistrySimple* registry) { |
Sylvain Defresne | 4363df4f | 2019-02-05 16:41:51 | [diff] [blame] | 103 | registry->RegisterDictionaryPref(prefs::kPluginsMetadata); |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 104 | registry->RegisterStringPref(prefs::kPluginsResourceCacheUpdate, "0"); |
[email protected] | 2366a3a | 2012-10-02 20:41:14 | [diff] [blame] | 105 | } |
| 106 | |
[email protected] | cb1078de | 2013-12-23 20:04:22 | [diff] [blame] | 107 | void PluginsResourceService::Unpack(const base::DictionaryValue& parsed_json) { |
[email protected] | 2366a3a | 2012-10-02 20:41:14 | [diff] [blame] | 108 | prefs_->Set(prefs::kPluginsMetadata, parsed_json); |
[email protected] | 97eddfe | 2013-02-12 19:16:30 | [diff] [blame] | 109 | PluginFinder::GetInstance()->ReinitializePlugins(&parsed_json); |
[email protected] | 2366a3a | 2012-10-02 20:41:14 | [diff] [blame] | 110 | } |