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 #ifndef CHROME_BROWSER_CHROMEOS_ARC_ARC_NAVIGATION_THROTTLE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_ARC_ARC_NAVIGATION_THROTTLE_H_ |
6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_NAVIGATION_THROTTLE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_NAVIGATION_THROTTLE_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 29 matching lines...) Expand all Loading... |
40 JUST_ONCE_PRESSED = 3, | 40 JUST_ONCE_PRESSED = 3, |
41 PREFERRED_ACTIVITY_FOUND = 4, | 41 PREFERRED_ACTIVITY_FOUND = 4, |
42 SIZE, | 42 SIZE, |
43 INVALID = SIZE, | 43 INVALID = SIZE, |
44 }; | 44 }; |
45 | 45 |
46 // Restricts the amount of apps displayed to the user without the need of a | 46 // Restricts the amount of apps displayed to the user without the need of a |
47 // ScrollView. | 47 // ScrollView. |
48 enum { kMaxAppResults = 3 }; | 48 enum { kMaxAppResults = 3 }; |
49 | 49 |
50 using NameAndIcon = std::pair<std::string, gfx::Image>; | 50 struct AppInfo { |
51 using ShowIntentPickerCallback = | 51 explicit AppInfo(gfx::Image img, std::string package, std::string activity) |
52 base::Callback<void(content::WebContents* web_contents, | 52 : icon(img), package_name(package), activity_name(activity) {} |
53 const std::vector<NameAndIcon>& app_info, | 53 gfx::Image icon; |
54 const base::Callback<void(size_t, CloseReason)>& cb)>; | 54 std::string package_name; |
| 55 std::string activity_name; |
| 56 }; |
| 57 |
| 58 using ShowIntentPickerCallback = base::Callback<void( |
| 59 content::WebContents* web_contents, |
| 60 const std::vector<AppInfo>& app_info, |
| 61 const base::Callback<void(std::string, CloseReason)>& cb)>; |
55 ArcNavigationThrottle(content::NavigationHandle* navigation_handle, | 62 ArcNavigationThrottle(content::NavigationHandle* navigation_handle, |
56 const ShowIntentPickerCallback& show_intent_picker_cb); | 63 const ShowIntentPickerCallback& show_intent_picker_cb); |
57 ~ArcNavigationThrottle() override; | 64 ~ArcNavigationThrottle() override; |
58 | 65 |
59 static bool ShouldOverrideUrlLoadingForTesting(const GURL& previous_url, | 66 static bool ShouldOverrideUrlLoadingForTesting(const GURL& previous_url, |
60 const GURL& current_url); | 67 const GURL& current_url); |
61 | 68 |
62 private: | 69 private: |
63 // content::Navigation implementation: | 70 // content::Navigation implementation: |
64 NavigationThrottle::ThrottleCheckResult WillStartRequest() override; | 71 NavigationThrottle::ThrottleCheckResult WillStartRequest() override; |
65 NavigationThrottle::ThrottleCheckResult WillRedirectRequest() override; | 72 NavigationThrottle::ThrottleCheckResult WillRedirectRequest() override; |
66 | 73 |
67 NavigationThrottle::ThrottleCheckResult HandleRequest(); | 74 NavigationThrottle::ThrottleCheckResult HandleRequest(); |
68 void OnAppCandidatesReceived( | 75 void OnAppCandidatesReceived( |
69 mojo::Array<mojom::IntentHandlerInfoPtr> handlers); | 76 mojo::Array<mojom::IntentHandlerInfoPtr> handlers); |
70 void OnAppIconsReceived( | 77 void OnAppIconsReceived( |
71 mojo::Array<mojom::IntentHandlerInfoPtr> handlers, | 78 mojo::Array<mojom::IntentHandlerInfoPtr> handlers, |
72 std::unique_ptr<ActivityIconLoader::ActivityToIconsMap> icons); | 79 std::unique_ptr<ActivityIconLoader::ActivityToIconsMap> icons); |
73 void OnIntentPickerClosed(mojo::Array<mojom::IntentHandlerInfoPtr> handlers, | 80 void OnIntentPickerClosed(mojo::Array<mojom::IntentHandlerInfoPtr> handlers, |
74 size_t selected_app_index, | 81 std::string selected_app_package, |
75 CloseReason close_reason); | 82 CloseReason close_reason); |
76 // A callback object that allow us to display an IntentPicker when Run() is | 83 // A callback object that allow us to display an IntentPicker when Run() is |
77 // executed, it also allow us to report the user's selection back to | 84 // executed, it also allow us to report the user's selection back to |
78 // OnIntentPickerClosed(). | 85 // OnIntentPickerClosed(). |
79 ShowIntentPickerCallback show_intent_picker_callback_; | 86 ShowIntentPickerCallback show_intent_picker_callback_; |
80 | 87 |
81 // A cache of the action the user took the last time this navigation throttle | 88 // A cache of the action the user took the last time this navigation throttle |
82 // popped up the intent picker dialog. If the dialog has never been popped up | 89 // popped up the intent picker dialog. If the dialog has never been popped up |
83 // before, this will have a value of CloseReason::INVALID. Used to avoid | 90 // before, this will have a value of CloseReason::INVALID. Used to avoid |
84 // popping up the dialog multiple times on chains of multiple redirects. | 91 // popping up the dialog multiple times on chains of multiple redirects. |
85 CloseReason previous_user_action_; | 92 CloseReason previous_user_action_; |
86 | 93 |
87 // This has to be the last member of the class. | 94 // This has to be the last member of the class. |
88 base::WeakPtrFactory<ArcNavigationThrottle> weak_ptr_factory_; | 95 base::WeakPtrFactory<ArcNavigationThrottle> weak_ptr_factory_; |
89 | 96 |
90 DISALLOW_COPY_AND_ASSIGN(ArcNavigationThrottle); | 97 DISALLOW_COPY_AND_ASSIGN(ArcNavigationThrottle); |
91 }; | 98 }; |
92 | 99 |
93 } // namespace arc | 100 } // namespace arc |
94 | 101 |
95 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_NAVIGATION_THROTTLE_H_ | 102 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_NAVIGATION_THROTTLE_H_ |
OLD | NEW |