Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: components/arc/intent_helper/open_with_menu_observer.h

Issue 1760773004: Add "Open with <ARC-app-name>" items to the context menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add a missing override; Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 COMPONENTS_ARC_INTENT_HELPER_OPEN_WITH_MENU_CONTROLLER_DELEGATE_H_
6 #define COMPONENTS_ARC_INTENT_HELPER_OPEN_WITH_MENU_CONTROLLER_DELEGATE_H_
7
8 #include <set>
9 #include <unordered_map>
10 #include <utility>
11
12 #include "base/compiler_specific.h"
13 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/strings/string16.h"
16 #include "base/timer/timer.h"
17 #include "components/arc/common/intent_helper.mojom.h"
18 #include "components/renderer_context_menu/render_view_context_menu_observer.h"
19 #include "ui/base/models/simple_menu_model.h"
20 #include "url/gurl.h"
21
22 class RenderViewContextMenuProxy;
23
24 namespace arc {
25
26 class ArcBridgeService;
27
28 // A class for populating "Open with <ARC app>" menu items in a renderer context
29 // menu.
30 class OpenWithMenuObserver : public RenderViewContextMenuObserver {
31 public:
32 using HandlerMap = std::unordered_map<int, UrlHandlerInfoPtr>;
33
34 OpenWithMenuObserver(ArcBridgeService* bridge_service,
35 RenderViewContextMenuProxy* proxy,
36 int main_menu_id_start,
37 size_t num_main_menu_items,
38 int sub_menu_id_start,
39 size_t num_sub_menu_items);
40 ~OpenWithMenuObserver() override;
41
42 // RenderViewContextMenuObserver implementation.
43 void InitMenu(const content::ContextMenuParams& params) override;
44 bool IsCommandIdSupported(int command_id) override;
45 bool IsCommandIdChecked(int command_id) override;
46 bool IsCommandIdEnabled(int command_id) override;
47 void ExecuteCommand(int command_id) override;
48 void OnMenuCancel() override;
49
50 static std::pair<HandlerMap, int> BuildHandlersMapForTesting(
51 int menu_id_start,
52 size_t num_menu_items,
53 int sub_menu_id_start,
54 size_t num_sub_menu_items,
55 mojo::Array<UrlHandlerInfoPtr> handlers);
56
57 private:
58 base::string16 GetLabelForCommandId(int command_id) const;
59 IntentHelperInstance* GetIntentHelper();
60
61 // A callback function called when a mojo IPC issued in InitMenu finishes.
62 void OnUrlHandlerList(mojo::Array<UrlHandlerInfoPtr> handlers);
63
64 // The callback function for base::RepeatingTimer. This function updates the
65 // "loading..." animation in the context-menu item.
66 void OnAnimationTimerExpired();
67
68 // The bridge service.
69 ArcBridgeService* const bridge_service_;
70
71 RenderViewContextMenuProxy* proxy_;
72 std::set<int> all_command_ids_;
73 int main_menu_id_start_;
74 size_t num_main_menu_items_;
75 int sub_menu_id_start_;
76 size_t num_sub_menu_items_;
77 GURL link_url_;
78 ui::SimpleMenuModel sub_menu_;
79
80 // The string used for animation until we receive a response from the ARC
81 // process. The current animation just adds periods at the end of this string:
82 // 'Loading' -> 'Loading.' -> 'Loading..' -> 'Loading...' (-> 'Loading')
83 base::string16 loading_message_;
84 size_t loading_frame_;
85
86 // A timer used for loading animation.
87 base::RepeatingTimer animation_timer_;
88
89 // A map from a command ID to a handler.
90 HandlerMap handlers_;
91
92 // Always keep this the last member of this class to make sure it's the
93 // first thing to be destructed.
94 base::WeakPtrFactory<OpenWithMenuObserver> weak_ptr_factory_;
95
96 DISALLOW_COPY_AND_ASSIGN(OpenWithMenuObserver);
97 };
98
99 } // namespace arc
100
101 #endif // COMPONENTS_ARC_INTENT_HELPER_OPEN_WITH_MENU_CONTROLLER_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698