| 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" | 28 #include "ui/views/widget/widget_observer.h" |
| 29 | 29 |
| 30 class AutomationProvider; | 30 class AutomationProvider; |
| 31 class Browser; | 31 class Browser; |
| 32 class Profile; | 32 class Profile; |
| 33 class TabContentsContainer; | 33 class TabContentsContainer; |
| 34 class RenderViewContextMenuViews; | 34 class RenderViewContextMenuViews; |
| 35 struct NavigationInfo; | 35 struct NavigationInfo; |
| 36 | 36 |
| 37 namespace ui { | 37 namespace ui { |
| 38 class ViewProp; | 38 class ViewProp; |
| 39 } | 39 } |
| 40 | 40 |
| 41 namespace views { | 41 namespace views { |
| 42 class View; |
| 42 class WebView; | 43 class WebView; |
| 44 class Widget; |
| 43 } | 45 } |
| 44 | 46 |
| 45 // This class serves as the container window for an external tab. | 47 // 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 | 48 // 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 | 49 // external process. This class provides the FocusManger needed by the |
| 48 // WebContents as well as an implementation of content::WebContentsDelegate. | 50 // WebContents as well as an implementation of content::WebContentsDelegate. |
| 49 class ExternalTabContainerWin : public ExternalTabContainer, | 51 class ExternalTabContainerWin : public ExternalTabContainer, |
| 50 public content::WebContentsDelegate, | 52 public content::WebContentsDelegate, |
| 51 public content::WebContentsObserver, | 53 public content::WebContentsObserver, |
| 52 public content::NotificationObserver, | 54 public content::NotificationObserver, |
| 53 public views::NativeWidgetWin, | 55 public views::WidgetObserver, |
| 54 public ui::AcceleratorTarget, | 56 public ui::AcceleratorTarget, |
| 55 public InfoBarContainer::Delegate, | 57 public InfoBarContainer::Delegate, |
| 56 public BlockedContentTabHelperDelegate { | 58 public BlockedContentTabHelperDelegate { |
| 57 public: | 59 public: |
| 58 typedef std::map<uintptr_t, | 60 typedef std::map<uintptr_t, |
| 59 scoped_refptr<ExternalTabContainerWin> > PendingTabs; | 61 scoped_refptr<ExternalTabContainerWin> > PendingTabs; |
| 60 | 62 |
| 61 ExternalTabContainerWin(AutomationProvider* automation, | 63 ExternalTabContainerWin(AutomationProvider* automation, |
| 62 AutomationResourceMessageFilter* filter); | 64 AutomationResourceMessageFilter* filter); |
| 63 | 65 |
| 64 static scoped_refptr<ExternalTabContainer> RemovePendingExternalTab( | 66 static scoped_refptr<ExternalTabContainer> RemovePendingExternalTab( |
| 65 uintptr_t cookie); | 67 uintptr_t cookie); |
| 66 | 68 |
| 67 // Overridden from ExternalTabContainer: | 69 // Overridden from ExternalTabContainer: |
| 68 virtual bool Init(Profile* profile, | 70 virtual bool Init(Profile* profile, |
| 69 HWND parent, | 71 HWND parent, |
| 70 const gfx::Rect& bounds, | 72 const gfx::Rect& bounds, |
| 71 DWORD style, | 73 DWORD style, |
| 72 bool load_requests_via_automation, | 74 bool load_requests_via_automation, |
| 73 bool handle_top_level_requests, | 75 bool handle_top_level_requests, |
| 74 content::WebContents* existing_contents, | 76 content::WebContents* existing_contents, |
| 75 const GURL& initial_url, | 77 const GURL& initial_url, |
| 76 const GURL& referrer, | 78 const GURL& referrer, |
| 77 bool infobars_enabled, | 79 bool infobars_enabled, |
| 78 bool supports_full_tab_mode) OVERRIDE; | 80 bool supports_full_tab_mode) OVERRIDE; |
| 79 virtual void Uninitialize() OVERRIDE; | 81 virtual void Uninitialize() OVERRIDE; |
| 80 virtual bool Reinitialize(AutomationProvider* automation_provider, | 82 virtual bool Reinitialize(AutomationProvider* automation_provider, |
| 81 AutomationResourceMessageFilter* filter, | 83 AutomationResourceMessageFilter* filter, |
| 82 gfx::NativeWindow parent_window) OVERRIDE; | 84 HWND parent_window) OVERRIDE; |
| 83 virtual content::WebContents* GetWebContents() const OVERRIDE; | 85 virtual content::WebContents* GetWebContents() const OVERRIDE; |
| 84 virtual gfx::NativeView GetExternalTabNativeView() const OVERRIDE; | 86 virtual HWND GetExternalTabHWND() const OVERRIDE; |
| 87 virtual HWND GetContentHWND() const OVERRIDE; |
| 85 virtual void SetTabHandle(int handle) OVERRIDE; | 88 virtual void SetTabHandle(int handle) OVERRIDE; |
| 86 virtual int GetTabHandle() const OVERRIDE; | 89 virtual int GetTabHandle() const OVERRIDE; |
| 87 virtual bool ExecuteContextMenuCommand(int command) OVERRIDE; | 90 virtual bool ExecuteContextMenuCommand(int command) OVERRIDE; |
| 88 virtual void RunUnloadHandlers(IPC::Message* reply_message) OVERRIDE; | 91 virtual void RunUnloadHandlers(IPC::Message* reply_message) OVERRIDE; |
| 89 virtual void ProcessUnhandledAccelerator(const MSG& msg) OVERRIDE; | 92 virtual void ProcessUnhandledAccelerator(const MSG& msg) OVERRIDE; |
| 90 virtual void FocusThroughTabTraversal(bool reverse, | 93 virtual void FocusThroughTabTraversal(bool reverse, |
| 91 bool restore_focus_to_view) OVERRIDE; | 94 bool restore_focus_to_view) OVERRIDE; |
| 92 | 95 |
| 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: | 96 // Overridden from content::WebContentsDelegate: |
| 104 virtual content::WebContents* OpenURLFromTab( | 97 virtual content::WebContents* OpenURLFromTab( |
| 105 content::WebContents* source, | 98 content::WebContents* source, |
| 106 const content::OpenURLParams& params) OVERRIDE; | 99 const content::OpenURLParams& params) OVERRIDE; |
| 107 virtual void NavigationStateChanged(const content::WebContents* source, | 100 virtual void NavigationStateChanged(const content::WebContents* source, |
| 108 unsigned changed_flags) OVERRIDE; | 101 unsigned changed_flags) OVERRIDE; |
| 109 virtual void AddNewContents(content::WebContents* source, | 102 virtual void AddNewContents(content::WebContents* source, |
| 110 content::WebContents* new_contents, | 103 content::WebContents* new_contents, |
| 111 WindowOpenDisposition disposition, | 104 WindowOpenDisposition disposition, |
| 112 const gfx::Rect& initial_pos, | 105 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; | 205 virtual void InfoBarContainerStateChanged(bool is_animating) OVERRIDE; |
| 213 virtual bool DrawInfoBarArrows(int* x) const OVERRIDE; | 206 virtual bool DrawInfoBarArrows(int* x) const OVERRIDE; |
| 214 | 207 |
| 215 // Overridden from BlockedContentTabHelperDelegate: | 208 // Overridden from BlockedContentTabHelperDelegate: |
| 216 virtual content::WebContents* GetConstrainingWebContents( | 209 virtual content::WebContents* GetConstrainingWebContents( |
| 217 content::WebContents* source) OVERRIDE; | 210 content::WebContents* source) OVERRIDE; |
| 218 | 211 |
| 219 protected: | 212 protected: |
| 220 virtual ~ExternalTabContainerWin(); | 213 virtual ~ExternalTabContainerWin(); |
| 221 | 214 |
| 222 // Overridden from views::NativeWidgetWin: | 215 // WidgetObserver overrides. |
| 223 virtual bool PreHandleMSG(UINT message, | 216 virtual void OnWidgetCreated(views::Widget* widget) OVERRIDE; |
| 224 WPARAM w_param, | 217 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; |
| 225 LPARAM l_param, | 218 virtual void OnWidgetDestroyed(views::Widget* widget) 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 | 219 |
| 232 bool InitNavigationInfo(NavigationInfo* nav_info, | 220 bool InitNavigationInfo(NavigationInfo* nav_info, |
| 233 content::NavigationType nav_type, | 221 content::NavigationType nav_type, |
| 234 int relative_offset); | 222 int relative_offset); |
| 235 void Navigate(const GURL& url, const GURL& referrer); | 223 void Navigate(const GURL& url, const GURL& referrer); |
| 236 | 224 |
| 237 // Helper resource automation registration method, allowing registration of | 225 // Helper resource automation registration method, allowing registration of |
| 238 // pending RenderViewHosts. | 226 // pending RenderViewHosts. |
| 239 void RegisterRenderViewHostForAutomation( | 227 void RegisterRenderViewHostForAutomation( |
| 240 content::RenderViewHost* render_view_host, | 228 content::RenderViewHost* render_view_host, |
| 241 bool pending_view); | 229 bool pending_view); |
| 242 | 230 |
| 243 // Helper function for processing keystokes coming back from the renderer | 231 // Helper function for processing keystokes coming back from the renderer |
| 244 // process. | 232 // process. |
| 245 bool ProcessUnhandledKeyStroke(HWND window, UINT message, WPARAM wparam, | 233 bool ProcessUnhandledKeyStroke(HWND window, UINT message, WPARAM wparam, |
| 246 LPARAM lparam); | 234 LPARAM lparam); |
| 247 | 235 |
| 248 void LoadAccelerators(); | 236 void LoadAccelerators(); |
| 249 | 237 |
| 250 // Sends over pending Open URL requests to the external host. | 238 // Sends over pending Open URL requests to the external host. |
| 251 void ServicePendingOpenURLRequests(); | 239 void ServicePendingOpenURLRequests(); |
| 252 | 240 |
| 253 // Scheduled as a task in ExternalTabContainerWin::Reinitialize. | 241 // Scheduled as a task in ExternalTabContainerWin::Reinitialize. |
| 254 void OnReinitialize(); | 242 void OnReinitialize(); |
| 255 | 243 |
| 256 // Creates and initializes the view hierarchy for this | 244 // Creates and initializes the view hierarchy for this |
| 257 // ExternalTabContainerWin. | 245 // ExternalTabContainerWin. |
| 258 void SetupExternalTabView(); | 246 void SetupExternalTabView(); |
| 259 | 247 |
| 248 views::Widget* widget_; |
| 260 scoped_ptr<content::WebContents> web_contents_; | 249 scoped_ptr<content::WebContents> web_contents_; |
| 261 scoped_refptr<AutomationProvider> automation_; | 250 scoped_refptr<AutomationProvider> automation_; |
| 262 | 251 |
| 263 content::NotificationRegistrar registrar_; | 252 content::NotificationRegistrar registrar_; |
| 264 | 253 |
| 265 // A view to handle focus cycling | 254 // A view to handle focus cycling |
| 266 views::WebView* tab_contents_container_; | 255 views::WebView* tab_contents_container_; |
| 267 | 256 |
| 268 int tab_handle_; | 257 int tab_handle_; |
| 269 // A failed navigation like a 404 is followed in chrome with a success | 258 // 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 | 259 // 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 | 260 // to avoid confusing the clients of the external tab. This member variable |
| 272 // is set when we need to ignore the next load notification. | 261 // is set when we need to ignore the next load notification. |
| 273 bool ignore_next_load_notification_; | 262 bool ignore_next_load_notification_; |
| 274 | 263 |
| 275 scoped_ptr<RenderViewContextMenuViews> external_context_menu_; | 264 scoped_ptr<RenderViewContextMenuViews> external_context_menu_; |
| 276 | 265 |
| 277 // A message filter to load resources via automation | 266 // A message filter to load resources via automation |
| 278 scoped_refptr<AutomationResourceMessageFilter> | 267 scoped_refptr<AutomationResourceMessageFilter> |
| 279 automation_resource_message_filter_; | 268 automation_resource_message_filter_; |
| 280 | 269 |
| 281 // If all the url requests for this tab are to be loaded via automation. | 270 // If all the url requests for this tab are to be loaded via automation. |
| 282 bool load_requests_via_automation_; | 271 bool load_requests_via_automation_; |
| 283 | 272 |
| 284 // whether top level URL requests are to be handled by the automation client. | 273 // whether top level URL requests are to be handled by the automation client. |
| 285 bool handle_top_level_requests_; | 274 bool handle_top_level_requests_; |
| 286 | 275 |
| 276 // Set to true if the host needs to get notified of all top level navigations |
| 277 // in this page. This typically applies to hosts which would render the new |
| 278 // page without chrome frame. |
| 279 bool route_all_top_level_navigations_; |
| 280 |
| 287 // Contains ExternalTabContainers that have not been connected to as yet. | 281 // Contains ExternalTabContainers that have not been connected to as yet. |
| 288 static base::LazyInstance<PendingTabs> pending_tabs_; | 282 static base::LazyInstance<PendingTabs> pending_tabs_; |
| 289 | 283 |
| 290 // Allows us to run tasks on the ExternalTabContainerWin instance which are | 284 // Allows us to run tasks on the ExternalTabContainerWin instance which are |
| 291 // bound by its lifetime. | 285 // bound by its lifetime. |
| 292 base::WeakPtrFactory<ExternalTabContainerWin> weak_factory_; | 286 base::WeakPtrFactory<ExternalTabContainerWin> weak_factory_; |
| 293 | 287 |
| 294 // The URL request context to be used for this tab. Can be NULL. | 288 // The URL request context to be used for this tab. Can be NULL. |
| 295 scoped_refptr<ChromeURLRequestContextGetter> request_context_; | 289 scoped_refptr<ChromeURLRequestContextGetter> request_context_; |
| 296 | 290 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 315 // Set to true if the ExternalTabContainerWin instance is waiting for an ack | 309 // Set to true if the ExternalTabContainerWin instance is waiting for an ack |
| 316 // from the host. | 310 // from the host. |
| 317 bool pending_; | 311 bool pending_; |
| 318 | 312 |
| 319 views::FocusManager* focus_manager_; | 313 views::FocusManager* focus_manager_; |
| 320 | 314 |
| 321 views::View* external_tab_view_; | 315 views::View* external_tab_view_; |
| 322 | 316 |
| 323 IPC::Message* unload_reply_message_; | 317 IPC::Message* unload_reply_message_; |
| 324 | 318 |
| 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_; | 319 scoped_ptr<ui::ViewProp> prop_; |
| 331 | 320 |
| 332 // if this tab is a popup | 321 // if this tab is a popup |
| 333 bool is_popup_window_; | 322 bool is_popup_window_; |
| 334 | 323 |
| 335 DISALLOW_COPY_AND_ASSIGN(ExternalTabContainerWin); | 324 DISALLOW_COPY_AND_ASSIGN(ExternalTabContainerWin); |
| 336 }; | 325 }; |
| 337 | 326 |
| 338 // This class is instantiated for handling requests to open popups for external | 327 // 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 | 328 // 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; | 383 return false; |
| 395 } | 384 } |
| 396 | 385 |
| 397 virtual void BeforeUnloadFired(content::WebContents* tab, bool proceed, | 386 virtual void BeforeUnloadFired(content::WebContents* tab, bool proceed, |
| 398 bool* proceed_to_fire_unload) { | 387 bool* proceed_to_fire_unload) { |
| 399 NOTREACHED(); | 388 NOTREACHED(); |
| 400 } | 389 } |
| 401 }; | 390 }; |
| 402 | 391 |
| 403 #endif // CHROME_BROWSER_UI_VIEWS_EXTERNAL_TAB_CONTAINER_WIN_H_ | 392 #endif // CHROME_BROWSER_UI_VIEWS_EXTERNAL_TAB_CONTAINER_WIN_H_ |
| OLD | NEW |