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#ifndef CHROME_BROWSER_EXTERNAL_TAB_EXTERNAL_TAB_CONTAINER_H_
6#define CHROME_BROWSER_EXTERNAL_TAB_EXTERNAL_TAB_CONTAINER_H_
7
8#include <windows.h>
9
10#include "base/memory/ref_counted.h"
11#include "ui/gfx/native_widget_types.h"
12
13class AutomationProvider;
14class AutomationResourceMessageFilter;
15class GURL;
16class Profile;
17
18namespace content {
19class WebContents;
20}
21
22namespace gfx {
23class Rect;
24}
25
26namespace IPC {
27class Message;
28}
29
30class ExternalTabContainer : public base::RefCounted<ExternalTabContainer> {
31 public:
32  static ExternalTabContainer* Create(
33      AutomationProvider* automation_provider,
34      AutomationResourceMessageFilter* filter);
35
36  // A helper method that retrieves the ExternalTabContainer object that
37  // hosts the given WebContents.
38  static ExternalTabContainer* GetContainerForTab(
39      content::WebContents* web_contents);
40
41  // Returns the ExternalTabContainer instance associated with the cookie
42  // passed in. It also erases the corresponding reference from the map.
43  // Returns NULL if we fail to find the cookie in the map.
44  static scoped_refptr<ExternalTabContainer> RemovePendingTab(uintptr_t cookie);
45
46  // Initializes the instance. This must be invoked before any other member
47  // functions.
48  virtual bool Init(Profile* profile,
49                    HWND parent,
50                    const gfx::Rect& bounds,
51                    DWORD style,
52                    bool load_requests_via_automation,
53                    bool handle_top_level_requests,
54                    content::WebContents* existing_contents,
55                    const GURL& initial_url,
56                    const GURL& referrer,
57                    bool infobars_enabled,
58                    bool supports_full_tab_mode) = 0;
59
60  // Unhook the keystroke listener and notify about the closing WebContents.
61  // This function gets called from three places, which is fine.
62  // 1. OnFinalMessage
63  // 2. In the destructor.
64  // 3. In AutomationProvider::CreateExternalTab
65  virtual void Uninitialize() = 0;
66
67  // Used to reinitialize the automation channel and related information
68  // for this container. Typically used when an ExternalTabContainer
69  // instance is created by Chrome and attached to an automation client.
70  virtual bool Reinitialize(AutomationProvider* automation_provider,
71                            AutomationResourceMessageFilter* filter,
72                            HWND parent_window) = 0;
73
74  // This is invoked when the external host reflects back to us a keyboard
75  // message it did not process.
76  virtual void ProcessUnhandledAccelerator(const MSG& msg) = 0;
77
78  // See WebContents::FocusThroughTabTraversal. Called from AutomationProvider.
79  virtual void FocusThroughTabTraversal(bool reverse,
80                                        bool restore_focus_to_view) = 0;
81
82  virtual void RunUnloadHandlers(IPC::Message* reply_message) = 0;
83
84  virtual content::WebContents* GetWebContents() const = 0;
85  virtual HWND GetExternalTabHWND() const = 0;
86  virtual HWND GetContentHWND() const = 0;
87
88  virtual void SetTabHandle(int handle) = 0;
89  virtual int GetTabHandle() const = 0;
90
91  // Returns true if the context menu command was handled
92  virtual bool ExecuteContextMenuCommand(int command) = 0;
93
94 protected:
95  virtual ~ExternalTabContainer() {}
96
97 private:
98  friend class base::RefCounted<ExternalTabContainer>;
99};
100
101#endif  // CHROME_BROWSER_EXTERNAL_TAB_EXTERNAL_TAB_CONTAINER_H_
102