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 #include "chrome/browser/ui/views/notifications/balloon_view_host.h"
7 #include "chrome/browser/notifications/balloon.h"
8 #include "content/public/browser/content_browser_client.h"
9 #include "content/public/browser/render_view_host.h"
10 #include "content/public/browser/render_widget_host_view.h"
11 #include "content/public/browser/web_contents.h"
12 #include "ui/views/widget/widget.h"
14 class BalloonViewHostView
: public views::NativeViewHost
{
16 explicit BalloonViewHostView(BalloonViewHost
* host
)
21 virtual void ViewHierarchyChanged(
22 const ViewHierarchyChangedDetails
& details
) OVERRIDE
{
23 NativeViewHost::ViewHierarchyChanged(details
);
24 if (details
.is_add
&& GetWidget() && !initialized_
) {
26 host_
->Init(GetWidget()->GetNativeView());
31 // The host owns this object.
32 BalloonViewHost
* host_
;
37 BalloonViewHost::BalloonViewHost(Balloon
* balloon
)
38 : BalloonHost(balloon
) {
39 native_host_
= new BalloonViewHostView(this);
42 BalloonViewHost::~BalloonViewHost() {
46 void BalloonViewHost::Init(gfx::NativeView parent_native_view
) {
47 parent_native_view_
= parent_native_view
;
50 content::RenderWidgetHostView
* render_widget_host_view
=
51 web_contents_
->GetRenderViewHost()->GetView();
53 native_host_
->Attach(render_widget_host_view
->GetNativeView());