| 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 <utility> |
| 8 | 8 |
| 9 #include "ash/common/new_window_controller.h" | 9 #include "ash/common/new_window_controller.h" |
| 10 #include "ash/common/shell_delegate.h" | 10 #include "ash/common/shell_delegate.h" |
| 11 #include "ash/common/wallpaper/wallpaper_controller.h" | 11 #include "ash/common/wallpaper/wallpaper_controller.h" |
| 12 #include "ash/common/wm_shell.h" | 12 #include "ash/common/wm_shell.h" |
| 13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "components/arc/arc_bridge_service.h" | 16 #include "components/arc/arc_bridge_service.h" |
| 17 #include "components/arc/arc_service_manager.h" | 17 #include "components/arc/arc_service_manager.h" |
| 18 #include "components/arc/arc_util.h" | |
| 19 #include "components/arc/intent_helper/activity_icon_loader.h" | |
| 20 #include "components/arc/intent_helper/link_handler_model_impl.h" | 18 #include "components/arc/intent_helper/link_handler_model_impl.h" |
| 21 #include "components/arc/intent_helper/local_activity_resolver.h" | 19 #include "components/arc/intent_helper/local_activity_resolver.h" |
| 22 #include "ui/base/layout.h" | 20 #include "ui/base/layout.h" |
| 23 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 24 | 22 |
| 25 namespace arc { | 23 namespace arc { |
| 26 | 24 |
| 27 // static | 25 // static |
| 28 const char ArcIntentHelperBridge::kArcServiceName[] = | 26 const char ArcIntentHelperBridge::kArcServiceName[] = |
| 29 "arc::ArcIntentHelperBridge"; | 27 "arc::ArcIntentHelperBridge"; |
| 30 | 28 |
| 31 // static | 29 // static |
| 32 const char ArcIntentHelperBridge::kArcIntentHelperPackageName[] = | 30 const char ArcIntentHelperBridge::kArcIntentHelperPackageName[] = |
| 33 "org.chromium.arc.intent_helper"; | 31 "org.chromium.arc.intent_helper"; |
| 34 | 32 |
| 35 ArcIntentHelperBridge::ArcIntentHelperBridge( | 33 ArcIntentHelperBridge::ArcIntentHelperBridge( |
| 36 ArcBridgeService* bridge_service, | 34 ArcBridgeService* bridge_service, |
| 37 const scoped_refptr<ActivityIconLoader>& icon_loader, | |
| 38 const scoped_refptr<LocalActivityResolver>& activity_resolver) | 35 const scoped_refptr<LocalActivityResolver>& activity_resolver) |
| 39 : ArcService(bridge_service), | 36 : ArcService(bridge_service), |
| 40 binding_(this), | 37 binding_(this), |
| 41 icon_loader_(icon_loader), | |
| 42 activity_resolver_(activity_resolver) { | 38 activity_resolver_(activity_resolver) { |
| 43 DCHECK(thread_checker_.CalledOnValidThread()); | 39 DCHECK(thread_checker_.CalledOnValidThread()); |
| 44 arc_bridge_service()->intent_helper()->AddObserver(this); | 40 arc_bridge_service()->intent_helper()->AddObserver(this); |
| 45 } | 41 } |
| 46 | 42 |
| 47 ArcIntentHelperBridge::~ArcIntentHelperBridge() { | 43 ArcIntentHelperBridge::~ArcIntentHelperBridge() { |
| 48 DCHECK(thread_checker_.CalledOnValidThread()); | 44 DCHECK(thread_checker_.CalledOnValidThread()); |
| 49 arc_bridge_service()->intent_helper()->RemoveObserver(this); | 45 arc_bridge_service()->intent_helper()->RemoveObserver(this); |
| 50 } | 46 } |
| 51 | 47 |
| 52 void ArcIntentHelperBridge::OnInstanceReady() { | 48 void ArcIntentHelperBridge::OnInstanceReady() { |
| 53 DCHECK(thread_checker_.CalledOnValidThread()); | 49 DCHECK(thread_checker_.CalledOnValidThread()); |
| 54 ash::Shell::GetInstance()->set_link_handler_model_factory(this); | 50 ash::Shell::GetInstance()->set_link_handler_model_factory(this); |
| 55 auto* instance = | 51 auto* instance = |
| 56 ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->intent_helper(), Init); | 52 ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->intent_helper(), Init); |
| 57 DCHECK(instance); | 53 DCHECK(instance); |
| 58 instance->Init(binding_.CreateInterfacePtrAndBind()); | 54 instance->Init(binding_.CreateInterfacePtrAndBind()); |
| 59 } | 55 } |
| 60 | 56 |
| 61 void ArcIntentHelperBridge::OnInstanceClosed() { | 57 void ArcIntentHelperBridge::OnInstanceClosed() { |
| 62 DCHECK(thread_checker_.CalledOnValidThread()); | 58 DCHECK(thread_checker_.CalledOnValidThread()); |
| 63 ash::Shell::GetInstance()->set_link_handler_model_factory(nullptr); | 59 ash::Shell::GetInstance()->set_link_handler_model_factory(nullptr); |
| 64 } | 60 } |
| 65 | 61 |
| 66 void ArcIntentHelperBridge::OnIconInvalidated(const std::string& package_name) { | 62 void ArcIntentHelperBridge::OnIconInvalidated(const std::string& package_name) { |
| 67 DCHECK(thread_checker_.CalledOnValidThread()); | 63 DCHECK(thread_checker_.CalledOnValidThread()); |
| 68 icon_loader_->InvalidateIcons(package_name); | 64 icon_loader_.InvalidateIcons(package_name); |
| 69 } | 65 } |
| 70 | 66 |
| 71 void ArcIntentHelperBridge::OnOpenDownloads() { | 67 void ArcIntentHelperBridge::OnOpenDownloads() { |
| 72 DCHECK(thread_checker_.CalledOnValidThread()); | 68 DCHECK(thread_checker_.CalledOnValidThread()); |
| 73 // TODO(607411): If the FileManager is not yet open this will open to | 69 // TODO(607411): If the FileManager is not yet open this will open to |
| 74 // downloads by default, which is what we want. However if it is open it will | 70 // downloads by default, which is what we want. However if it is open it will |
| 75 // simply be brought to the forgeground without forcibly being navigated to | 71 // simply be brought to the forgeground without forcibly being navigated to |
| 76 // downloads, which is probably not ideal. | 72 // downloads, which is probably not ideal. |
| 77 ash::WmShell::Get()->new_window_controller()->OpenFileManager(); | 73 ash::WmShell::Get()->new_window_controller()->OpenFileManager(); |
| 78 } | 74 } |
| 79 | 75 |
| 80 void ArcIntentHelperBridge::OnOpenUrl(const std::string& url) { | 76 void ArcIntentHelperBridge::OnOpenUrl(const std::string& url) { |
| 81 DCHECK(thread_checker_.CalledOnValidThread()); | 77 DCHECK(thread_checker_.CalledOnValidThread()); |
| 82 ash::WmShell::Get()->delegate()->OpenUrlFromArc(GURL(url)); | 78 ash::WmShell::Get()->delegate()->OpenUrlFromArc(GURL(url)); |
| 83 } | 79 } |
| 84 | 80 |
| 85 void ArcIntentHelperBridge::OpenWallpaperPicker() { | 81 void ArcIntentHelperBridge::OpenWallpaperPicker() { |
| 86 DCHECK(thread_checker_.CalledOnValidThread()); | 82 DCHECK(thread_checker_.CalledOnValidThread()); |
| 87 ash::WmShell::Get()->wallpaper_controller()->OpenSetWallpaperPage(); | 83 ash::WmShell::Get()->wallpaper_controller()->OpenSetWallpaperPage(); |
| 88 } | 84 } |
| 89 | 85 |
| 90 void ArcIntentHelperBridge::SetWallpaperDeprecated( | 86 void ArcIntentHelperBridge::SetWallpaperDeprecated( |
| 91 const std::vector<uint8_t>& jpeg_data) { | 87 const std::vector<uint8_t>& jpeg_data) { |
| 92 DCHECK(thread_checker_.CalledOnValidThread()); | 88 DCHECK(thread_checker_.CalledOnValidThread()); |
| 93 LOG(ERROR) << "IntentHelper.SetWallpaper is deprecated"; | 89 LOG(ERROR) << "IntentHelper.SetWallpaper is deprecated"; |
| 94 } | 90 } |
| 95 | 91 |
| 92 ArcIntentHelperBridge::GetResult ArcIntentHelperBridge::GetActivityIcons( |
| 93 const std::vector<ActivityName>& activities, |
| 94 const OnIconsReadyCallback& callback) { |
| 95 DCHECK(thread_checker_.CalledOnValidThread()); |
| 96 return icon_loader_.GetActivityIcons(activities, callback); |
| 97 } |
| 98 |
| 96 void ArcIntentHelperBridge::AddObserver(ArcIntentHelperObserver* observer) { | 99 void ArcIntentHelperBridge::AddObserver(ArcIntentHelperObserver* observer) { |
| 97 observer_list_.AddObserver(observer); | 100 observer_list_.AddObserver(observer); |
| 98 } | 101 } |
| 99 | 102 |
| 100 void ArcIntentHelperBridge::RemoveObserver(ArcIntentHelperObserver* observer) { | 103 void ArcIntentHelperBridge::RemoveObserver(ArcIntentHelperObserver* observer) { |
| 101 observer_list_.RemoveObserver(observer); | 104 observer_list_.RemoveObserver(observer); |
| 102 } | 105 } |
| 103 | 106 |
| 104 std::unique_ptr<ash::LinkHandlerModel> ArcIntentHelperBridge::CreateModel( | 107 std::unique_ptr<ash::LinkHandlerModel> ArcIntentHelperBridge::CreateModel( |
| 105 const GURL& url) { | 108 const GURL& url) { |
| 106 DCHECK(thread_checker_.CalledOnValidThread()); | 109 DCHECK(thread_checker_.CalledOnValidThread()); |
| 107 std::unique_ptr<LinkHandlerModelImpl> impl( | 110 auto impl = base::MakeUnique<LinkHandlerModelImpl>(); |
| 108 new LinkHandlerModelImpl(icon_loader_)); | |
| 109 if (!impl->Init(url)) | 111 if (!impl->Init(url)) |
| 110 return nullptr; | 112 return nullptr; |
| 111 return std::move(impl); | 113 return std::move(impl); |
| 112 } | 114 } |
| 113 | 115 |
| 114 // static | 116 // static |
| 115 bool ArcIntentHelperBridge::IsIntentHelperPackage( | 117 bool ArcIntentHelperBridge::IsIntentHelperPackage( |
| 116 const std::string& package_name) { | 118 const std::string& package_name) { |
| 117 return package_name == kArcIntentHelperPackageName; | 119 return package_name == kArcIntentHelperPackageName; |
| 118 } | 120 } |
| 119 | 121 |
| 120 // static | 122 // static |
| 121 std::vector<mojom::IntentHandlerInfoPtr> | 123 std::vector<mojom::IntentHandlerInfoPtr> |
| 122 ArcIntentHelperBridge::FilterOutIntentHelper( | 124 ArcIntentHelperBridge::FilterOutIntentHelper( |
| 123 std::vector<mojom::IntentHandlerInfoPtr> handlers) { | 125 std::vector<mojom::IntentHandlerInfoPtr> handlers) { |
| 124 std::vector<mojom::IntentHandlerInfoPtr> handlers_filtered; | 126 std::vector<mojom::IntentHandlerInfoPtr> handlers_filtered; |
| 125 for (auto& handler : handlers) { | 127 for (auto& handler : handlers) { |
| 126 if (IsIntentHelperPackage(handler->package_name)) | 128 if (IsIntentHelperPackage(handler->package_name)) |
| 127 continue; | 129 continue; |
| 128 handlers_filtered.push_back(std::move(handler)); | 130 handlers_filtered.push_back(std::move(handler)); |
| 129 } | 131 } |
| 130 return handlers_filtered; | 132 return handlers_filtered; |
| 131 } | 133 } |
| 132 | 134 |
| 133 // static | |
| 134 bool ArcIntentHelperBridge::IsIntentHelperAvailable(GetResult* out_error_code) { | |
| 135 auto* arc_service_manager = ArcServiceManager::Get(); | |
| 136 if (!arc_service_manager) { | |
| 137 // TODO(hidehiko): IsArcAvailable() looks not the condition to be checked | |
| 138 // here, because ArcServiceManager instance is created regardless of ARC | |
| 139 // availability. This happens only before MessageLoop starts or after | |
| 140 // MessageLoop stops, practically. | |
| 141 // Also, returning FAILED_ARC_NOT_READY looks problematic at the moment, | |
| 142 // because ArcProcessTask::StartIconLoading accesses to | |
| 143 // ArcServiceManager::Get() return value, which can be nullptr. | |
| 144 if (!IsArcAvailable()) { | |
| 145 VLOG(2) << "ARC bridge is not supported."; | |
| 146 if (out_error_code) | |
| 147 *out_error_code = GetResult::FAILED_ARC_NOT_SUPPORTED; | |
| 148 } else { | |
| 149 VLOG(2) << "ARC bridge is not ready."; | |
| 150 if (out_error_code) | |
| 151 *out_error_code = GetResult::FAILED_ARC_NOT_READY; | |
| 152 } | |
| 153 return false; | |
| 154 } | |
| 155 | |
| 156 auto* intent_helper_holder = | |
| 157 arc_service_manager->arc_bridge_service()->intent_helper(); | |
| 158 if (!intent_helper_holder->has_instance()) { | |
| 159 VLOG(2) << "ARC intent helper instance is not ready."; | |
| 160 if (out_error_code) | |
| 161 *out_error_code = GetResult::FAILED_ARC_NOT_READY; | |
| 162 return false; | |
| 163 } | |
| 164 | |
| 165 return true; | |
| 166 } | |
| 167 | |
| 168 void ArcIntentHelperBridge::OnIntentFiltersUpdated( | 135 void ArcIntentHelperBridge::OnIntentFiltersUpdated( |
| 169 std::vector<IntentFilter> filters) { | 136 std::vector<IntentFilter> filters) { |
| 170 DCHECK(thread_checker_.CalledOnValidThread()); | 137 DCHECK(thread_checker_.CalledOnValidThread()); |
| 171 activity_resolver_->UpdateIntentFilters(std::move(filters)); | 138 activity_resolver_->UpdateIntentFilters(std::move(filters)); |
| 172 | 139 |
| 173 for (auto& observer : observer_list_) | 140 for (auto& observer : observer_list_) |
| 174 observer.OnIntentFiltersUpdated(); | 141 observer.OnIntentFiltersUpdated(); |
| 175 } | 142 } |
| 176 | 143 |
| 177 } // namespace arc | 144 } // namespace arc |
| OLD | NEW |