Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / tab_contents / render_view_context_menu_win.cc
1 // Copyright (c) 2012 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/ui/views/tab_contents/render_view_context_menu_win.h"
6
7 #include "chrome/app/chrome_command_ids.h"
8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/tab_contents/retargeting_details.h"
11 #include "chrome/browser/ui/browser_finder.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "content/public/browser/web_contents.h"
14 #include "win8/util/win8_util.h"
15
16 using content::WebContents;
17
18 RenderViewContextMenuWin::RenderViewContextMenuWin(
19     content::RenderFrameHost* render_frame_host,
20     const content::ContextMenuParams& params)
21     : RenderViewContextMenuViews(render_frame_host, params) {
22 }
23
24 RenderViewContextMenuWin::~RenderViewContextMenuWin() {
25 }
26
27 // static
28 RenderViewContextMenuViews* RenderViewContextMenuViews::Create(
29     content::RenderFrameHost* render_frame_host,
30     const content::ContextMenuParams& params) {
31   return new RenderViewContextMenuWin(render_frame_host, params);
32 }
33
34 bool RenderViewContextMenuWin::IsCommandIdVisible(int command_id) const {
35   // In windows 8 metro mode no new window option on normal browser windows.
36   if (win8::IsSingleWindowMetroMode() && !profile_->IsOffTheRecord() &&
37       command_id == IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW) {
38     return false;
39   }
40   return RenderViewContextMenu::IsCommandIdVisible(command_id);
41 }
42
43 void RenderViewContextMenuWin::ExecuteCommand(int command_id,
44                                               int event_flags) {
45   if (win8::IsSingleWindowMetroMode() &&
46       command_id == IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW) {
47     // The open link in new window command should only be enabled for
48     // incognito windows in metro mode.
49     DCHECK(profile_->IsOffTheRecord());
50     // We directly go to the Browser object to open the url in effect
51     // bypassing the delegate. Currently the Browser is the only class which
52     // implements the delegate for the context menu. This would break if there
53     // are other delegates for the context menu. This is ok for now as this
54     // code only executes for Windows 8 metro mode.
55     // TODO(robertshield): FTB - Switch this to HOST_DESKTOP_TYPE_ASH when
56     //                     we make that the default for metro.
57     Browser* browser =
58         chrome::FindTabbedBrowser(profile_->GetOriginalProfile(),
59                                   false,
60                                   chrome::HOST_DESKTOP_TYPE_NATIVE);
61     if (browser) {
62       content::OpenURLParams url_params(
63           params_.link_url,
64           content::Referrer(params_.frame_url.is_empty() ?
65                                 params_.page_url : params_.frame_url,
66                             params_.referrer_policy),
67           NEW_FOREGROUND_TAB,
68           content::PAGE_TRANSITION_LINK,
69           false);
70       WebContents* source_web_contents =
71           browser->tab_strip_model()->GetActiveWebContents();
72       WebContents* new_contents = source_web_contents->OpenURL(url_params);
73       DCHECK(new_contents);
74       return;
75     }
76   }
77   RenderViewContextMenu::ExecuteCommand(command_id, event_flags);
78 }