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_RENDERER_CONTEXT_MENU_ARC_APP_MENU_OBSERVER_CHROMEOS_H_ |
| 6 #define CHROME_BROWSER_RENDERER_CONTEXT_MENU_ARC_APP_MENU_OBSERVER_CHROMEOS_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 // An observer that listens to events from the RenderViewContextMenu class and |
| 23 // shows app names received from ARC that can handle the current URL. |
| 24 class ArcAppMenuObserver : public RenderViewContextMenuObserver { |
| 25 public: |
| 26 explicit ArcAppMenuObserver(RenderViewContextMenuProxy* proxy); |
| 27 ~ArcAppMenuObserver() override; |
| 28 |
| 29 // RenderViewContextMenuObserver implementation. |
| 30 void InitMenu(const content::ContextMenuParams& params) override; |
| 31 bool IsCommandIdSupported(int command_id) override; |
| 32 bool IsCommandIdChecked(int command_id) override; |
| 33 bool IsCommandIdEnabled(int command_id) override; |
| 34 void ExecuteCommand(int command_id) override; |
| 35 void OnMenuCancel() override; |
| 36 |
| 37 static std::set<int> GetCommandIdsToEnableForTesting(size_t num_apps); |
| 38 static std::set<int> GetCommandIdsToDisableForTesting(size_t num_apps); |
| 39 static int GetIndexForCommandIdForTesting(int command_id); |
| 40 |
| 41 private: |
| 42 base::string16 GetLabelForCommandId(int command_id) const; |
| 43 arc::IntentHelperInstance* GetIntentHelper(); |
| 44 |
| 45 // A callback function called when a mojo IPC issued in InitMenu finishes. |
| 46 void OnUrlHandlerList(mojo::Array<arc::UrlHandlerInfoPtr> handlers); |
| 47 |
| 48 // The callback function for base::RepeatingTimer. This function updates the |
| 49 // "loading..." animation in the context-menu item. |
| 50 void OnAnimationTimerExpired(); |
| 51 |
| 52 // The interface to add a context-menu item and update it. This class uses |
| 53 // this interface to avoid accesing context-menu items directly. |
| 54 RenderViewContextMenuProxy* proxy_; |
| 55 |
| 56 const std::set<int> all_command_ids_; |
| 57 GURL link_url_; |
| 58 mojo::Array<arc::UrlHandlerInfoPtr> handlers_; |
| 59 ui::SimpleMenuModel sub_menu_; |
| 60 |
| 61 // The string used for animation until we receive a response from the ARC |
| 62 // process. The current animation just adds periods at the end of this string: |
| 63 // 'Loading' -> 'Loading.' -> 'Loading..' -> 'Loading...' (-> 'Loading') |
| 64 base::string16 loading_message_; |
| 65 size_t loading_frame_; |
| 66 |
| 67 // A timer used for loading animation. |
| 68 base::RepeatingTimer animation_timer_; |
| 69 |
| 70 // Always keep this the last member of this class to make sure it's the |
| 71 // first thing to be destructed. |
| 72 base::WeakPtrFactory<ArcAppMenuObserver> weak_ptr_factory_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(ArcAppMenuObserver); |
| 75 }; |
| 76 |
| 77 #endif // CHROME_BROWSER_RENDERER_CONTEXT_MENU_ARC_APP_MENU_OBSERVER_CHROMEOS_H
_ |
OLD | NEW |