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 "content/browser/tab_contents/tab_contents_view_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/tab_contents/tab_contents.h" | 9 #include "content/browser/tab_contents/tab_contents.h" |
10 #include "content/common/view_messages.h" | 10 #include "content/common/view_messages.h" |
11 #include "content/port/browser/render_widget_host_view_port.h" | 11 #include "content/port/browser/render_widget_host_view_port.h" |
12 #include "content/public/browser/notification_service.h" | 12 #include "content/public/browser/notification_service.h" |
13 #include "content/public/browser/notification_source.h" | 13 #include "content/public/browser/notification_source.h" |
14 #include "content/public/browser/notification_types.h" | 14 #include "content/public/browser/notification_types.h" |
| 15 #include "content/public/browser/site_instance.h" |
15 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
16 #include "content/public/browser/web_contents_delegate.h" | 17 #include "content/public/browser/web_contents_delegate.h" |
17 #include "content/public/browser/web_contents_view.h" | 18 #include "content/public/browser/web_contents_view.h" |
18 | 19 |
19 using content::RenderWidgetHostView; | 20 using content::RenderWidgetHostView; |
20 using content::RenderWidgetHostViewPort; | 21 using content::RenderWidgetHostViewPort; |
21 using content::WebContents; | 22 using content::WebContents; |
22 | 23 |
23 TabContentsViewHelper::TabContentsViewHelper() { | 24 TabContentsViewHelper::TabContentsViewHelper() { |
24 registrar_.Add(this, | 25 registrar_.Add(this, |
(...skipping 27 matching lines...) Expand all Loading... |
52 should_create = web_contents->GetDelegate()->ShouldCreateWebContents( | 53 should_create = web_contents->GetDelegate()->ShouldCreateWebContents( |
53 web_contents, | 54 web_contents, |
54 route_id, | 55 route_id, |
55 params.window_container_type, | 56 params.window_container_type, |
56 params.frame_name); | 57 params.frame_name); |
57 } | 58 } |
58 | 59 |
59 if (!should_create) | 60 if (!should_create) |
60 return NULL; | 61 return NULL; |
61 | 62 |
| 63 // We usually create the new window in the same BrowsingInstance (group of |
| 64 // script-related windows), by passing in the current SiteInstance. However, |
| 65 // if the opener is being suppressed, we create a new SiteInstance in its own |
| 66 // BrowsingInstance. |
| 67 scoped_refptr<content::SiteInstance> site_instance = |
| 68 params.opener_suppressed ? |
| 69 content::SiteInstance::Create(web_contents->GetBrowserContext()) : |
| 70 web_contents->GetSiteInstance(); |
| 71 |
62 // Create the new web contents. This will automatically create the new | 72 // Create the new web contents. This will automatically create the new |
63 // WebContentsView. In the future, we may want to create the view separately. | 73 // WebContentsView. In the future, we may want to create the view separately. |
64 TabContents* new_contents = | 74 TabContents* new_contents = |
65 new TabContents(web_contents->GetBrowserContext(), | 75 new TabContents(web_contents->GetBrowserContext(), |
66 web_contents->GetSiteInstance(), | 76 site_instance, |
67 route_id, | 77 route_id, |
68 static_cast<TabContents*>(web_contents), | 78 static_cast<TabContents*>(web_contents), |
69 NULL); | 79 NULL); |
70 new_contents->set_opener_web_ui_type( | 80 new_contents->set_opener_web_ui_type( |
71 web_contents->GetWebUITypeForCurrentState()); | 81 web_contents->GetWebUITypeForCurrentState()); |
| 82 |
| 83 if (params.opener_suppressed) { |
| 84 // When the opener is suppressed, the original renderer cannot access the |
| 85 // new window. As a result, we need to show and navigate the window here. |
| 86 gfx::Rect initial_pos; |
| 87 web_contents->AddNewContents(new_contents, |
| 88 params.disposition, |
| 89 initial_pos, |
| 90 params.user_gesture); |
| 91 content::OpenURLParams open_params(params.target_url, content::Referrer(), |
| 92 CURRENT_TAB, |
| 93 content::PAGE_TRANSITION_LINK, |
| 94 true /* is_renderer_initiated */); |
| 95 WebContents* opened_contents = new_contents->OpenURL(open_params); |
| 96 DCHECK_EQ(new_contents, opened_contents); |
| 97 return new_contents; |
| 98 } |
| 99 |
72 content::WebContentsView* new_view = new_contents->GetView(); | 100 content::WebContentsView* new_view = new_contents->GetView(); |
73 | 101 |
74 // TODO(brettw): It seems bogus that we have to call this function on the | 102 // TODO(brettw): It seems bogus that we have to call this function on the |
75 // newly created object and give it one of its own member variables. | 103 // newly created object and give it one of its own member variables. |
76 new_view->CreateViewForWidget(new_contents->GetRenderViewHost()); | 104 new_view->CreateViewForWidget(new_contents->GetRenderViewHost()); |
77 | 105 |
78 // Save the created window associated with the route so we can show it later. | 106 // Save the created window associated with the route so we can show it later. |
| 107 DCHECK_NE(MSG_ROUTING_NONE, route_id); |
79 pending_contents_[route_id] = new_contents; | 108 pending_contents_[route_id] = new_contents; |
80 | 109 |
81 if (web_contents->GetDelegate()) | 110 if (web_contents->GetDelegate()) |
82 web_contents->GetDelegate()->WebContentsCreated(web_contents, | 111 web_contents->GetDelegate()->WebContentsCreated(web_contents, |
83 params.opener_frame_id, | 112 params.opener_frame_id, |
84 params.target_url, | 113 params.target_url, |
85 new_contents); | 114 new_contents); |
86 | 115 |
87 return new_contents; | 116 return new_contents; |
88 } | 117 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id)); | 203 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id)); |
175 if (is_fullscreen) { | 204 if (is_fullscreen) { |
176 widget_host_view->InitAsFullscreen(web_contents->GetRenderWidgetHostView()); | 205 widget_host_view->InitAsFullscreen(web_contents->GetRenderWidgetHostView()); |
177 } else { | 206 } else { |
178 widget_host_view->InitAsPopup(web_contents->GetRenderWidgetHostView(), | 207 widget_host_view->InitAsPopup(web_contents->GetRenderWidgetHostView(), |
179 initial_pos); | 208 initial_pos); |
180 } | 209 } |
181 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost())->Init(); | 210 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost())->Init(); |
182 return widget_host_view; | 211 return widget_host_view; |
183 } | 212 } |
OLD | NEW |