1// Copyright 2014 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/context_menu_content_type_platform_app.h"
6
7#include "base/command_line.h"
8#include "chrome/common/chrome_switches.h"
9#include "extensions/common/extension.h"
10#include "extensions/common/manifest.h"
11
12ContextMenuContentTypePlatformApp::ContextMenuContentTypePlatformApp(
13    content::WebContents* web_contents,
14    const content::ContextMenuParams& params)
15    : ContextMenuContentType(web_contents, params, false) {
16}
17
18ContextMenuContentTypePlatformApp::~ContextMenuContentTypePlatformApp() {
19}
20
21bool ContextMenuContentTypePlatformApp::SupportsGroup(int group) {
22  const extensions::Extension* platform_app = GetExtension();
23
24  // The RVH might be for a process sandboxed from the extension.
25  if (!platform_app)
26    return false;
27
28  DCHECK(platform_app->is_platform_app());
29
30  switch (group) {
31    // Add undo/redo, cut/copy/paste etc for text fields.
32    case ITEM_GROUP_EDITABLE:
33    case ITEM_GROUP_COPY:
34      return ContextMenuContentType::SupportsGroup(group);
35    case ITEM_GROUP_CURRENT_EXTENSION:
36      return true;
37    case ITEM_GROUP_DEVTOOLS_UNPACKED_EXT:
38      // Add dev tools for unpacked extensions.
39      return extensions::Manifest::IsUnpackedLocation(
40                 platform_app->location()) ||
41             CommandLine::ForCurrentProcess()->HasSwitch(
42                 switches::kDebugPackedApps);
43    default:
44      return false;
45  }
46}
47