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

Unified Diff: chrome/browser/renderer_context_menu/arc_app_menu_observer_chromeos.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: address comments 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/renderer_context_menu/arc_app_menu_observer_chromeos.h
diff --git a/chrome/browser/renderer_context_menu/arc_app_menu_observer_chromeos.h b/chrome/browser/renderer_context_menu/arc_app_menu_observer_chromeos.h
new file mode 100644
index 0000000000000000000000000000000000000000..2fb691dd76b8a0c6383c9938dc715322dc9dd914
--- /dev/null
+++ b/chrome/browser/renderer_context_menu/arc_app_menu_observer_chromeos.h
@@ -0,0 +1,77 @@
+// 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_RENDERER_CONTEXT_MENU_ARC_APP_MENU_OBSERVER_CHROMEOS_H_
+#define CHROME_BROWSER_RENDERER_CONTEXT_MENU_ARC_APP_MENU_OBSERVER_CHROMEOS_H_
+
+#include <set>
+
+#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;
+
+// An observer that listens to events from the RenderViewContextMenu class and
+// shows app names received from ARC that can handle the current URL.
+class ArcAppMenuObserver : public RenderViewContextMenuObserver {
+ public:
+ explicit ArcAppMenuObserver(RenderViewContextMenuProxy* proxy);
+ ~ArcAppMenuObserver() override;
+
+ // RenderViewContextMenuObserver implementation.
+ void InitMenu(const content::ContextMenuParams& params) override;
+ bool IsCommandIdSupported(int command_id) override;
+ bool IsCommandIdChecked(int command_id) override;
+ bool IsCommandIdEnabled(int command_id) override;
+ void ExecuteCommand(int command_id) override;
+ void OnMenuCancel() override;
+
+ static std::set<int> GetCommandIdsToEnableForTesting(size_t num_apps);
+ static std::set<int> GetCommandIdsToDisableForTesting(size_t num_apps);
+ static int GetIndexForCommandIdForTesting(int command_id);
+
+ private:
+ base::string16 GetLabelForCommandId(int command_id) const;
+ arc::IntentHelperInstance* GetIntentHelper();
+
+ // A callback function called when a mojo IPC issued in InitMenu finishes.
+ void OnUrlHandlerList(mojo::Array<arc::UrlHandlerInfoPtr> handlers);
+
+ // The callback function for base::RepeatingTimer. This function updates the
+ // "loading..." animation in the context-menu item.
+ void OnAnimationTimerExpired();
+
+ // The interface to add a context-menu item and update it. This class uses
+ // this interface to avoid accesing context-menu items directly.
+ RenderViewContextMenuProxy* proxy_;
+
+ const std::set<int> all_command_ids_;
+ GURL link_url_;
+ mojo::Array<arc::UrlHandlerInfoPtr> handlers_;
+ 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_;
+
+ // Always keep this the last member of this class to make sure it's the
+ // first thing to be destructed.
+ base::WeakPtrFactory<ArcAppMenuObserver> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(ArcAppMenuObserver);
+};
+
+#endif // CHROME_BROWSER_RENDERER_CONTEXT_MENU_ARC_APP_MENU_OBSERVER_CHROMEOS_H_

Powered by Google App Engine
This is Rietveld 408576698