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 #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 19 matching lines...) Expand all Loading... | |
| 30 // These enums are used to define the buckets for an enumerated UMA histogram | 30 // These enums are used to define the buckets for an enumerated UMA histogram |
| 31 // and need to be synced with histograms.xml. This enum class should also be | 31 // and need to be synced with histograms.xml. This enum class should also be |
| 32 // treated as append-only. | 32 // treated as append-only. |
| 33 enum class CloseReason : int { | 33 enum class CloseReason : int { |
| 34 ERROR = 0, | 34 ERROR = 0, |
| 35 DIALOG_DEACTIVATED = 1, | 35 DIALOG_DEACTIVATED = 1, |
| 36 ALWAYS_PRESSED = 2, | 36 ALWAYS_PRESSED = 2, |
| 37 JUST_ONCE_PRESSED = 3, | 37 JUST_ONCE_PRESSED = 3, |
| 38 PREFERRED_ACTIVITY_FOUND = 4, | 38 PREFERRED_ACTIVITY_FOUND = 4, |
| 39 SIZE, | 39 SIZE, |
| 40 INVALID = SIZE, | |
| 40 }; | 41 }; |
| 41 | 42 |
| 42 // Restricts the amount of apps displayed to the user without the need of a | 43 // Restricts the amount of apps displayed to the user without the need of a |
| 43 // ScrollView. | 44 // ScrollView. |
| 44 enum { kMaxAppResults = 3 }; | 45 enum { kMaxAppResults = 3 }; |
| 45 | 46 |
| 46 using NameAndIcon = std::pair<std::string, gfx::Image>; | 47 using NameAndIcon = std::pair<std::string, gfx::Image>; |
| 47 using ShowDisambigDialogCallback = | 48 using ShowIntentPickerCallback = |
|
djacobo_
2016/07/29 20:23:17
Thanks for renaming here and all the repetitions,
| |
| 48 base::Callback<void(content::NavigationHandle* handle, | 49 base::Callback<void(content::NavigationHandle* handle, |
| 49 const std::vector<NameAndIcon>& app_info, | 50 const std::vector<NameAndIcon>& app_info, |
| 50 const base::Callback<void(size_t, CloseReason)>& cb)>; | 51 const base::Callback<void(size_t, CloseReason)>& cb)>; |
| 51 ArcNavigationThrottle( | 52 ArcNavigationThrottle(content::NavigationHandle* navigation_handle, |
| 52 content::NavigationHandle* navigation_handle, | 53 const ShowIntentPickerCallback& show_intent_picker_cb); |
| 53 const ShowDisambigDialogCallback& show_disambig_dialog_cb); | |
| 54 ~ArcNavigationThrottle() override; | 54 ~ArcNavigationThrottle() override; |
| 55 | 55 |
| 56 private: | 56 private: |
| 57 // content::Navigation implementation: | 57 // content::Navigation implementation: |
| 58 NavigationThrottle::ThrottleCheckResult WillStartRequest() override; | 58 NavigationThrottle::ThrottleCheckResult WillStartRequest() override; |
| 59 NavigationThrottle::ThrottleCheckResult WillRedirectRequest() override; | 59 NavigationThrottle::ThrottleCheckResult WillRedirectRequest() override; |
| 60 | 60 |
| 61 NavigationThrottle::ThrottleCheckResult HandleRequest(); | |
| 61 void OnAppCandidatesReceived(mojo::Array<mojom::UrlHandlerInfoPtr> handlers); | 62 void OnAppCandidatesReceived(mojo::Array<mojom::UrlHandlerInfoPtr> handlers); |
| 62 void OnAppIconsReceived( | 63 void OnAppIconsReceived( |
| 63 mojo::Array<mojom::UrlHandlerInfoPtr> handlers, | 64 mojo::Array<mojom::UrlHandlerInfoPtr> handlers, |
| 64 std::unique_ptr<ActivityIconLoader::ActivityToIconsMap> icons); | 65 std::unique_ptr<ActivityIconLoader::ActivityToIconsMap> icons); |
| 65 void OnDisambigDialogClosed(mojo::Array<mojom::UrlHandlerInfoPtr> handlers, | 66 void OnIntentPickerClosed(mojo::Array<mojom::UrlHandlerInfoPtr> handlers, |
| 66 size_t selected_app_index, | 67 size_t selected_app_index, |
| 67 CloseReason close_reason); | 68 CloseReason close_reason); |
| 68 // Compares the host name of the referrer and target URL to decide whether | 69 // Compares the host name of the referrer and target URL to decide whether |
| 69 // the navigation needs to be overriden. | 70 // the navigation needs to be overriden. |
| 70 bool ShouldOverrideUrlLoading(content::NavigationHandle* navigation_handle); | 71 bool ShouldOverrideUrlLoading(content::NavigationHandle* navigation_handle); |
| 71 | 72 |
| 72 // A callback object that allow us to display an IntentPicker when Run() is | 73 // A callback object that allow us to display an IntentPicker when Run() is |
| 73 // executed, it also allow us to report the user's selection back to | 74 // executed, it also allow us to report the user's selection back to |
| 74 // OnDisambigDialogClosed(). | 75 // OnIntentPickerClosed(). |
| 75 ShowDisambigDialogCallback show_disambig_dialog_callback_; | 76 ShowIntentPickerCallback show_intent_picker_callback_; |
| 76 | 77 |
| 78 // A cache of the action the user took the last time this navigation throttle | |
| 79 // popped up the intent picker dialog. If the dialog has never been popped up | |
| 80 // before, this will have a value of CloseReason::INVALID. Used to avoid | |
| 81 // popping up the dialog multiple times on chains of multiple redirects. | |
| 82 CloseReason previous_user_action_; | |
| 83 | |
| 84 // This has to be the last member of the class. | |
| 77 base::WeakPtrFactory<ArcNavigationThrottle> weak_ptr_factory_; | 85 base::WeakPtrFactory<ArcNavigationThrottle> weak_ptr_factory_; |
| 78 | 86 |
| 79 DISALLOW_COPY_AND_ASSIGN(ArcNavigationThrottle); | 87 DISALLOW_COPY_AND_ASSIGN(ArcNavigationThrottle); |
| 80 }; | 88 }; |
| 81 | 89 |
| 82 } // namespace arc | 90 } // namespace arc |
| 83 | 91 |
| 84 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_NAVIGATION_THROTTLE_H_ | 92 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_NAVIGATION_THROTTLE_H_ |
| OLD | NEW |