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