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