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.
5 #include "chrome/browser/ui/views/tab_contents/render_view_context_menu_win.h"
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"
16 using content::WebContents
;
18 RenderViewContextMenuWin::RenderViewContextMenuWin(
19 WebContents
* web_contents
,
20 const content::ContextMenuParams
& params
)
21 : RenderViewContextMenuViews(web_contents
, params
) {
24 RenderViewContextMenuWin::~RenderViewContextMenuWin() {
28 RenderViewContextMenuViews
* RenderViewContextMenuViews::Create(
29 content::WebContents
* web_contents
,
30 const content::ContextMenuParams
& params
) {
31 return new RenderViewContextMenuWin(web_contents
, params
);
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
) {
40 return RenderViewContextMenu::IsCommandIdVisible(command_id
);
43 void RenderViewContextMenuWin::ExecuteCommand(int command_id
,
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.
58 chrome::FindTabbedBrowser(profile_
->GetOriginalProfile(),
60 chrome::HOST_DESKTOP_TYPE_NATIVE
);
62 content::OpenURLParams
url_params(
64 content::Referrer(params_
.frame_url
.is_empty() ?
65 params_
.page_url
: params_
.frame_url
,
66 params_
.referrer_policy
),
68 content::PAGE_TRANSITION_LINK
,
70 WebContents
* source_web_contents
=
71 browser
->tab_strip_model()->GetActiveWebContents();
72 WebContents
* new_contents
= source_web_contents
->OpenURL(url_params
);
77 RenderViewContextMenu::ExecuteCommand(command_id
, event_flags
);