| 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/link_handler_model_impl.h" | 5 #include "components/arc/intent_helper/link_handler_model_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "components/arc/arc_bridge_service.h" | 11 #include "components/arc/arc_bridge_service.h" |
| 12 #include "components/arc/arc_service_manager.h" | 12 #include "components/arc/arc_service_manager.h" |
| 13 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" | 13 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" |
| 14 #include "components/google/core/browser/google_util.h" | 14 #include "components/google/core/browser/google_util.h" |
| 15 #include "url/gurl.h" | |
| 16 #include "url/url_util.h" | 15 #include "url/url_util.h" |
| 17 | 16 |
| 18 namespace arc { | 17 namespace arc { |
| 19 | 18 |
| 20 namespace { | 19 namespace { |
| 21 | 20 |
| 22 constexpr int kMaxValueLen = 2048; | 21 constexpr int kMaxValueLen = 2048; |
| 23 | 22 |
| 24 bool GetQueryValue(const GURL& url, | 23 bool GetQueryValue(const GURL& url, |
| 25 const std::string& key_to_find, | 24 const std::string& key_to_find, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 41 &output); | 40 &output); |
| 42 *out = base::string16(output.data(), output.length()); | 41 *out = base::string16(output.data(), output.length()); |
| 43 return true; | 42 return true; |
| 44 } | 43 } |
| 45 } | 44 } |
| 46 return false; | 45 return false; |
| 47 } | 46 } |
| 48 | 47 |
| 49 } // namespace | 48 } // namespace |
| 50 | 49 |
| 51 LinkHandlerModelImpl::LinkHandlerModelImpl( | 50 LinkHandlerModelImpl::LinkHandlerModelImpl() : weak_ptr_factory_(this) {} |
| 52 scoped_refptr<ActivityIconLoader> icon_loader) | |
| 53 : icon_loader_(icon_loader), weak_ptr_factory_(this) {} | |
| 54 | 51 |
| 55 LinkHandlerModelImpl::~LinkHandlerModelImpl() {} | 52 LinkHandlerModelImpl::~LinkHandlerModelImpl() = default; |
| 56 | 53 |
| 57 bool LinkHandlerModelImpl::Init(const GURL& url) { | 54 bool LinkHandlerModelImpl::Init(const GURL& url) { |
| 58 auto* arc_service_manager = ArcServiceManager::Get(); | 55 auto* arc_service_manager = ArcServiceManager::Get(); |
| 59 if (!arc_service_manager) | 56 if (!arc_service_manager) |
| 60 return false; | 57 return false; |
| 61 auto* instance = ARC_GET_INSTANCE_FOR_METHOD( | 58 auto* instance = ARC_GET_INSTANCE_FOR_METHOD( |
| 62 arc_service_manager->arc_bridge_service()->intent_helper(), | 59 arc_service_manager->arc_bridge_service()->intent_helper(), |
| 63 RequestUrlHandlerList); | 60 RequestUrlHandlerList); |
| 64 if (!instance) | 61 if (!instance) |
| 65 return false; | 62 return false; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 92 return; | 89 return; |
| 93 const GURL rewritten(RewriteUrlFromQueryIfAvailable(url)); | 90 const GURL rewritten(RewriteUrlFromQueryIfAvailable(url)); |
| 94 instance->HandleUrl(rewritten.spec(), handlers_[handler_id]->package_name); | 91 instance->HandleUrl(rewritten.spec(), handlers_[handler_id]->package_name); |
| 95 } | 92 } |
| 96 | 93 |
| 97 void LinkHandlerModelImpl::OnUrlHandlerList( | 94 void LinkHandlerModelImpl::OnUrlHandlerList( |
| 98 std::vector<mojom::IntentHandlerInfoPtr> handlers) { | 95 std::vector<mojom::IntentHandlerInfoPtr> handlers) { |
| 99 handlers_ = ArcIntentHelperBridge::FilterOutIntentHelper(std::move(handlers)); | 96 handlers_ = ArcIntentHelperBridge::FilterOutIntentHelper(std::move(handlers)); |
| 100 | 97 |
| 101 bool icon_info_notified = false; | 98 bool icon_info_notified = false; |
| 102 if (icon_loader_) { | 99 auto* intent_helper_bridge = |
| 103 std::vector<ActivityIconLoader::ActivityName> activities; | 100 ArcServiceManager::GetGlobalService<ArcIntentHelperBridge>(); |
| 101 if (intent_helper_bridge) { |
| 102 std::vector<ArcIntentHelperBridge::ActivityName> activities; |
| 104 for (size_t i = 0; i < handlers_.size(); ++i) { | 103 for (size_t i = 0; i < handlers_.size(); ++i) { |
| 105 activities.emplace_back(handlers_[i]->package_name, | 104 activities.emplace_back(handlers_[i]->package_name, |
| 106 handlers_[i]->activity_name); | 105 handlers_[i]->activity_name); |
| 107 } | 106 } |
| 108 const ActivityIconLoader::GetResult result = icon_loader_->GetActivityIcons( | 107 const ArcIntentHelperBridge::GetResult result = |
| 109 activities, base::Bind(&LinkHandlerModelImpl::NotifyObserver, | 108 intent_helper_bridge->GetActivityIcons( |
| 110 weak_ptr_factory_.GetWeakPtr())); | 109 activities, base::Bind(&LinkHandlerModelImpl::NotifyObserver, |
| 111 icon_info_notified = ActivityIconLoader::HasIconsReadyCallbackRun(result); | 110 weak_ptr_factory_.GetWeakPtr())); |
| 111 icon_info_notified = |
| 112 internal::ActivityIconLoader::HasIconsReadyCallbackRun(result); |
| 112 } | 113 } |
| 113 | 114 |
| 114 if (!icon_info_notified) { | 115 if (!icon_info_notified) { |
| 115 // Call NotifyObserver() without icon information, unless | 116 // Call NotifyObserver() without icon information, unless |
| 116 // GetActivityIcons has already called it. Otherwise if we delay the | 117 // GetActivityIcons has already called it. Otherwise if we delay the |
| 117 // notification waiting for all icons, context menu may flicker. | 118 // notification waiting for all icons, context menu may flicker. |
| 118 NotifyObserver(nullptr); | 119 NotifyObserver(nullptr); |
| 119 } | 120 } |
| 120 } | 121 } |
| 121 | 122 |
| 122 void LinkHandlerModelImpl::NotifyObserver( | 123 void LinkHandlerModelImpl::NotifyObserver( |
| 123 std::unique_ptr<ActivityIconLoader::ActivityToIconsMap> icons) { | 124 std::unique_ptr<ArcIntentHelperBridge::ActivityToIconsMap> icons) { |
| 124 if (icons) { | 125 if (icons) { |
| 125 icons_.insert(icons->begin(), icons->end()); | 126 icons_.insert(icons->begin(), icons->end()); |
| 126 icons.reset(); | 127 icons.reset(); |
| 127 } | 128 } |
| 128 | 129 |
| 129 std::vector<ash::LinkHandlerInfo> handlers; | 130 std::vector<ash::LinkHandlerInfo> handlers; |
| 130 for (size_t i = 0; i < handlers_.size(); ++i) { | 131 for (size_t i = 0; i < handlers_.size(); ++i) { |
| 131 gfx::Image icon; | 132 gfx::Image icon; |
| 132 const ActivityIconLoader::ActivityName activity( | 133 const ArcIntentHelperBridge::ActivityName activity( |
| 133 handlers_[i]->package_name, handlers_[i]->activity_name); | 134 handlers_[i]->package_name, handlers_[i]->activity_name); |
| 134 const auto it = icons_.find(activity); | 135 const auto it = icons_.find(activity); |
| 135 if (it != icons_.end()) | 136 if (it != icons_.end()) |
| 136 icon = it->second.icon16; | 137 icon = it->second.icon16; |
| 137 // Use the handler's index as an ID. | 138 // Use the handler's index as an ID. |
| 138 ash::LinkHandlerInfo handler = {handlers_[i]->name, icon, i}; | 139 ash::LinkHandlerInfo handler = {handlers_[i]->name, icon, i}; |
| 139 handlers.push_back(handler); | 140 handlers.push_back(handler); |
| 140 } | 141 } |
| 141 for (auto& observer : observer_list_) | 142 for (auto& observer : observer_list_) |
| 142 observer.ModelChanged(handlers); | 143 observer.ModelChanged(handlers); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 164 if (!GetQueryValue(url, kKeyToFind, &value)) | 165 if (!GetQueryValue(url, kKeyToFind, &value)) |
| 165 return url; | 166 return url; |
| 166 | 167 |
| 167 const GURL new_url(value); | 168 const GURL new_url(value); |
| 168 if (!new_url.is_valid()) | 169 if (!new_url.is_valid()) |
| 169 return url; | 170 return url; |
| 170 return new_url; | 171 return new_url; |
| 171 } | 172 } |
| 172 | 173 |
| 173 } // namespace arc | 174 } // namespace arc |
| OLD | NEW |