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/web_contents/web_contents_view_helper.h" | 5 #include "content/browser/web_contents/web_contents_view_helper.h" |
6 | 6 |
7 #include "content/browser/renderer_host/render_view_host_impl.h" | 7 #include "content/browser/renderer_host/render_view_host_impl.h" |
8 #include "content/browser/web_contents/web_contents_impl.h" | 8 #include "content/browser/web_contents/web_contents_impl.h" |
9 #include "content/common/view_messages.h" | 9 #include "content/common/view_messages.h" |
10 #include "content/port/browser/render_widget_host_view_port.h" | 10 #include "content/port/browser/render_widget_host_view_port.h" |
11 #include "content/public/browser/notification_service.h" | 11 #include "content/public/browser/notification_service.h" |
12 #include "content/public/browser/notification_source.h" | 12 #include "content/public/browser/notification_source.h" |
13 #include "content/public/browser/notification_types.h" | 13 #include "content/public/browser/notification_types.h" |
14 #include "content/public/browser/site_instance.h" | 14 #include "content/public/browser/site_instance.h" |
15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
16 #include "content/public/browser/web_contents_delegate.h" | 16 #include "content/public/browser/web_contents_delegate.h" |
17 #include "content/public/browser/web_contents_view.h" | 17 #include "content/public/browser/web_contents_view.h" |
18 | 18 |
19 using content::RenderViewHostImpl; | 19 using content::RenderViewHostImpl; |
20 using content::RenderWidgetHost; | 20 using content::RenderWidgetHost; |
21 using content::RenderWidgetHostImpl; | 21 using content::RenderWidgetHostImpl; |
22 using content::RenderWidgetHostView; | 22 using content::RenderWidgetHostView; |
23 using content::RenderWidgetHostViewPort; | 23 using content::RenderWidgetHostViewPort; |
| 24 using content::SiteInstance; |
24 | 25 |
25 WebContentsViewHelper::WebContentsViewHelper() { | 26 WebContentsViewHelper::WebContentsViewHelper() { |
26 registrar_.Add(this, | 27 registrar_.Add(this, |
27 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 28 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
28 content::NotificationService::AllBrowserContextsAndSources()); | 29 content::NotificationService::AllBrowserContextsAndSources()); |
29 } | 30 } |
30 | 31 |
31 WebContentsViewHelper::~WebContentsViewHelper() {} | 32 WebContentsViewHelper::~WebContentsViewHelper() {} |
32 | 33 |
33 void WebContentsViewHelper::Observe( | 34 void WebContentsViewHelper::Observe( |
34 int type, | 35 int type, |
35 const content::NotificationSource& source, | 36 const content::NotificationSource& source, |
36 const content::NotificationDetails& details) { | 37 const content::NotificationDetails& details) { |
37 DCHECK_EQ(type, content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED); | 38 DCHECK_EQ(type, content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED); |
38 RenderWidgetHost* host = content::Source<RenderWidgetHost>(source).ptr(); | 39 RenderWidgetHost* host = content::Source<RenderWidgetHost>(source).ptr(); |
39 for (PendingWidgetViews::iterator i = pending_widget_views_.begin(); | 40 for (PendingWidgetViews::iterator i = pending_widget_views_.begin(); |
40 i != pending_widget_views_.end(); ++i) { | 41 i != pending_widget_views_.end(); ++i) { |
41 if (host->GetView() == i->second) { | 42 if (host->GetView() == i->second) { |
42 pending_widget_views_.erase(i); | 43 pending_widget_views_.erase(i); |
43 break; | 44 break; |
44 } | 45 } |
45 } | 46 } |
46 } | 47 } |
47 | 48 |
48 WebContentsImpl* WebContentsViewHelper::CreateNewWindow( | 49 WebContentsImpl* WebContentsViewHelper::CreateNewWindow( |
49 WebContentsImpl* web_contents, | 50 WebContentsImpl* opener, |
50 int route_id, | 51 int route_id, |
51 const ViewHostMsg_CreateWindow_Params& params) { | 52 const ViewHostMsg_CreateWindow_Params& params) { |
52 bool should_create = true; | 53 bool should_create = true; |
53 if (web_contents->GetDelegate()) { | 54 if (opener->GetDelegate()) { |
54 should_create = web_contents->GetDelegate()->ShouldCreateWebContents( | 55 should_create = opener->GetDelegate()->ShouldCreateWebContents( |
55 web_contents, | 56 opener, |
56 route_id, | 57 route_id, |
57 params.window_container_type, | 58 params.window_container_type, |
58 params.frame_name, | 59 params.frame_name, |
59 params.target_url); | 60 params.target_url); |
60 } | 61 } |
61 | 62 |
62 if (!should_create) | 63 if (!should_create) |
63 return NULL; | 64 return NULL; |
64 | 65 |
65 // We usually create the new window in the same BrowsingInstance (group of | 66 // We usually create the new window in the same BrowsingInstance (group of |
66 // script-related windows), by passing in the current SiteInstance. However, | 67 // script-related windows), by passing in the current SiteInstance. However, |
67 // if the opener is being suppressed, we create a new SiteInstance in its own | 68 // if the opener is being suppressed, we create a new SiteInstance in its own |
68 // BrowsingInstance. | 69 // BrowsingInstance. |
69 scoped_refptr<content::SiteInstance> site_instance = | 70 scoped_refptr<SiteInstance> site_instance = |
70 params.opener_suppressed ? | 71 params.opener_suppressed ? |
71 content::SiteInstance::Create(web_contents->GetBrowserContext()) : | 72 SiteInstance::Create(opener->GetBrowserContext()) : |
72 web_contents->GetSiteInstance(); | 73 opener->GetSiteInstance(); |
73 | 74 |
74 // Create the new web contents. This will automatically create the new | 75 // Create the new web contents. This will automatically create the new |
75 // WebContentsView. In the future, we may want to create the view separately. | 76 // WebContentsView. In the future, we may want to create the view separately. |
76 WebContentsImpl* new_contents = | 77 WebContentsImpl* new_contents = |
77 new WebContentsImpl(web_contents->GetBrowserContext(), | 78 new WebContentsImpl(opener->GetBrowserContext(), |
78 site_instance, | 79 site_instance, |
79 route_id, | 80 route_id, |
80 web_contents, | 81 opener, |
| 82 params.opener_suppressed ? NULL : opener, |
81 NULL); | 83 NULL); |
82 new_contents->set_opener_web_ui_type( | 84 new_contents->set_opener_web_ui_type( |
83 web_contents->GetWebUITypeForCurrentState()); | 85 opener->GetWebUITypeForCurrentState()); |
84 new_contents->set_has_opener(!params.opener_url.is_empty()); | |
85 | 86 |
86 if (!params.opener_suppressed) { | 87 if (!params.opener_suppressed) { |
87 content::WebContentsView* new_view = new_contents->GetView(); | 88 content::WebContentsView* new_view = new_contents->GetView(); |
88 | 89 |
89 // TODO(brettw): It seems bogus that we have to call this function on the | 90 // TODO(brettw): It seems bogus that we have to call this function on the |
90 // newly created object and give it one of its own member variables. | 91 // newly created object and give it one of its own member variables. |
91 new_view->CreateViewForWidget(new_contents->GetRenderViewHost()); | 92 new_view->CreateViewForWidget(new_contents->GetRenderViewHost()); |
92 | 93 |
93 // Save the created window associated with the route so we can show it | 94 // Save the created window associated with the route so we can show it |
94 // later. | 95 // later. |
95 DCHECK_NE(MSG_ROUTING_NONE, route_id); | 96 DCHECK_NE(MSG_ROUTING_NONE, route_id); |
96 pending_contents_[route_id] = new_contents; | 97 pending_contents_[route_id] = new_contents; |
97 } | 98 } |
98 | 99 |
99 if (web_contents->GetDelegate()) | 100 if (opener->GetDelegate()) { |
100 web_contents->GetDelegate()->WebContentsCreated(web_contents, | 101 opener->GetDelegate()->WebContentsCreated(opener, |
101 params.opener_frame_id, | 102 params.opener_frame_id, |
102 params.target_url, | 103 params.target_url, |
103 new_contents); | 104 new_contents); |
| 105 } |
104 | 106 |
105 if (params.opener_suppressed) { | 107 if (params.opener_suppressed) { |
106 // When the opener is suppressed, the original renderer cannot access the | 108 // When the opener is suppressed, the original renderer cannot access the |
107 // new window. As a result, we need to show and navigate the window here. | 109 // new window. As a result, we need to show and navigate the window here. |
108 gfx::Rect initial_pos; | 110 gfx::Rect initial_pos; |
109 web_contents->AddNewContents(new_contents, | 111 opener->AddNewContents(new_contents, |
110 params.disposition, | 112 params.disposition, |
111 initial_pos, | 113 initial_pos, |
112 params.user_gesture); | 114 params.user_gesture); |
113 | 115 |
114 content::OpenURLParams open_params(params.target_url, content::Referrer(), | 116 content::OpenURLParams open_params(params.target_url, content::Referrer(), |
115 CURRENT_TAB, | 117 CURRENT_TAB, |
116 content::PAGE_TRANSITION_LINK, | 118 content::PAGE_TRANSITION_LINK, |
117 true /* is_renderer_initiated */); | 119 true /* is_renderer_initiated */); |
118 new_contents->OpenURL(open_params); | 120 new_contents->OpenURL(open_params); |
119 } | 121 } |
120 | 122 |
121 return new_contents; | 123 return new_contents; |
122 } | 124 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id)); | 210 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id)); |
209 if (is_fullscreen) { | 211 if (is_fullscreen) { |
210 widget_host_view->InitAsFullscreen(web_contents->GetRenderWidgetHostView()); | 212 widget_host_view->InitAsFullscreen(web_contents->GetRenderWidgetHostView()); |
211 } else { | 213 } else { |
212 widget_host_view->InitAsPopup(web_contents->GetRenderWidgetHostView(), | 214 widget_host_view->InitAsPopup(web_contents->GetRenderWidgetHostView(), |
213 initial_pos); | 215 initial_pos); |
214 } | 216 } |
215 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost())->Init(); | 217 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost())->Init(); |
216 return widget_host_view; | 218 return widget_host_view; |
217 } | 219 } |
OLD | NEW |