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

Side by Side Diff: apps/app_window_contents.cc

Issue 378193002: AppWindowContents: Clean up unnecessary SuspendRenderViewHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove even more unused includes. Created 6 years, 5 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 | Annotate | Revision Log
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 "apps/app_window_contents.h" 5 #include "apps/app_window_contents.h"
6 6
7 #include "apps/ui/native_app_window.h" 7 #include "apps/ui/native_app_window.h"
8 #include "chrome/browser/chrome_notification_types.h" 8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/common/extensions/api/app_window.h" 9 #include "chrome/common/extensions/api/app_window.h"
10 #include "content/public/browser/browser_context.h" 10 #include "content/public/browser/browser_context.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/notification_details.h"
13 #include "content/public/browser/notification_source.h"
14 #include "content/public/browser/render_process_host.h"
15 #include "content/public/browser/render_view_host.h" 11 #include "content/public/browser/render_view_host.h"
16 #include "content/public/browser/resource_dispatcher_host.h"
17 #include "content/public/browser/site_instance.h" 12 #include "content/public/browser/site_instance.h"
18 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
19 #include "content/public/common/renderer_preferences.h" 14 #include "content/public/common/renderer_preferences.h"
20 #include "extensions/common/extension_messages.h" 15 #include "extensions/common/extension_messages.h"
21 16
22 namespace app_window = extensions::api::app_window; 17 namespace app_window = extensions::api::app_window;
23 18
24 namespace apps { 19 namespace apps {
25 20
26 AppWindowContentsImpl::AppWindowContentsImpl(AppWindow* host) : host_(host) {} 21 AppWindowContentsImpl::AppWindowContentsImpl(AppWindow* host) : host_(host) {}
(...skipping 10 matching lines...) Expand all
37 web_contents_.reset( 32 web_contents_.reset(
38 content::WebContents::Create(content::WebContents::CreateParams( 33 content::WebContents::Create(content::WebContents::CreateParams(
39 context, content::SiteInstance::CreateForURL(context, url_)))); 34 context, content::SiteInstance::CreateForURL(context, url_))));
40 35
41 content::WebContentsObserver::Observe(web_contents_.get()); 36 content::WebContentsObserver::Observe(web_contents_.get());
42 web_contents_->GetMutableRendererPrefs()-> 37 web_contents_->GetMutableRendererPrefs()->
43 browser_handles_all_top_level_requests = true; 38 browser_handles_all_top_level_requests = true;
44 web_contents_->GetRenderViewHost()->SyncRendererPrefs(); 39 web_contents_->GetRenderViewHost()->SyncRendererPrefs();
45 } 40 }
46 41
47 void AppWindowContentsImpl::LoadContents(int32 creator_process_id) { 42 void AppWindowContentsImpl::LoadContents() {
48 // If the new view is in the same process as the creator, block the created
49 // RVH from loading anything until the background page has had a chance to
not at google - send to devlin 2014/07/09 13:48:50 RVH is the browser side of a RV. Examples of RVs i
not at google - send to devlin 2014/07/09 13:51:30 Actually one thing that does invalidate my claim w
scheib 2014/07/09 17:31:55 I'm not certain that the Service worker will alway
Matt Giuca 2014/07/10 03:37:06 Well it seems that I'm not changing the behaviour
50 // do any initialization it wants. If it's a different process, the new RVH
51 // shouldn't communicate with the background page anyway (e.g. sandboxed).
52 if (web_contents_->GetRenderViewHost()->GetProcess()->GetID() ==
53 creator_process_id) {
54 SuspendRenderViewHost(web_contents_->GetRenderViewHost());
55 } else {
56 VLOG(1) << "AppWindow created in new process ("
57 << web_contents_->GetRenderViewHost()->GetProcess()->GetID()
58 << ") != creator (" << creator_process_id << "). Routing disabled.";
59 }
60
61 // TODO(jeremya): there's a bug where navigating a web contents to an
62 // extension URL causes it to create a new RVH and discard the old (perfectly
63 // usable) one. To work around this, we watch for a
64 // NOTIFICATION_RENDER_VIEW_HOST_CHANGED message from the web contents (which
65 // will be sent during LoadURL) and suspend resource requests on the new RVH
66 // to ensure that we block the new RVH from loading anything. It should be
67 // okay to remove the NOTIFICATION_RENDER_VIEW_HOST_CHANGED registration once
68 // http://crbug.com/123007 is fixed.
69 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
70 content::Source<content::WebContents>(web_contents()));
71 web_contents_->GetController().LoadURL( 43 web_contents_->GetController().LoadURL(
72 url_, content::Referrer(), content::PAGE_TRANSITION_LINK, 44 url_, content::Referrer(), content::PAGE_TRANSITION_LINK,
73 std::string()); 45 std::string());
74 registrar_.RemoveAll();
75 } 46 }
76 47
77 void AppWindowContentsImpl::NativeWindowChanged( 48 void AppWindowContentsImpl::NativeWindowChanged(
78 NativeAppWindow* native_app_window) { 49 NativeAppWindow* native_app_window) {
79 base::ListValue args; 50 base::ListValue args;
80 base::DictionaryValue* dictionary = new base::DictionaryValue(); 51 base::DictionaryValue* dictionary = new base::DictionaryValue();
81 args.Append(dictionary); 52 args.Append(dictionary);
82 host_->GetSerializedState(dictionary); 53 host_->GetSerializedState(dictionary);
83 54
84 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost(); 55 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost();
(...skipping 18 matching lines...) Expand all
103 "app.window", 74 "app.window",
104 "appWindowShownForTests", 75 "appWindowShownForTests",
105 args, 76 args,
106 false)); 77 false));
107 } 78 }
108 79
109 content::WebContents* AppWindowContentsImpl::GetWebContents() const { 80 content::WebContents* AppWindowContentsImpl::GetWebContents() const {
110 return web_contents_.get(); 81 return web_contents_.get();
111 } 82 }
112 83
113 void AppWindowContentsImpl::Observe(
114 int type,
115 const content::NotificationSource& source,
116 const content::NotificationDetails& details) {
117 switch (type) {
118 case content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED: {
119 // TODO(jeremya): once http://crbug.com/123007 is fixed, we'll no longer
120 // need to suspend resource requests here (the call in the constructor
121 // should be enough).
122 content::Details<std::pair<content::RenderViewHost*,
123 content::RenderViewHost*> >
124 host_details(details);
125 if (host_details->first)
126 SuspendRenderViewHost(host_details->second);
127 break;
128 }
129 default:
130 NOTREACHED() << "Received unexpected notification";
131 }
132 }
133
134 bool AppWindowContentsImpl::OnMessageReceived(const IPC::Message& message) { 84 bool AppWindowContentsImpl::OnMessageReceived(const IPC::Message& message) {
135 bool handled = true; 85 bool handled = true;
136 IPC_BEGIN_MESSAGE_MAP(AppWindowContentsImpl, message) 86 IPC_BEGIN_MESSAGE_MAP(AppWindowContentsImpl, message)
137 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) 87 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest)
138 IPC_MESSAGE_HANDLER(ExtensionHostMsg_UpdateDraggableRegions, 88 IPC_MESSAGE_HANDLER(ExtensionHostMsg_UpdateDraggableRegions,
139 UpdateDraggableRegions) 89 UpdateDraggableRegions)
140 IPC_MESSAGE_UNHANDLED(handled = false) 90 IPC_MESSAGE_UNHANDLED(handled = false)
141 IPC_END_MESSAGE_MAP() 91 IPC_END_MESSAGE_MAP()
142 return handled; 92 return handled;
143 } 93 }
(...skipping 11 matching lines...) Expand all
155 const ExtensionHostMsg_Request_Params& params) { 105 const ExtensionHostMsg_Request_Params& params) {
156 extension_function_dispatcher_->Dispatch( 106 extension_function_dispatcher_->Dispatch(
157 params, web_contents_->GetRenderViewHost()); 107 params, web_contents_->GetRenderViewHost());
158 } 108 }
159 109
160 void AppWindowContentsImpl::UpdateDraggableRegions( 110 void AppWindowContentsImpl::UpdateDraggableRegions(
161 const std::vector<extensions::DraggableRegion>& regions) { 111 const std::vector<extensions::DraggableRegion>& regions) {
162 host_->UpdateDraggableRegions(regions); 112 host_->UpdateDraggableRegions(regions);
163 } 113 }
164 114
165 void AppWindowContentsImpl::SuspendRenderViewHost(
166 content::RenderViewHost* rvh) {
167 DCHECK(rvh);
168 content::BrowserThread::PostTask(
169 content::BrowserThread::IO, FROM_HERE,
170 base::Bind(&content::ResourceDispatcherHost::BlockRequestsForRoute,
171 base::Unretained(content::ResourceDispatcherHost::Get()),
172 rvh->GetProcess()->GetID(), rvh->GetRoutingID()));
173 }
174
175 } // namespace apps 115 } // namespace apps
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698