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 <unordered_map> |
| 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 void BuildHandlersMapForTesting( |
| 40 int menu_id_start, |
| 41 size_t num_menu_items, |
| 42 mojo::Array<UrlHandlerInfoPtr> handlers, |
| 43 std::unordered_map<int, UrlHandlerInfoPtr>* out_map, |
| 44 int* out_sub_menu_parent_command_id); |
| 45 |
| 46 private: |
| 47 base::string16 GetLabelForCommandId(int command_id) const; |
| 48 IntentHelperInstance* GetIntentHelper(); |
| 49 |
| 50 // A callback function called when a mojo IPC issued in InitMenu finishes. |
| 51 void OnUrlHandlerList(mojo::Array<UrlHandlerInfoPtr> handlers); |
| 52 |
| 53 // The callback function for base::RepeatingTimer. This function updates the |
| 54 // "loading..." animation in the context-menu item. |
| 55 void OnAnimationTimerExpired(); |
| 56 |
| 57 // The bridge service. |
| 58 ArcBridgeService* const bridge_service_; |
| 59 |
| 60 RenderViewContextMenuProxy* proxy_; |
| 61 std::set<int> all_command_ids_; |
| 62 int main_menu_id_start_; |
| 63 size_t num_main_menu_items_; |
| 64 GURL link_url_; |
| 65 ui::SimpleMenuModel sub_menu_; |
| 66 |
| 67 // The string used for animation until we receive a response from the ARC |
| 68 // process. The current animation just adds periods at the end of this string: |
| 69 // 'Loading' -> 'Loading.' -> 'Loading..' -> 'Loading...' (-> 'Loading') |
| 70 base::string16 loading_message_; |
| 71 size_t loading_frame_; |
| 72 |
| 73 // A timer used for loading animation. |
| 74 base::RepeatingTimer animation_timer_; |
| 75 |
| 76 // A map from a command ID to a handler. |
| 77 std::unordered_map<int, UrlHandlerInfoPtr> handlers_; |
| 78 |
| 79 // Always keep this the last member of this class to make sure it's the |
| 80 // first thing to be destructed. |
| 81 base::WeakPtrFactory<OpenWithMenuControllerDelegate> weak_ptr_factory_; |
| 82 |
| 83 DISALLOW_COPY_AND_ASSIGN(OpenWithMenuControllerDelegate); |
| 84 }; |
| 85 |
| 86 } // namespace arc |
| 87 |
| 88 #endif // CHROME_BROWSER_CHROMEOS_ARC_OPEN_WITH_MENU_CONTROLLER_DELEGATE_H_ |
OLD | NEW |