| 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 30 matching lines...) Expand all Loading... |
| 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 struct AppInfo { | 50 struct AppInfo { |
| 51 explicit AppInfo(gfx::Image img, std::string package, std::string activity) | 51 AppInfo(gfx::Image img, std::string package, std::string activity) |
| 52 : icon(img), package_name(package), activity_name(activity) {} | 52 : icon(img), package_name(package), activity_name(activity) {} |
| 53 gfx::Image icon; | 53 gfx::Image icon; |
| 54 std::string package_name; | 54 std::string package_name; |
| 55 std::string activity_name; | 55 std::string activity_name; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 using ShowIntentPickerCallback = base::Callback<void( | 58 using ShowIntentPickerCallback = base::Callback<void( |
| 59 content::WebContents* web_contents, | 59 content::WebContents* web_contents, |
| 60 const std::vector<AppInfo>& app_info, | 60 const std::vector<AppInfo>& app_info, |
| 61 const base::Callback<void(std::string, CloseReason)>& cb)>; | 61 const base::Callback<void(const std::string&, CloseReason)>& cb)>; |
| 62 ArcNavigationThrottle(content::NavigationHandle* navigation_handle, | 62 ArcNavigationThrottle(content::NavigationHandle* navigation_handle, |
| 63 const ShowIntentPickerCallback& show_intent_picker_cb); | 63 const ShowIntentPickerCallback& show_intent_picker_cb); |
| 64 ~ArcNavigationThrottle() override; | 64 ~ArcNavigationThrottle() override; |
| 65 | 65 |
| 66 static bool ShouldOverrideUrlLoadingForTesting(const GURL& previous_url, | 66 static bool ShouldOverrideUrlLoadingForTesting(const GURL& previous_url, |
| 67 const GURL& current_url); | 67 const GURL& current_url); |
| 68 | 68 |
| 69 private: | 69 private: |
| 70 // content::Navigation implementation: | 70 // content::Navigation implementation: |
| 71 NavigationThrottle::ThrottleCheckResult WillStartRequest() override; | 71 NavigationThrottle::ThrottleCheckResult WillStartRequest() override; |
| 72 NavigationThrottle::ThrottleCheckResult WillRedirectRequest() override; | 72 NavigationThrottle::ThrottleCheckResult WillRedirectRequest() override; |
| 73 | 73 |
| 74 NavigationThrottle::ThrottleCheckResult HandleRequest(); | 74 NavigationThrottle::ThrottleCheckResult HandleRequest(); |
| 75 void OnAppCandidatesReceived( | 75 void OnAppCandidatesReceived( |
| 76 mojo::Array<mojom::IntentHandlerInfoPtr> handlers); | 76 mojo::Array<mojom::IntentHandlerInfoPtr> handlers); |
| 77 void OnAppIconsReceived( | 77 void OnAppIconsReceived( |
| 78 mojo::Array<mojom::IntentHandlerInfoPtr> handlers, | 78 mojo::Array<mojom::IntentHandlerInfoPtr> handlers, |
| 79 std::unique_ptr<ActivityIconLoader::ActivityToIconsMap> icons); | 79 std::unique_ptr<ActivityIconLoader::ActivityToIconsMap> icons); |
| 80 void OnIntentPickerClosed(mojo::Array<mojom::IntentHandlerInfoPtr> handlers, | 80 void OnIntentPickerClosed(mojo::Array<mojom::IntentHandlerInfoPtr> handlers, |
| 81 std::string selected_app_package, | 81 const std::string& selected_app_package, |
| 82 CloseReason close_reason); | 82 CloseReason close_reason); |
| 83 // 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 |
| 84 // 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 |
| 85 // OnIntentPickerClosed(). | 85 // OnIntentPickerClosed(). |
| 86 ShowIntentPickerCallback show_intent_picker_callback_; | 86 ShowIntentPickerCallback show_intent_picker_callback_; |
| 87 | 87 |
| 88 // 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 |
| 89 // 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 |
| 90 // 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 |
| 91 // popping up the dialog multiple times on chains of multiple redirects. | 91 // popping up the dialog multiple times on chains of multiple redirects. |
| 92 CloseReason previous_user_action_; | 92 CloseReason previous_user_action_; |
| 93 | 93 |
| 94 // This has to be the last member of the class. | 94 // This has to be the last member of the class. |
| 95 base::WeakPtrFactory<ArcNavigationThrottle> weak_ptr_factory_; | 95 base::WeakPtrFactory<ArcNavigationThrottle> weak_ptr_factory_; |
| 96 | 96 |
| 97 DISALLOW_COPY_AND_ASSIGN(ArcNavigationThrottle); | 97 DISALLOW_COPY_AND_ASSIGN(ArcNavigationThrottle); |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 } // namespace arc | 100 } // namespace arc |
| 101 | 101 |
| 102 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_NAVIGATION_THROTTLE_H_ | 102 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_NAVIGATION_THROTTLE_H_ |
| OLD | NEW |