summaryrefslogtreecommitdiffstats
path: root/chrome/browser/tab_contents/render_view_context_menu.h
diff options
context:
space:
mode:
authorasargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-23 06:52:41 +0000
committerasargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-23 06:52:41 +0000
commit2e3b520ff4318342b027ea8aa303e5981ea9ce79 (patch)
treef2eba7cf4a7d6179033d9cc0f4bba5981984ec55 /chrome/browser/tab_contents/render_view_context_menu.h
parentd11a34ba95bc98cf2c4b6caa2ce6ed469ae229ce (diff)
downloadchromium_src-2e3b520ff4318342b027ea8aa303e5981ea9ce79.zip
chromium_src-2e3b520ff4318342b027ea8aa303e5981ea9ce79.tar.gz
chromium_src-2e3b520ff4318342b027ea8aa303e5981ea9ce79.tar.bz2
Initial version of an experimental Extensions Context Menu API.
The proposal for the API is documented at: http://dev.chromium.org/developers/design-documents/extensions/context-menu-api Notable limitations in this initial implementation: -No reliable way to get at the unique, actual node clicked on in contexts like IMAGE/LINK/etc. We'll need to fix this in the long run - see the API proposal page for some notes on this. -No update or deleteAll methods ; the only way you can change items is to delete by id and re-add. -We aren't yet matching the UI goal of having the extension items at the top level include the extension icon on the left. This will require a refactoring of RenderViewContextMenu to steal some of the code from the bookmarks bar context menus, which can display favicons. -The only kind of parent->child menu that currently works is if you have a single top-level parent, and only one level of children. (This is because of how RenderViewContextMenu currently works) -No browser tests that the menu items actually get drawn (will wait on those until the above mentioned refactor is complete), or API tests (the API may change a bit based on feedback, at which point I'll write more tests). -Unit tests need to cover some more cases. BUG=32363 TEST=Should be able to create context menus with this API. Review URL: http://codereview.chromium.org/1042003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42321 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents/render_view_context_menu.h')
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.h40
1 files changed, 39 insertions, 1 deletions
diff --git a/chrome/browser/tab_contents/render_view_context_menu.h b/chrome/browser/tab_contents/render_view_context_menu.h
index c06af95..aa90ca9 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.h
+++ b/chrome/browser/tab_contents/render_view_context_menu.h
@@ -1,15 +1,20 @@
-// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_H_
#define CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_H_
+#include <map>
+#include <string>
+#include <vector>
+
#include "base/string16.h"
#include "chrome/common/page_transition_types.h"
#include "webkit/glue/context_menu.h"
#include "webkit/glue/window_open_disposition.h"
+class ExtensionMenuItem;
class Profile;
class TabContents;
@@ -89,6 +94,28 @@ class RenderViewContextMenu {
void AppendCopyItem();
void AppendEditableItems();
void AppendSearchProvider();
+ void AppendAllExtensionItems();
+
+ // When extensions have more than 1 top-level item or a single parent item
+ // with children, we will start a sub menu. In the case of 1 parent with
+ // children, we will remove the parent from |items| and insert the children
+ // into it. The |index| parameter is incremented if we start a submenu. This
+ // returns true if a submenu was started. If we had multiple top-level items
+ // that needed to be pushed into a submenu, we'll use |extension_name| as the
+ // title.
+ bool MaybeStartExtensionSubMenu(const string16& selection_text,
+ const std::string& extension_name,
+ std::vector<const ExtensionMenuItem*>* items,
+ int* index);
+
+ // Fills in |items| with matching items for extension with |extension_id|.
+ void GetItemsForExtension(const std::string& extension_id,
+ std::vector<const ExtensionMenuItem*>* items);
+
+ // This is a helper function to append items for one particular extension.
+ // The |index| parameter is used for assigning id's, and is incremented for
+ // each item actually added.
+ void AppendExtensionItems(const std::string& extension_id, int* index);
// Opens the specified URL string in a new tab. If |in_current_window| is
// false, a new window is created to hold the new tab.
@@ -110,10 +137,21 @@ class RenderViewContextMenu {
bool IsDevCommandEnabled(int id) const;
+ // Returns a (possibly truncated) version of the current selection text
+ // suitable or putting in the title of a menu item.
+ string16 PrintableSelectionText();
+
+ // Attempts to get an ExtensionMenuItem given the id of a context menu item.
+ ExtensionMenuItem* GetExtensionMenuItem(int id) const;
+
// The destination URL to use if the user tries to search for or navigate to
// a text selection.
GURL selection_navigation_url_;
+ // Maps the id from a context menu item to the ExtensionMenuItem's internal
+ // id.
+ std::map<int, int> extension_item_map_;
+
DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenu);
};