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

Unified Diff: chrome/browser/chromeos/arc/open_with_menu_controller_delegate.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: return std::pair Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/arc/open_with_menu_controller_delegate.h
diff --git a/chrome/browser/chromeos/arc/open_with_menu_controller_delegate.h b/chrome/browser/chromeos/arc/open_with_menu_controller_delegate.h
new file mode 100644
index 0000000000000000000000000000000000000000..cc355f4f9987ea4e9be24ceeacb952699515c1dc
--- /dev/null
+++ b/chrome/browser/chromeos/arc/open_with_menu_controller_delegate.h
@@ -0,0 +1,88 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_ARC_OPEN_WITH_MENU_CONTROLLER_DELEGATE_H_
+#define CHROME_BROWSER_CHROMEOS_ARC_OPEN_WITH_MENU_CONTROLLER_DELEGATE_H_
+
+#include <unordered_map>
+
hidehiko 2016/03/16 02:23:53 nit: #include <utility> here for std::pair
Yusuke Sato 2016/03/31 14:46:29 Done.
+#include "base/compiler_specific.h"
+#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
+#include "base/strings/string16.h"
+#include "base/timer/timer.h"
+#include "components/arc/common/intent_helper.mojom.h"
+#include "components/renderer_context_menu/render_view_context_menu_observer.h"
+#include "ui/base/models/simple_menu_model.h"
+#include "url/gurl.h"
+
+class RenderViewContextMenuProxy;
+
+namespace arc {
+
+class ArcBridgeService;
+
+// A class for populating "Open with <ARC app>" menu items in a renderer context
+// menu.
+class OpenWithMenuControllerDelegate {
+ public:
+ using HandlerMap = std::unordered_map<int, UrlHandlerInfoPtr>;
+
+ explicit OpenWithMenuControllerDelegate(ArcBridgeService* bridge_service);
+ ~OpenWithMenuControllerDelegate();
+
+ int Init(RenderViewContextMenuProxy* proxy,
+ int main_menu_id_start,
+ size_t num_main_menu_items,
+ const GURL& url);
+ void ExecuteCommand(int id);
+
+ static std::pair<HandlerMap, int> BuildHandlersMapForTesting(
+ int menu_id_start,
+ size_t num_menu_items,
+ mojo::Array<UrlHandlerInfoPtr> handlers);
+
+ private:
+ base::string16 GetLabelForCommandId(int command_id) const;
+ IntentHelperInstance* GetIntentHelper();
+
+ // A callback function called when a mojo IPC issued in InitMenu finishes.
+ void OnUrlHandlerList(mojo::Array<UrlHandlerInfoPtr> handlers);
+
+ // The callback function for base::RepeatingTimer. This function updates the
+ // "loading..." animation in the context-menu item.
+ void OnAnimationTimerExpired();
+
+ // The bridge service.
+ ArcBridgeService* const bridge_service_;
+
+ RenderViewContextMenuProxy* proxy_;
+ std::set<int> all_command_ids_;
+ int main_menu_id_start_;
+ size_t num_main_menu_items_;
+ GURL link_url_;
+ ui::SimpleMenuModel sub_menu_;
+
+ // The string used for animation until we receive a response from the ARC
+ // process. The current animation just adds periods at the end of this string:
+ // 'Loading' -> 'Loading.' -> 'Loading..' -> 'Loading...' (-> 'Loading')
+ base::string16 loading_message_;
+ size_t loading_frame_;
+
+ // A timer used for loading animation.
+ base::RepeatingTimer animation_timer_;
+
+ // A map from a command ID to a handler.
+ HandlerMap handlers_;
+
+ // Always keep this the last member of this class to make sure it's the
+ // first thing to be destructed.
+ base::WeakPtrFactory<OpenWithMenuControllerDelegate> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(OpenWithMenuControllerDelegate);
+};
+
+} // namespace arc
+
+#endif // CHROME_BROWSER_CHROMEOS_ARC_OPEN_WITH_MENU_CONTROLLER_DELEGATE_H_

Powered by Google App Engine
This is Rietveld 408576698