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

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: Revert initial suspension of resource requests on app window open. 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
« no previous file with comments | « apps/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 "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" 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" 12 #include "content/public/browser/render_process_host.h"
15 #include "content/public/browser/render_view_host.h" 13 #include "content/public/browser/render_view_host.h"
16 #include "content/public/browser/resource_dispatcher_host.h" 14 #include "content/public/browser/resource_dispatcher_host.h"
17 #include "content/public/browser/site_instance.h" 15 #include "content/public/browser/site_instance.h"
18 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
19 #include "content/public/common/renderer_preferences.h" 17 #include "content/public/common/renderer_preferences.h"
20 #include "extensions/common/extension_messages.h" 18 #include "extensions/common/extension_messages.h"
21 19
22 namespace app_window = extensions::api::app_window; 20 namespace app_window = extensions::api::app_window;
23 21
24 namespace apps { 22 namespace apps {
25 23
26 AppWindowContentsImpl::AppWindowContentsImpl(AppWindow* host) : host_(host) {} 24 AppWindowContentsImpl::AppWindowContentsImpl(AppWindow* host) : host_(host) {}
27 25
28 AppWindowContentsImpl::~AppWindowContentsImpl() {} 26 AppWindowContentsImpl::~AppWindowContentsImpl() {}
29 27
30 void AppWindowContentsImpl::Initialize(content::BrowserContext* context, 28 void AppWindowContentsImpl::Initialize(content::BrowserContext* context,
31 const GURL& url) { 29 const GURL& url) {
32 url_ = url; 30 url_ = url;
33 31
34 extension_function_dispatcher_.reset( 32 extension_function_dispatcher_.reset(
35 new extensions::ExtensionFunctionDispatcher(context, this)); 33 new extensions::ExtensionFunctionDispatcher(context, this));
36 34
37 web_contents_.reset( 35 web_contents_.reset(
38 content::WebContents::Create(content::WebContents::CreateParams( 36 content::WebContents::Create(content::WebContents::CreateParams(
39 context, content::SiteInstance::CreateForURL(context, url_)))); 37 context, content::SiteInstance::CreateForURL(context, url_))));
40 38
41 content::WebContentsObserver::Observe(web_contents_.get()); 39 Observe(web_contents_.get());
42 web_contents_->GetMutableRendererPrefs()-> 40 web_contents_->GetMutableRendererPrefs()->
43 browser_handles_all_top_level_requests = true; 41 browser_handles_all_top_level_requests = true;
44 web_contents_->GetRenderViewHost()->SyncRendererPrefs(); 42 web_contents_->GetRenderViewHost()->SyncRendererPrefs();
45 } 43 }
46 44
47 void AppWindowContentsImpl::LoadContents(int32 creator_process_id) { 45 void AppWindowContentsImpl::LoadContents(int32 creator_process_id) {
48 // If the new view is in the same process as the creator, block the created 46 // 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 47 // RVH from loading anything until the background page has had a chance to
50 // do any initialization it wants. If it's a different process, the new RVH 48 // 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). 49 // shouldn't communicate with the background page anyway (e.g. sandboxed).
52 if (web_contents_->GetRenderViewHost()->GetProcess()->GetID() == 50 if (web_contents_->GetRenderViewHost()->GetProcess()->GetID() ==
53 creator_process_id) { 51 creator_process_id) {
54 SuspendRenderViewHost(web_contents_->GetRenderViewHost()); 52 SuspendRenderViewHost(web_contents_->GetRenderViewHost());
55 } else { 53 } else {
56 VLOG(1) << "AppWindow created in new process (" 54 VLOG(1) << "AppWindow created in new process ("
57 << web_contents_->GetRenderViewHost()->GetProcess()->GetID() 55 << web_contents_->GetRenderViewHost()->GetProcess()->GetID()
58 << ") != creator (" << creator_process_id << "). Routing disabled."; 56 << ") != creator (" << creator_process_id << "). Routing disabled.";
59 } 57 }
60 58
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( 59 web_contents_->GetController().LoadURL(
72 url_, content::Referrer(), content::PAGE_TRANSITION_LINK, 60 url_, content::Referrer(), content::PAGE_TRANSITION_LINK,
73 std::string()); 61 std::string());
74 registrar_.RemoveAll();
75 } 62 }
76 63
77 void AppWindowContentsImpl::NativeWindowChanged( 64 void AppWindowContentsImpl::NativeWindowChanged(
78 NativeAppWindow* native_app_window) { 65 NativeAppWindow* native_app_window) {
79 base::ListValue args; 66 base::ListValue args;
80 base::DictionaryValue* dictionary = new base::DictionaryValue(); 67 base::DictionaryValue* dictionary = new base::DictionaryValue();
81 args.Append(dictionary); 68 args.Append(dictionary);
82 host_->GetSerializedState(dictionary); 69 host_->GetSerializedState(dictionary);
83 70
84 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost(); 71 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost();
(...skipping 18 matching lines...) Expand all
103 "app.window", 90 "app.window",
104 "appWindowShownForTests", 91 "appWindowShownForTests",
105 args, 92 args,
106 false)); 93 false));
107 } 94 }
108 95
109 content::WebContents* AppWindowContentsImpl::GetWebContents() const { 96 content::WebContents* AppWindowContentsImpl::GetWebContents() const {
110 return web_contents_.get(); 97 return web_contents_.get();
111 } 98 }
112 99
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) { 100 bool AppWindowContentsImpl::OnMessageReceived(const IPC::Message& message) {
135 bool handled = true; 101 bool handled = true;
136 IPC_BEGIN_MESSAGE_MAP(AppWindowContentsImpl, message) 102 IPC_BEGIN_MESSAGE_MAP(AppWindowContentsImpl, message)
137 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) 103 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest)
138 IPC_MESSAGE_HANDLER(ExtensionHostMsg_UpdateDraggableRegions, 104 IPC_MESSAGE_HANDLER(ExtensionHostMsg_UpdateDraggableRegions,
139 UpdateDraggableRegions) 105 UpdateDraggableRegions)
140 IPC_MESSAGE_UNHANDLED(handled = false) 106 IPC_MESSAGE_UNHANDLED(handled = false)
141 IPC_END_MESSAGE_MAP() 107 IPC_END_MESSAGE_MAP()
142 return handled; 108 return handled;
143 } 109 }
(...skipping 22 matching lines...) Expand all
166 content::RenderViewHost* rvh) { 132 content::RenderViewHost* rvh) {
167 DCHECK(rvh); 133 DCHECK(rvh);
168 content::BrowserThread::PostTask( 134 content::BrowserThread::PostTask(
169 content::BrowserThread::IO, FROM_HERE, 135 content::BrowserThread::IO, FROM_HERE,
170 base::Bind(&content::ResourceDispatcherHost::BlockRequestsForRoute, 136 base::Bind(&content::ResourceDispatcherHost::BlockRequestsForRoute,
171 base::Unretained(content::ResourceDispatcherHost::Get()), 137 base::Unretained(content::ResourceDispatcherHost::Get()),
172 rvh->GetProcess()->GetID(), rvh->GetRoutingID())); 138 rvh->GetProcess()->GetID(), rvh->GetRoutingID()));
173 } 139 }
174 140
175 } // namespace apps 141 } // namespace apps
OLDNEW
« no previous file with comments | « apps/app_window_contents.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698