OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_ARC_OPEN_WITH_MENU_CONTROLLER_DELEGATE_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_ARC_OPEN_WITH_MENU_CONTROLLER_DELEGATE_H_ |
| 7 |
| 8 #include <set> |
| 9 |
| 10 #include "base/compiler_specific.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/strings/string16.h" |
| 14 #include "base/timer/timer.h" |
| 15 #include "components/arc/common/intent_helper.mojom.h" |
| 16 #include "components/renderer_context_menu/render_view_context_menu_observer.h" |
| 17 #include "ui/base/models/simple_menu_model.h" |
| 18 #include "url/gurl.h" |
| 19 |
| 20 class RenderViewContextMenuProxy; |
| 21 |
| 22 namespace arc { |
| 23 |
| 24 class ArcBridgeService; |
| 25 |
| 26 // A class for populating "Open with <ARC app>" menu items in a renderer context |
| 27 // menu. |
| 28 class OpenWithMenuControllerDelegate { |
| 29 public: |
| 30 explicit OpenWithMenuControllerDelegate(ArcBridgeService* bridge_service); |
| 31 ~OpenWithMenuControllerDelegate(); |
| 32 |
| 33 int Init(RenderViewContextMenuProxy* proxy, |
| 34 int main_menu_id_start, |
| 35 size_t num_main_menu_items, |
| 36 const GURL& url); |
| 37 void ExecuteCommand(int id); |
| 38 |
| 39 static std::set<int> GetCommandIdsToEnableForTesting(size_t num_apps); |
| 40 static std::set<int> GetCommandIdsToDisableForTesting(size_t num_apps); |
| 41 static int GetIndexForCommandIdForTesting(int command_id); |
| 42 |
| 43 private: |
| 44 base::string16 GetLabelForCommandId(int command_id) const; |
| 45 IntentHelperInstance* GetIntentHelper(); |
| 46 |
| 47 // A callback function called when a mojo IPC issued in InitMenu finishes. |
| 48 void OnUrlHandlerList(mojo::Array<UrlHandlerInfoPtr> handlers); |
| 49 |
| 50 // The callback function for base::RepeatingTimer. This function updates the |
| 51 // "loading..." animation in the context-menu item. |
| 52 void OnAnimationTimerExpired(); |
| 53 |
| 54 // The bridge service. |
| 55 ArcBridgeService* const bridge_service_; |
| 56 |
| 57 RenderViewContextMenuProxy* proxy_; |
| 58 std::set<int> all_command_ids_; |
| 59 int main_menu_id_start_; |
| 60 size_t num_main_menu_items_; |
| 61 GURL link_url_; |
| 62 ui::SimpleMenuModel sub_menu_; |
| 63 |
| 64 // The string used for animation until we receive a response from the ARC |
| 65 // process. The current animation just adds periods at the end of this string: |
| 66 // 'Loading' -> 'Loading.' -> 'Loading..' -> 'Loading...' (-> 'Loading') |
| 67 base::string16 loading_message_; |
| 68 size_t loading_frame_; |
| 69 |
| 70 // A timer used for loading animation. |
| 71 base::RepeatingTimer animation_timer_; |
| 72 |
| 73 mojo::Array<UrlHandlerInfoPtr> handlers_; |
| 74 |
| 75 // Always keep this the last member of this class to make sure it's the |
| 76 // first thing to be destructed. |
| 77 base::WeakPtrFactory<OpenWithMenuControllerDelegate> weak_ptr_factory_; |
| 78 |
| 79 DISALLOW_COPY_AND_ASSIGN(OpenWithMenuControllerDelegate); |
| 80 }; |
| 81 |
| 82 } // namespace arc |
| 83 |
| 84 #endif // CHROME_BROWSER_CHROMEOS_ARC_OPEN_WITH_MENU_CONTROLLER_DELEGATE_H_ |
OLD | NEW |