| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_VIEWS_EXTERNAL_TAB_CONTAINER_WIN_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_EXTERNAL_TAB_CONTAINER_WIN_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_EXTERNAL_TAB_CONTAINER_WIN_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_EXTERNAL_TAB_CONTAINER_WIN_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "chrome/browser/automation/automation_resource_message_filter.h" | 16 #include "chrome/browser/automation/automation_resource_message_filter.h" |
| 17 #include "chrome/browser/external_tab/external_tab_container.h" | 17 #include "chrome/browser/external_tab/external_tab_container.h" |
| 18 #include "chrome/browser/infobars/infobar_container.h" | 18 #include "chrome/browser/infobars/infobar_container.h" |
| 19 #include "chrome/browser/net/chrome_url_request_context.h" | 19 #include "chrome/browser/net/chrome_url_request_context.h" |
| 20 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper_delegate.
h" | 20 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper_delegate.
h" |
| 21 #include "chrome/browser/ui/views/unhandled_keyboard_event_handler.h" | 21 #include "chrome/browser/ui/views/unhandled_keyboard_event_handler.h" |
| 22 #include "content/public/browser/navigation_type.h" | 22 #include "content/public/browser/navigation_type.h" |
| 23 #include "content/public/browser/notification_observer.h" | 23 #include "content/public/browser/notification_observer.h" |
| 24 #include "content/public/browser/notification_registrar.h" | 24 #include "content/public/browser/notification_registrar.h" |
| 25 #include "content/public/browser/web_contents_delegate.h" | 25 #include "content/public/browser/web_contents_delegate.h" |
| 26 #include "content/public/browser/web_contents_observer.h" | 26 #include "content/public/browser/web_contents_observer.h" |
| 27 #include "ui/base/accelerators/accelerator.h" | 27 #include "ui/base/accelerators/accelerator.h" |
| 28 #include "ui/views/widget/native_widget_win.h" | |
| 29 | 28 |
| 30 class AutomationProvider; | 29 class AutomationProvider; |
| 31 class Browser; | 30 class Browser; |
| 32 class Profile; | 31 class Profile; |
| 33 class TabContentsContainer; | 32 class TabContentsContainer; |
| 34 class RenderViewContextMenuViews; | 33 class RenderViewContextMenuViews; |
| 35 struct NavigationInfo; | 34 struct NavigationInfo; |
| 36 | 35 |
| 37 namespace ui { | 36 namespace ui { |
| 38 class ViewProp; | 37 class ViewProp; |
| 39 } | 38 } |
| 40 | 39 |
| 41 namespace views { | 40 namespace views { |
| 41 class View; |
| 42 class WebView; | 42 class WebView; |
| 43 class Widget; |
| 43 } | 44 } |
| 44 | 45 |
| 46 // A delegate interface through which an ExternalTabContainerWin is notified |
| 47 // when its native widget experiences a lifecycle event. |
| 48 class WidgetLifecycleDelegate { |
| 49 public: |
| 50 virtual void OnNativeWidgetCreated() = 0; |
| 51 virtual void OnNativeWidgetDestroying() = 0; |
| 52 virtual void OnNativeWidgetDestroyed() = 0; |
| 53 }; |
| 54 |
| 45 // This class serves as the container window for an external tab. | 55 // This class serves as the container window for an external tab. |
| 46 // An external tab is a Chrome tab that is meant to displayed in an | 56 // An external tab is a Chrome tab that is meant to displayed in an |
| 47 // external process. This class provides the FocusManger needed by the | 57 // external process. This class provides the FocusManger needed by the |
| 48 // WebContents as well as an implementation of content::WebContentsDelegate. | 58 // WebContents as well as an implementation of content::WebContentsDelegate. |
| 49 class ExternalTabContainerWin : public ExternalTabContainer, | 59 class ExternalTabContainerWin : public ExternalTabContainer, |
| 50 public content::WebContentsDelegate, | 60 public content::WebContentsDelegate, |
| 51 public content::WebContentsObserver, | 61 public content::WebContentsObserver, |
| 52 public content::NotificationObserver, | 62 public content::NotificationObserver, |
| 53 public views::NativeWidgetWin, | 63 public WidgetLifecycleDelegate, |
| 54 public ui::AcceleratorTarget, | 64 public ui::AcceleratorTarget, |
| 55 public InfoBarContainer::Delegate, | 65 public InfoBarContainer::Delegate, |
| 56 public BlockedContentTabHelperDelegate { | 66 public BlockedContentTabHelperDelegate { |
| 57 public: | 67 public: |
| 58 typedef std::map<uintptr_t, | 68 typedef std::map<uintptr_t, |
| 59 scoped_refptr<ExternalTabContainerWin> > PendingTabs; | 69 scoped_refptr<ExternalTabContainerWin> > PendingTabs; |
| 60 | 70 |
| 61 ExternalTabContainerWin(AutomationProvider* automation, | 71 ExternalTabContainerWin(AutomationProvider* automation, |
| 62 AutomationResourceMessageFilter* filter); | 72 AutomationResourceMessageFilter* filter); |
| 63 | 73 |
| 64 static scoped_refptr<ExternalTabContainer> RemovePendingExternalTab( | 74 static scoped_refptr<ExternalTabContainer> RemovePendingExternalTab( |
| 65 uintptr_t cookie); | 75 uintptr_t cookie); |
| 66 | 76 |
| 67 // Overridden from ExternalTabContainer: | 77 // Overridden from ExternalTabContainer: |
| 68 virtual bool Init(Profile* profile, | 78 virtual bool Init(Profile* profile, |
| 69 HWND parent, | 79 HWND parent, |
| 70 const gfx::Rect& bounds, | 80 const gfx::Rect& bounds, |
| 71 DWORD style, | 81 DWORD style, |
| 72 bool load_requests_via_automation, | 82 bool load_requests_via_automation, |
| 73 bool handle_top_level_requests, | 83 bool handle_top_level_requests, |
| 74 content::WebContents* existing_contents, | 84 content::WebContents* existing_contents, |
| 75 const GURL& initial_url, | 85 const GURL& initial_url, |
| 76 const GURL& referrer, | 86 const GURL& referrer, |
| 77 bool infobars_enabled, | 87 bool infobars_enabled, |
| 78 bool supports_full_tab_mode) OVERRIDE; | 88 bool supports_full_tab_mode) OVERRIDE; |
| 79 virtual void Uninitialize() OVERRIDE; | 89 virtual void Uninitialize() OVERRIDE; |
| 80 virtual bool Reinitialize(AutomationProvider* automation_provider, | 90 virtual bool Reinitialize(AutomationProvider* automation_provider, |
| 81 AutomationResourceMessageFilter* filter, | 91 AutomationResourceMessageFilter* filter, |
| 82 gfx::NativeWindow parent_window) OVERRIDE; | 92 HWND parent_window) OVERRIDE; |
| 83 virtual content::WebContents* GetWebContents() const OVERRIDE; | 93 virtual content::WebContents* GetWebContents() const OVERRIDE; |
| 84 virtual gfx::NativeView GetExternalTabNativeView() const OVERRIDE; | 94 virtual HWND GetExternalTabHWND() const OVERRIDE; |
| 95 virtual HWND GetContentHWND() const OVERRIDE; |
| 85 virtual void SetTabHandle(int handle) OVERRIDE; | 96 virtual void SetTabHandle(int handle) OVERRIDE; |
| 86 virtual int GetTabHandle() const OVERRIDE; | 97 virtual int GetTabHandle() const OVERRIDE; |
| 87 virtual bool ExecuteContextMenuCommand(int command) OVERRIDE; | 98 virtual bool ExecuteContextMenuCommand(int command) OVERRIDE; |
| 88 virtual void RunUnloadHandlers(IPC::Message* reply_message) OVERRIDE; | 99 virtual void RunUnloadHandlers(IPC::Message* reply_message) OVERRIDE; |
| 89 virtual void ProcessUnhandledAccelerator(const MSG& msg) OVERRIDE; | 100 virtual void ProcessUnhandledAccelerator(const MSG& msg) OVERRIDE; |
| 90 virtual void FocusThroughTabTraversal(bool reverse, | 101 virtual void FocusThroughTabTraversal(bool reverse, |
| 91 bool restore_focus_to_view) OVERRIDE; | 102 bool restore_focus_to_view) OVERRIDE; |
| 92 | 103 |
| 93 // A helper method that tests whether the given window is an | |
| 94 // ExternalTabContainerWin window. | |
| 95 static bool IsExternalTabContainer(HWND window); | |
| 96 | |
| 97 // A helper function that returns a pointer to the ExternalTabContainerWin | |
| 98 // instance associated with a native view. Returns NULL if the window | |
| 99 // is not an ExternalTabContainerWin. | |
| 100 static ExternalTabContainer* GetExternalContainerFromNativeWindow( | |
| 101 gfx::NativeView native_window); | |
| 102 | |
| 103 // Overridden from content::WebContentsDelegate: | 104 // Overridden from content::WebContentsDelegate: |
| 104 virtual content::WebContents* OpenURLFromTab( | 105 virtual content::WebContents* OpenURLFromTab( |
| 105 content::WebContents* source, | 106 content::WebContents* source, |
| 106 const content::OpenURLParams& params) OVERRIDE; | 107 const content::OpenURLParams& params) OVERRIDE; |
| 107 virtual void NavigationStateChanged(const content::WebContents* source, | 108 virtual void NavigationStateChanged(const content::WebContents* source, |
| 108 unsigned changed_flags) OVERRIDE; | 109 unsigned changed_flags) OVERRIDE; |
| 109 virtual void AddNewContents(content::WebContents* source, | 110 virtual void AddNewContents(content::WebContents* source, |
| 110 content::WebContents* new_contents, | 111 content::WebContents* new_contents, |
| 111 WindowOpenDisposition disposition, | 112 WindowOpenDisposition disposition, |
| 112 const gfx::Rect& initial_pos, | 113 const gfx::Rect& initial_pos, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 virtual void InfoBarContainerStateChanged(bool is_animating) OVERRIDE; | 213 virtual void InfoBarContainerStateChanged(bool is_animating) OVERRIDE; |
| 213 virtual bool DrawInfoBarArrows(int* x) const OVERRIDE; | 214 virtual bool DrawInfoBarArrows(int* x) const OVERRIDE; |
| 214 | 215 |
| 215 // Overridden from BlockedContentTabHelperDelegate: | 216 // Overridden from BlockedContentTabHelperDelegate: |
| 216 virtual content::WebContents* GetConstrainingWebContents( | 217 virtual content::WebContents* GetConstrainingWebContents( |
| 217 content::WebContents* source) OVERRIDE; | 218 content::WebContents* source) OVERRIDE; |
| 218 | 219 |
| 219 protected: | 220 protected: |
| 220 virtual ~ExternalTabContainerWin(); | 221 virtual ~ExternalTabContainerWin(); |
| 221 | 222 |
| 222 // Overridden from views::NativeWidgetWin: | 223 // WidgetLifecycleDelegate overrides. |
| 223 virtual bool PreHandleMSG(UINT message, | 224 virtual void OnNativeWidgetCreated() OVERRIDE; |
| 224 WPARAM w_param, | 225 virtual void OnNativeWidgetDestroying() OVERRIDE; |
| 225 LPARAM l_param, | 226 virtual void OnNativeWidgetDestroyed() OVERRIDE; |
| 226 LRESULT* result) OVERRIDE; | |
| 227 virtual void PostHandleMSG(UINT message, | |
| 228 WPARAM w_param, | |
| 229 LPARAM l_param) OVERRIDE; | |
| 230 virtual void OnFinalMessage(HWND window); | |
| 231 | 227 |
| 232 bool InitNavigationInfo(NavigationInfo* nav_info, | 228 bool InitNavigationInfo(NavigationInfo* nav_info, |
| 233 content::NavigationType nav_type, | 229 content::NavigationType nav_type, |
| 234 int relative_offset); | 230 int relative_offset); |
| 235 void Navigate(const GURL& url, const GURL& referrer); | 231 void Navigate(const GURL& url, const GURL& referrer); |
| 236 | 232 |
| 237 // Helper resource automation registration method, allowing registration of | 233 // Helper resource automation registration method, allowing registration of |
| 238 // pending RenderViewHosts. | 234 // pending RenderViewHosts. |
| 239 void RegisterRenderViewHostForAutomation( | 235 void RegisterRenderViewHostForAutomation( |
| 240 content::RenderViewHost* render_view_host, | 236 content::RenderViewHost* render_view_host, |
| 241 bool pending_view); | 237 bool pending_view); |
| 242 | 238 |
| 243 // Helper function for processing keystokes coming back from the renderer | 239 // Helper function for processing keystokes coming back from the renderer |
| 244 // process. | 240 // process. |
| 245 bool ProcessUnhandledKeyStroke(HWND window, UINT message, WPARAM wparam, | 241 bool ProcessUnhandledKeyStroke(HWND window, UINT message, WPARAM wparam, |
| 246 LPARAM lparam); | 242 LPARAM lparam); |
| 247 | 243 |
| 248 void LoadAccelerators(); | 244 void LoadAccelerators(); |
| 249 | 245 |
| 250 // Sends over pending Open URL requests to the external host. | 246 // Sends over pending Open URL requests to the external host. |
| 251 void ServicePendingOpenURLRequests(); | 247 void ServicePendingOpenURLRequests(); |
| 252 | 248 |
| 253 // Scheduled as a task in ExternalTabContainerWin::Reinitialize. | 249 // Scheduled as a task in ExternalTabContainerWin::Reinitialize. |
| 254 void OnReinitialize(); | 250 void OnReinitialize(); |
| 255 | 251 |
| 256 // Creates and initializes the view hierarchy for this | 252 // Creates and initializes the view hierarchy for this |
| 257 // ExternalTabContainerWin. | 253 // ExternalTabContainerWin. |
| 258 void SetupExternalTabView(); | 254 void SetupExternalTabView(); |
| 259 | 255 |
| 256 views::Widget* widget_; |
| 260 scoped_ptr<content::WebContents> web_contents_; | 257 scoped_ptr<content::WebContents> web_contents_; |
| 261 scoped_refptr<AutomationProvider> automation_; | 258 scoped_refptr<AutomationProvider> automation_; |
| 262 | 259 |
| 263 content::NotificationRegistrar registrar_; | 260 content::NotificationRegistrar registrar_; |
| 264 | 261 |
| 265 // A view to handle focus cycling | 262 // A view to handle focus cycling |
| 266 views::WebView* tab_contents_container_; | 263 views::WebView* tab_contents_container_; |
| 267 | 264 |
| 268 int tab_handle_; | 265 int tab_handle_; |
| 269 // A failed navigation like a 404 is followed in chrome with a success | 266 // A failed navigation like a 404 is followed in chrome with a success |
| 270 // navigation for the 404 page. We need to ignore the next navigation | 267 // navigation for the 404 page. We need to ignore the next navigation |
| 271 // to avoid confusing the clients of the external tab. This member variable | 268 // to avoid confusing the clients of the external tab. This member variable |
| 272 // is set when we need to ignore the next load notification. | 269 // is set when we need to ignore the next load notification. |
| 273 bool ignore_next_load_notification_; | 270 bool ignore_next_load_notification_; |
| 274 | 271 |
| 275 scoped_ptr<RenderViewContextMenuViews> external_context_menu_; | 272 scoped_ptr<RenderViewContextMenuViews> external_context_menu_; |
| 276 | 273 |
| 277 // A message filter to load resources via automation | 274 // A message filter to load resources via automation |
| 278 scoped_refptr<AutomationResourceMessageFilter> | 275 scoped_refptr<AutomationResourceMessageFilter> |
| 279 automation_resource_message_filter_; | 276 automation_resource_message_filter_; |
| 280 | 277 |
| 281 // If all the url requests for this tab are to be loaded via automation. | 278 // If all the url requests for this tab are to be loaded via automation. |
| 282 bool load_requests_via_automation_; | 279 bool load_requests_via_automation_; |
| 283 | 280 |
| 284 // whether top level URL requests are to be handled by the automation client. | 281 // whether top level URL requests are to be handled by the automation client. |
| 285 bool handle_top_level_requests_; | 282 bool handle_top_level_requests_; |
| 286 | 283 |
| 284 // set to true if the host needs to get notified of all top level navigations |
| 285 // in this page. This typically applies to hosts which would render the new |
| 286 // page without chrome frame. |
| 287 bool route_all_top_level_navigations_; |
| 288 |
| 287 // Contains ExternalTabContainers that have not been connected to as yet. | 289 // Contains ExternalTabContainers that have not been connected to as yet. |
| 288 static base::LazyInstance<PendingTabs> pending_tabs_; | 290 static base::LazyInstance<PendingTabs> pending_tabs_; |
| 289 | 291 |
| 290 // Allows us to run tasks on the ExternalTabContainerWin instance which are | 292 // Allows us to run tasks on the ExternalTabContainerWin instance which are |
| 291 // bound by its lifetime. | 293 // bound by its lifetime. |
| 292 base::WeakPtrFactory<ExternalTabContainerWin> weak_factory_; | 294 base::WeakPtrFactory<ExternalTabContainerWin> weak_factory_; |
| 293 | 295 |
| 294 // The URL request context to be used for this tab. Can be NULL. | 296 // The URL request context to be used for this tab. Can be NULL. |
| 295 scoped_refptr<ChromeURLRequestContextGetter> request_context_; | 297 scoped_refptr<ChromeURLRequestContextGetter> request_context_; |
| 296 | 298 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 315 // Set to true if the ExternalTabContainerWin instance is waiting for an ack | 317 // Set to true if the ExternalTabContainerWin instance is waiting for an ack |
| 316 // from the host. | 318 // from the host. |
| 317 bool pending_; | 319 bool pending_; |
| 318 | 320 |
| 319 views::FocusManager* focus_manager_; | 321 views::FocusManager* focus_manager_; |
| 320 | 322 |
| 321 views::View* external_tab_view_; | 323 views::View* external_tab_view_; |
| 322 | 324 |
| 323 IPC::Message* unload_reply_message_; | 325 IPC::Message* unload_reply_message_; |
| 324 | 326 |
| 325 // set to true if the host needs to get notified of all top level navigations | |
| 326 // in this page. This typically applies to hosts which would render the new | |
| 327 // page without chrome frame. | |
| 328 bool route_all_top_level_navigations_; | |
| 329 | |
| 330 scoped_ptr<ui::ViewProp> prop_; | 327 scoped_ptr<ui::ViewProp> prop_; |
| 331 | 328 |
| 332 // if this tab is a popup | 329 // if this tab is a popup |
| 333 bool is_popup_window_; | 330 bool is_popup_window_; |
| 334 | 331 |
| 335 DISALLOW_COPY_AND_ASSIGN(ExternalTabContainerWin); | 332 DISALLOW_COPY_AND_ASSIGN(ExternalTabContainerWin); |
| 336 }; | 333 }; |
| 337 | 334 |
| 338 // This class is instantiated for handling requests to open popups for external | 335 // This class is instantiated for handling requests to open popups for external |
| 339 // tabs hosted in browsers which need to be notified about all top level | 336 // tabs hosted in browsers which need to be notified about all top level |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 return false; | 391 return false; |
| 395 } | 392 } |
| 396 | 393 |
| 397 virtual void BeforeUnloadFired(content::WebContents* tab, bool proceed, | 394 virtual void BeforeUnloadFired(content::WebContents* tab, bool proceed, |
| 398 bool* proceed_to_fire_unload) { | 395 bool* proceed_to_fire_unload) { |
| 399 NOTREACHED(); | 396 NOTREACHED(); |
| 400 } | 397 } |
| 401 }; | 398 }; |
| 402 | 399 |
| 403 #endif // CHROME_BROWSER_UI_VIEWS_EXTERNAL_TAB_CONTAINER_WIN_H_ | 400 #endif // CHROME_BROWSER_UI_VIEWS_EXTERNAL_TAB_CONTAINER_WIN_H_ |
| OLD | NEW |