Chromium Code Reviews| 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 | |
| 18 namespace arc { | 9 namespace arc { |
| 19 | 10 |
| 20 LocalActivityResolver::LocalActivityResolver() = default; | 11 LocalActivityResolver::LocalActivityResolver() = default; |
| 21 | 12 |
| 22 LocalActivityResolver::~LocalActivityResolver() = default; | 13 LocalActivityResolver::~LocalActivityResolver() = default; |
| 23 | 14 |
| 24 bool LocalActivityResolver::ShouldChromeHandleUrl(const GURL& url) { | 15 bool LocalActivityResolver::ShouldChromeHandleUrl(const GURL& url) { |
| 25 if (!url.SchemeIsHTTPOrHTTPS()) { | 16 if (!url.SchemeIsHTTPOrHTTPS()) { |
| 26 // Chrome will handle everything that is not http and https. | 17 // Chrome will handle everything that is not http and https. |
| 27 return true; | 18 return true; |
| 28 } | 19 } |
| 29 | 20 |
| 30 for (const mojom::IntentFilterPtr& filter : intent_filters_) { | 21 for (const IntentFilter &filter: intent_filters_) { |
|
Yusuke Sato
2016/07/11 04:38:32
nit: I think we use '& filter' in arc/.
Ben Kwa
2016/07/11 21:22:58
Done.
| |
| 31 if (IsRelevantIntentFilter(filter)) { | 22 if (filter.match(url)) { |
| 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; | 23 return false; |
| 36 } | 24 } |
| 37 } | 25 } |
| 38 | 26 |
| 39 // Didn't find any matches for Android so let Chrome handle it. | 27 // Didn't find any matches for Android so let Chrome handle it. |
| 40 return true; | 28 return true; |
| 41 } | 29 } |
| 42 | 30 |
| 43 void LocalActivityResolver::UpdateIntentFilters( | 31 void LocalActivityResolver::UpdateIntentFilters( |
| 44 mojo::Array<mojom::IntentFilterPtr> intent_filters) { | 32 mojo::Array<mojom::IntentFilterPtr> mojo_intent_filters) { |
| 45 intent_filters_ = std::move(intent_filters); | 33 intent_filters_.clear(); |
| 46 } | 34 for (mojom::IntentFilterPtr& mojo_filter : mojo_intent_filters) { |
| 47 | 35 intent_filters_.push_back(IntentFilter(mojo_filter)); |
| 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 } | 36 } |
| 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 } | 37 } |
| 87 | 38 |
| 88 } // namespace arc | 39 } // namespace arc |
| OLD | NEW |