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

Side by Side Diff: extensions/browser/app_window/app_window_contents.cc

Issue 1567903002: [Test - Do Not Commit] Stop blocking requests for new windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge onto #371523 Created 4 years, 11 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
« no previous file with comments | « extensions/browser/app_window/app_window_contents.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "extensions/browser/app_window/app_window_contents.h" 5 #include "extensions/browser/app_window/app_window_contents.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "content/public/browser/browser_context.h" 10 #include "content/public/browser/browser_context.h"
11 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/render_frame_host.h" 12 #include "content/public/browser/render_frame_host.h"
13 #include "content/public/browser/render_process_host.h" 13 #include "content/public/browser/render_process_host.h"
14 #include "content/public/browser/render_view_host.h" 14 #include "content/public/browser/render_view_host.h"
15 #include "content/public/browser/resource_dispatcher_host.h" 15 #include "content/public/browser/resource_dispatcher_host.h"
16 #include "content/public/browser/site_instance.h" 16 #include "content/public/browser/site_instance.h"
17 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
18 #include "content/public/common/renderer_preferences.h" 18 #include "content/public/common/renderer_preferences.h"
19 #include "extensions/browser/app_window/native_app_window.h" 19 #include "extensions/browser/app_window/native_app_window.h"
20 #include "extensions/common/extension_messages.h" 20 #include "extensions/common/extension_messages.h"
21 21
22 namespace extensions { 22 namespace extensions {
23 23
24 AppWindowContentsImpl::AppWindowContentsImpl(AppWindow* host) 24 AppWindowContentsImpl::AppWindowContentsImpl(AppWindow* host)
25 : host_(host), is_blocking_requests_(false), is_window_ready_(false) {} 25 : host_(host), is_window_ready_(false) {}
26 26
27 AppWindowContentsImpl::~AppWindowContentsImpl() {} 27 AppWindowContentsImpl::~AppWindowContentsImpl() {}
28 28
29 void AppWindowContentsImpl::Initialize(content::BrowserContext* context, 29 void AppWindowContentsImpl::Initialize(content::BrowserContext* context,
30 const GURL& url) { 30 const GURL& url) {
31 url_ = url; 31 url_ = url;
32 32
33 web_contents_.reset( 33 web_contents_.reset(
34 content::WebContents::Create(content::WebContents::CreateParams( 34 content::WebContents::Create(content::WebContents::CreateParams(
35 context, content::SiteInstance::CreateForURL(context, url_)))); 35 context, content::SiteInstance::CreateForURL(context, url_))));
36 36
37 Observe(web_contents_.get()); 37 Observe(web_contents_.get());
38 web_contents_->GetMutableRendererPrefs()-> 38 web_contents_->GetMutableRendererPrefs()->
39 browser_handles_all_top_level_requests = true; 39 browser_handles_all_top_level_requests = true;
40 web_contents_->GetRenderViewHost()->SyncRendererPrefs(); 40 web_contents_->GetRenderViewHost()->SyncRendererPrefs();
41 } 41 }
42 42
43 void AppWindowContentsImpl::LoadContents(int32_t creator_process_id) { 43 void AppWindowContentsImpl::LoadContents(int32_t creator_process_id) {
44 // If the new view is in the same process as the creator, block the created
45 // RVH from loading anything until the background page has had a chance to
46 // do any initialization it wants. If it's a different process, the new RVH
47 // shouldn't communicate with the background page anyway (e.g. sandboxed).
48 if (web_contents_->GetMainFrame()->GetProcess()->GetID() ==
49 creator_process_id) {
50 SuspendRenderFrameHost(web_contents_->GetMainFrame());
51 } else {
52 VLOG(1) << "AppWindow created in new process ("
53 << web_contents_->GetMainFrame()->GetProcess()->GetID()
54 << ") != creator (" << creator_process_id << "). Routing disabled.";
55 }
56
57 web_contents_->GetController().LoadURL( 44 web_contents_->GetController().LoadURL(
58 url_, content::Referrer(), ui::PAGE_TRANSITION_LINK, 45 url_, content::Referrer(), ui::PAGE_TRANSITION_LINK,
59 std::string()); 46 std::string());
60 } 47 }
61 48
62 void AppWindowContentsImpl::NativeWindowChanged( 49 void AppWindowContentsImpl::NativeWindowChanged(
63 NativeAppWindow* native_app_window) { 50 NativeAppWindow* native_app_window) {
64 base::ListValue args; 51 base::ListValue args;
65 base::DictionaryValue* dictionary = new base::DictionaryValue(); 52 base::DictionaryValue* dictionary = new base::DictionaryValue();
66 args.Append(dictionary); 53 args.Append(dictionary);
(...skipping 13 matching lines...) Expand all
80 void AppWindowContentsImpl::DispatchWindowShownForTests() const { 67 void AppWindowContentsImpl::DispatchWindowShownForTests() const {
81 base::ListValue args; 68 base::ListValue args;
82 content::RenderFrameHost* rfh = web_contents_->GetMainFrame(); 69 content::RenderFrameHost* rfh = web_contents_->GetMainFrame();
83 rfh->Send(new ExtensionMsg_MessageInvoke( 70 rfh->Send(new ExtensionMsg_MessageInvoke(
84 rfh->GetRoutingID(), host_->extension_id(), "app.window", 71 rfh->GetRoutingID(), host_->extension_id(), "app.window",
85 "appWindowShownForTests", args, false)); 72 "appWindowShownForTests", args, false));
86 } 73 }
87 74
88 void AppWindowContentsImpl::OnWindowReady() { 75 void AppWindowContentsImpl::OnWindowReady() {
89 is_window_ready_ = true; 76 is_window_ready_ = true;
90 if (is_blocking_requests_) {
91 is_blocking_requests_ = false;
92 content::RenderFrameHost* frame = web_contents_->GetMainFrame();
93 content::BrowserThread::PostTask(
94 content::BrowserThread::IO, FROM_HERE,
95 base::Bind(
96 &content::ResourceDispatcherHost::ResumeBlockedRequestsForRoute,
97 base::Unretained(content::ResourceDispatcherHost::Get()),
98 frame->GetProcess()->GetID(),
99 frame->GetRenderViewHost()->GetRoutingID()));
100 }
101 } 77 }
102 78
103 content::WebContents* AppWindowContentsImpl::GetWebContents() const { 79 content::WebContents* AppWindowContentsImpl::GetWebContents() const {
104 return web_contents_.get(); 80 return web_contents_.get();
105 } 81 }
106 82
107 WindowController* AppWindowContentsImpl::GetWindowController() const { 83 WindowController* AppWindowContentsImpl::GetWindowController() const {
108 return nullptr; 84 return nullptr;
109 } 85 }
110 86
(...skipping 11 matching lines...) Expand all
122 content::NavigationHandle* handle) { 98 content::NavigationHandle* handle) {
123 if (!is_window_ready_) 99 if (!is_window_ready_)
124 host_->OnReadyToCommitFirstNavigation(); 100 host_->OnReadyToCommitFirstNavigation();
125 } 101 }
126 102
127 void AppWindowContentsImpl::UpdateDraggableRegions( 103 void AppWindowContentsImpl::UpdateDraggableRegions(
128 const std::vector<DraggableRegion>& regions) { 104 const std::vector<DraggableRegion>& regions) {
129 host_->UpdateDraggableRegions(regions); 105 host_->UpdateDraggableRegions(regions);
130 } 106 }
131 107
132 void AppWindowContentsImpl::SuspendRenderFrameHost(
133 content::RenderFrameHost* rfh) {
134 DCHECK(rfh);
135 // Don't bother blocking requests if the renderer side is already good to go.
136 if (is_window_ready_)
137 return;
138 is_blocking_requests_ = true;
139 // The ResourceDispatcherHost only accepts RenderViewHost child ids.
140 // TODO(devlin): This will need to change for site isolation.
141 content::BrowserThread::PostTask(
142 content::BrowserThread::IO, FROM_HERE,
143 base::Bind(&content::ResourceDispatcherHost::BlockRequestsForRoute,
144 base::Unretained(content::ResourceDispatcherHost::Get()),
145 rfh->GetProcess()->GetID(),
146 rfh->GetRenderViewHost()->GetRoutingID()));
147 }
148
149 } // namespace extensions 108 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/app_window/app_window_contents.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698