Added #ifdefs around PrintHeaderAndFooter for Windows and Mac.
[chromium-blink-merge.git] / athena / content / web_contents_view_delegate_factory_impl.cc
blob63f6ebab82147db020ba5164b3036a777a124daa
1 // Copyright 2014 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 "athena/content/public/web_contents_view_delegate_creator.h"
7 #include "athena/content/render_view_context_menu_impl.h"
8 #include "components/renderer_context_menu/context_menu_delegate.h"
9 #include "components/web_modal/popup_manager.h"
10 #include "components/web_modal/single_web_contents_dialog_manager.h"
11 #include "components/web_modal/web_contents_modal_dialog_host.h"
12 #include "components/web_modal/web_contents_modal_dialog_manager.h"
13 #include "content/public/browser/render_widget_host_view.h"
14 #include "content/public/browser/web_contents.h"
15 #include "content/public/browser/web_contents_delegate.h"
16 #include "content/public/browser/web_contents_view_delegate.h"
17 #include "ui/aura/client/screen_position_client.h"
18 #include "ui/aura/window.h"
19 #include "ui/views/widget/widget.h"
21 namespace athena {
22 namespace {
24 class WebContentsViewDelegateImpl : public content::WebContentsViewDelegate,
25 public ContextMenuDelegate {
26 public:
27 explicit WebContentsViewDelegateImpl(content::WebContents* web_contents)
28 : ContextMenuDelegate(web_contents), web_contents_(web_contents) {}
29 ~WebContentsViewDelegateImpl() override {}
31 content::WebDragDestDelegate* GetDragDestDelegate() override {
32 // TODO(oshima): crbug.com/401610
33 NOTIMPLEMENTED();
34 return nullptr;
37 bool Focus() override {
38 web_modal::PopupManager* popup_manager =
39 web_modal::PopupManager::FromWebContents(web_contents_);
40 if (popup_manager)
41 popup_manager->WasFocused(web_contents_);
42 return false;
45 void ShowContextMenu(content::RenderFrameHost* render_frame_host,
46 const content::ContextMenuParams& params) override {
47 ShowMenu(BuildMenu(
48 content::WebContents::FromRenderFrameHost(render_frame_host), params));
51 void SizeChanged(const gfx::Size& size) override {
52 // TODO(oshima|sadrul): Implement this when sad_tab is componentized.
53 // See c/b/ui/views/tab_contents/chrome_web_contents_view_delegate_views.cc
56 void ShowDisambiguationPopup(
57 const gfx::Rect& target_rect,
58 const SkBitmap& zoomed_bitmap,
59 const gfx::NativeView content,
60 const base::Callback<void(ui::GestureEvent*)>& gesture_cb,
61 const base::Callback<void(ui::MouseEvent*)>& mouse_cb) override {
62 NOTIMPLEMENTED();
65 void HideDisambiguationPopup() override { NOTIMPLEMENTED(); }
67 // ContextMenuDelegate:
68 scoped_ptr<RenderViewContextMenuBase> BuildMenu(
69 content::WebContents* web_contents,
70 const content::ContextMenuParams& params) override {
71 scoped_ptr<RenderViewContextMenuBase> menu;
72 content::RenderFrameHost* focused_frame = web_contents->GetFocusedFrame();
73 // If the frame tree does not have a focused frame at this point, do not
74 // bother creating RenderViewContextMenuViews.
75 // This happens if the frame has navigated to a different page before
76 // ContextMenu message was received by the current RenderFrameHost.
77 if (focused_frame) {
78 menu.reset(new RenderViewContextMenuImpl(focused_frame, params));
79 menu->Init();
81 return menu.Pass();
83 void ShowMenu(scoped_ptr<RenderViewContextMenuBase> menu) override {
84 context_menu_.reset(menu.release());
86 if (!context_menu_)
87 return;
89 context_menu_->Show();
92 aura::Window* GetActiveNativeView() {
93 return web_contents_->GetFullscreenRenderWidgetHostView()
94 ? web_contents_->GetFullscreenRenderWidgetHostView()
95 ->GetNativeView()
96 : web_contents_->GetNativeView();
99 views::Widget* GetTopLevelWidget() {
100 return views::Widget::GetTopLevelWidgetForNativeView(GetActiveNativeView());
103 views::FocusManager* GetFocusManager() {
104 views::Widget* toplevel_widget = GetTopLevelWidget();
105 return toplevel_widget ? toplevel_widget->GetFocusManager() : nullptr;
108 void SetInitialFocus() {
109 if (web_contents_->FocusLocationBarByDefault()) {
110 if (web_contents_->GetDelegate())
111 web_contents_->GetDelegate()->SetFocusToLocationBar(false);
112 } else {
113 web_contents_->Focus();
116 scoped_ptr<RenderViewContextMenuBase> context_menu_;
117 content::WebContents* web_contents_;
118 DISALLOW_COPY_AND_ASSIGN(WebContentsViewDelegateImpl);
121 } // namespace
123 content::WebContentsViewDelegate* CreateWebContentsViewDelegate(
124 content::WebContents* web_contents) {
125 return new WebContentsViewDelegateImpl(web_contents);
128 } // namespace athena