| 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/local_activity_resolver.h" | 5 #include "components/arc/intent_helper/local_activity_resolver.h" |
| 6 | 6 |
| 7 #include "url/gurl.h" | 7 #include "url/gurl.h" |
| 8 | 8 |
| 9 namespace { |
| 10 |
| 11 constexpr char kIntentActionView[] = "android.intent.action.VIEW"; |
| 12 constexpr char kIntentCategoryBrowsable[] = "android.intent.category.BROWSABLE"; |
| 13 constexpr char kSchemeHttp[] = "http"; |
| 14 constexpr char kSchemeHttps[] = "https"; |
| 15 |
| 16 } // namespace |
| 17 |
| 9 namespace arc { | 18 namespace arc { |
| 10 | 19 |
| 20 LocalActivityResolver::LocalActivityResolver() = default; |
| 21 |
| 22 LocalActivityResolver::~LocalActivityResolver() = default; |
| 23 |
| 11 bool LocalActivityResolver::ShouldChromeHandleUrl(const GURL& url) { | 24 bool LocalActivityResolver::ShouldChromeHandleUrl(const GURL& url) { |
| 12 // Stub implementation for now. | 25 if (!url.SchemeIsHTTPOrHTTPS()) { |
| 26 // Chrome will handle everything that is not http and https. |
| 27 return true; |
| 28 } |
| 29 |
| 30 for (const mojom::IntentFilterPtr& filter : intent_filters_) { |
| 31 if (IsRelevantIntentFilter(filter)) { |
| 32 // For now err on the side of caution and let Android |
| 33 // handle cases where there are possible matching intent |
| 34 // filters. |
| 35 return false; |
| 36 } |
| 37 } |
| 38 |
| 39 // Didn't find any matches for Android so let Chrome handle it. |
| 13 return true; | 40 return true; |
| 14 } | 41 } |
| 15 | 42 |
| 43 void LocalActivityResolver::UpdateIntentFilters( |
| 44 mojo::Array<mojom::IntentFilterPtr> intent_filters) { |
| 45 intent_filters_ = std::move(intent_filters); |
| 46 } |
| 47 |
| 48 bool LocalActivityResolver::IsRelevantIntentFilter( |
| 49 const mojom::IntentFilterPtr& intent_filter) { |
| 50 return FilterHasViewAction(intent_filter) && |
| 51 FilterCategoryIsBrowsable(intent_filter) && |
| 52 FilterHandlesWebSchemes(intent_filter); |
| 53 } |
| 54 |
| 55 bool LocalActivityResolver::FilterHasViewAction( |
| 56 const mojom::IntentFilterPtr& intent_filter) { |
| 57 for (const mojo::String& action : intent_filter->actions) { |
| 58 if (action == kIntentActionView) { |
| 59 return true; |
| 60 } |
| 61 } |
| 62 |
| 63 return false; |
| 64 } |
| 65 |
| 66 bool LocalActivityResolver::FilterCategoryIsBrowsable( |
| 67 const mojom::IntentFilterPtr& intent_filter) { |
| 68 for (const mojo::String& category : intent_filter->categories) { |
| 69 if (category == kIntentCategoryBrowsable) { |
| 70 return true; |
| 71 } |
| 72 } |
| 73 |
| 74 return false; |
| 75 } |
| 76 |
| 77 bool LocalActivityResolver::FilterHandlesWebSchemes( |
| 78 const mojom::IntentFilterPtr& intent_filter) { |
| 79 for (const mojo::String& scheme : intent_filter->data_schemes) { |
| 80 if (scheme == kSchemeHttp || scheme == kSchemeHttps) { |
| 81 return true; |
| 82 } |
| 83 } |
| 84 |
| 85 return false; |
| 86 } |
| 87 |
| 16 } // namespace arc | 88 } // namespace arc |
| OLD | NEW |