1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_ASH_PLUGIN_VM_PLUGIN_VM_UTIL_H_
#define CHROME_BROWSER_ASH_PLUGIN_VM_PLUGIN_VM_UTIL_H_
#include <memory>
#include <optional>
#include <string>
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/observer_list_types.h"
#include "chromeos/ash/components/settings/cros_settings.h"
#include "components/prefs/pref_change_registrar.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
namespace aura {
class Window;
} // namespace aura
class Profile;
class GURL;
namespace plugin_vm {
class PluginVmAvailabilitySubscription;
// Name of the pita DLC.
extern const char kPitaDlc[];
// This is used by both the Plugin VM app and its installer.
// Generated as crx_file::id_util::GenerateId("org.chromium.plugin_vm");
extern const char kPluginVmShelfAppId[];
// Name of the Plugin VM.
extern const char kPluginVmName[];
// Base directory for shared paths in Plugin VM, formatted for display.
extern const char kChromeOSBaseDirectoryDisplayText[];
inline constexpr net::NetworkTrafficAnnotationTag
kPluginVmNetworkTrafficAnnotation =
net::DefineNetworkTrafficAnnotation("plugin_vm_image_download", R"(
semantics {
sender: "Plugin VM image manager"
description: "Request to download Plugin VM image is sent in order "
"to allow user to run Plugin VM."
trigger: "User clicking on Plugin VM icon when Plugin VM is not yet "
"installed."
data: "Request to download Plugin VM image. Sends cookies to "
"authenticate the user."
destination: WEBSITE
}
policy {
cookies_allowed: YES
cookies_store: "user"
chrome_policy {
PluginVmImage {
PluginVmImage: "{'url': 'example.com', 'hash': 'sha256hash'}"
}
}
}
)");
// Determines if the default Plugin VM is running and visible.
bool IsPluginVmRunning(Profile* profile);
void ShowPluginVmInstallerView(Profile* profile);
// Checks if an window is for the Plugin VM app. Note that it returns false for
// the Plugin VM installer.
bool IsPluginVmAppWindow(const aura::Window* window);
// Retrieves the User Id to be used for Plugin VM. If none is set this will
// return an empty string.
std::string GetPluginVmUserIdForProfile(const Profile* profile);
// Sets fake policy values and enables Plugin VM for tast tests. Device license
// keys are no longer supported in policy, but for testing purposes this key
// will still be used by the PluginVmService. This function also makes the
// installer skip its license check.
// This sets global state, not per-profile state.
// TODO(crbug.com/40107731): Set policy directly from tast instead of using a
// test helper function.
void SetFakePluginVmPolicy(Profile* profile,
const std::string& image_path,
const std::string& image_hash,
const std::string& license_key);
bool FakeLicenseKeyIsSet();
std::string GetFakeLicenseKey();
// Used to clean up the Plugin VM Drive download directory if it did not get
// removed when it should have, perhaps due to a crash.
void RemoveDriveDownloadDirectoryIfExists();
// Returns nullopt if not a drive URL.
std::optional<std::string> GetIdFromDriveUrl(const GURL& url);
// Returns true if window is PluginVM.
bool IsPluginvmWindowId(const std::string& window_id);
// A subscription for changes to Plugin VM's availability. The callback is
// called whenever there are changes that would affect either
// PluginVmFeatures::Get()->IsAllowed() or IsConfigured().
class PluginVmAvailabilitySubscription {
public:
using AvailabilityChangeCallback =
base::RepeatingCallback<void(bool is_allowed, bool is_configured)>;
PluginVmAvailabilitySubscription(Profile* profile,
AvailabilityChangeCallback callback);
~PluginVmAvailabilitySubscription();
PluginVmAvailabilitySubscription(const PluginVmAvailabilitySubscription&) =
delete;
PluginVmAvailabilitySubscription& operator=(
const PluginVmAvailabilitySubscription&) = delete;
private:
void OnPolicyChanged();
void OnImageExistsChanged();
raw_ptr<Profile> profile_;
// Whether Plugin VM was previously allowed for the profile.
bool is_allowed_;
bool is_configured_;
// The user-provided callback method.
AvailabilityChangeCallback callback_;
std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
base::CallbackListSubscription device_allowed_subscription_;
base::CallbackListSubscription fake_license_subscription_;
};
} // namespace plugin_vm
#endif // CHROME_BROWSER_ASH_PLUGIN_VM_PLUGIN_VM_UTIL_H_
|