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