| 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/intent_helper/arc_intent_helper_bridge.h" | 13 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" |
| 13 #include "components/google/core/browser/google_util.h" | 14 #include "components/google/core/browser/google_util.h" |
| 14 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 15 #include "url/url_util.h" | 16 #include "url/url_util.h" |
| 16 | 17 |
| 17 namespace arc { | 18 namespace arc { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 constexpr int kMinInstanceVersion = 2; // see intent_helper.mojom | |
| 22 constexpr int kMaxValueLen = 2048; | 22 constexpr int kMaxValueLen = 2048; |
| 23 | 23 |
| 24 bool GetQueryValue(const GURL& url, | 24 bool GetQueryValue(const GURL& url, |
| 25 const std::string& key_to_find, | 25 const std::string& key_to_find, |
| 26 base::string16* out) { | 26 base::string16* out) { |
| 27 const std::string str(url.query()); | 27 const std::string str(url.query()); |
| 28 | 28 |
| 29 url::Component query(0, str.length()); | 29 url::Component query(0, str.length()); |
| 30 url::Component key; | 30 url::Component key; |
| 31 url::Component value; | 31 url::Component value; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 48 | 48 |
| 49 } // namespace | 49 } // namespace |
| 50 | 50 |
| 51 LinkHandlerModelImpl::LinkHandlerModelImpl( | 51 LinkHandlerModelImpl::LinkHandlerModelImpl( |
| 52 scoped_refptr<ActivityIconLoader> icon_loader) | 52 scoped_refptr<ActivityIconLoader> icon_loader) |
| 53 : icon_loader_(icon_loader), weak_ptr_factory_(this) {} | 53 : icon_loader_(icon_loader), weak_ptr_factory_(this) {} |
| 54 | 54 |
| 55 LinkHandlerModelImpl::~LinkHandlerModelImpl() {} | 55 LinkHandlerModelImpl::~LinkHandlerModelImpl() {} |
| 56 | 56 |
| 57 bool LinkHandlerModelImpl::Init(const GURL& url) { | 57 bool LinkHandlerModelImpl::Init(const GURL& url) { |
| 58 auto* instance = ArcIntentHelperBridge::GetIntentHelperInstance( | 58 auto* arc_service_manager = ArcServiceManager::Get(); |
| 59 "RequestUrlHandlerList", kMinInstanceVersion); | 59 if (!arc_service_manager) |
| 60 return false; |
| 61 auto* instance = ARC_GET_INSTANCE_FOR_METHOD( |
| 62 arc_service_manager->arc_bridge_service()->intent_helper(), |
| 63 RequestUrlHandlerList); |
| 60 if (!instance) | 64 if (!instance) |
| 61 return false; | 65 return false; |
| 62 | 66 |
| 63 // Check if ARC apps can handle the |url|. Since the information is held in | 67 // Check if ARC apps can handle the |url|. Since the information is held in |
| 64 // a different (ARC) process, issue a mojo IPC request. Usually, the | 68 // a different (ARC) process, issue a mojo IPC request. Usually, the |
| 65 // callback function, OnUrlHandlerList, is called within a few milliseconds | 69 // callback function, OnUrlHandlerList, is called within a few milliseconds |
| 66 // even on the slowest Chromebook we support. | 70 // even on the slowest Chromebook we support. |
| 67 const GURL rewritten(RewriteUrlFromQueryIfAvailable(url)); | 71 const GURL rewritten(RewriteUrlFromQueryIfAvailable(url)); |
| 68 instance->RequestUrlHandlerList( | 72 instance->RequestUrlHandlerList( |
| 69 rewritten.spec(), base::Bind(&LinkHandlerModelImpl::OnUrlHandlerList, | 73 rewritten.spec(), base::Bind(&LinkHandlerModelImpl::OnUrlHandlerList, |
| 70 weak_ptr_factory_.GetWeakPtr())); | 74 weak_ptr_factory_.GetWeakPtr())); |
| 71 return true; | 75 return true; |
| 72 } | 76 } |
| 73 | 77 |
| 74 void LinkHandlerModelImpl::AddObserver(Observer* observer) { | 78 void LinkHandlerModelImpl::AddObserver(Observer* observer) { |
| 75 observer_list_.AddObserver(observer); | 79 observer_list_.AddObserver(observer); |
| 76 } | 80 } |
| 77 | 81 |
| 78 void LinkHandlerModelImpl::OpenLinkWithHandler(const GURL& url, | 82 void LinkHandlerModelImpl::OpenLinkWithHandler(const GURL& url, |
| 79 uint32_t handler_id) { | 83 uint32_t handler_id) { |
| 80 auto* instance = ArcIntentHelperBridge::GetIntentHelperInstance( | 84 auto* arc_service_manager = ArcServiceManager::Get(); |
| 81 "HandleUrl", kMinInstanceVersion); | 85 if (!arc_service_manager) |
| 86 return; |
| 87 auto* instance = ARC_GET_INSTANCE_FOR_METHOD( |
| 88 arc_service_manager->arc_bridge_service()->intent_helper(), HandleUrl); |
| 82 if (!instance) | 89 if (!instance) |
| 83 return; | 90 return; |
| 84 if (handler_id >= handlers_.size()) | 91 if (handler_id >= handlers_.size()) |
| 85 return; | 92 return; |
| 86 const GURL rewritten(RewriteUrlFromQueryIfAvailable(url)); | 93 const GURL rewritten(RewriteUrlFromQueryIfAvailable(url)); |
| 87 instance->HandleUrl(rewritten.spec(), handlers_[handler_id]->package_name); | 94 instance->HandleUrl(rewritten.spec(), handlers_[handler_id]->package_name); |
| 88 } | 95 } |
| 89 | 96 |
| 90 void LinkHandlerModelImpl::OnUrlHandlerList( | 97 void LinkHandlerModelImpl::OnUrlHandlerList( |
| 91 std::vector<mojom::IntentHandlerInfoPtr> handlers) { | 98 std::vector<mojom::IntentHandlerInfoPtr> handlers) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 if (!GetQueryValue(url, kKeyToFind, &value)) | 164 if (!GetQueryValue(url, kKeyToFind, &value)) |
| 158 return url; | 165 return url; |
| 159 | 166 |
| 160 const GURL new_url(value); | 167 const GURL new_url(value); |
| 161 if (!new_url.is_valid()) | 168 if (!new_url.is_valid()) |
| 162 return url; | 169 return url; |
| 163 return new_url; | 170 return new_url; |
| 164 } | 171 } |
| 165 | 172 |
| 166 } // namespace arc | 173 } // namespace arc |
| OLD | NEW |