123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- // Copyright 2016 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.
- #ifndef COMPONENTS_ARC_INTENT_HELPER_ARC_INTENT_HELPER_BRIDGE_H_
- #define COMPONENTS_ARC_INTENT_HELPER_ARC_INTENT_HELPER_BRIDGE_H_
- #include <map>
- #include <memory>
- #include <set>
- #include <string>
- #include <vector>
- #include "ash/components/arc/mojom/intent_helper.mojom.h"
- #include "base/memory/weak_ptr.h"
- #include "base/observer_list.h"
- #include "base/threading/thread_checker.h"
- #include "components/arc/common/intent_helper/arc_icon_cache_delegate.h"
- #include "components/arc/intent_helper/arc_intent_helper_observer.h"
- #include "components/keyed_service/core/keyed_service.h"
- #include "url/gurl.h"
- class BrowserContextKeyedServiceFactory;
- namespace content {
- class BrowserContext;
- } // namespace content
- namespace arc {
- class AdaptiveIconDelegate;
- class ArcBridgeService;
- class ControlCameraAppDelegate;
- class IntentFilter;
- class OpenUrlDelegate;
- // Receives intents from ARC.
- class ArcIntentHelperBridge : public KeyedService,
- public mojom::IntentHelperHost,
- public ArcIconCacheDelegate {
- public:
- class Delegate {
- public:
- virtual ~Delegate() = default;
- // Resets ARC; this wipes all user data, stops ARC, then
- // re-enables ARC.
- virtual void ResetArc() = 0;
- };
- // Returns singleton instance for the given BrowserContext,
- // or nullptr if the browser |context| is not allowed to use ARC.
- static ArcIntentHelperBridge* GetForBrowserContext(
- content::BrowserContext* context);
- static ArcIntentHelperBridge* GetForBrowserContextForTesting(
- content::BrowserContext* context);
- // Returns factory for the ArcIntentHelperBridge.
- static BrowserContextKeyedServiceFactory* GetFactory();
- // Appends '.' + |to_append| to the intent helper package name.
- static std::string AppendStringToIntentHelperPackageName(
- const std::string& to_append);
- static void SetOpenUrlDelegate(OpenUrlDelegate* delegate);
- static void SetControlCameraAppDelegate(ControlCameraAppDelegate* delegate);
- // Sets the Delegate instance.
- void SetDelegate(std::unique_ptr<Delegate> delegate);
- ArcIntentHelperBridge(content::BrowserContext* context,
- ArcBridgeService* bridge_service);
- ArcIntentHelperBridge(const ArcIntentHelperBridge&) = delete;
- ArcIntentHelperBridge& operator=(const ArcIntentHelperBridge&) = delete;
- ~ArcIntentHelperBridge() override;
- // KeyedService:
- void Shutdown() override;
- // mojom::IntentHelperHost
- void OnIconInvalidated(const std::string& package_name) override;
- void OnIntentFiltersUpdated(
- std::vector<IntentFilter> intent_filters) override;
- void OnOpenDownloads() override;
- void OnOpenUrl(const std::string& url) override;
- void OnOpenCustomTab(const std::string& url,
- int32_t task_id,
- OnOpenCustomTabCallback callback) override;
- void OnOpenChromePage(mojom::ChromePage page) override;
- void FactoryResetArc() override;
- void OpenWallpaperPicker() override;
- void OpenVolumeControl() override;
- void OnOpenWebApp(const std::string& url) override;
- void RecordShareFilesMetricsDeprecated(mojom::ShareFiles flag) override;
- void LaunchCameraApp(uint32_t intent_id,
- arc::mojom::CameraIntentMode mode,
- bool should_handle_result,
- bool should_down_scale,
- bool is_secure,
- int32_t task_id) override;
- void OnIntentFiltersUpdatedForPackage(
- const std::string& package_name,
- std::vector<IntentFilter> intent_filters) override;
- void CloseCameraApp() override;
- void IsChromeAppEnabled(arc::mojom::ChromeApp app,
- IsChromeAppEnabledCallback callback) override;
- void OnSupportedLinksChanged(
- std::vector<arc::mojom::SupportedLinksPtr> added_packages,
- std::vector<arc::mojom::SupportedLinksPtr> removed_packages,
- arc::mojom::SupportedLinkChangeSource source) override;
- void OnDownloadAdded(const std::string& relative_path,
- const std::string& owner_package_name) override;
- void OnOpenAppWithIntent(const GURL& start_url,
- arc::mojom::LaunchIntentPtr intent) override;
- void OnOpenGlobalActions() override;
- void OnCloseSystemDialogs() override;
- // ArcIconCacheDelegete:
- GetResult GetActivityIcons(const std::vector<ActivityName>& activities,
- OnIconsReadyCallback callback) override;
- void SetAdaptiveIconDelegate(AdaptiveIconDelegate* delegate);
- void AddObserver(ArcIntentHelperObserver* observer);
- void RemoveObserver(ArcIntentHelperObserver* observer);
- bool HasObserver(ArcIntentHelperObserver* observer) const;
- void HandleCameraResult(
- uint32_t intent_id,
- arc::mojom::CameraIntentAction action,
- const std::vector<uint8_t>& data,
- arc::mojom::IntentHelperInstance::HandleCameraResultCallback callback);
- void SendNewCaptureBroadcast(bool is_video, std::string file_path);
- // Filters out handlers that belong to the intent_helper apk and returns
- // a new array.
- static std::vector<mojom::IntentHandlerInfoPtr> FilterOutIntentHelper(
- std::vector<mojom::IntentHandlerInfoPtr> handlers);
- const std::vector<IntentFilter>& GetIntentFilterForPackage(
- const std::string& package_name);
- private:
- THREAD_CHECKER(thread_checker_);
- content::BrowserContext* const context_;
- ArcBridgeService* const arc_bridge_service_; // Owned by ArcServiceManager.
- ActivityIconLoader icon_loader_;
- // A map of each package name to the intent filters for that package.
- // Used to determine if Chrome should handle a URL without handing off to
- // Android.
- // TODO(crbug.com/853604): Now the package name exists in the map key as well
- // as the IntentFilter struct, it is a duplication. Should update the ARC
- // mojom type to optimise the structure.
- std::map<std::string, std::vector<IntentFilter>> intent_filters_;
- base::ObserverList<ArcIntentHelperObserver>::Unchecked observer_list_;
- // Schemes that ARC is known to send via OnOpenUrl.
- const std::set<std::string> allowed_arc_schemes_;
- std::unique_ptr<Delegate> delegate_;
- base::WeakPtrFactory<ArcIntentHelperBridge> weak_ptr_factory_{this};
- };
- } // namespace arc
- #endif // COMPONENTS_ARC_INTENT_HELPER_ARC_INTENT_HELPER_BRIDGE_H_
|