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