Commit cf8c4908 authored by oshima@chromium.org's avatar oshima@chromium.org

Separate chrome independent part from RVContextMenu

 and move it to components/renderer_context_menu/renderer_view_context_menu_base.{h|cc}

BUG=397320
TBR=blundell@chromium.org

Review URL: https://codereview.chromium.org/432003007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287971 0039d316-1c4b-4281-b951-d872f2087c98
parent 0f9e5b14
......@@ -15,6 +15,7 @@
#include "chrome/browser/extensions/context_menu_matcher.h"
#include "chrome/browser/extensions/menu_manager.h"
#include "components/renderer_context_menu/context_menu_content_type.h"
#include "components/renderer_context_menu/render_view_context_menu_base.h"
#include "components/renderer_context_menu/render_view_context_menu_observer.h"
#include "components/renderer_context_menu/render_view_context_menu_proxy.h"
#include "content/public/common/context_menu_params.h"
......@@ -46,99 +47,20 @@ struct WebMediaPlayerAction;
struct WebPluginAction;
}
class RenderViewContextMenu : public ui::SimpleMenuModel::Delegate,
public RenderViewContextMenuProxy {
class RenderViewContextMenu : public RenderViewContextMenuBase {
public:
// A delegate interface to communicate with the toolkit used by
// the embedder.
class ToolkitDelegate {
public:
virtual ~ToolkitDelegate() {}
// Initialize the toolkit's menu.
virtual void Init(ui::SimpleMenuModel* menu_model) = 0;
virtual void Cancel() = 0;
// Updates the actual menu items controlled by the toolkit.
virtual void UpdateMenuItem(int command_id,
bool enabled,
bool hidden,
const base::string16& title) = 0;
};
static const size_t kMaxSelectionTextLength;
// Convert a command ID so that it fits within the range for
// content context menu.
static int ConvertToContentCustomCommandId(int id);
// True if the given id is the one generated for content context menu.
static bool IsContentCustomCommandId(int id);
RenderViewContextMenu(content::RenderFrameHost* render_frame_host,
const content::ContextMenuParams& params);
virtual ~RenderViewContextMenu();
// Initializes the context menu.
void Init();
// Programmatically closes the context menu.
void Cancel();
const ui::SimpleMenuModel& menu_model() const { return menu_model_; }
const content::ContextMenuParams& params() const { return params_; }
// SimpleMenuModel::Delegate implementation.
// SimpleMenuModel::Delegate:
virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
virtual void MenuWillShow(ui::SimpleMenuModel* source) OVERRIDE;
virtual void MenuClosed(ui::SimpleMenuModel* source) OVERRIDE;
// RenderViewContextMenuProxy implementation.
virtual void AddMenuItem(int command_id,
const base::string16& title) OVERRIDE;
virtual void AddCheckItem(int command_id,
const base::string16& title) OVERRIDE;
virtual void AddSeparator() OVERRIDE;
virtual void AddSubMenu(int command_id,
const base::string16& label,
ui::MenuModel* model) OVERRIDE;
virtual void UpdateMenuItem(int command_id,
bool enabled,
bool hidden,
const base::string16& title) OVERRIDE;
virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE;
virtual content::WebContents* GetWebContents() const OVERRIDE;
virtual content::BrowserContext* GetBrowserContext() const OVERRIDE;
protected:
void set_toolkit_delegate(scoped_ptr<ToolkitDelegate> delegate) {
toolkit_delegate_ = delegate.Pass();
}
ToolkitDelegate* toolkit_delegate() {
return toolkit_delegate_.get();
}
void InitMenu();
Profile* GetProfile();
// Platform specific functions.
virtual bool GetAcceleratorForCommandId(
int command_id,
ui::Accelerator* accelerator) = 0;
virtual void AppendPlatformEditableItems();
content::ContextMenuParams params_;
content::WebContents* source_web_contents_;
// The RenderFrameHost's IDs.
int render_process_id_;
int render_frame_id_;
content::BrowserContext* browser_context_;
ui::SimpleMenuModel menu_model_;
extensions::ContextMenuMatcher extension_items_;
private:
......@@ -154,9 +76,19 @@ class RenderViewContextMenu : public ui::SimpleMenuModel::Delegate,
static bool MenuItemMatchesParams(const content::ContextMenuParams& params,
const extensions::MenuItem* item);
// RenderViewContextMenuBase:
virtual void InitMenu() OVERRIDE;
virtual void RecordShownItem(int id) OVERRIDE;
virtual void RecordUsedItem(int id) OVERRIDE;
#if defined(ENABLE_PLUGINS)
virtual void HandleAuthorizeAllPlugins() OVERRIDE;
#endif
virtual void NotifyMenuShown() OVERRIDE;
virtual void NotifyURLOpened(const GURL& url,
content::WebContents* new_contents) OVERRIDE;
// Gets the extension (if any) associated with the WebContents that we're in.
const extensions::Extension* GetExtension() const;
bool AppendCustomItems();
void AppendDeveloperItems();
void AppendDevtoolsForUnpackedExtensions();
......@@ -181,11 +113,6 @@ class RenderViewContextMenu : public ui::SimpleMenuModel::Delegate,
void AppendSpellcheckOptionsSubMenu();
void AppendProtocolHandlerSubMenu();
// Opens the specified URL string in a new tab.
void OpenURL(const GURL& url, const GURL& referrer,
WindowOpenDisposition disposition,
content::PageTransition transition);
// Copy to the clipboard an image located at a point in the RenderView
void CopyImageAt(int x, int y);
......@@ -231,17 +158,6 @@ class RenderViewContextMenu : public ui::SimpleMenuModel::Delegate,
scoped_ptr<PrintPreviewContextMenuObserver> print_preview_menu_observer_;
#endif
// Our observers.
mutable ObserverList<RenderViewContextMenuObserver> observers_;
// Whether a command has been executed. Used to track whether menu observers
// should be notified of menu closing without execution.
bool command_executed_;
scoped_ptr<ContextMenuContentType> content_type_;
scoped_ptr<ToolkitDelegate> toolkit_delegate_;
DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenu);
};
......
......@@ -44,7 +44,6 @@
'pref_registry.gypi',
'query_parser.gypi',
'rappor.gypi',
'renderer_context_menu.gypi',
'search.gypi',
'search_provider_logos.gypi',
'signin.gypi',
......@@ -103,6 +102,7 @@
'includes': [
'autocomplete.gypi',
'gcm_driver.gypi',
'renderer_context_menu.gypi',
'search_engines.gypi',
'sync_driver.gypi',
'invalidation.gypi',
......
......@@ -9,6 +9,8 @@
'dependencies': [
'../base/base.gyp:base',
'../content/content.gyp:content_browser',
'../components/components.gyp:search_engines',
'../components/components.gyp:component_metrics_proto',
],
'include_dirs': [
'..',
......@@ -18,6 +20,8 @@
'renderer_context_menu/context_menu_content_type.h',
'renderer_context_menu/context_menu_delegate.cc',
'renderer_context_menu/context_menu_delegate.h',
'renderer_context_menu/render_view_context_menu_base.cc',
'renderer_context_menu/render_view_context_menu_base.h',
'renderer_context_menu/render_view_context_menu_observer.cc',
'renderer_context_menu/render_view_context_menu_observer.h',
'renderer_context_menu/render_view_context_menu_proxy.h',
......
// Copyright 2014 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 COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_BASE_H_
#define COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_BASE_H_
#include <map>
#include <string>
#include "base/memory/scoped_ptr.h"
#include "base/observer_list.h"
#include "base/strings/string16.h"
#include "components/renderer_context_menu/context_menu_content_type.h"
#include "components/renderer_context_menu/render_view_context_menu_observer.h"
#include "components/renderer_context_menu/render_view_context_menu_proxy.h"
#include "content/public/common/context_menu_params.h"
#include "content/public/common/page_transition_types.h"
#include "ui/base/models/simple_menu_model.h"
#include "ui/base/window_open_disposition.h"
namespace content {
class RenderFrameHost;
class WebContents;
}
namespace gfx {
class Point;
}
namespace blink {
struct WebMediaPlayerAction;
struct WebPluginAction;
}
class RenderViewContextMenuBase : public ui::SimpleMenuModel::Delegate,
public RenderViewContextMenuProxy {
public:
// A delegate interface to communicate with the toolkit used by
// the embedder.
class ToolkitDelegate {
public:
virtual ~ToolkitDelegate() {}
// Initialize the toolkit's menu.
virtual void Init(ui::SimpleMenuModel* menu_model) = 0;
virtual void Cancel() = 0;
// Updates the actual menu items controlled by the toolkit.
virtual void UpdateMenuItem(int command_id,
bool enabled,
bool hidden,
const base::string16& title) = 0;
};
static const size_t kMaxSelectionTextLength;
static void SetContentCustomCommandIdRange(int first, int last);
// Convert a command ID so that it fits within the range for
// content context menu.
static int ConvertToContentCustomCommandId(int id);
// True if the given id is the one generated for content context menu.
static bool IsContentCustomCommandId(int id);
RenderViewContextMenuBase(content::RenderFrameHost* render_frame_host,
const content::ContextMenuParams& params);
virtual ~RenderViewContextMenuBase();
// Initializes the context menu.
void Init();
// Programmatically closes the context menu.
void Cancel();
const ui::SimpleMenuModel& menu_model() const { return menu_model_; }
const content::ContextMenuParams& params() const { return params_; }
// SimpleMenuModel::Delegate implementation.
virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
virtual void MenuWillShow(ui::SimpleMenuModel* source) OVERRIDE;
virtual void MenuClosed(ui::SimpleMenuModel* source) OVERRIDE;
// RenderViewContextMenuProxy implementation.
virtual void AddMenuItem(int command_id,
const base::string16& title) OVERRIDE;
virtual void AddCheckItem(int command_id,
const base::string16& title) OVERRIDE;
virtual void AddSeparator() OVERRIDE;
virtual void AddSubMenu(int command_id,
const base::string16& label,
ui::MenuModel* model) OVERRIDE;
virtual void UpdateMenuItem(int command_id,
bool enabled,
bool hidden,
const base::string16& title) OVERRIDE;
virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE;
virtual content::WebContents* GetWebContents() const OVERRIDE;
virtual content::BrowserContext* GetBrowserContext() const OVERRIDE;
protected:
friend class RenderViewContextMenuTest;
friend class RenderViewContextMenuPrefsTest;
void set_content_type(ContextMenuContentType* content_type) {
content_type_.reset(content_type);
}
void set_toolkit_delegate(scoped_ptr<ToolkitDelegate> delegate) {
toolkit_delegate_ = delegate.Pass();
}
ToolkitDelegate* toolkit_delegate() {
return toolkit_delegate_.get();
}
// TODO(oshima): Make these methods delegate.
// Menu Construction.
virtual void InitMenu();
// Increments histogram value for used items specified by |id|.
virtual void RecordUsedItem(int id) = 0;
// Increments histogram value for visible context menu item specified by |id|.
virtual void RecordShownItem(int id) = 0;
#if defined(ENABLE_PLUGINS)
virtual void HandleAuthorizeAllPlugins() = 0;
#endif
// Returns the accelerator for given |command_id|.
virtual bool GetAcceleratorForCommandId(
int command_id,
ui::Accelerator* accelerator) = 0;
// Subclasses should send notification.
virtual void NotifyMenuShown() = 0;
virtual void NotifyURLOpened(const GURL& url,
content::WebContents* new_contents) = 0;
// TODO(oshima): Remove this.
virtual void AppendPlatformEditableItems() {}
content::RenderFrameHost* GetRenderFrameHost();
bool IsCustomItemChecked(int id) const;
bool IsCustomItemEnabled(int id) const;
// Opens the specified URL string in a new tab.
void OpenURL(const GURL& url, const GURL& referrer,
WindowOpenDisposition disposition,
content::PageTransition transition);
content::ContextMenuParams params_;
content::WebContents* source_web_contents_;
content::BrowserContext* browser_context_;
ui::SimpleMenuModel menu_model_;
// Our observers.
mutable ObserverList<RenderViewContextMenuObserver> observers_;
// Whether a command has been executed. Used to track whether menu observers
// should be notified of menu closing without execution.
bool command_executed_;
scoped_ptr<ContextMenuContentType> content_type_;
private:
bool AppendCustomItems();
// The RenderFrameHost's IDs.
int render_process_id_;
int render_frame_id_;
scoped_ptr<ToolkitDelegate> toolkit_delegate_;
DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenuBase);
};
#endif // COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_BASE_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment