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

Side by Side 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 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 #include "chrome/browser/renderer_context_menu/open_with_menu_observer.h"
6
7 #include "chrome/app/chrome_command_ids.h"
8 #include "content/public/browser/browser_thread.h"
9 #include "content/public/common/context_menu_params.h"
10
11 #if defined(USE_ASH)
12 #include "ash/renderer_context_menu/open_with_menu_controller.h"
13 #include "ash/shell.h"
14
15 namespace {
16
17 const size_t kMaxOpenWithMenuItems =
18 IDC_CONTENT_CONTEXT_OPEN_WITH_LAST - IDC_CONTENT_CONTEXT_OPEN_WITH1 + 1;
19
20 ash::OpenWithMenuController* GetController() {
21 if (!ash::Shell::HasInstance())
22 return nullptr;
23 return ash::Shell::GetInstance()->open_with_menu_controller();
24 }
25
26 } // namespace
27 #endif
28
29 OpenWithMenuObserver::OpenWithMenuObserver(RenderViewContextMenuProxy* proxy)
30 : proxy_(proxy), num_items_initially_enabled_(0) {}
31
32 OpenWithMenuObserver::~OpenWithMenuObserver() {}
33
34 void OpenWithMenuObserver::InitMenu(const content::ContextMenuParams& params) {
35 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
36 if (params.link_url.is_empty())
37 return;
38 #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
39 ash::OpenWithMenuController* controller = GetController();
40 if (controller) {
41 num_items_initially_enabled_ = controller->PopulateOpenWithMenu(
42 proxy_, IDC_CONTENT_CONTEXT_OPEN_WITH1, kMaxOpenWithMenuItems,
43 params.link_url);
44 }
45 #endif
46 }
47
48 bool OpenWithMenuObserver::IsCommandIdSupported(int command_id) {
49 return (command_id >= IDC_CONTENT_CONTEXT_OPEN_WITH1) &&
50 (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
51 }
52
53 bool OpenWithMenuObserver::IsCommandIdChecked(int command_id) {
54 return false;
55 }
56
57 bool OpenWithMenuObserver::IsCommandIdEnabled(int command_id) {
58 return (command_id >= IDC_CONTENT_CONTEXT_OPEN_WITH1) &&
59 (command_id <
60 IDC_CONTENT_CONTEXT_OPEN_WITH1 + num_items_initially_enabled_);
61 }
62
63 void OpenWithMenuObserver::ExecuteCommand(int command_id) {
64 #if defined(USE_ASH)
65 ash::OpenWithMenuController* controller = GetController();
66 if (controller) {
67 controller->ExecuteCommand(command_id);
68 controller->MenuClosed();
69 }
70 #endif
71 }
72
73 void OpenWithMenuObserver::OnMenuCancel() {
74 #if defined(USE_ASH)
75 ash::OpenWithMenuController* controller = GetController();
76 if (controller)
77 controller->MenuClosed();
78 #endif
79 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698