Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: content/browser/web_contents/web_contents_impl.cc

Issue 2821473002: Service CreateNewWindow on the UI thread with a new mojo interface (Closed)
Patch Set: dcheng fixes + security exploit browsertest nerfing Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_impl.h" 5 #include "content/browser/web_contents/web_contents_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <cmath> 9 #include <cmath>
10 #include <utility> 10 #include <utility>
(...skipping 2027 matching lines...) Expand 10 before | Expand all | Expand 10 after
2038 2038
2039 void WebContentsImpl::OnRenderFrameProxyVisibilityChanged(bool visible) { 2039 void WebContentsImpl::OnRenderFrameProxyVisibilityChanged(bool visible) {
2040 if (visible && !GetOuterWebContents()->IsHidden()) 2040 if (visible && !GetOuterWebContents()->IsHidden())
2041 WasShown(); 2041 WasShown();
2042 else if (!visible) 2042 else if (!visible)
2043 WasHidden(); 2043 WasHidden();
2044 } 2044 }
2045 2045
2046 void WebContentsImpl::CreateNewWindow( 2046 void WebContentsImpl::CreateNewWindow(
2047 SiteInstance* source_site_instance, 2047 SiteInstance* source_site_instance,
2048 RenderFrameHost* opener,
2048 int32_t render_view_route_id, 2049 int32_t render_view_route_id,
2049 int32_t main_frame_route_id, 2050 int32_t main_frame_route_id,
2050 int32_t main_frame_widget_route_id, 2051 int32_t main_frame_widget_route_id,
2051 const mojom::CreateNewWindowParams& params, 2052 const mojom::CreateNewWindowParams& params,
2052 SessionStorageNamespace* session_storage_namespace) { 2053 SessionStorageNamespace* session_storage_namespace) {
2053 // We should have zero valid routing ids, or three valid routing IDs. 2054 // We should have zero valid routing ids, or three valid routing IDs.
2054 DCHECK_EQ((render_view_route_id == MSG_ROUTING_NONE), 2055 DCHECK_EQ((render_view_route_id == MSG_ROUTING_NONE),
2055 (main_frame_route_id == MSG_ROUTING_NONE)); 2056 (main_frame_route_id == MSG_ROUTING_NONE));
2056 DCHECK_EQ((render_view_route_id == MSG_ROUTING_NONE), 2057 DCHECK_EQ((render_view_route_id == MSG_ROUTING_NONE),
2057 (main_frame_widget_route_id == MSG_ROUTING_NONE)); 2058 (main_frame_widget_route_id == MSG_ROUTING_NONE));
2058 2059
2059 int render_process_id = source_site_instance->GetProcess()->GetID(); 2060 int render_process_id = source_site_instance->GetProcess()->GetID();
2060 // The route IDs passed into this function can be trusted not to already be in 2061 // The route IDs passed into this function can be trusted not to already be in
2061 // use; they were allocated by the RenderWidgetHelper on the IO thread. 2062 // use; they were allocated by the RenderWidgetHelper on the IO thread.
ncarter (slow) 2017/04/20 21:30:36 The "on the IO thread" clause is now inaccurate.
Charlie Harrison 2017/04/21 15:30:07 Done.
2062 DCHECK(!RenderFrameHostImpl::FromID(render_process_id, main_frame_route_id)); 2063 DCHECK(!RenderFrameHostImpl::FromID(render_process_id, main_frame_route_id));
2063 2064
2064 // We usually create the new window in the same BrowsingInstance (group of 2065 // We usually create the new window in the same BrowsingInstance (group of
2065 // script-related windows), by passing in the current SiteInstance. However, 2066 // script-related windows), by passing in the current SiteInstance. However,
2066 // if the opener is being suppressed (in a non-guest), we create a new 2067 // if the opener is being suppressed (in a non-guest), we create a new
2067 // SiteInstance in its own BrowsingInstance. 2068 // SiteInstance in its own BrowsingInstance.
2068 bool is_guest = BrowserPluginGuest::IsGuest(this); 2069 bool is_guest = BrowserPluginGuest::IsGuest(this);
2069 2070
2070 // If the opener is to be suppressed, the new window can be in any process. 2071 // If the opener is to be suppressed, the new window can be in any process.
2071 // Since routing ids are process specific, we must not have one passed in 2072 // Since routing ids are process specific, we must not have one passed in
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2105 // have a chance to create more frames at this point. 2106 // have a chance to create more frames at this point.
2106 RenderFrameHostImpl* rfh = 2107 RenderFrameHostImpl* rfh =
2107 RenderFrameHostImpl::FromID(render_process_id, main_frame_route_id); 2108 RenderFrameHostImpl::FromID(render_process_id, main_frame_route_id);
2108 if (rfh) { 2109 if (rfh) {
2109 DCHECK(rfh->IsRenderFrameLive()); 2110 DCHECK(rfh->IsRenderFrameLive());
2110 rfh->Init(); 2111 rfh->Init();
2111 } 2112 }
2112 return; 2113 return;
2113 } 2114 }
2114 2115
2116 int opener_render_frame_id = opener->GetRoutingID();
ncarter (slow) 2017/04/20 21:30:36 Just inline this: there are multiple render_frame_
Charlie Harrison 2017/04/21 15:30:07 Done.
2117
2115 // Create the new web contents. This will automatically create the new 2118 // Create the new web contents. This will automatically create the new
2116 // WebContentsView. In the future, we may want to create the view separately. 2119 // WebContentsView. In the future, we may want to create the view separately.
2117 CreateParams create_params(GetBrowserContext(), site_instance.get()); 2120 CreateParams create_params(GetBrowserContext(), site_instance.get());
2118 create_params.routing_id = render_view_route_id; 2121 create_params.routing_id = render_view_route_id;
2119 create_params.main_frame_routing_id = main_frame_route_id; 2122 create_params.main_frame_routing_id = main_frame_route_id;
2120 create_params.main_frame_widget_routing_id = main_frame_widget_route_id; 2123 create_params.main_frame_widget_routing_id = main_frame_widget_route_id;
2121 create_params.main_frame_name = params.frame_name; 2124 create_params.main_frame_name = params.frame_name;
2122 create_params.opener_render_process_id = render_process_id; 2125 create_params.opener_render_process_id = render_process_id;
2123 create_params.opener_render_frame_id = params.opener_render_frame_id; 2126 create_params.opener_render_frame_id = opener_render_frame_id;
2124 create_params.opener_suppressed = params.opener_suppressed; 2127 create_params.opener_suppressed = params.opener_suppressed;
2125 if (params.disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB) 2128 if (params.disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB)
2126 create_params.initially_hidden = true; 2129 create_params.initially_hidden = true;
2127 create_params.renderer_initiated_creation = 2130 create_params.renderer_initiated_creation =
2128 main_frame_route_id != MSG_ROUTING_NONE; 2131 main_frame_route_id != MSG_ROUTING_NONE;
2129 2132
2130 WebContentsImpl* new_contents = NULL; 2133 WebContentsImpl* new_contents = NULL;
2131 if (!is_guest) { 2134 if (!is_guest) {
2132 create_params.context = view_->GetNativeView(); 2135 create_params.context = view_->GetNativeView();
2133 create_params.initial_size = GetContainerBounds().size(); 2136 create_params.initial_size = GetContainerBounds().size();
(...skipping 26 matching lines...) Expand all
2160 } 2163 }
2161 // Save the created window associated with the route so we can show it 2164 // Save the created window associated with the route so we can show it
2162 // later. 2165 // later.
2163 DCHECK_NE(MSG_ROUTING_NONE, main_frame_widget_route_id); 2166 DCHECK_NE(MSG_ROUTING_NONE, main_frame_widget_route_id);
2164 pending_contents_[std::make_pair( 2167 pending_contents_[std::make_pair(
2165 render_process_id, main_frame_widget_route_id)] = new_contents; 2168 render_process_id, main_frame_widget_route_id)] = new_contents;
2166 AddDestructionObserver(new_contents); 2169 AddDestructionObserver(new_contents);
2167 } 2170 }
2168 2171
2169 if (delegate_) { 2172 if (delegate_) {
2170 delegate_->WebContentsCreated( 2173 delegate_->WebContentsCreated(this, render_process_id,
2171 this, render_process_id, params.opener_render_frame_id, 2174 opener->GetRoutingID(), params.frame_name,
2172 params.frame_name, params.target_url, new_contents); 2175 params.target_url, new_contents);
2173 } 2176 }
2174 2177
2175 RenderFrameHost* source_render_frame_host = 2178 if (opener) {
2176 RenderFrameHost::FromID(render_process_id, params.opener_render_frame_id);
2177
2178 if (source_render_frame_host) {
2179 for (auto& observer : observers_) { 2179 for (auto& observer : observers_) {
2180 observer.DidOpenRequestedURL(new_contents, source_render_frame_host, 2180 observer.DidOpenRequestedURL(new_contents, opener, params.target_url,
2181 params.target_url, params.referrer, 2181 params.referrer, params.disposition,
2182 params.disposition, ui::PAGE_TRANSITION_LINK, 2182 ui::PAGE_TRANSITION_LINK,
2183 false, // started_from_context_menu 2183 false, // started_from_context_menu
2184 true); // renderer_initiated 2184 true); // renderer_initiated
2185 } 2185 }
2186 } 2186 }
2187 2187
2188 if (params.opener_suppressed) { 2188 if (params.opener_suppressed) {
2189 // When the opener is suppressed, the original renderer cannot access the 2189 // When the opener is suppressed, the original renderer cannot access the
2190 // new window. As a result, we need to show and navigate the window here. 2190 // new window. As a result, we need to show and navigate the window here.
2191 bool was_blocked = false; 2191 bool was_blocked = false;
2192 if (delegate_) { 2192 if (delegate_) {
(...skipping 3279 matching lines...) Expand 10 before | Expand all | Expand 10 after
5472 RenderViewHost* render_view_host = RenderViewHost::From(render_widget_host); 5472 RenderViewHost* render_view_host = RenderViewHost::From(render_widget_host);
5473 if (!render_view_host) 5473 if (!render_view_host)
5474 continue; 5474 continue;
5475 render_view_host_set.insert(render_view_host); 5475 render_view_host_set.insert(render_view_host);
5476 } 5476 }
5477 for (RenderViewHost* render_view_host : render_view_host_set) 5477 for (RenderViewHost* render_view_host : render_view_host_set)
5478 render_view_host->OnWebkitPreferencesChanged(); 5478 render_view_host->OnWebkitPreferencesChanged();
5479 } 5479 }
5480 5480
5481 } // namespace content 5481 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698