Minor Cleanup for SafeBrowsingResourceThrottleFactory.
[chromium-blink-merge.git] / components / renderer_context_menu / render_view_context_menu_proxy.h
blob789b149c3e1271dd534755b8fb65f2bcccd69a27
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.
5 #ifndef COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_PROXY_H_
6 #define COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_PROXY_H_
8 #include "base/strings/string16.h"
10 namespace content {
11 class BrowserContext;
12 class RenderViewHost;
13 class WebContents;
16 // An interface that controls a RenderViewContextMenu instance from observers.
17 // This interface is designed mainly for controlling the instance while showing
18 // so we can add a context-menu item that takes long time to create its text,
19 // such as retrieving the item text from a server. The simplest usage is:
20 // 1. Adding an item with temporary text;
21 // 2. Posting a background task that creates the item text, and;
22 // 3. Calling UpdateMenuItem() in the callback function.
23 // The following snippet describes the simple usage that updates a context-menu
24 // item with this interface.
26 // class MyTask : public net::URLFetcherDelegate {
27 // public:
28 // MyTask(RenderViewContextMenuProxy* proxy, int id)
29 // : proxy_(proxy),
30 // id_(id) {
31 // }
32 // virtual ~MyTask() {
33 // }
34 // virtual void OnURLFetchComplete(const net::URLFetcher* source,
35 // const GURL& url,
36 // const net::URLRequestStatus& status,
37 // int response,
38 // const net::ResponseCookies& cookies,
39 // const std::string& data) {
40 // bool enabled = response == 200;
41 // const char* text = enabled ? "OK" : "ERROR";
42 // proxy_->UpdateMenuItem(id_, enabled, base::ASCIIToUTF16(text));
43 // }
44 // void Start(const GURL* url, net::URLRequestContextGetter* context) {
45 // fetcher_.reset(new URLFetcher(url, URLFetcher::GET, this));
46 // fetcher_->SetRequestContext(context);
47 // content::AssociateURLFetcherWithRenderView(
48 // fetcher_.get(),
49 // proxy_->GetRenderViewHost()->GetSiteInstance()->GetSite(),
50 // proxy_->GetRenderViewHost()->GetProcess()->GetID(),
51 // proxy_->GetRenderViewHost()->GetRoutingID());
52 // fetcher_->Start();
53 // }
55 // private:
56 // URLFetcher fetcher_;
57 // RenderViewContextMenuProxy* proxy_;
58 // int id_;
59 // };
61 // void RenderViewContextMenu::AppendEditableItems() {
62 // // Add a menu item with temporary text shown while we create the final
63 // // text.
64 // menu_model_.AddItemWithStringId(IDC_MY_ITEM, IDC_MY_TEXT);
66 // // Start a task that creates the final text.
67 // my_task_ = new MyTask(this, IDC_MY_ITEM);
68 // my_task_->Start(...);
69 // }
71 class RenderViewContextMenuProxy {
72 public:
73 // Add a menu item to a context menu.
74 virtual void AddMenuItem(int command_id, const base::string16& title) = 0;
75 virtual void AddCheckItem(int command_id, const base::string16& title) = 0;
76 virtual void AddSeparator() = 0;
78 // Add a submenu item to a context menu.
79 virtual void AddSubMenu(int command_id,
80 const base::string16& label,
81 ui::MenuModel* model) = 0;
83 // Update the status and text of the specified context-menu item.
84 virtual void UpdateMenuItem(int command_id,
85 bool enabled,
86 bool hidden,
87 const base::string16& title) = 0;
89 // Retrieve the given associated objects with a context menu.
90 virtual content::RenderViewHost* GetRenderViewHost() const = 0;
91 virtual content::WebContents* GetWebContents() const = 0;
92 virtual content::BrowserContext* GetBrowserContext() const = 0;
95 #endif // COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_PROXY_H_