1 // Copyright 2014 Samsung Electronics. 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 #include "content/shell/browser/shell_web_contents_view_delegate.h"
8 #include <Elementary.h>
10 #include "base/command_line.h"
11 #include "content/public/browser/render_view_host.h"
12 #include "content/shell/browser/shell.h"
13 #include "content/shell/browser/shell_browser_context.h"
14 #include "content/shell/browser/shell_content_browser_client.h"
15 #include "content/shell/browser/shell_devtools_frontend.h"
16 #include "content/shell/common/shell_switches.h"
17 #include "third_party/WebKit/public/web/WebContextMenuData.h"
19 using blink::WebContextMenuData;
25 static Evas_Object* g_context_menu = NULL;
27 void OpenInNewWindow(void* data, Evas_Object*, void*) {
28 const ContextMenuParams* params =
29 static_cast<const ContextMenuParams*>(data);
30 ShellBrowserContext* browser_context =
31 ShellContentBrowserClient::Get()->browser_context();
32 Shell::CreateNewWindow(browser_context,
38 void StartDragging(void* data, Evas_Object*, void*) {
39 WebContents* wc = static_cast<WebContents*>(data);
40 RenderViewHost* rvh = wc->GetRenderViewHost();
41 #if !defined(EWK_BRINGUP)
46 void Cut(void* data, Evas_Object*, void*) {
47 WebContents* wc = static_cast<WebContents*>(data);
51 void Copy(void* data, Evas_Object*, void*) {
52 WebContents* wc = static_cast<WebContents*>(data);
56 void Paste(void* data, Evas_Object*, void*) {
57 WebContents* wc = static_cast<WebContents*>(data);
61 void Delete(void* data, Evas_Object*, void*) {
62 WebContents* wc = static_cast<WebContents*>(data);
66 void Forward(void* data, Evas_Object*, void*) {
67 WebContents* wc = static_cast<WebContents*>(data);
68 wc->GetController().GoToOffset(1);
72 void Back(void* data, Evas_Object*, void*) {
73 WebContents* wc = static_cast<WebContents*>(data);
74 wc->GetController().GoToOffset(-1);
78 void Reload(void* data, Evas_Object*, void*) {
79 WebContents* wc = static_cast<WebContents*>(data);
80 wc->GetController().Reload(false);
86 WebContentsViewDelegate* CreateShellWebContentsViewDelegate(
87 WebContents* web_contents) {
88 return new ShellWebContentsViewDelegate(web_contents);
91 ShellWebContentsViewDelegate::ShellWebContentsViewDelegate(
92 WebContents* web_contents)
93 : web_contents_(web_contents) {
96 ShellWebContentsViewDelegate::~ShellWebContentsViewDelegate() {
99 void ShellWebContentsViewDelegate::ShowContextMenu(
100 RenderFrameHost* render_frame_host,
101 const ContextMenuParams& params) {
102 #if !defined(EWK_BRINGUP)
103 // [M47_2526] Temporary disabling the codes for switching to new chromium
105 if (base::CommandLine::ForCurrentProcess()->
106 HasSwitch(switches::kDumpRenderTree))
110 if (g_context_menu) {
111 elm_menu_close(g_context_menu);
112 evas_object_del(g_context_menu);
117 bool has_link = !params.unfiltered_link_url.is_empty();
118 Evas_Object* parent =
119 static_cast<Evas_Object*>(web_contents_->GetContentNativeView());
121 Evas_Object* menu = elm_menu_add(parent);
122 Elm_Object_Item* menu_it = NULL;
125 elm_menu_item_add(menu, NULL, NULL, "Open in new window",
126 OpenInNewWindow, ¶ms_);
127 elm_menu_item_separator_add(menu, NULL);
130 #if !defined(EWK_BRINGUP)
131 if (params.is_draggable) {
132 elm_menu_item_add(menu, NULL, NULL, "Start dragging",
133 StartDragging, web_contents_);
137 if (params_.is_editable) {
138 menu_it = elm_menu_item_add(menu, NULL, NULL, "Cut",
140 elm_object_item_disabled_set(menu_it,
141 (params_.edit_flags & WebContextMenuData::CanCut) == 0);
142 menu_it = elm_menu_item_add(menu, NULL, NULL, "Copy",
143 Copy, web_contents_);
144 elm_object_item_disabled_set(menu_it,
145 (params_.edit_flags & WebContextMenuData::CanCopy) == 0);
146 menu_it = elm_menu_item_add(menu, NULL, NULL, "Paste",
147 Paste, web_contents_);
148 elm_object_item_disabled_set(menu_it,
149 (params_.edit_flags & WebContextMenuData::CanPaste) == 0);
150 menu_it = elm_menu_item_add(menu, NULL, "delete", "Delete",
151 Delete, web_contents_);
152 elm_object_item_disabled_set(menu_it,
153 (params_.edit_flags & WebContextMenuData::CanDelete) == 0);
154 elm_menu_item_separator_add(menu, NULL);
157 menu_it = elm_menu_item_add(menu, NULL, "back", "Back",
158 Back, web_contents_);
159 elm_object_item_disabled_set(menu_it,
160 !web_contents_->GetController().CanGoBack());
161 menu_it = elm_menu_item_add(menu, NULL, "forward", "Forward",
162 Forward, web_contents_);
163 elm_object_item_disabled_set(menu_it,
164 !web_contents_->GetController().CanGoForward());
165 elm_menu_item_add(menu, NULL, "reload", "Reload",
166 Reload, web_contents_);
168 g_context_menu = menu;
169 elm_menu_move(menu, params.x, params.y);
170 evas_object_show(menu);
173 } // namespace content