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

Unified Diff: chrome/browser/renderer_context_menu/open_with_menu_observer.cc

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: fix unit_tests 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/open_with_menu_observer.cc
diff --git a/chrome/browser/renderer_context_menu/open_with_menu_observer.cc b/chrome/browser/renderer_context_menu/open_with_menu_observer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4f4ad713ae86024acb50d19f0f7a455a47b4cd0c
--- /dev/null
+++ b/chrome/browser/renderer_context_menu/open_with_menu_observer.cc
@@ -0,0 +1,79 @@
+// 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.
+
+#include "chrome/browser/renderer_context_menu/open_with_menu_observer.h"
+
+#include "chrome/app/chrome_command_ids.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/common/context_menu_params.h"
+
+#if defined(USE_ASH)
+#include "ash/renderer_context_menu/open_with_menu_controller.h"
+#include "ash/shell.h"
+
+namespace {
+
+const size_t kMaxOpenWithMenuItems =
+ IDC_CONTENT_CONTEXT_OPEN_WITH_LAST - IDC_CONTENT_CONTEXT_OPEN_WITH1 + 1;
+
+ash::OpenWithMenuController* GetController() {
+ if (!ash::Shell::HasInstance())
+ return nullptr;
+ return ash::Shell::GetInstance()->open_with_menu_controller();
+}
+
+} // namespace
+#endif
+
+OpenWithMenuObserver::OpenWithMenuObserver(RenderViewContextMenuProxy* proxy)
+ : proxy_(proxy), num_items_initially_enabled_(0) {}
+
+OpenWithMenuObserver::~OpenWithMenuObserver() {}
+
+void OpenWithMenuObserver::InitMenu(const content::ContextMenuParams& params) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ if (params.link_url.is_empty())
+ return;
+#if defined(USE_ASH)
hidehiko 2016/03/14 12:07:05 No error handling is needed?
Yusuke Sato 2016/03/15 00:00:13 For non-ASH configurations, InitMenu does nothing
+ ash::OpenWithMenuController* controller = GetController();
+ if (controller) {
+ num_items_initially_enabled_ = controller->PopulateOpenWithMenu(
+ proxy_, IDC_CONTENT_CONTEXT_OPEN_WITH1, kMaxOpenWithMenuItems,
+ params.link_url);
+ }
+#endif
+}
+
+bool OpenWithMenuObserver::IsCommandIdSupported(int command_id) {
+ return (command_id >= IDC_CONTENT_CONTEXT_OPEN_WITH1) &&
+ (command_id <= IDC_CONTENT_CONTEXT_OPEN_WITH_LAST);
hidehiko 2016/03/14 12:07:05 Handled value range was changed from, at least, PS
Yusuke Sato 2016/03/15 00:00:13 PS4's also works fine, but was overkill. The funct
+}
+
+bool OpenWithMenuObserver::IsCommandIdChecked(int command_id) {
+ return false;
+}
+
+bool OpenWithMenuObserver::IsCommandIdEnabled(int command_id) {
+ return (command_id >= IDC_CONTENT_CONTEXT_OPEN_WITH1) &&
+ (command_id <
+ IDC_CONTENT_CONTEXT_OPEN_WITH1 + num_items_initially_enabled_);
+}
+
+void OpenWithMenuObserver::ExecuteCommand(int command_id) {
+#if defined(USE_ASH)
+ ash::OpenWithMenuController* controller = GetController();
+ if (controller) {
+ controller->ExecuteCommand(command_id);
+ controller->MenuClosed();
+ }
+#endif
+}
+
+void OpenWithMenuObserver::OnMenuCancel() {
+#if defined(USE_ASH)
+ ash::OpenWithMenuController* controller = GetController();
+ if (controller)
+ controller->MenuClosed();
+#endif
+}

Powered by Google App Engine
This is Rietveld 408576698