| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_COCOA_NOTIFICATIONS_BALLOON_VIEW_HOST_MAC_H_ | 5 #ifndef CHROME_BROWSER_COCOA_NOTIFICATIONS_BALLOON_VIEW_HOST_MAC_H_ |
| 6 #define CHROME_BROWSER_COCOA_NOTIFICATIONS_BALLOON_VIEW_HOST_MAC_H_ | 6 #define CHROME_BROWSER_COCOA_NOTIFICATIONS_BALLOON_VIEW_HOST_MAC_H_ |
| 7 | 7 |
| 8 #include "chrome/browser/notifications/balloon.h" | 8 #include "chrome/browser/notifications/balloon_host.h" |
| 9 #include "chrome/browser/notifications/notification.h" | |
| 10 #include "chrome/browser/renderer_host/render_view_host_delegate.h" | |
| 11 #import "chrome/browser/renderer_host/render_widget_host_view_mac.h" | 9 #import "chrome/browser/renderer_host/render_widget_host_view_mac.h" |
| 12 #include "chrome/browser/renderer_host/site_instance.h" | |
| 13 #include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" | |
| 14 #include "gfx/native_widget_types.h" | |
| 15 #include "webkit/glue/webpreferences.h" | |
| 16 | |
| 17 class Profile; | |
| 18 class RenderViewHost; | |
| 19 class SkBitmap; | |
| 20 namespace gfx { | |
| 21 class Point; | |
| 22 } | |
| 23 | 10 |
| 24 // BalloonViewHost class is a delegate to the renderer host for the HTML | 11 // BalloonViewHost class is a delegate to the renderer host for the HTML |
| 25 // notification. When initialized it creates a new RenderViewHost and loads | 12 // notification. When initialized it creates a new RenderViewHost and loads |
| 26 // the contents of the toast into it. It also handles links within the toast, | 13 // the contents of the toast into it. It also handles links within the toast, |
| 27 // loading them into a new tab. | 14 // loading them into a new tab. |
| 28 class BalloonViewHost : public RenderViewHostDelegate, | 15 class BalloonViewHost : public BalloonHost { |
| 29 public RenderViewHostDelegate::View { | |
| 30 public: | 16 public: |
| 31 explicit BalloonViewHost(Balloon* balloon); | 17 explicit BalloonViewHost(Balloon* balloon); |
| 32 | 18 |
| 33 ~BalloonViewHost() { | 19 ~BalloonViewHost() { |
| 34 Shutdown(); | 20 Shutdown(); |
| 35 } | 21 } |
| 36 | 22 |
| 37 // Initialize the view. | 23 // Changes the size of the balloon. |
| 38 void Init(); | |
| 39 | |
| 40 // Stops showing the balloon. | |
| 41 void Shutdown(); | |
| 42 | |
| 43 // RenderViewHostDelegate overrides. | |
| 44 virtual WebPreferences GetWebkitPrefs(); | |
| 45 virtual RendererPreferences GetRendererPrefs(Profile* profile) const; | |
| 46 virtual SiteInstance* GetSiteInstance() const { | |
| 47 return site_instance_.get(); | |
| 48 } | |
| 49 virtual Profile* GetProfile() const { return balloon_->profile(); } | |
| 50 virtual const GURL& GetURL() const { | |
| 51 return balloon_->notification().content_url(); | |
| 52 } | |
| 53 virtual void Close(RenderViewHost* render_view_host); | |
| 54 virtual void RenderViewCreated(RenderViewHost* render_view_host); | |
| 55 virtual void DidStopLoading() {} | |
| 56 virtual void RendererReady(RenderViewHost* render_view_host); | |
| 57 virtual void RendererGone(RenderViewHost* render_view_host); | |
| 58 virtual void UpdateTitle(RenderViewHost* /* render_view_host */, | |
| 59 int32 /* page_id */, const std::wstring& title) { | |
| 60 title_ = title; | |
| 61 } | |
| 62 virtual int GetBrowserWindowID() const { return -1; } | |
| 63 virtual ViewType::Type GetRenderViewType() const { | |
| 64 return ViewType::TAB_CONTENTS; | |
| 65 } | |
| 66 virtual RenderViewHostDelegate::View* GetViewDelegate() { | |
| 67 return this; | |
| 68 } | |
| 69 | |
| 70 void UpdateActualSize(const gfx::Size& new_size); | 24 void UpdateActualSize(const gfx::Size& new_size); |
| 71 | 25 |
| 72 // RenderViewHostDelegate::View methods. Only the ones for opening new | |
| 73 // windows are currently implemented. | |
| 74 virtual void CreateNewWindow(int route_id); | |
| 75 virtual void CreateNewWidget(int route_id, bool activatable) {} | |
| 76 virtual void ShowCreatedWindow(int route_id, | |
| 77 WindowOpenDisposition disposition, | |
| 78 const gfx::Rect& initial_pos, | |
| 79 bool user_gesture); | |
| 80 virtual void ShowCreatedWidget(int route_id, | |
| 81 const gfx::Rect& initial_pos) {} | |
| 82 virtual void ShowContextMenu(const ContextMenuParams& params) {} | |
| 83 virtual void StartDragging(const WebDropData& drop_data, | |
| 84 WebKit::WebDragOperationsMask allowed_ops, | |
| 85 const SkBitmap& image, | |
| 86 const gfx::Point& image_offset) {} | |
| 87 virtual void UpdateDragCursor(WebKit::WebDragOperation operation) {} | |
| 88 virtual void GotFocus() {} | |
| 89 virtual void TakeFocus(bool reverse) {} | |
| 90 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, | |
| 91 bool* is_keyboard_shortcut) { | |
| 92 return false; | |
| 93 } | |
| 94 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {} | |
| 95 virtual void HandleMouseEvent() {} | |
| 96 virtual void HandleMouseLeave() {} | |
| 97 virtual void UpdatePreferredSize(const gfx::Size& pref_size); | |
| 98 | |
| 99 // Accessors. | 26 // Accessors. |
| 100 RenderViewHost* render_view_host() const { return render_view_host_; } | |
| 101 gfx::NativeView native_view() const { | 27 gfx::NativeView native_view() const { |
| 102 return render_widget_host_view_->native_view(); | 28 return render_widget_host_view_->native_view(); |
| 103 } | 29 } |
| 104 const std::wstring& title() const { return title_; } | 30 |
| 31 protected: |
| 32 virtual void InitRenderWidgetHostView(); |
| 33 virtual RenderWidgetHostView* render_widget_host_view() const { |
| 34 return render_widget_host_view_; |
| 35 } |
| 105 | 36 |
| 106 private: | 37 private: |
| 107 // True after Init() has completed. | |
| 108 bool initialized_; | |
| 109 | |
| 110 // Non-owned pointer to the associated balloon. | |
| 111 Balloon* balloon_; | |
| 112 | |
| 113 // Site instance for the balloon/profile, to be used for opening new links. | |
| 114 scoped_refptr<SiteInstance> site_instance_; | |
| 115 | |
| 116 // Owned pointer to to host for the renderer process. | |
| 117 RenderViewHost* render_view_host_; | |
| 118 | |
| 119 // Indicates whether we should notify about disconnection of this balloon. | |
| 120 // This is used to ensure disconnection notifications only happen if | |
| 121 // a connection notification has happened and that they happen only once. | |
| 122 bool should_notify_on_disconnect_; | |
| 123 | |
| 124 // The title of the balloon page. | |
| 125 std::wstring title_; | |
| 126 | |
| 127 // The Mac-specific widget host view. This is owned by its native view, | 38 // The Mac-specific widget host view. This is owned by its native view, |
| 128 // which this class frees in its destructor. | 39 // which this class frees in its destructor. |
| 129 RenderWidgetHostViewMac* render_widget_host_view_; | 40 RenderWidgetHostViewMac* render_widget_host_view_; |
| 130 | 41 |
| 131 // Common implementations of some RenderViewHostDelegate::View methods. | |
| 132 RenderViewHostDelegateViewHelper delegate_view_helper_; | |
| 133 | |
| 134 DISALLOW_COPY_AND_ASSIGN(BalloonViewHost); | 42 DISALLOW_COPY_AND_ASSIGN(BalloonViewHost); |
| 135 }; | 43 }; |
| 136 | 44 |
| 137 #endif // CHROME_BROWSER_COCOA_NOTIFICATIONS_BALLOON_VIEW_HOST_MAC_H_ | 45 #endif // CHROME_BROWSER_COCOA_NOTIFICATIONS_BALLOON_VIEW_HOST_MAC_H_ |
| OLD | NEW |