Fix WindowAndroid leak in Android WebView
[chromium-blink-merge.git] / win8 / metro_driver / chrome_app_view.h
blob77d67815924bf098ae5d826ddd5ce86e7e89c6c5
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 #ifndef WIN8_METRO_DRIVER_CHROME_APP_VIEW_H_
6 #define WIN8_METRO_DRIVER_CHROME_APP_VIEW_H_
8 #include <windows.applicationmodel.core.h>
9 #include <windows.ui.core.h>
10 #include <windows.ui.input.h>
11 #include <windows.ui.viewmanagement.h>
13 #include <list>
14 #include <map>
15 #include <string>
16 #include <utility>
18 #include "base/memory/scoped_ptr.h"
19 #include "base/message_loop/message_loop.h"
20 #include "base/synchronization/lock.h"
21 #include "win8/metro_driver/chrome_url_launch_handler.h"
22 #include "win8/metro_driver/devices_handler.h"
23 #include "win8/metro_driver/metro_dialog_box.h"
24 #include "win8/metro_driver/settings_handler.h"
25 #include "win8/metro_driver/toast_notification_handler.h"
27 namespace IPC {
28 class Listener;
29 class ChannelProxy;
32 class ChromeAppView
33 : public mswr::RuntimeClass<winapp::Core::IFrameworkView> {
34 public:
35 ChromeAppView();
36 ~ChromeAppView();
38 // IViewProvider overrides.
39 IFACEMETHOD(Initialize)(winapp::Core::ICoreApplicationView* view);
40 IFACEMETHOD(SetWindow)(winui::Core::ICoreWindow* window);
41 IFACEMETHOD(Load)(HSTRING entryPoint);
42 IFACEMETHOD(Run)();
43 IFACEMETHOD(Uninitialize)();
45 static LRESULT CALLBACK CoreWindowProc(HWND window, UINT message, WPARAM wp,
46 LPARAM lp);
48 bool osk_visible_notification_received() const {
49 return osk_visible_notification_received_;
52 // Displays the notification.
53 void DisplayNotification(
54 const ToastNotificationHandler::DesktopNotification& notification);
56 // Cancels the notification.
57 void CancelNotification(const std::string& notification);
59 // Returns true if the notification passed in is valid.
60 bool IsValidNotification(const std::string& notification);
62 // Displays a dialog box.
63 void ShowDialogBox(const MetroDialogBox::DialogBoxInfo& dialog_box_info);
64 // Dismisses the dialog box.
65 void DismissDialogBox();
67 // Helper function to unsnap the chrome metro app if it is snapped.
68 // Returns S_OK on success.
69 static HRESULT Unsnap();
71 // Notification from chrome that a full screen operation is being performed.
72 void SetFullscreen(bool fullscreen);
74 // Returns the current view state of the chrome window.
75 winui::ViewManagement::ApplicationViewState GetViewState();
77 HWND core_window_hwnd() { return core_window_hwnd_; }
79 private:
80 HRESULT OnActivate(winapp::Core::ICoreApplicationView* view,
81 winapp::Activation::IActivatedEventArgs* args);
83 HRESULT OnSizeChanged(winui::Core::ICoreWindow* sender,
84 winui::Core::IWindowSizeChangedEventArgs* args);
86 HRESULT OnEdgeGestureCompleted(winui::Input::IEdgeGesture* gesture,
87 winui::Input::IEdgeGestureEventArgs* args);
89 HRESULT OnShareDataRequested(
90 winapp::DataTransfer::IDataTransferManager* data_transfer_mgr,
91 winapp::DataTransfer::IDataRequestedEventArgs* event_args);
93 HRESULT OnInputPaneVisible(
94 winui::ViewManagement::IInputPane* input_pane,
95 winui::ViewManagement::IInputPaneVisibilityEventArgs* event_args);
97 HRESULT OnInputPaneHiding(
98 winui::ViewManagement::IInputPane* input_pane,
99 winui::ViewManagement::IInputPaneVisibilityEventArgs* event_args);
101 HRESULT OnPositionChanged(int x, int y);
103 void CheckForOSKActivation();
105 HRESULT RegisterInputPaneNotifications();
107 void HandleInputPaneVisible(const RECT& osk_rect);
108 void HandleInputPaneHidden(const RECT& osk_rect);
110 mswr::ComPtr<winui::Core::ICoreWindow> window_;
111 mswr::ComPtr<winapp::Core::ICoreApplicationView> view_;
112 EventRegistrationToken activated_token_;
113 EventRegistrationToken edgeevent_token_;
114 EventRegistrationToken sizechange_token_;
115 EventRegistrationToken share_data_requested_token_;
116 EventRegistrationToken input_pane_visible_token_;
117 EventRegistrationToken input_pane_hiding_token_;
118 EventRegistrationToken app_exit_token_;
120 // The actual window behind the view surface.
121 HWND core_window_hwnd_;
123 ChromeUrlLaunchHandler url_launch_handler_;
124 metro_driver::DevicesHandler devices_handler_;
125 SettingsHandler settings_handler_;
126 mswr::ComPtr<winui::ViewManagement::IInputPane> input_pane_;
127 mswr::ComPtr<winui::ViewManagement::IApplicationViewStatics> app_view_;
129 bool osk_visible_notification_received_;
131 // map of notification id to the ToastNotificationHandler instance.
132 typedef std::map<std::string, scoped_ptr<ToastNotificationHandler> >
133 NotificationMap;
134 NotificationMap notification_map_;
136 // Synchronizes access to the notification_map_ member.
137 base::Lock notification_lock_;
139 // If the OSK covers the input area we scroll the window by the height of the
140 // OSK + an additional offset. This member holds this offset. Set to 0 if the
141 // window was not scrolled.
142 int osk_offset_adjustment_;
144 MetroDialogBox dialog_box_;
147 // Global information used across the metro driver.
148 struct Globals {
149 LPTHREAD_START_ROUTINE host_main;
150 void* host_context;
151 // The pair below contains the HWND and a bool which indicates whether the
152 // window was displaced to ensure that the focused region is visible when
153 // the OSK is displayed.
154 std::list<std::pair<HWND, bool> > host_windows;
155 HANDLE host_thread;
156 ChromeAppView* view;
157 WNDPROC g_core_proc;
158 base::string16 navigation_url;
159 base::string16 search_string;
160 winapp::Activation::ApplicationExecutionState previous_state;
161 winapp::Activation::ActivationKind initial_activation_kind;
162 bool is_initial_activation;
163 // This message loop lives in the app view's thread. Some operations have
164 // to be initiated from that thread, notably spawning file pickers.
165 base::MessageLoopProxy* appview_msg_loop;
166 winapp::Core::ICoreApplicationExit* app_exit;
167 base::string16 metro_command_line_switches;
170 extern Globals globals;
172 #endif // WIN8_METRO_DRIVER_CHROME_APP_VIEW_H_