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/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/common/view_messages.h" | 11 #include "content/common/view_messages.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::WebContents; | 20 using content::WebContents; |
20 | 21 |
21 TabContentsViewHelper::TabContentsViewHelper() { | 22 TabContentsViewHelper::TabContentsViewHelper() { |
22 registrar_.Add(this, | 23 registrar_.Add(this, |
23 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 24 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
24 content::NotificationService::AllBrowserContextsAndSources()); | 25 content::NotificationService::AllBrowserContextsAndSources()); |
(...skipping 25 matching lines...) Expand all Loading... |
50 should_create = web_contents->GetDelegate()->ShouldCreateWebContents( | 51 should_create = web_contents->GetDelegate()->ShouldCreateWebContents( |
51 web_contents, | 52 web_contents, |
52 route_id, | 53 route_id, |
53 params.window_container_type, | 54 params.window_container_type, |
54 params.frame_name); | 55 params.frame_name); |
55 } | 56 } |
56 | 57 |
57 if (!should_create) | 58 if (!should_create) |
58 return NULL; | 59 return NULL; |
59 | 60 |
| 61 // We usually create the new window in the same BrowsingInstance (group of |
| 62 // script-related windows), by passing in the current SiteInstance. However, |
| 63 // if the opener is being suppressed, we create a new BrowsingInstance |
| 64 // instead by passing a NULL SiteInstance. There's no risk of deleting the |
| 65 // SiteInstance here, so we can use a normal pointer. |
| 66 scoped_refptr<content::SiteInstance> site_instance = |
| 67 params.opener_suppressed ? |
| 68 content::SiteInstance::Create(web_contents->GetBrowserContext()) : |
| 69 web_contents->GetSiteInstance(); |
| 70 |
60 // Create the new web contents. This will automatically create the new | 71 // Create the new web contents. This will automatically create the new |
61 // WebContentsView. In the future, we may want to create the view separately. | 72 // WebContentsView. In the future, we may want to create the view separately. |
62 TabContents* new_contents = | 73 TabContents* new_contents = |
63 new TabContents(web_contents->GetBrowserContext(), | 74 new TabContents(web_contents->GetBrowserContext(), |
64 web_contents->GetSiteInstance(), | 75 site_instance, |
65 route_id, | 76 route_id, |
66 static_cast<TabContents*>(web_contents), | 77 static_cast<TabContents*>(web_contents), |
67 NULL); | 78 NULL); |
68 new_contents->set_opener_web_ui_type( | 79 new_contents->set_opener_web_ui_type( |
69 web_contents->GetWebUITypeForCurrentState()); | 80 web_contents->GetWebUITypeForCurrentState()); |
| 81 |
| 82 if (params.opener_suppressed) { |
| 83 // Now show and navigate it to the intended destination, since the original |
| 84 // renderer can't access it anymore. |
| 85 gfx::Rect initial_pos; |
| 86 web_contents->AddNewContents(new_contents, |
| 87 params.disposition, |
| 88 initial_pos, |
| 89 params.user_gesture); |
| 90 content::OpenURLParams open_params(params.target_url, content::Referrer(), |
| 91 CURRENT_TAB, |
| 92 content::PAGE_TRANSITION_LINK, |
| 93 true /* is_renderer_initiated */); |
| 94 WebContents* opened_contents = new_contents->OpenURL(open_params); |
| 95 DCHECK_EQ(new_contents, opened_contents); |
| 96 return new_contents; |
| 97 } |
| 98 |
70 content::WebContentsView* new_view = new_contents->GetView(); | 99 content::WebContentsView* new_view = new_contents->GetView(); |
71 | 100 |
72 // TODO(brettw): It seems bogus that we have to call this function on the | 101 // TODO(brettw): It seems bogus that we have to call this function on the |
73 // newly created object and give it one of its own member variables. | 102 // newly created object and give it one of its own member variables. |
74 new_view->CreateViewForWidget(new_contents->GetRenderViewHost()); | 103 new_view->CreateViewForWidget(new_contents->GetRenderViewHost()); |
75 | 104 |
76 // Save the created window associated with the route so we can show it later. | 105 // Save the created window associated with the route so we can show it later. |
| 106 DCHECK_NE(MSG_ROUTING_NONE, route_id); |
77 pending_contents_[route_id] = new_contents; | 107 pending_contents_[route_id] = new_contents; |
78 | 108 |
79 if (web_contents->GetDelegate()) | 109 if (web_contents->GetDelegate()) |
80 web_contents->GetDelegate()->WebContentsCreated(web_contents, | 110 web_contents->GetDelegate()->WebContentsCreated(web_contents, |
81 params.opener_frame_id, | 111 params.opener_frame_id, |
82 params.target_url, | 112 params.target_url, |
83 new_contents); | 113 new_contents); |
84 | 114 |
85 return new_contents; | 115 return new_contents; |
86 } | 116 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 RenderWidgetHostView* widget_host_view = GetCreatedWidget(route_id); | 200 RenderWidgetHostView* widget_host_view = GetCreatedWidget(route_id); |
171 if (is_fullscreen) { | 201 if (is_fullscreen) { |
172 widget_host_view->InitAsFullscreen(web_contents->GetRenderWidgetHostView()); | 202 widget_host_view->InitAsFullscreen(web_contents->GetRenderWidgetHostView()); |
173 } else { | 203 } else { |
174 widget_host_view->InitAsPopup(web_contents->GetRenderWidgetHostView(), | 204 widget_host_view->InitAsPopup(web_contents->GetRenderWidgetHostView(), |
175 initial_pos); | 205 initial_pos); |
176 } | 206 } |
177 widget_host_view->GetRenderWidgetHost()->Init(); | 207 widget_host_view->GetRenderWidgetHost()->Init(); |
178 return widget_host_view; | 208 return widget_host_view; |
179 } | 209 } |
OLD | NEW |