diff options
author | ananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-04 23:33:30 +0000 |
---|---|---|
committer | ananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-04 23:33:30 +0000 |
commit | 09b5135db1063c1ecef46e75b5f3773f7aeaff27 (patch) | |
tree | 219f0a01817569753633a9457aeffbce213333bd /chrome/browser | |
parent | 7c44902b0b2f37e06cec5a6d38fe8cfb154dcde1 (diff) | |
download | chromium_src-09b5135db1063c1ecef46e75b5f3773f7aeaff27.zip chromium_src-09b5135db1063c1ecef46e75b5f3773f7aeaff27.tar.gz chromium_src-09b5135db1063c1ecef46e75b5f3773f7aeaff27.tar.bz2 |
Ensure that the new window context menu option does not show up in windows 8 metro mode.
When the new window option is executed from the incognito window, we find an existing normal
browser window and open the url in a new tab.
BUG=124404
R=sky
Review URL: https://chromiumcodereview.appspot.com/10442119
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140426 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
6 files changed, 138 insertions, 20 deletions
diff --git a/chrome/browser/external_tab/external_tab_container_win.cc b/chrome/browser/external_tab/external_tab_container_win.cc index 9c06ad8..227c656 100644 --- a/chrome/browser/external_tab/external_tab_container_win.cc +++ b/chrome/browser/external_tab/external_tab_container_win.cc @@ -26,6 +26,7 @@ #include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/repost_form_warning_controller.h" +#include "chrome/browser/tab_contents/render_view_context_menu_win.h" #include "chrome/browser/themes/theme_service.h" #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_creator.h" #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" @@ -34,7 +35,6 @@ #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/browser/ui/views/infobars/infobar_container_view.h" -#include "chrome/browser/ui/views/tab_contents/render_view_context_menu_views.h" #include "chrome/common/automation_messages.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_notification_types.h" @@ -625,9 +625,10 @@ bool ExternalTabContainer::HandleContextMenu( NOTREACHED(); return false; } - external_context_menu_.reset( - new RenderViewContextMenuViews(web_contents(), params)); - external_context_menu_->SetExternal(); + external_context_menu_.reset(RenderViewContextMenuViews::Create( + web_contents(), params)); + static_cast<RenderViewContextMenuWin*>( + external_context_menu_.get())->SetExternal(); external_context_menu_->Init(); external_context_menu_->UpdateMenuItemStates(); diff --git a/chrome/browser/tab_contents/render_view_context_menu_win.cc b/chrome/browser/tab_contents/render_view_context_menu_win.cc new file mode 100644 index 0000000..8493a23 --- /dev/null +++ b/chrome/browser/tab_contents/render_view_context_menu_win.cc @@ -0,0 +1,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::GetMetroModule() && !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::GetMetroModule() && + 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->GetSelectedWebContents(); + WebContents* new_contents = source_web_contents->OpenURL(url_params); + DCHECK(new_contents); + return; + } + } + RenderViewContextMenu::ExecuteCommand(command_id, event_flags); +} + +void RenderViewContextMenuWin::SetExternal() { + external_ = true; +} diff --git a/chrome/browser/tab_contents/render_view_context_menu_win.h b/chrome/browser/tab_contents/render_view_context_menu_win.h new file mode 100644 index 0000000..d6309b9 --- /dev/null +++ b/chrome/browser/tab_contents/render_view_context_menu_win.h @@ -0,0 +1,35 @@ +// 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. + +#ifndef CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_WIN_H_ +#define CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_WIN_H_ +#pragma once + +#include "chrome/browser/ui/views/tab_contents/render_view_context_menu_views.h" + +namespace content { +class WebContents; +} + +// Windows specific implementation of the render view context menu. +class RenderViewContextMenuWin : public RenderViewContextMenuViews { + public: + RenderViewContextMenuWin(content::WebContents* web_contents, + const content::ContextMenuParams& params); + virtual ~RenderViewContextMenuWin(); + + // Set this menu to show for an external tab contents. This + // only has an effect before Init() is called. + void SetExternal(); + + // SimpleMenuModel::Delegate implementation. + virtual bool IsCommandIdVisible(int command_id) const OVERRIDE; + virtual void ExecuteCommand(int command_id) OVERRIDE; + virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenuWin); +}; + +#endif // CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_WIN_H_ diff --git a/chrome/browser/ui/views/tab_contents/chrome_web_contents_view_delegate_views.cc b/chrome/browser/ui/views/tab_contents/chrome_web_contents_view_delegate_views.cc index da6f030..fa2e0af 100644 --- a/chrome/browser/ui/views/tab_contents/chrome_web_contents_view_delegate_views.cc +++ b/chrome/browser/ui/views/tab_contents/chrome_web_contents_view_delegate_views.cc @@ -125,7 +125,8 @@ void ChromeWebContentsViewDelegateViews::RestoreFocus() { void ChromeWebContentsViewDelegateViews::ShowContextMenu( const content::ContextMenuParams& params) { - context_menu_.reset(new RenderViewContextMenuViews(web_contents_, params)); + context_menu_.reset( + RenderViewContextMenuViews::Create(web_contents_, params)); context_menu_->Init(); // Don't show empty menus. diff --git a/chrome/browser/ui/views/tab_contents/render_view_context_menu_views.cc b/chrome/browser/ui/views/tab_contents/render_view_context_menu_views.cc index 056178d..6a8f360 100644 --- a/chrome/browser/ui/views/tab_contents/render_view_context_menu_views.cc +++ b/chrome/browser/ui/views/tab_contents/render_view_context_menu_views.cc @@ -33,6 +33,15 @@ RenderViewContextMenuViews::RenderViewContextMenuViews( RenderViewContextMenuViews::~RenderViewContextMenuViews() { } +#if !defined(OS_WIN) +// static +RenderViewContextMenuViews* RenderViewContextMenuViews::Create + content::WebContents* tab_contents, + const content::ContextMenuParams& params) { + return new RenderViewContextMenuViews(tab_contents, params); +} +#endif // OS_WIN + void RenderViewContextMenuViews::RunMenuAt(views::Widget* parent, const gfx::Point& point) { if (menu_runner_->RunMenuAt(parent, NULL, gfx::Rect(point, gfx::Size()), @@ -41,12 +50,6 @@ void RenderViewContextMenuViews::RunMenuAt(views::Widget* parent, return; } -#if defined(OS_WIN) -void RenderViewContextMenuViews::SetExternal() { - external_ = true; -} -#endif - void RenderViewContextMenuViews::UpdateMenuItemStates() { menu_delegate_->BuildMenu(menu_); } diff --git a/chrome/browser/ui/views/tab_contents/render_view_context_menu_views.h b/chrome/browser/ui/views/tab_contents/render_view_context_menu_views.h index 24e7d15..d9ff728 100644 --- a/chrome/browser/ui/views/tab_contents/render_view_context_menu_views.h +++ b/chrome/browser/ui/views/tab_contents/render_view_context_menu_views.h @@ -24,18 +24,14 @@ class Widget; class RenderViewContextMenuViews : public RenderViewContextMenu { public: - RenderViewContextMenuViews(content::WebContents* tab_contents, - const content::ContextMenuParams& params); - virtual ~RenderViewContextMenuViews(); - void RunMenuAt(views::Widget* parent, const gfx::Point& point); + // Factory function to create an instance. + static RenderViewContextMenuViews* Create( + content::WebContents* tab_contents, + const content::ContextMenuParams& params); -#if defined(OS_WIN) - // Set this menu to show for an external tab contents. This - // only has an effect before Init() is called. - void SetExternal(); -#endif + void RunMenuAt(views::Widget* parent, const gfx::Point& point); void UpdateMenuItemStates(); @@ -46,6 +42,8 @@ class RenderViewContextMenuViews : public RenderViewContextMenu { const string16& title) OVERRIDE; protected: + RenderViewContextMenuViews(content::WebContents* tab_contents, + const content::ContextMenuParams& params); // RenderViewContextMenu implementation. virtual void PlatformInit() OVERRIDE; virtual void PlatformCancel() OVERRIDE; |