| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" | 5 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" |
| 6 | 6 |
| 7 #include <utility> |
| 7 #include <vector> | 8 #include <vector> |
| 8 | 9 |
| 9 #include "ash/desktop_background/user_wallpaper_delegate.h" | 10 #include "ash/desktop_background/user_wallpaper_delegate.h" |
| 10 #include "ash/new_window_delegate.h" | 11 #include "ash/new_window_delegate.h" |
| 11 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 12 #include "ash/shell_delegate.h" | 13 #include "ash/shell_delegate.h" |
| 13 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 14 #include "components/arc/intent_helper/activity_icon_loader.h" | 15 #include "components/arc/intent_helper/activity_icon_loader.h" |
| 15 #include "components/arc/intent_helper/link_handler_model_impl.h" | 16 #include "components/arc/intent_helper/link_handler_model_impl.h" |
| 17 #include "components/arc/set_wallpaper_delegate.h" |
| 16 #include "ui/base/layout.h" | 18 #include "ui/base/layout.h" |
| 17 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 18 | 20 |
| 19 namespace arc { | 21 namespace arc { |
| 20 | 22 |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 constexpr char kArcIntentHelperPackageName[] = "org.chromium.arc.intent_helper"; | 25 constexpr char kArcIntentHelperPackageName[] = "org.chromium.arc.intent_helper"; |
| 24 | 26 |
| 25 } // namespace | 27 } // namespace |
| 26 | 28 |
| 27 ArcIntentHelperBridge::ArcIntentHelperBridge( | 29 ArcIntentHelperBridge::ArcIntentHelperBridge( |
| 28 ArcBridgeService* bridge_service, | 30 ArcBridgeService* bridge_service, |
| 29 const scoped_refptr<ActivityIconLoader>& icon_loader) | 31 const scoped_refptr<ActivityIconLoader>& icon_loader, |
| 30 : ArcService(bridge_service), binding_(this), icon_loader_(icon_loader) { | 32 std::unique_ptr<SetWallpaperDelegate> set_wallpaper_delegate) |
| 33 : ArcService(bridge_service), |
| 34 binding_(this), |
| 35 icon_loader_(icon_loader), |
| 36 set_wallpaper_delegate_(std::move(set_wallpaper_delegate)) { |
| 37 DCHECK(thread_checker_.CalledOnValidThread()); |
| 31 arc_bridge_service()->AddObserver(this); | 38 arc_bridge_service()->AddObserver(this); |
| 32 } | 39 } |
| 33 | 40 |
| 34 ArcIntentHelperBridge::~ArcIntentHelperBridge() { | 41 ArcIntentHelperBridge::~ArcIntentHelperBridge() { |
| 42 DCHECK(thread_checker_.CalledOnValidThread()); |
| 35 arc_bridge_service()->RemoveObserver(this); | 43 arc_bridge_service()->RemoveObserver(this); |
| 36 } | 44 } |
| 37 | 45 |
| 38 void ArcIntentHelperBridge::OnIntentHelperInstanceReady() { | 46 void ArcIntentHelperBridge::OnIntentHelperInstanceReady() { |
| 47 DCHECK(thread_checker_.CalledOnValidThread()); |
| 39 ash::Shell::GetInstance()->set_link_handler_model_factory(this); | 48 ash::Shell::GetInstance()->set_link_handler_model_factory(this); |
| 40 arc_bridge_service()->intent_helper_instance()->Init( | 49 arc_bridge_service()->intent_helper_instance()->Init( |
| 41 binding_.CreateInterfacePtrAndBind()); | 50 binding_.CreateInterfacePtrAndBind()); |
| 42 } | 51 } |
| 43 | 52 |
| 44 void ArcIntentHelperBridge::OnIntentHelperInstanceClosed() { | 53 void ArcIntentHelperBridge::OnIntentHelperInstanceClosed() { |
| 54 DCHECK(thread_checker_.CalledOnValidThread()); |
| 45 ash::Shell::GetInstance()->set_link_handler_model_factory(nullptr); | 55 ash::Shell::GetInstance()->set_link_handler_model_factory(nullptr); |
| 46 } | 56 } |
| 47 | 57 |
| 48 void ArcIntentHelperBridge::OnIconInvalidated( | 58 void ArcIntentHelperBridge::OnIconInvalidated( |
| 49 const mojo::String& package_name) { | 59 const mojo::String& package_name) { |
| 60 DCHECK(thread_checker_.CalledOnValidThread()); |
| 50 icon_loader_->InvalidateIcons(package_name); | 61 icon_loader_->InvalidateIcons(package_name); |
| 51 } | 62 } |
| 52 | 63 |
| 53 void ArcIntentHelperBridge::OnOpenDownloads() { | 64 void ArcIntentHelperBridge::OnOpenDownloads() { |
| 65 DCHECK(thread_checker_.CalledOnValidThread()); |
| 54 // TODO(607411): If the FileManager is not yet open this will open to | 66 // TODO(607411): If the FileManager is not yet open this will open to |
| 55 // downloads by default, which is what we want. However if it is open it will | 67 // downloads by default, which is what we want. However if it is open it will |
| 56 // simply be brought to the forgeground without forcibly being navigated to | 68 // simply be brought to the forgeground without forcibly being navigated to |
| 57 // downloads, which is probably not ideal. | 69 // downloads, which is probably not ideal. |
| 58 ash::Shell::GetInstance()->new_window_delegate()->OpenFileManager(); | 70 ash::Shell::GetInstance()->new_window_delegate()->OpenFileManager(); |
| 59 } | 71 } |
| 60 | 72 |
| 61 void ArcIntentHelperBridge::OnOpenUrl(const mojo::String& url) { | 73 void ArcIntentHelperBridge::OnOpenUrl(const mojo::String& url) { |
| 74 DCHECK(thread_checker_.CalledOnValidThread()); |
| 62 GURL gurl(url.get()); | 75 GURL gurl(url.get()); |
| 63 ash::Shell::GetInstance()->delegate()->OpenUrl(gurl); | 76 ash::Shell::GetInstance()->delegate()->OpenUrl(gurl); |
| 64 } | 77 } |
| 65 | 78 |
| 66 void ArcIntentHelperBridge::OpenWallpaperPicker() { | 79 void ArcIntentHelperBridge::OpenWallpaperPicker() { |
| 80 DCHECK(thread_checker_.CalledOnValidThread()); |
| 67 ash::Shell::GetInstance()->user_wallpaper_delegate()->OpenSetWallpaperPage(); | 81 ash::Shell::GetInstance()->user_wallpaper_delegate()->OpenSetWallpaperPage(); |
| 68 } | 82 } |
| 69 | 83 |
| 84 void ArcIntentHelperBridge::SetWallpaper(mojo::Array<uint8_t> jpeg_data) { |
| 85 DCHECK(thread_checker_.CalledOnValidThread()); |
| 86 set_wallpaper_delegate_->SetWallpaper(jpeg_data.PassStorage()); |
| 87 } |
| 88 |
| 70 std::unique_ptr<ash::LinkHandlerModel> ArcIntentHelperBridge::CreateModel( | 89 std::unique_ptr<ash::LinkHandlerModel> ArcIntentHelperBridge::CreateModel( |
| 71 const GURL& url) { | 90 const GURL& url) { |
| 91 DCHECK(thread_checker_.CalledOnValidThread()); |
| 72 std::unique_ptr<LinkHandlerModelImpl> impl( | 92 std::unique_ptr<LinkHandlerModelImpl> impl( |
| 73 new LinkHandlerModelImpl(icon_loader_)); | 93 new LinkHandlerModelImpl(icon_loader_)); |
| 74 if (!impl->Init(url)) | 94 if (!impl->Init(url)) |
| 75 return nullptr; | 95 return nullptr; |
| 76 return std::move(impl); | 96 return std::move(impl); |
| 77 } | 97 } |
| 78 | 98 |
| 79 // static | 99 // static |
| 80 bool ArcIntentHelperBridge::IsIntentHelperPackage( | 100 bool ArcIntentHelperBridge::IsIntentHelperPackage( |
| 81 const std::string& package_name) { | 101 const std::string& package_name) { |
| 82 return package_name == kArcIntentHelperPackageName; | 102 return package_name == kArcIntentHelperPackageName; |
| 83 } | 103 } |
| 84 | 104 |
| 85 // static | 105 // static |
| 86 mojo::Array<mojom::UrlHandlerInfoPtr> | 106 mojo::Array<mojom::UrlHandlerInfoPtr> |
| 87 ArcIntentHelperBridge::FilterOutIntentHelper( | 107 ArcIntentHelperBridge::FilterOutIntentHelper( |
| 88 mojo::Array<mojom::UrlHandlerInfoPtr> handlers) { | 108 mojo::Array<mojom::UrlHandlerInfoPtr> handlers) { |
| 89 mojo::Array<mojom::UrlHandlerInfoPtr> handlers_filtered; | 109 mojo::Array<mojom::UrlHandlerInfoPtr> handlers_filtered; |
| 90 for (auto& handler : handlers) { | 110 for (auto& handler : handlers) { |
| 91 if (IsIntentHelperPackage(handler->package_name.get())) | 111 if (IsIntentHelperPackage(handler->package_name.get())) |
| 92 continue; | 112 continue; |
| 93 handlers_filtered.push_back(std::move(handler)); | 113 handlers_filtered.push_back(std::move(handler)); |
| 94 } | 114 } |
| 95 return handlers_filtered; | 115 return handlers_filtered; |
| 96 } | 116 } |
| 97 | 117 |
| 98 } // namespace arc | 118 } // namespace arc |
| OLD | NEW |