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 #include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" | 5 #include "content/browser/tab_contents/tab_contents_view_helper.h" |
6 | 6 |
7 #include "content/browser/renderer_host/render_view_host.h" | 7 #include "content/browser/renderer_host/render_view_host.h" |
8 #include "content/browser/renderer_host/render_widget_host.h" | 8 #include "content/browser/renderer_host/render_widget_host.h" |
9 #include "content/browser/renderer_host/render_widget_host_view.h" | 9 #include "content/browser/renderer_host/render_widget_host_view.h" |
10 #include "content/browser/tab_contents/tab_contents.h" | 10 #include "content/browser/tab_contents/tab_contents.h" |
11 #include "content/browser/tab_contents/tab_contents_view.h" | 11 #include "content/browser/tab_contents/tab_contents_view.h" |
12 #include "content/common/view_messages.h" | 12 #include "content/common/view_messages.h" |
13 #include "content/public/browser/notification_service.h" | 13 #include "content/public/browser/notification_service.h" |
14 #include "content/public/browser/notification_source.h" | 14 #include "content/public/browser/notification_source.h" |
15 #include "content/public/browser/notification_types.h" | 15 #include "content/public/browser/notification_types.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "content/public/browser/web_contents_delegate.h" | 17 #include "content/public/browser/web_contents_delegate.h" |
18 | 18 |
19 using content::WebContents; | 19 using content::WebContents; |
20 | 20 |
21 RenderViewHostDelegateViewHelper::RenderViewHostDelegateViewHelper() { | 21 TabContentsViewHelper::TabContentsViewHelper() { |
22 registrar_.Add(this, | 22 registrar_.Add(this, |
23 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 23 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
24 content::NotificationService::AllBrowserContextsAndSources()); | 24 content::NotificationService::AllBrowserContextsAndSources()); |
25 } | 25 } |
26 | 26 |
27 RenderViewHostDelegateViewHelper::~RenderViewHostDelegateViewHelper() {} | 27 TabContentsViewHelper::~TabContentsViewHelper() {} |
28 | 28 |
29 void RenderViewHostDelegateViewHelper::Observe( | 29 void TabContentsViewHelper::Observe( |
30 int type, | 30 int type, |
31 const content::NotificationSource& source, | 31 const content::NotificationSource& source, |
32 const content::NotificationDetails& details) { | 32 const content::NotificationDetails& details) { |
33 DCHECK_EQ(type, content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED); | 33 DCHECK_EQ(type, content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED); |
34 RenderWidgetHost* host = content::Source<RenderWidgetHost>(source).ptr(); | 34 RenderWidgetHost* host = content::Source<RenderWidgetHost>(source).ptr(); |
35 for (PendingWidgetViews::iterator i = pending_widget_views_.begin(); | 35 for (PendingWidgetViews::iterator i = pending_widget_views_.begin(); |
36 i != pending_widget_views_.end(); ++i) { | 36 i != pending_widget_views_.end(); ++i) { |
37 if (host->view() == i->second) { | 37 if (host->view() == i->second) { |
38 pending_widget_views_.erase(i); | 38 pending_widget_views_.erase(i); |
39 break; | 39 break; |
40 } | 40 } |
41 } | 41 } |
42 } | 42 } |
43 | 43 |
44 TabContents* RenderViewHostDelegateViewHelper::CreateNewWindow( | 44 TabContents* TabContentsViewHelper::CreateNewWindow( |
45 WebContents* web_contents, | 45 WebContents* web_contents, |
46 int route_id, | 46 int route_id, |
47 const ViewHostMsg_CreateWindow_Params& params) { | 47 const ViewHostMsg_CreateWindow_Params& params) { |
48 bool should_create = true; | 48 bool should_create = true; |
49 if (web_contents->GetDelegate()) { | 49 if (web_contents->GetDelegate()) { |
50 should_create = web_contents->GetDelegate()->ShouldCreateWebContents( | 50 should_create = web_contents->GetDelegate()->ShouldCreateWebContents( |
51 web_contents, | 51 web_contents, |
52 route_id, | 52 route_id, |
53 params.window_container_type, | 53 params.window_container_type, |
54 params.frame_name); | 54 params.frame_name); |
(...skipping 23 matching lines...) Expand all Loading... |
78 | 78 |
79 if (web_contents->GetDelegate()) | 79 if (web_contents->GetDelegate()) |
80 web_contents->GetDelegate()->WebContentsCreated(web_contents, | 80 web_contents->GetDelegate()->WebContentsCreated(web_contents, |
81 params.opener_frame_id, | 81 params.opener_frame_id, |
82 params.target_url, | 82 params.target_url, |
83 new_contents); | 83 new_contents); |
84 | 84 |
85 return new_contents; | 85 return new_contents; |
86 } | 86 } |
87 | 87 |
88 RenderWidgetHostView* RenderViewHostDelegateViewHelper::CreateNewWidget( | 88 RenderWidgetHostView* TabContentsViewHelper::CreateNewWidget( |
89 WebContents* web_contents, | 89 WebContents* web_contents, |
90 int route_id, | 90 int route_id, |
91 bool is_fullscreen, | 91 bool is_fullscreen, |
92 WebKit::WebPopupType popup_type) { | 92 WebKit::WebPopupType popup_type) { |
93 content::RenderProcessHost* process = web_contents->GetRenderProcessHost(); | 93 content::RenderProcessHost* process = web_contents->GetRenderProcessHost(); |
94 RenderWidgetHost* widget_host = new RenderWidgetHost(process, route_id); | 94 RenderWidgetHost* widget_host = new RenderWidgetHost(process, route_id); |
95 RenderWidgetHostView* widget_view = | 95 RenderWidgetHostView* widget_view = |
96 RenderWidgetHostView::CreateViewForWidget(widget_host); | 96 RenderWidgetHostView::CreateViewForWidget(widget_host); |
97 if (!is_fullscreen) { | 97 if (!is_fullscreen) { |
98 // Popups should not get activated. | 98 // Popups should not get activated. |
99 widget_view->set_popup_type(popup_type); | 99 widget_view->set_popup_type(popup_type); |
100 } | 100 } |
101 // Save the created widget associated with the route so we can show it later. | 101 // Save the created widget associated with the route so we can show it later. |
102 pending_widget_views_[route_id] = widget_view; | 102 pending_widget_views_[route_id] = widget_view; |
103 return widget_view; | 103 return widget_view; |
104 } | 104 } |
105 | 105 |
106 TabContents* RenderViewHostDelegateViewHelper::GetCreatedWindow(int route_id) { | 106 TabContents* TabContentsViewHelper::GetCreatedWindow(int route_id) { |
107 PendingContents::iterator iter = pending_contents_.find(route_id); | 107 PendingContents::iterator iter = pending_contents_.find(route_id); |
108 | 108 |
109 // Certain systems can block the creation of new windows. If we didn't succeed | 109 // Certain systems can block the creation of new windows. If we didn't succeed |
110 // in creating one, just return NULL. | 110 // in creating one, just return NULL. |
111 if (iter == pending_contents_.end()) { | 111 if (iter == pending_contents_.end()) { |
112 return NULL; | 112 return NULL; |
113 } | 113 } |
114 | 114 |
115 TabContents* new_contents = iter->second; | 115 TabContents* new_contents = iter->second; |
116 pending_contents_.erase(route_id); | 116 pending_contents_.erase(route_id); |
117 | 117 |
118 if (!new_contents->GetRenderProcessHost()->HasConnection() || | 118 if (!new_contents->GetRenderProcessHost()->HasConnection() || |
119 !new_contents->GetRenderViewHost()->view()) | 119 !new_contents->GetRenderViewHost()->view()) |
120 return NULL; | 120 return NULL; |
121 | 121 |
122 // TODO(brettw): It seems bogus to reach into here and initialize the host. | 122 // TODO(brettw): It seems bogus to reach into here and initialize the host. |
123 new_contents->GetRenderViewHost()->Init(); | 123 new_contents->GetRenderViewHost()->Init(); |
124 return new_contents; | 124 return new_contents; |
125 } | 125 } |
126 | 126 |
127 RenderWidgetHostView* RenderViewHostDelegateViewHelper::GetCreatedWidget( | 127 RenderWidgetHostView* TabContentsViewHelper::GetCreatedWidget(int route_id) { |
128 int route_id) { | |
129 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id); | 128 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id); |
130 if (iter == pending_widget_views_.end()) { | 129 if (iter == pending_widget_views_.end()) { |
131 DCHECK(false); | 130 DCHECK(false); |
132 return NULL; | 131 return NULL; |
133 } | 132 } |
134 | 133 |
135 RenderWidgetHostView* widget_host_view = iter->second; | 134 RenderWidgetHostView* widget_host_view = iter->second; |
136 pending_widget_views_.erase(route_id); | 135 pending_widget_views_.erase(route_id); |
137 | 136 |
138 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost(); | 137 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost(); |
139 if (!widget_host->process()->HasConnection()) { | 138 if (!widget_host->process()->HasConnection()) { |
140 // The view has gone away or the renderer crashed. Nothing to do. | 139 // The view has gone away or the renderer crashed. Nothing to do. |
141 return NULL; | 140 return NULL; |
142 } | 141 } |
143 | 142 |
144 return widget_host_view; | 143 return widget_host_view; |
145 } | 144 } |
146 | 145 |
147 TabContents* RenderViewHostDelegateViewHelper::ShowCreatedWindow( | 146 TabContents* TabContentsViewHelper::ShowCreatedWindow( |
148 WebContents* web_contents, | 147 WebContents* web_contents, |
149 int route_id, | 148 int route_id, |
150 WindowOpenDisposition disposition, | 149 WindowOpenDisposition disposition, |
151 const gfx::Rect& initial_pos, | 150 const gfx::Rect& initial_pos, |
152 bool user_gesture) { | 151 bool user_gesture) { |
153 TabContents* contents = GetCreatedWindow(route_id); | 152 TabContents* contents = GetCreatedWindow(route_id); |
154 if (contents) { | 153 if (contents) { |
155 web_contents->AddNewContents(contents, | 154 web_contents->AddNewContents(contents, |
156 disposition, | 155 disposition, |
157 initial_pos, | 156 initial_pos, |
158 user_gesture); | 157 user_gesture); |
159 } | 158 } |
160 return contents; | 159 return contents; |
161 } | 160 } |
162 | 161 |
163 RenderWidgetHostView* RenderViewHostDelegateViewHelper::ShowCreatedWidget( | 162 RenderWidgetHostView* TabContentsViewHelper::ShowCreatedWidget( |
164 WebContents* web_contents, | 163 WebContents* web_contents, |
165 int route_id, | 164 int route_id, |
166 bool is_fullscreen, | 165 bool is_fullscreen, |
167 const gfx::Rect& initial_pos) { | 166 const gfx::Rect& initial_pos) { |
168 if (web_contents->GetDelegate()) | 167 if (web_contents->GetDelegate()) |
169 web_contents->GetDelegate()->RenderWidgetShowing(); | 168 web_contents->GetDelegate()->RenderWidgetShowing(); |
170 | 169 |
171 RenderWidgetHostView* widget_host_view = GetCreatedWidget(route_id); | 170 RenderWidgetHostView* widget_host_view = GetCreatedWidget(route_id); |
172 if (is_fullscreen) { | 171 if (is_fullscreen) { |
173 widget_host_view->InitAsFullscreen(web_contents->GetRenderWidgetHostView()); | 172 widget_host_view->InitAsFullscreen(web_contents->GetRenderWidgetHostView()); |
174 } else { | 173 } else { |
175 widget_host_view->InitAsPopup(web_contents->GetRenderWidgetHostView(), | 174 widget_host_view->InitAsPopup(web_contents->GetRenderWidgetHostView(), |
176 initial_pos); | 175 initial_pos); |
177 } | 176 } |
178 widget_host_view->GetRenderWidgetHost()->Init(); | 177 widget_host_view->GetRenderWidgetHost()->Init(); |
179 return widget_host_view; | 178 return widget_host_view; |
180 } | 179 } |
OLD | NEW |