#include "chrome/browser/apps/platform_apps/api/media_galleries/media_galleries_api.h"
#include <stddef.h>
#include <memory>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/lazy_instance.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/notreached.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/apps/platform_apps/api/deprecation_features.h"
#include "chrome/browser/apps/platform_apps/api/media_galleries/blob_data_source_factory.h"
#include "chrome/browser/apps/platform_apps/api/media_galleries/media_galleries_api_util.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/media_galleries/gallery_watch_manager.h"
#include "chrome/browser/media_galleries/media_file_system_registry.h"
#include "chrome/browser/media_galleries/media_galleries_permission_controller.h"
#include "chrome/browser/media_galleries/media_galleries_preferences.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/chrome_select_file_policy.h"
#include "chrome/common/apps/platform_apps/api/media_galleries.h"
#include "chrome/common/apps/platform_apps/media_galleries_permission.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/services/media_gallery_util/public/cpp/safe_media_metadata_parser.h"
#include "components/storage_monitor/storage_info.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "content/public/browser/blob_handle.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_security_policy.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/api/file_system/file_system_api.h"
#include "extensions/browser/app_window/app_window.h"
#include "extensions/browser/app_window/app_window_registry.h"
#include "extensions/browser/blob_reader.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
#include "extensions/common/permissions/api_permission.h"
#include "extensions/common/permissions/permissions_data.h"
#include "net/base/mime_sniffer.h"
#include "storage/browser/blob/blob_data_handle.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/shell_dialogs/select_file_dialog.h"
#include "ui/shell_dialogs/selected_file_info.h"
WebContents;
MediaStorageUtil;
StorageInfo;
namespace chrome_apps {
namespace api {
MediaGalleries;
GetMediaFileSystems;
AddGalleryWatch;
RemoveGalleryWatch;
namespace {
const char kDisallowedByPolicy[] = …;
const char kInvalidGalleryIdMsg[] = …;
const char kMissingEventListener[] = …;
const char kDeviceIdKey[] = …;
const char kGalleryIdKey[] = …;
const char kIsAvailableKey[] = …;
const char kIsMediaDeviceKey[] = …;
const char kIsRemovableKey[] = …;
const char kNameKey[] = …;
const char kMetadataKey[] = …;
const char kInvalidGalleryId[] = …;
const char kDeprecatedError[] = …;
const char kNoRenderFrameOrRenderProcessError[] = …;
const char kNoWebContentsError[] = …;
MediaFileSystemRegistry* media_file_system_registry() { … }
GalleryWatchManager* gallery_watch_manager() { … }
bool Setup(Profile* profile, std::string* error, base::OnceClosure callback) { … }
bool GetGalleryFilePathAndId(const std::string& gallery_id,
Profile* profile,
const extensions::Extension* extension,
base::FilePath* gallery_file_path,
MediaGalleryPrefId* gallery_pref_id) { … }
std::optional<base::Value::List> ConstructFileSystemList(
content::RenderFrameHost* rfh,
const extensions::Extension* extension,
const std::vector<MediaFileSystemInfo>& filesystems) { … }
class SelectDirectoryDialog : public ui::SelectFileDialog::Listener,
public base::RefCounted<SelectDirectoryDialog> { … };
content::WebContents* GetWebContentsForPrompt(
content::WebContents* sender_web_contents,
content::BrowserContext* browser_context,
const std::string& app_id) { … }
}
MediaGalleriesEventRouter::MediaGalleriesEventRouter(
content::BrowserContext* context)
: … { … }
MediaGalleriesEventRouter::~MediaGalleriesEventRouter() = default;
void MediaGalleriesEventRouter::Shutdown() { … }
static base::LazyInstance<extensions::BrowserContextKeyedAPIFactory<
MediaGalleriesEventRouter>>::DestructorAtExit
g_media_galleries_api_factory = …;
extensions::BrowserContextKeyedAPIFactory<MediaGalleriesEventRouter>*
MediaGalleriesEventRouter::GetFactoryInstance() { … }
MediaGalleriesEventRouter* MediaGalleriesEventRouter::Get(
content::BrowserContext* context) { … }
bool MediaGalleriesEventRouter::ExtensionHasGalleryChangeListener(
const std::string& extension_id) const { … }
void MediaGalleriesEventRouter::DispatchEventToExtension(
const std::string& extension_id,
extensions::events::HistogramValue histogram_value,
const std::string& event_name,
base::Value::List event_args) { … }
void MediaGalleriesEventRouter::OnGalleryChanged(
const std::string& extension_id,
MediaGalleryPrefId gallery_id) { … }
void MediaGalleriesEventRouter::OnGalleryWatchDropped(
const std::string& extension_id,
MediaGalleryPrefId gallery_id) { … }
void MediaGalleriesEventRouter::OnListenerRemoved(
const extensions::EventListenerInfo& details) { … }
MediaGalleriesGetMediaFileSystemsFunction::
~MediaGalleriesGetMediaFileSystemsFunction() { … }
ExtensionFunction::ResponseAction
MediaGalleriesGetMediaFileSystemsFunction::Run() { … }
void MediaGalleriesGetMediaFileSystemsFunction::OnPreferencesInit(
MediaGalleries::GetMediaFileSystemsInteractivity interactive) { … }
void MediaGalleriesGetMediaFileSystemsFunction::AlwaysShowDialog(
const std::vector<MediaFileSystemInfo>& ) { … }
void MediaGalleriesGetMediaFileSystemsFunction::ShowDialogIfNoGalleries(
const std::vector<MediaFileSystemInfo>& filesystems) { … }
void MediaGalleriesGetMediaFileSystemsFunction::GetAndReturnGalleries() { … }
void MediaGalleriesGetMediaFileSystemsFunction::ReturnGalleries(
const std::vector<MediaFileSystemInfo>& filesystems) { … }
void MediaGalleriesGetMediaFileSystemsFunction::ShowDialog() { … }
void MediaGalleriesGetMediaFileSystemsFunction::GetMediaFileSystemsForExtension(
MediaFileSystemsCallback cb) { … }
MediaGalleriesAddUserSelectedFolderFunction::
~MediaGalleriesAddUserSelectedFolderFunction() { … }
ExtensionFunction::ResponseAction
MediaGalleriesAddUserSelectedFolderFunction::Run() { … }
void MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit() { … }
void MediaGalleriesAddUserSelectedFolderFunction::OnDirectorySelected(
const base::FilePath& selected_directory) { … }
void MediaGalleriesAddUserSelectedFolderFunction::ReturnGalleriesAndId(
MediaGalleryPrefId pref_id,
const std::vector<MediaFileSystemInfo>& filesystems) { … }
void MediaGalleriesAddUserSelectedFolderFunction::
GetMediaFileSystemsForExtension(MediaFileSystemsCallback cb) { … }
MediaGalleriesGetMetadataFunction::~MediaGalleriesGetMetadataFunction() { … }
ExtensionFunction::ResponseAction MediaGalleriesGetMetadataFunction::Run() { … }
void MediaGalleriesGetMetadataFunction::OnPreferencesInit(
MediaGalleries::GetMetadataType metadata_type,
const std::string& blob_uuid) { … }
void MediaGalleriesGetMetadataFunction::GetMetadata(
MediaGalleries::GetMetadataType metadata_type,
const std::string& blob_uuid,
std::string blob_header,
int64_t total_blob_length) { … }
void MediaGalleriesGetMetadataFunction::OnSafeMediaMetadataParserDone(
std::unique_ptr<SafeMediaMetadataParser> parser_keep_alive,
bool parse_success,
chrome::mojom::MediaMetadataPtr metadata,
std::unique_ptr<std::vector<metadata::AttachedImage>> attached_images) { … }
void MediaGalleriesGetMetadataFunction::ConstructNextBlob(
base::Value::Dict result_dictionary,
std::unique_ptr<std::vector<metadata::AttachedImage>> attached_images,
std::vector<blink::mojom::SerializedBlobPtr> blobs,
std::unique_ptr<content::BlobHandle> current_blob) { … }
MediaGalleriesAddGalleryWatchFunction::
~MediaGalleriesAddGalleryWatchFunction() { … }
ExtensionFunction::ResponseAction MediaGalleriesAddGalleryWatchFunction::Run() { … }
void MediaGalleriesAddGalleryWatchFunction::OnPreferencesInit(
const std::string& pref_id) { … }
void MediaGalleriesAddGalleryWatchFunction::HandleResponse(
MediaGalleryPrefId gallery_id,
const std::string& error) { … }
MediaGalleriesRemoveGalleryWatchFunction::
~MediaGalleriesRemoveGalleryWatchFunction() { … }
ExtensionFunction::ResponseAction
MediaGalleriesRemoveGalleryWatchFunction::Run() { … }
void MediaGalleriesRemoveGalleryWatchFunction::OnPreferencesInit(
const std::string& pref_id) { … }
}
}