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> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "components/arc/intent_helper/activity_icon_loader.h" | 16 #include "components/arc/intent_helper/activity_icon_loader.h" |
| 17 #include "content/public/browser/navigation_throttle.h" | 17 #include "content/public/browser/navigation_throttle.h" |
| 18 #include "ui/gfx/image/image.h" | 18 #include "ui/gfx/image/image.h" |
| 19 | 19 |
| 20 class GURL; | |
| 21 | |
| 20 namespace content { | 22 namespace content { |
| 21 class NavigationHandle; | 23 class NavigationHandle; |
| 22 class WebContents; | 24 class WebContents; |
| 23 } // namespace content | 25 } // namespace content |
| 24 | 26 |
| 25 namespace arc { | 27 namespace arc { |
| 26 | 28 |
| 27 // A class that allow us to retrieve ARC app's information and handle URL | 29 // A class that allow us to retrieve ARC app's information and handle URL |
| 28 // traffic initiated on Chrome browser, either on Chrome or an ARC's app. | 30 // traffic initiated on Chrome browser, either on Chrome or an ARC's app. |
| 29 class ArcNavigationThrottle : public content::NavigationThrottle { | 31 class ArcNavigationThrottle : public content::NavigationThrottle { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 47 | 49 |
| 48 using NameAndIcon = std::pair<std::string, gfx::Image>; | 50 using NameAndIcon = std::pair<std::string, gfx::Image>; |
| 49 using ShowIntentPickerCallback = | 51 using ShowIntentPickerCallback = |
| 50 base::Callback<void(content::WebContents* web_contents, | 52 base::Callback<void(content::WebContents* web_contents, |
| 51 const std::vector<NameAndIcon>& app_info, | 53 const std::vector<NameAndIcon>& app_info, |
| 52 const base::Callback<void(size_t, CloseReason)>& cb)>; | 54 const base::Callback<void(size_t, CloseReason)>& cb)>; |
| 53 ArcNavigationThrottle(content::NavigationHandle* navigation_handle, | 55 ArcNavigationThrottle(content::NavigationHandle* navigation_handle, |
| 54 const ShowIntentPickerCallback& show_intent_picker_cb); | 56 const ShowIntentPickerCallback& show_intent_picker_cb); |
| 55 ~ArcNavigationThrottle() override; | 57 ~ArcNavigationThrottle() override; |
| 56 | 58 |
| 59 static bool ShouldOverrideUrlLoadingForTesting(const GURL& previous_url, | |
| 60 const GURL& current_url); | |
| 61 | |
| 57 private: | 62 private: |
| 58 // content::Navigation implementation: | 63 // content::Navigation implementation: |
| 59 NavigationThrottle::ThrottleCheckResult WillStartRequest() override; | 64 NavigationThrottle::ThrottleCheckResult WillStartRequest() override; |
| 60 NavigationThrottle::ThrottleCheckResult WillRedirectRequest() override; | 65 NavigationThrottle::ThrottleCheckResult WillRedirectRequest() override; |
| 61 | 66 |
| 62 NavigationThrottle::ThrottleCheckResult HandleRequest(); | 67 NavigationThrottle::ThrottleCheckResult HandleRequest(); |
| 63 void OnAppCandidatesReceived(mojo::Array<mojom::UrlHandlerInfoPtr> handlers); | 68 void OnAppCandidatesReceived(mojo::Array<mojom::UrlHandlerInfoPtr> handlers); |
| 64 void OnAppIconsReceived( | 69 void OnAppIconsReceived( |
| 65 mojo::Array<mojom::UrlHandlerInfoPtr> handlers, | 70 mojo::Array<mojom::UrlHandlerInfoPtr> handlers, |
| 66 std::unique_ptr<ActivityIconLoader::ActivityToIconsMap> icons); | 71 std::unique_ptr<ActivityIconLoader::ActivityToIconsMap> icons); |
| 67 void OnIntentPickerClosed(mojo::Array<mojom::UrlHandlerInfoPtr> handlers, | 72 void OnIntentPickerClosed(mojo::Array<mojom::UrlHandlerInfoPtr> handlers, |
| 68 size_t selected_app_index, | 73 size_t selected_app_index, |
| 69 CloseReason close_reason); | 74 CloseReason close_reason); |
| 70 // Compares the host name of the referrer and target URL to decide whether | 75 // Compares the host name of the referrer and target URL to decide whether |
| 71 // the navigation needs to be overriden. | 76 // the navigation needs to be overriden. |
| 72 bool ShouldOverrideUrlLoading(content::NavigationHandle* navigation_handle); | 77 static bool ShouldOverrideUrlLoading(const GURL& previous_url, |
|
xiyuan
2016/09/20 22:27:58
nit: Move this to cc in an anonymous namespace ?
Yusuke Sato
2016/09/20 22:47:56
That's better, thanks. Done.
| |
| 78 const GURL& current_url); | |
| 73 | 79 |
| 74 // A callback object that allow us to display an IntentPicker when Run() is | 80 // A callback object that allow us to display an IntentPicker when Run() is |
| 75 // executed, it also allow us to report the user's selection back to | 81 // executed, it also allow us to report the user's selection back to |
| 76 // OnIntentPickerClosed(). | 82 // OnIntentPickerClosed(). |
| 77 ShowIntentPickerCallback show_intent_picker_callback_; | 83 ShowIntentPickerCallback show_intent_picker_callback_; |
| 78 | 84 |
| 79 // A cache of the action the user took the last time this navigation throttle | 85 // A cache of the action the user took the last time this navigation throttle |
| 80 // popped up the intent picker dialog. If the dialog has never been popped up | 86 // popped up the intent picker dialog. If the dialog has never been popped up |
| 81 // before, this will have a value of CloseReason::INVALID. Used to avoid | 87 // before, this will have a value of CloseReason::INVALID. Used to avoid |
| 82 // popping up the dialog multiple times on chains of multiple redirects. | 88 // popping up the dialog multiple times on chains of multiple redirects. |
| 83 CloseReason previous_user_action_; | 89 CloseReason previous_user_action_; |
| 84 | 90 |
| 85 // This has to be the last member of the class. | 91 // This has to be the last member of the class. |
| 86 base::WeakPtrFactory<ArcNavigationThrottle> weak_ptr_factory_; | 92 base::WeakPtrFactory<ArcNavigationThrottle> weak_ptr_factory_; |
| 87 | 93 |
| 88 DISALLOW_COPY_AND_ASSIGN(ArcNavigationThrottle); | 94 DISALLOW_COPY_AND_ASSIGN(ArcNavigationThrottle); |
| 89 }; | 95 }; |
| 90 | 96 |
| 91 } // namespace arc | 97 } // namespace arc |
| 92 | 98 |
| 93 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_NAVIGATION_THROTTLE_H_ | 99 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_NAVIGATION_THROTTLE_H_ |
| OLD | NEW |