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