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

Side by Side Diff: content/renderer/render_thread.cc

Issue 6873014: Clear RenderThread of any Chrome specific code, and move a bunch of stuff out of RenderView. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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 | Annotate | Revision Log
« no previous file with comments | « content/renderer/render_thread.h ('k') | content/renderer/render_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/renderer/render_thread.h" 5 #include "content/renderer/render_thread.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <map> 9 #include <map>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/debug/trace_event.h" 13 #include "base/debug/trace_event.h"
14 #include "base/lazy_instance.h" 14 #include "base/lazy_instance.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/metrics/field_trial.h" 16 #include "base/metrics/field_trial.h"
17 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
18 #include "base/metrics/stats_table.h" 18 #include "base/metrics/stats_table.h"
19 #include "base/process_util.h" 19 #include "base/process_util.h"
20 #include "base/shared_memory.h" 20 #include "base/shared_memory.h"
21 #include "base/string_util.h"
22 #include "base/task.h" 21 #include "base/task.h"
23 #include "base/threading/thread_local.h" 22 #include "base/threading/thread_local.h"
24 #include "base/utf_string_conversions.h"
25 #include "base/values.h" 23 #include "base/values.h"
26 #include "chrome/common/chrome_switches.h" 24 // DO NOT ADD ANY MORE INCLUDES TO "chrome/"!
27 #include "chrome/common/render_messages.h"
28 #include "chrome/common/safe_browsing/safebrowsing_messages.h"
29 #include "chrome/common/url_constants.h"
30 #include "content/common/appcache/appcache_dispatcher.h" 25 #include "content/common/appcache/appcache_dispatcher.h"
26 #include "content/common/content_switches.h"
31 #include "content/common/database_messages.h" 27 #include "content/common/database_messages.h"
32 #include "content/common/db_message_filter.h" 28 #include "content/common/db_message_filter.h"
33 #include "content/common/dom_storage_messages.h" 29 #include "content/common/dom_storage_messages.h"
34 #include "content/common/gpu_messages.h" 30 #include "content/common/gpu_messages.h"
35 #include "content/common/plugin_messages.h" 31 #include "content/common/plugin_messages.h"
36 #include "content/common/renderer_preferences.h" 32 #include "content/common/renderer_preferences.h"
37 #include "content/common/resource_messages.h" 33 #include "content/common/resource_messages.h"
38 #include "content/common/view_messages.h" 34 #include "content/common/view_messages.h"
39 #include "content/common/web_database_observer_impl.h" 35 #include "content/common/web_database_observer_impl.h"
40 #include "content/plugin/npobject_util.h" 36 #include "content/plugin/npobject_util.h"
41 #include "content/renderer/content_renderer_client.h" 37 #include "content/renderer/content_renderer_client.h"
42 #include "content/renderer/cookie_message_filter.h"
43 #include "content/renderer/gpu_channel_host.h" 38 #include "content/renderer/gpu_channel_host.h"
44 #include "content/renderer/gpu_video_service_host.h" 39 #include "content/renderer/gpu_video_service_host.h"
45 #include "content/renderer/indexed_db_dispatcher.h" 40 #include "content/renderer/indexed_db_dispatcher.h"
46 #include "content/renderer/plugin_channel_host.h" 41 #include "content/renderer/plugin_channel_host.h"
47 #include "content/renderer/render_process_impl.h" 42 #include "content/renderer/render_process_impl.h"
48 #include "content/renderer/render_process_observer.h" 43 #include "content/renderer/render_process_observer.h"
49 #include "content/renderer/render_view.h" 44 #include "content/renderer/render_view.h"
50 #include "content/renderer/render_view_visitor.h" 45 #include "content/renderer/render_view_visitor.h"
51 #include "content/renderer/renderer_webidbfactory_impl.h" 46 #include "content/renderer/renderer_webidbfactory_impl.h"
52 #include "content/renderer/renderer_webkitclient_impl.h" 47 #include "content/renderer/renderer_webkitclient_impl.h"
53 #include "ipc/ipc_channel_handle.h" 48 #include "ipc/ipc_channel_handle.h"
54 #include "ipc/ipc_platform_file.h" 49 #include "ipc/ipc_platform_file.h"
55 #include "net/base/net_errors.h" 50 #include "net/base/net_errors.h"
56 #include "net/base/net_util.h" 51 #include "net/base/net_util.h"
57 #include "third_party/sqlite/sqlite3.h"
58 #include "third_party/tcmalloc/chromium/src/google/malloc_extension.h" 52 #include "third_party/tcmalloc/chromium/src/google/malloc_extension.h"
59 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h"
60 #include "third_party/WebKit/Source/WebKit/chromium/public/WebColor.h" 53 #include "third_party/WebKit/Source/WebKit/chromium/public/WebColor.h"
61 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCrossOriginPreflig htResultCache.h"
62 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDatabase.h" 54 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDatabase.h"
63 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 55 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
64 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFontCache.h"
65 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 56 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
66 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" 57 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
67 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h" 58 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h"
68 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h " 59 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h "
69 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
70 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageEventDispat cher.h" 60 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageEventDispat cher.h"
71 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" 61 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
72 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 62 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
73 #include "v8/include/v8.h" 63 #include "v8/include/v8.h"
74 #include "webkit/extensions/v8/benchmarking_extension.h" 64 #include "webkit/extensions/v8/benchmarking_extension.h"
75 #include "webkit/extensions/v8/playback_extension.h" 65 #include "webkit/extensions/v8/playback_extension.h"
76 #include "webkit/glue/webkit_glue.h" 66 #include "webkit/glue/webkit_glue.h"
77 67
78 // TODO(port) 68 // TODO(port)
79 #if defined(OS_WIN) 69 #if defined(OS_WIN)
80 #include "content/plugin/plugin_channel.h" 70 #include "content/plugin/plugin_channel.h"
81 #else 71 #else
82 #include "base/memory/scoped_handle.h" 72 #include "base/memory/scoped_handle.h"
83 #include "content/plugin/plugin_channel_base.h" 73 #include "content/plugin/plugin_channel_base.h"
84 #endif 74 #endif
85 75
86 #if defined(OS_WIN) 76 #if defined(OS_WIN)
87 #include <windows.h> 77 #include <windows.h>
88 #include <objbase.h> 78 #include <objbase.h>
89 #endif 79 #endif
90 80
91 #if defined(OS_POSIX) 81 #if defined(OS_POSIX)
92 #include "ipc/ipc_channel_posix.h" 82 #include "ipc/ipc_channel_posix.h"
93 #endif 83 #endif
94 84
95 using WebKit::WebCache;
96 using WebKit::WebCrossOriginPreflightResultCache;
97 using WebKit::WebFontCache;
98 using WebKit::WebFrame; 85 using WebKit::WebFrame;
99 using WebKit::WebRuntimeFeatures; 86 using WebKit::WebRuntimeFeatures;
100 using WebKit::WebSecurityPolicy;
101 using WebKit::WebScriptController; 87 using WebKit::WebScriptController;
102 using WebKit::WebString; 88 using WebKit::WebString;
103 using WebKit::WebStorageEventDispatcher; 89 using WebKit::WebStorageEventDispatcher;
104 using WebKit::WebView; 90 using WebKit::WebView;
105 91
106 namespace { 92 namespace {
107 static const double kInitialIdleHandlerDelayS = 1.0 /* seconds */; 93 static const double kInitialIdleHandlerDelayS = 1.0 /* seconds */;
108 94
109 // Keep the global RenderThread in a TLS slot so it is impossible to access 95 // Keep the global RenderThread in a TLS slot so it is impossible to access
110 // incorrectly from the wrong thread. 96 // incorrectly from the wrong thread.
111 static base::LazyInstance<base::ThreadLocalPointer<RenderThread> > lazy_tls( 97 static base::LazyInstance<base::ThreadLocalPointer<RenderThread> > lazy_tls(
112 base::LINKER_INITIALIZED); 98 base::LINKER_INITIALIZED);
113 99
114 class RenderViewContentSettingsSetter : public RenderViewVisitor {
115 public:
116 RenderViewContentSettingsSetter(const GURL& url,
117 const ContentSettings& content_settings)
118 : url_(url),
119 content_settings_(content_settings) {
120 }
121
122 virtual bool Visit(RenderView* render_view) {
123 if (GURL(render_view->webview()->mainFrame()->url()) == url_)
124 render_view->SetContentSettings(content_settings_);
125 return true;
126 }
127
128 private:
129 GURL url_;
130 ContentSettings content_settings_;
131
132 DISALLOW_COPY_AND_ASSIGN(RenderViewContentSettingsSetter);
133 };
134
135 class RenderViewZoomer : public RenderViewVisitor { 100 class RenderViewZoomer : public RenderViewVisitor {
136 public: 101 public:
137 RenderViewZoomer(const GURL& url, double zoom_level) 102 RenderViewZoomer(const GURL& url, double zoom_level)
138 : zoom_level_(zoom_level) { 103 : zoom_level_(zoom_level) {
139 host_ = net::GetHostOrSpecFromURL(url); 104 host_ = net::GetHostOrSpecFromURL(url);
140 } 105 }
141 106
142 virtual bool Visit(RenderView* render_view) { 107 virtual bool Visit(RenderView* render_view) {
143 WebView* webview = render_view->webview(); // Guaranteed non-NULL. 108 WebView* webview = render_view->webview(); // Guaranteed non-NULL.
144 109
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 147
183 lazy_tls.Pointer()->Set(this); 148 lazy_tls.Pointer()->Set(this);
184 #if defined(OS_WIN) 149 #if defined(OS_WIN)
185 // If you are running plugins in this thread you need COM active but in 150 // If you are running plugins in this thread you need COM active but in
186 // the normal case you don't. 151 // the normal case you don't.
187 if (RenderProcessImpl::InProcessPlugins()) 152 if (RenderProcessImpl::InProcessPlugins())
188 CoInitialize(0); 153 CoInitialize(0);
189 #endif 154 #endif
190 155
191 // In single process the single process is all there is. 156 // In single process the single process is all there is.
192 is_incognito_process_ = false;
193 suspend_webkit_shared_timer_ = true; 157 suspend_webkit_shared_timer_ = true;
194 notify_webkit_of_modal_loop_ = true; 158 notify_webkit_of_modal_loop_ = true;
195 plugin_refresh_allowed_ = true; 159 plugin_refresh_allowed_ = true;
196 widget_count_ = 0; 160 widget_count_ = 0;
197 hidden_widget_count_ = 0; 161 hidden_widget_count_ = 0;
198 idle_notification_delay_in_s_ = kInitialIdleHandlerDelayS; 162 idle_notification_delay_in_s_ = kInitialIdleHandlerDelayS;
199 task_factory_.reset(new ScopedRunnableMethodFactory<RenderThread>(this)); 163 task_factory_.reset(new ScopedRunnableMethodFactory<RenderThread>(this));
200 164
201 appcache_dispatcher_.reset(new AppCacheDispatcher(this)); 165 appcache_dispatcher_.reset(new AppCacheDispatcher(this));
202 indexed_db_dispatcher_.reset(new IndexedDBDispatcher()); 166 indexed_db_dispatcher_.reset(new IndexedDBDispatcher());
203 167
204 db_message_filter_ = new DBMessageFilter(); 168 db_message_filter_ = new DBMessageFilter();
205 AddFilter(db_message_filter_.get()); 169 AddFilter(db_message_filter_.get());
206 170
207 cookie_message_filter_ = new CookieMessageFilter();
208 AddFilter(cookie_message_filter_.get());
209
210 content::GetContentClient()->renderer()->RenderThreadStarted(); 171 content::GetContentClient()->renderer()->RenderThreadStarted();
211 172
212 TRACE_EVENT_END("RenderThread::Init", 0, ""); 173 TRACE_EVENT_END("RenderThread::Init", 0, "");
213 } 174 }
214 175
215 RenderThread::~RenderThread() { 176 RenderThread::~RenderThread() {
216 FOR_EACH_OBSERVER( 177 FOR_EACH_OBSERVER(
217 RenderProcessObserver, observers_, OnRenderProcessShutdown()); 178 RenderProcessObserver, observers_, OnRenderProcessShutdown());
218 179
219 // Wait for all databases to be closed. 180 // Wait for all databases to be closed.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 // Certain synchronous messages cannot always be processed synchronously by 227 // Certain synchronous messages cannot always be processed synchronously by
267 // the browser, e.g., Chrome frame communicating with the embedding browser. 228 // the browser, e.g., Chrome frame communicating with the embedding browser.
268 // This could cause a complete hang of Chrome if a windowed plug-in is trying 229 // This could cause a complete hang of Chrome if a windowed plug-in is trying
269 // to communicate with the renderer thread since the browser's UI thread 230 // to communicate with the renderer thread since the browser's UI thread
270 // could be stuck (within a Windows API call) trying to synchronously 231 // could be stuck (within a Windows API call) trying to synchronously
271 // communicate with the plug-in. The remedy is to pump messages on this 232 // communicate with the plug-in. The remedy is to pump messages on this
272 // thread while the browser is processing this request. This creates an 233 // thread while the browser is processing this request. This creates an
273 // opportunity for re-entrancy into WebKit, so we need to take care to disable 234 // opportunity for re-entrancy into WebKit, so we need to take care to disable
274 // callbacks, timers, and pending network loads that could trigger such 235 // callbacks, timers, and pending network loads that could trigger such
275 // callbacks. 236 // callbacks.
276 bool pumping_events = false, may_show_cookie_prompt = false; 237 bool pumping_events = false;
277 if (msg->is_sync()) { 238 if (msg->is_sync()) {
278 if (msg->is_caller_pumping_messages()) { 239 if (msg->is_caller_pumping_messages()) {
279 pumping_events = true; 240 pumping_events = true;
280 } else { 241 } else {
281 // We only need to pump events for chrome frame processes as the 242 if ((msg->type() == ViewHostMsg_GetCookies::ID ||
282 // cookie policy is controlled by the host browser (IE). If the 243 msg->type() == ViewHostMsg_GetRawCookies::ID ||
283 // policy is set to prompt then the host would put up UI which 244 msg->type() == ViewHostMsg_CookiesEnabled::ID) &&
284 // would require plugins if any to also pump to ensure that we 245 content::GetContentClient()->renderer()->
285 // don't have a deadlock. 246 ShouldPumpEventsDuringCookieMessage()) {
286 if (CommandLine::ForCurrentProcess()->HasSwitch( 247 pumping_events = true;
287 switches::kChromeFrame)) {
288 switch (msg->type()) {
289 case ViewHostMsg_GetCookies::ID:
290 case ViewHostMsg_GetRawCookies::ID:
291 case ViewHostMsg_CookiesEnabled::ID:
292 case DOMStorageHostMsg_SetItem::ID:
293 case ResourceHostMsg_SyncLoad::ID:
294 case DatabaseHostMsg_Allow::ID:
295 may_show_cookie_prompt = true;
296 pumping_events = true;
297 break;
298 default:
299 break;
300 }
301 } 248 }
302 } 249 }
303 } 250 }
304 251
305 bool suspend_webkit_shared_timer = true; // default value 252 bool suspend_webkit_shared_timer = true; // default value
306 std::swap(suspend_webkit_shared_timer, suspend_webkit_shared_timer_); 253 std::swap(suspend_webkit_shared_timer, suspend_webkit_shared_timer_);
307 254
308 bool notify_webkit_of_modal_loop = true; // default value 255 bool notify_webkit_of_modal_loop = true; // default value
309 std::swap(notify_webkit_of_modal_loop, notify_webkit_of_modal_loop_); 256 std::swap(notify_webkit_of_modal_loop, notify_webkit_of_modal_loop_);
310 257
311 gfx::NativeViewId host_window = 0; 258 gfx::NativeViewId host_window = 0;
312 259
313 if (pumping_events) { 260 if (pumping_events) {
314 // See ViewMsg_SignalCookiePromptEvent.
315 if (may_show_cookie_prompt) {
316 static_cast<IPC::SyncMessage*>(msg)->set_pump_messages_event(
317 cookie_message_filter_->pump_messages_event());
318 }
319
320 if (suspend_webkit_shared_timer) 261 if (suspend_webkit_shared_timer)
321 webkit_client_->SuspendSharedTimer(); 262 webkit_client_->SuspendSharedTimer();
322 263
323 if (notify_webkit_of_modal_loop) 264 if (notify_webkit_of_modal_loop)
324 WebView::willEnterModalLoop(); 265 WebView::willEnterModalLoop();
325 266
326 RenderWidget* widget = 267 RenderWidget* widget =
327 static_cast<RenderWidget*>(ResolveRoute(msg->routing_id())); 268 static_cast<RenderWidget*>(ResolveRoute(msg->routing_id()));
328 if (widget) { 269 if (widget) {
329 host_window = widget->host_window(); 270 host_window = widget->host_window();
330 PluginChannelHost::Broadcast( 271 PluginChannelHost::Broadcast(
331 new PluginMsg_SignalModalDialogEvent(host_window)); 272 new PluginMsg_SignalModalDialogEvent(host_window));
332 } 273 }
333 } 274 }
334 275
335 bool rv = ChildThread::Send(msg); 276 bool rv = ChildThread::Send(msg);
336 277
337 if (pumping_events) { 278 if (pumping_events) {
338 if (host_window) { 279 if (host_window) {
339 PluginChannelHost::Broadcast( 280 PluginChannelHost::Broadcast(
340 new PluginMsg_ResetModalDialogEvent(host_window)); 281 new PluginMsg_ResetModalDialogEvent(host_window));
341 } 282 }
342 283
343 if (notify_webkit_of_modal_loop) 284 if (notify_webkit_of_modal_loop)
344 WebView::didExitModalLoop(); 285 WebView::didExitModalLoop();
345 286
346 if (suspend_webkit_shared_timer) 287 if (suspend_webkit_shared_timer)
347 webkit_client_->ResumeSharedTimer(); 288 webkit_client_->ResumeSharedTimer();
348
349 // We may end up nesting calls to Send, so we defer the reset until we
350 // return to the top-most message loop.
351 if (may_show_cookie_prompt &&
352 cookie_message_filter_->pump_messages_event()->IsSignaled()) {
353 MessageLoop::current()->PostNonNestableTask(FROM_HERE,
354 NewRunnableMethod(cookie_message_filter_.get(),
355 &CookieMessageFilter::ResetPumpMessagesEvent));
356 }
357 } 289 }
358 290
359 return rv; 291 return rv;
360 } 292 }
361 293
362 void RenderThread::AddRoute(int32 routing_id, 294 void RenderThread::AddRoute(int32 routing_id,
363 IPC::Channel::Listener* listener) { 295 IPC::Channel::Listener* listener) {
364 widget_count_++; 296 widget_count_++;
365 return ChildThread::AddRoute(routing_id, listener); 297 return ChildThread::AddRoute(routing_id, listener);
366 } 298 }
(...skipping 28 matching lines...) Expand all
395 DCHECK_GT(hidden_widget_count_, 0); 327 DCHECK_GT(hidden_widget_count_, 0);
396 hidden_widget_count_--; 328 hidden_widget_count_--;
397 if (!content::GetContentClient()->renderer()-> 329 if (!content::GetContentClient()->renderer()->
398 RunIdleHandlerWhenWidgetsHidden()) { 330 RunIdleHandlerWhenWidgetsHidden()) {
399 return; 331 return;
400 } 332 }
401 333
402 idle_timer_.Stop(); 334 idle_timer_.Stop();
403 } 335 }
404 336
405 bool RenderThread::IsIncognitoProcess() const {
406 return is_incognito_process_;
407 }
408
409 void RenderThread::AddObserver(RenderProcessObserver* observer) { 337 void RenderThread::AddObserver(RenderProcessObserver* observer) {
410 observers_.AddObserver(observer); 338 observers_.AddObserver(observer);
411 } 339 }
412 340
413 void RenderThread::RemoveObserver(RenderProcessObserver* observer) { 341 void RenderThread::RemoveObserver(RenderProcessObserver* observer) {
414 observers_.RemoveObserver(observer); 342 observers_.RemoveObserver(observer);
415 } 343 }
416 344
417 void RenderThread::DoNotSuspendWebKitSharedTimer() { 345 void RenderThread::DoNotSuspendWebKitSharedTimer() {
418 suspend_webkit_shared_timer_ = false; 346 suspend_webkit_shared_timer_ = false;
419 } 347 }
420 348
421 void RenderThread::DoNotNotifyWebKitOfModalLoop() { 349 void RenderThread::DoNotNotifyWebKitOfModalLoop() {
422 notify_webkit_of_modal_loop_ = false; 350 notify_webkit_of_modal_loop_ = false;
423 } 351 }
424 352
425 void RenderThread::OnSetContentSettingsForCurrentURL(
426 const GURL& url,
427 const ContentSettings& content_settings) {
428 RenderViewContentSettingsSetter setter(url, content_settings);
429 RenderView::ForEach(&setter);
430 }
431
432 void RenderThread::OnSetZoomLevelForCurrentURL(const GURL& url, 353 void RenderThread::OnSetZoomLevelForCurrentURL(const GURL& url,
433 double zoom_level) { 354 double zoom_level) {
434 RenderViewZoomer zoomer(url, zoom_level); 355 RenderViewZoomer zoomer(url, zoom_level);
435 RenderView::ForEach(&zoomer); 356 RenderView::ForEach(&zoomer);
436 } 357 }
437 358
438 void RenderThread::OnDOMStorageEvent( 359 void RenderThread::OnDOMStorageEvent(
439 const DOMStorageMsg_Event_Params& params) { 360 const DOMStorageMsg_Event_Params& params) {
440 if (!dom_storage_event_dispatcher_.get()) 361 if (!dom_storage_event_dispatcher_.get())
441 dom_storage_event_dispatcher_.reset(WebStorageEventDispatcher::create()); 362 dom_storage_event_dispatcher_.reset(WebStorageEventDispatcher::create());
(...skipping 11 matching lines...) Expand all
453 } 374 }
454 375
455 // Some messages are handled by delegates. 376 // Some messages are handled by delegates.
456 if (appcache_dispatcher_->OnMessageReceived(msg)) 377 if (appcache_dispatcher_->OnMessageReceived(msg))
457 return true; 378 return true;
458 if (indexed_db_dispatcher_->OnMessageReceived(msg)) 379 if (indexed_db_dispatcher_->OnMessageReceived(msg))
459 return true; 380 return true;
460 381
461 bool handled = true; 382 bool handled = true;
462 IPC_BEGIN_MESSAGE_MAP(RenderThread, msg) 383 IPC_BEGIN_MESSAGE_MAP(RenderThread, msg)
463 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForCurrentURL,
464 OnSetContentSettingsForCurrentURL)
465 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForCurrentURL, 384 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForCurrentURL,
466 OnSetZoomLevelForCurrentURL) 385 OnSetZoomLevelForCurrentURL)
467 IPC_MESSAGE_HANDLER(ViewMsg_SetIsIncognitoProcess, OnSetIsIncognitoProcess)
468 IPC_MESSAGE_HANDLER(ViewMsg_SetNextPageID, OnSetNextPageID) 386 IPC_MESSAGE_HANDLER(ViewMsg_SetNextPageID, OnSetNextPageID)
469 IPC_MESSAGE_HANDLER(ViewMsg_SetCSSColors, OnSetCSSColors) 387 IPC_MESSAGE_HANDLER(ViewMsg_SetCSSColors, OnSetCSSColors)
470 // TODO(port): removed from render_messages_internal.h; 388 // TODO(port): removed from render_messages_internal.h;
471 // is there a new non-windows message I should add here? 389 // is there a new non-windows message I should add here?
472 IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView) 390 IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView)
473 IPC_MESSAGE_HANDLER(ViewMsg_SetCacheCapacities, OnSetCacheCapacities)
474 IPC_MESSAGE_HANDLER(ViewMsg_ClearCache, OnClearCache)
475 #if defined(USE_TCMALLOC)
476 IPC_MESSAGE_HANDLER(ViewMsg_GetRendererTcmalloc, OnGetRendererTcmalloc)
477 #endif
478 IPC_MESSAGE_HANDLER(ViewMsg_GetV8HeapStats, OnGetV8HeapStats)
479 IPC_MESSAGE_HANDLER(ViewMsg_GetCacheResourceStats, OnGetCacheResourceStats)
480 IPC_MESSAGE_HANDLER(ViewMsg_PurgeMemory, OnPurgeMemory)
481 IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache, OnPurgePluginListCache) 391 IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache, OnPurgePluginListCache)
482 IPC_MESSAGE_HANDLER(DOMStorageMsg_Event, OnDOMStorageEvent) 392 IPC_MESSAGE_HANDLER(DOMStorageMsg_Event, OnDOMStorageEvent)
483 IPC_MESSAGE_HANDLER(GpuMsg_GpuChannelEstablished, OnGpuChannelEstablished) 393 IPC_MESSAGE_HANDLER(GpuMsg_GpuChannelEstablished, OnGpuChannelEstablished)
484 IPC_MESSAGE_UNHANDLED(handled = false) 394 IPC_MESSAGE_UNHANDLED(handled = false)
485 IPC_END_MESSAGE_MAP() 395 IPC_END_MESSAGE_MAP()
486 return handled; 396 return handled;
487 } 397 }
488 398
489 void RenderThread::OnSetNextPageID(int32 next_page_id) { 399 void RenderThread::OnSetNextPageID(int32 next_page_id) {
490 // This should only be called at process initialization time, so we shouldn't 400 // This should only be called at process initialization time, so we shouldn't
(...skipping 30 matching lines...) Expand all
521 params.parent_window, 431 params.parent_window,
522 MSG_ROUTING_NONE, 432 MSG_ROUTING_NONE,
523 params.renderer_preferences, 433 params.renderer_preferences,
524 params.web_preferences, 434 params.web_preferences,
525 new SharedRenderViewCounter(0), 435 new SharedRenderViewCounter(0),
526 params.view_id, 436 params.view_id,
527 params.session_storage_namespace_id, 437 params.session_storage_namespace_id,
528 params.frame_name); 438 params.frame_name);
529 } 439 }
530 440
531 void RenderThread::OnSetCacheCapacities(size_t min_dead_capacity,
532 size_t max_dead_capacity,
533 size_t capacity) {
534 EnsureWebKitInitialized();
535 WebCache::setCapacities(
536 min_dead_capacity, max_dead_capacity, capacity);
537 }
538
539 void RenderThread::OnClearCache() {
540 EnsureWebKitInitialized();
541 WebCache::clear();
542 }
543
544 void RenderThread::OnGetCacheResourceStats() {
545 EnsureWebKitInitialized();
546 WebCache::ResourceTypeStats stats;
547 WebCache::getResourceTypeStats(&stats);
548 Send(new ViewHostMsg_ResourceTypeStats(stats));
549 }
550
551 #if defined(USE_TCMALLOC)
552 void RenderThread::OnGetRendererTcmalloc() {
553 std::string result;
554 char buffer[1024 * 32];
555 base::ProcessId pid = base::GetCurrentProcId();
556 MallocExtension::instance()->GetStats(buffer, sizeof(buffer));
557 result.append(buffer);
558 Send(new ViewHostMsg_RendererTcmalloc(pid, result));
559 }
560 #endif
561
562 void RenderThread::OnGetV8HeapStats() {
563 v8::HeapStatistics heap_stats;
564 v8::V8::GetHeapStatistics(&heap_stats);
565 Send(new ViewHostMsg_V8HeapStats(heap_stats.total_heap_size(),
566 heap_stats.used_heap_size()));
567 }
568
569 void RenderThread::CloseCurrentConnections() { 441 void RenderThread::CloseCurrentConnections() {
570 Send(new ViewHostMsg_CloseCurrentConnections()); 442 Send(new ViewHostMsg_CloseCurrentConnections());
571 } 443 }
572 444
573 void RenderThread::SetCacheMode(bool enabled) { 445 void RenderThread::SetCacheMode(bool enabled) {
574 Send(new ViewHostMsg_SetCacheMode(enabled)); 446 Send(new ViewHostMsg_SetCacheMode(enabled));
575 } 447 }
576 448
577 void RenderThread::ClearCache(bool preserve_ssl_host_info) { 449 void RenderThread::ClearCache(bool preserve_ssl_host_info) {
578 int rv; 450 int rv;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 webkit_client_.reset(new RendererWebKitClientImpl); 528 webkit_client_.reset(new RendererWebKitClientImpl);
657 WebKit::initialize(webkit_client_.get()); 529 WebKit::initialize(webkit_client_.get());
658 530
659 WebScriptController::enableV8SingleThreadMode(); 531 WebScriptController::enableV8SingleThreadMode();
660 532
661 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 533 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
662 534
663 webkit_glue::EnableWebCoreLogChannels( 535 webkit_glue::EnableWebCoreLogChannels(
664 command_line.GetSwitchValueASCII(switches::kWebCoreLogChannels)); 536 command_line.GetSwitchValueASCII(switches::kWebCoreLogChannels));
665 537
666 // chrome: pages should not be accessible by normal content, and should
667 // also be unable to script anything but themselves (to help limit the damage
668 // that a corrupt chrome: page could cause).
669 WebString chrome_ui_scheme(ASCIIToUTF16(chrome::kChromeUIScheme));
670 WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(chrome_ui_scheme);
671
672 // chrome-extension: resources shouldn't trigger insecure content warnings.
673 WebString extension_scheme(ASCIIToUTF16(chrome::kExtensionScheme));
674 WebSecurityPolicy::registerURLSchemeAsSecure(extension_scheme);
675
676 if (command_line.HasSwitch(switches::kEnableBenchmarking)) 538 if (command_line.HasSwitch(switches::kEnableBenchmarking))
677 RegisterExtension(extensions_v8::BenchmarkingExtension::Get()); 539 RegisterExtension(extensions_v8::BenchmarkingExtension::Get());
678 540
679 if (command_line.HasSwitch(switches::kPlaybackMode) || 541 if (command_line.HasSwitch(switches::kPlaybackMode) ||
680 command_line.HasSwitch(switches::kRecordMode) || 542 command_line.HasSwitch(switches::kRecordMode) ||
681 command_line.HasSwitch(switches::kNoJsRandomness)) { 543 command_line.HasSwitch(switches::kNoJsRandomness)) {
682 RegisterExtension(extensions_v8::PlaybackExtension::Get()); 544 RegisterExtension(extensions_v8::PlaybackExtension::Get());
683 } 545 }
684 546
685 web_database_observer_impl_.reset(new WebDatabaseObserverImpl(this)); 547 web_database_observer_impl_.reset(new WebDatabaseObserverImpl(this));
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 } 627 }
766 628
767 void RenderThread::ScheduleIdleHandler(double initial_delay_s) { 629 void RenderThread::ScheduleIdleHandler(double initial_delay_s) {
768 idle_notification_delay_in_s_ = initial_delay_s; 630 idle_notification_delay_in_s_ = initial_delay_s;
769 idle_timer_.Stop(); 631 idle_timer_.Stop();
770 idle_timer_.Start( 632 idle_timer_.Start(
771 base::TimeDelta::FromSeconds(static_cast<int64>(initial_delay_s)), 633 base::TimeDelta::FromSeconds(static_cast<int64>(initial_delay_s)),
772 this, &RenderThread::IdleHandler); 634 this, &RenderThread::IdleHandler);
773 } 635 }
774 636
775 void RenderThread::OnPurgeMemory() {
776 EnsureWebKitInitialized();
777
778 // Clear the object cache (as much as possible; some live objects cannot be
779 // freed).
780 WebCache::clear();
781
782 // Clear the font/glyph cache.
783 WebFontCache::clear();
784
785 // Clear the Cross-Origin Preflight cache.
786 WebCrossOriginPreflightResultCache::clear();
787
788 // Release all freeable memory from the SQLite process-global page cache (a
789 // low-level object which backs the Connection-specific page caches).
790 while (sqlite3_release_memory(std::numeric_limits<int>::max()) > 0) {
791 }
792
793 // Repeatedly call the V8 idle notification until it returns true ("nothing
794 // more to free"). Note that it makes more sense to do this than to implement
795 // a new "delete everything" pass because object references make it difficult
796 // to free everything possible in just one pass.
797 while (!v8::V8::IdleNotification()) {
798 }
799
800 #if (defined(OS_WIN) || defined(OS_LINUX)) && defined(USE_TCMALLOC)
801 // Tell tcmalloc to release any free pages it's still holding.
802 MallocExtension::instance()->ReleaseFreeMemory();
803 #endif
804 }
805
806 void RenderThread::OnPurgePluginListCache(bool reload_pages) { 637 void RenderThread::OnPurgePluginListCache(bool reload_pages) {
807 EnsureWebKitInitialized(); 638 EnsureWebKitInitialized();
808 // The call below will cause a GetPlugins call with refresh=true, but at this 639 // The call below will cause a GetPlugins call with refresh=true, but at this
809 // point we already know that the browser has refreshed its list, so disable 640 // point we already know that the browser has refreshed its list, so disable
810 // refresh temporarily to prevent each renderer process causing the list to be 641 // refresh temporarily to prevent each renderer process causing the list to be
811 // regenerated. 642 // regenerated.
812 plugin_refresh_allowed_ = false; 643 plugin_refresh_allowed_ = false;
813 WebKit::resetPluginCache(reload_pages); 644 WebKit::resetPluginCache(reload_pages);
814 plugin_refresh_allowed_ = true; 645 plugin_refresh_allowed_ = true;
815 } 646 }
816 647
817 void RenderThread::OnSetIsIncognitoProcess(bool is_incognito_process) {
818 is_incognito_process_ = is_incognito_process;
819 }
820
821 void RenderThread::OnGpuChannelEstablished( 648 void RenderThread::OnGpuChannelEstablished(
822 const IPC::ChannelHandle& channel_handle, 649 const IPC::ChannelHandle& channel_handle,
823 base::ProcessHandle renderer_process_for_gpu, 650 base::ProcessHandle renderer_process_for_gpu,
824 const GPUInfo& gpu_info) { 651 const GPUInfo& gpu_info) {
825 gpu_channel_->set_gpu_info(gpu_info); 652 gpu_channel_->set_gpu_info(gpu_info);
826 content::GetContentClient()->SetGpuInfo(gpu_info); 653 content::GetContentClient()->SetGpuInfo(gpu_info);
827 654
828 if (!channel_handle.name.empty() && renderer_process_for_gpu != 0) { 655 if (!channel_handle.name.empty() && renderer_process_for_gpu != 0) {
829 // Connect to the GPU process if a channel name was received. 656 // Connect to the GPU process if a channel name was received.
830 gpu_channel_->Connect(channel_handle, renderer_process_for_gpu); 657 gpu_channel_->Connect(channel_handle, renderer_process_for_gpu);
(...skipping 27 matching lines...) Expand all
858 return true; 685 return true;
859 } 686 }
860 687
861 return false; 688 return false;
862 } 689 }
863 690
864 void RenderThread::RegisterExtension(v8::Extension* extension) { 691 void RenderThread::RegisterExtension(v8::Extension* extension) {
865 WebScriptController::registerExtension(extension); 692 WebScriptController::registerExtension(extension);
866 v8_extensions_.insert(extension->name()); 693 v8_extensions_.insert(extension->name());
867 } 694 }
OLDNEW
« no previous file with comments | « content/renderer/render_thread.h ('k') | content/renderer/render_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698