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

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: MakeShared goodness Created 3 years, 7 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 2026 matching lines...) Expand 10 before | Expand all | Expand 10 after
2037 } 2037 }
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 RenderFrameHost* opener,
2048 int32_t render_view_route_id, 2048 int32_t render_view_route_id,
2049 int32_t main_frame_route_id, 2049 int32_t main_frame_route_id,
2050 int32_t main_frame_widget_route_id, 2050 int32_t main_frame_widget_route_id,
2051 const mojom::CreateNewWindowParams& params, 2051 const mojom::CreateNewWindowParams& params,
2052 SessionStorageNamespace* session_storage_namespace) { 2052 SessionStorageNamespace* session_storage_namespace) {
2053 // We should have zero valid routing ids, or three valid routing IDs. 2053 // We should have zero valid routing ids, or three valid routing IDs.
2054 DCHECK_EQ((render_view_route_id == MSG_ROUTING_NONE), 2054 DCHECK_EQ((render_view_route_id == MSG_ROUTING_NONE),
2055 (main_frame_route_id == MSG_ROUTING_NONE)); 2055 (main_frame_route_id == MSG_ROUTING_NONE));
2056 DCHECK_EQ((render_view_route_id == MSG_ROUTING_NONE), 2056 DCHECK_EQ((render_view_route_id == MSG_ROUTING_NONE),
2057 (main_frame_widget_route_id == MSG_ROUTING_NONE)); 2057 (main_frame_widget_route_id == MSG_ROUTING_NONE));
2058 DCHECK(opener);
2058 2059
2059 int render_process_id = source_site_instance->GetProcess()->GetID(); 2060 int render_process_id = opener->GetProcess()->GetID();
2060 // The route IDs passed into this function can be trusted not to already be in 2061 SiteInstance* source_site_instance = opener->GetSiteInstance();
2061 // use; they were allocated by the RenderWidgetHelper on the IO thread. 2062
2063 // The route IDs passed into this function can be trusted not to already
2064 // be in use; they were allocated by the RenderWidgetHelper by the caller.
2062 DCHECK(!RenderFrameHostImpl::FromID(render_process_id, main_frame_route_id)); 2065 DCHECK(!RenderFrameHostImpl::FromID(render_process_id, main_frame_route_id));
2063 2066
2064 // We usually create the new window in the same BrowsingInstance (group of 2067 // We usually create the new window in the same BrowsingInstance (group of
2065 // script-related windows), by passing in the current SiteInstance. However, 2068 // 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 2069 // if the opener is being suppressed (in a non-guest), we create a new
2067 // SiteInstance in its own BrowsingInstance. 2070 // SiteInstance in its own BrowsingInstance.
2068 bool is_guest = BrowserPluginGuest::IsGuest(this); 2071 bool is_guest = BrowserPluginGuest::IsGuest(this);
2069 2072
2070 // If the opener is to be suppressed, the new window can be in any process. 2073 // 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 2074 // Since routing ids are process specific, we must not have one passed in
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2113 } 2116 }
2114 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->GetRoutingID();
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