blob: ccd82df44996b92c17fd123914efdf42d147e0ff [file] [log] [blame]
[email protected]f85f0702010-01-30 09:31:011// Copyright (c) 2010 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
initial.commit09911bf2008-07-26 23:55:295#include "chrome/renderer/render_thread.h"
6
[email protected]da00a2882009-03-09 17:51:197#include <algorithm>
[email protected]61a9b2d82010-02-26 00:31:088#include <limits>
[email protected]75e126b932009-09-28 19:38:499#include <map>
[email protected]da00a2882009-03-09 17:51:1910#include <vector>
11
[email protected]06533c0b2009-03-05 21:39:1112#include "base/command_line.h"
[email protected]58580352010-10-26 04:07:5013#include "base/debug/trace_event.h"
[email protected]94f9a0f682009-06-15 18:30:3014#include "base/lazy_instance.h"
[email protected]bee16aab2009-08-26 15:55:0315#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3816#include "base/metrics/field_trial.h"
17#include "base/metrics/stats_table.h"
[email protected]b7c7bcf2009-10-03 07:07:3418#include "base/nullable_string16.h"
[email protected]d41041092009-10-08 06:56:5719#include "base/process_util.h"
[email protected]3ead1322010-11-19 20:01:0020#include "base/scoped_callback_factory.h"
initial.commit09911bf2008-07-26 23:55:2921#include "base/shared_memory.h"
[email protected]b7c7bcf2009-10-03 07:07:3422#include "base/string_util.h"
[email protected]46f36a492010-07-28 19:36:4123#include "base/task.h"
[email protected]94f9a0f682009-06-15 18:30:3024#include "base/thread_local.h"
[email protected]be1ce6a72010-08-03 14:35:2225#include "base/utf_string_conversions.h"
[email protected]7a4de7a62010-08-17 18:38:2426#include "base/values.h"
[email protected]f430b5712009-08-21 21:46:3127#include "chrome/common/appcache/appcache_dispatcher.h"
[email protected]c8865962009-12-16 07:47:3928#include "chrome/common/child_process_logging.h"
[email protected]06533c0b2009-03-05 21:39:1129#include "chrome/common/chrome_switches.h"
[email protected]017022b2009-07-27 23:06:3430#include "chrome/common/db_message_filter.h"
[email protected]e13ad79b2010-07-22 21:36:5031#include "chrome/common/dom_storage_common.h"
[email protected]c1f50aa2010-02-18 03:46:5732#include "chrome/common/plugin_messages.h"
[email protected]e09ba552009-02-05 03:26:2933#include "chrome/common/render_messages.h"
[email protected]939856a2010-08-24 20:29:0234#include "chrome/common/render_messages_params.h"
[email protected]9b6f40e2009-06-11 15:54:2635#include "chrome/common/renderer_preferences.h"
[email protected]90a3fbb12009-02-28 01:13:4736#include "chrome/common/url_constants.h"
[email protected]2b437e232010-04-02 01:30:0837#include "chrome/common/web_database_observer_impl.h"
[email protected]8930d472009-02-21 08:05:2838#include "chrome/plugin/npobject_util.h"
[email protected]2c62b562009-01-27 19:04:5039// TODO(port)
40#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:2941#include "chrome/plugin/plugin_channel.h"
[email protected]2c62b562009-01-27 19:04:5042#else
[email protected]2c62b562009-01-27 19:04:5043#include "base/scoped_handle.h"
44#include "chrome/plugin/plugin_channel_base.h"
[email protected]2c62b562009-01-27 19:04:5045#endif
[email protected]a9602de2010-03-18 23:43:1146#include "chrome/renderer/automation/dom_automation_v8_extension.h"
[email protected]dd9241932010-02-24 19:23:1347#include "chrome/renderer/cookie_message_filter.h"
[email protected]a8624712009-04-17 00:51:3548#include "chrome/renderer/devtools_agent_filter.h"
[email protected]ad1f9bd2009-07-30 20:23:1549#include "chrome/renderer/extension_groups.h"
[email protected]2747dd842010-08-27 14:22:1250#include "chrome/renderer/extensions/chrome_app_bindings.h"
[email protected]5351dbc2010-08-27 15:22:1151#include "chrome/renderer/extensions/extension_renderer_info.h"
[email protected]a40caa972009-04-08 18:35:3452#include "chrome/renderer/extensions/event_bindings.h"
[email protected]309d7a282009-03-24 09:18:2753#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]be77f0a2009-08-25 08:31:1754#include "chrome/renderer/extensions/js_only_v8_extensions.h"
[email protected]0aa477bd2009-03-23 22:21:4355#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]3c8e3702009-05-01 16:27:4256#include "chrome/renderer/external_extension.h"
[email protected]e13ad79b2010-07-22 21:36:5057#include "chrome/renderer/gpu_channel_host.h"
[email protected]ee68378a2010-08-10 01:05:4158#include "chrome/renderer/gpu_video_service_host.h"
[email protected]70c19a932010-05-14 12:59:1159#include "chrome/renderer/indexed_db_dispatcher.h"
[email protected]0bc46552009-04-07 21:56:4260#include "chrome/renderer/loadtimes_extension_bindings.h"
[email protected]3530cd92010-06-27 06:22:0161#include "chrome/renderer/net/renderer_net_predictor.h"
[email protected]c1f50aa2010-02-18 03:46:5762#include "chrome/renderer/plugin_channel_host.h"
[email protected]00c39612010-03-06 02:53:2863#include "chrome/renderer/render_process_impl.h"
initial.commit09911bf2008-07-26 23:55:2964#include "chrome/renderer/render_view.h"
[email protected]40bd6582009-12-04 23:49:5165#include "chrome/renderer/render_view_visitor.h"
[email protected]e13ad79b2010-07-22 21:36:5066#include "chrome/renderer/renderer_histogram_snapshots.h"
[email protected]7ef8f602010-07-30 11:09:4767#include "chrome/renderer/renderer_webidbfactory_impl.h"
[email protected]8d86fce2009-02-26 23:37:5568#include "chrome/renderer/renderer_webkitclient_impl.h"
[email protected]3ead1322010-11-19 20:01:0069#include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h"
70#include "chrome/renderer/safe_browsing/scorer.h"
[email protected]15d9c0c2010-09-10 22:36:2671#include "chrome/renderer/search_extension.h"
[email protected]ce833282010-11-04 15:48:3972#include "chrome/renderer/searchbox_extension.h"
[email protected]85c55dc2009-11-06 03:05:4673#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]0938d3c2009-01-09 20:37:3574#include "chrome/renderer/user_script_slave.h"
[email protected]46f36a492010-07-28 19:36:4175#include "ipc/ipc_channel_handle.h"
[email protected]d55aaa132009-09-28 21:08:0476#include "ipc/ipc_message.h"
[email protected]cb6037d2009-11-16 22:55:1777#include "ipc/ipc_platform_file.h"
[email protected]9d797f32010-04-23 07:17:5478#include "net/base/net_util.h"
[email protected]e33cba42010-08-18 23:37:0379#include "third_party/sqlite/sqlite3.h"
[email protected]1b1f3eb2009-12-01 13:48:0480#include "third_party/tcmalloc/chromium/src/google/malloc_extension.h"
[email protected]418ed5ab2009-11-12 01:14:4981#include "third_party/WebKit/WebKit/chromium/public/WebCache.h"
82#include "third_party/WebKit/WebKit/chromium/public/WebColor.h"
83#include "third_party/WebKit/WebKit/chromium/public/WebCrossOriginPreflightResultCache.h"
84#include "third_party/WebKit/WebKit/chromium/public/WebDatabase.h"
[email protected]b75b8292010-10-01 07:28:2585#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
[email protected]418ed5ab2009-11-12 01:14:4986#include "third_party/WebKit/WebKit/chromium/public/WebFontCache.h"
[email protected]40bd6582009-12-04 23:49:5187#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
[email protected]418ed5ab2009-11-12 01:14:4988#include "third_party/WebKit/WebKit/chromium/public/WebKit.h"
89#include "third_party/WebKit/WebKit/chromium/public/WebRuntimeFeatures.h"
90#include "third_party/WebKit/WebKit/chromium/public/WebScriptController.h"
91#include "third_party/WebKit/WebKit/chromium/public/WebSecurityPolicy.h"
92#include "third_party/WebKit/WebKit/chromium/public/WebStorageEventDispatcher.h"
93#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
[email protected]4d51d5bf2010-07-26 18:48:2694#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
[email protected]b07f29092009-06-05 07:33:2195#include "webkit/extensions/v8/benchmarking_extension.h"
[email protected]06533c0b2009-03-05 21:39:1196#include "webkit/extensions/v8/gears_extension.h"
[email protected]06533c0b2009-03-05 21:39:1197#include "webkit/extensions/v8/playback_extension.h"
[email protected]e0d92f282010-04-03 06:04:2798#include "v8/include/v8.h"
[email protected]2c62b562009-01-27 19:04:5099
[email protected]da00a2882009-03-09 17:51:19100#if defined(OS_WIN)
101#include <windows.h>
102#include <objbase.h>
103#endif
104
[email protected]fe819f52009-12-15 07:58:11105#if defined(OS_MACOSX)
106#include "chrome/app/breakpad_mac.h"
107#endif
108
[email protected]6217d392010-03-25 22:08:35109#if defined(OS_POSIX)
110#include "ipc/ipc_channel_posix.h"
111#endif
112
[email protected]2c434b32009-03-19 06:27:47113using WebKit::WebCache;
[email protected]fede6ca12009-10-08 18:24:26114using WebKit::WebCrossOriginPreflightResultCache;
115using WebKit::WebFontCache;
[email protected]f85f0702010-01-30 09:31:01116using WebKit::WebFrame;
[email protected]adf00bc2009-11-02 18:35:00117using WebKit::WebRuntimeFeatures;
[email protected]204758c2009-10-22 03:56:30118using WebKit::WebSecurityPolicy;
[email protected]98d7127b2009-10-23 18:26:51119using WebKit::WebScriptController;
[email protected]2c434b32009-03-19 06:27:47120using WebKit::WebString;
[email protected]b7c7bcf2009-10-03 07:07:34121using WebKit::WebStorageEventDispatcher;
[email protected]50ae00ef2009-10-19 05:11:03122using WebKit::WebView;
initial.commit09911bf2008-07-26 23:55:29123
[email protected]42f1d7822009-07-23 18:17:55124namespace {
[email protected]2c434b32009-03-19 06:27:47125static const unsigned int kCacheStatsDelayMS = 2000 /* milliseconds */;
[email protected]bee16aab2009-08-26 15:55:03126static const double kInitialIdleHandlerDelayS = 1.0 /* seconds */;
[email protected]71d6d852009-12-07 22:12:36127static const double kInitialExtensionIdleHandlerDelayS = 5.0 /* seconds */;
128static const int64 kMaxExtensionIdleHandlerDelayS = 5*60 /* seconds */;
[email protected]bee16aab2009-08-26 15:55:03129
[email protected]c53165ee2010-08-16 21:40:07130static const int kPrelauchGpuPercentage = 5;
131static const int kPrelauchGpuProcessDelayMS = 10000;
132
[email protected]f3ede412010-06-21 22:52:16133// Keep the global RenderThread in a TLS slot so it is impossible to access
134// incorrectly from the wrong thread.
[email protected]94f9a0f682009-06-15 18:30:30135static base::LazyInstance<base::ThreadLocalPointer<RenderThread> > lazy_tls(
136 base::LINKER_INITIALIZED);
[email protected]1edc16b82009-04-07 17:45:54137
[email protected]5fa1c542009-05-05 20:36:07138#if defined(OS_POSIX)
139class SuicideOnChannelErrorFilter : public IPC::ChannelProxy::MessageFilter {
140 void OnChannelError() {
141 // On POSIX, at least, one can install an unload handler which loops
142 // forever and leave behind a renderer process which eats 100% CPU forever.
143 //
144 // This is because the terminate signals (ViewMsg_ShouldClose and the error
145 // from the IPC channel) are routed to the main message loop but never
146 // processed (because that message loop is stuck in V8).
147 //
148 // One could make the browser SIGKILL the renderers, but that leaves open a
149 // large window where a browser failure (or a user, manually terminating
150 // the browser because "it's stuck") will leave behind a process eating all
151 // the CPU.
152 //
153 // So, we install a filter on the channel so that we can process this event
154 // here and kill the process.
[email protected]fe819f52009-12-15 07:58:11155
156#if defined(OS_MACOSX)
157 // TODO(viettrungluu): crbug.com/28547: The following is needed, as a
158 // stopgap, to avoid leaking due to not releasing Breakpad properly.
159 // TODO(viettrungluu): Investigate why this is being called.
160 if (IsCrashReporterEnabled()) {
[email protected]593df612010-10-20 20:20:21161 VLOG(1) << "Cleaning up Breakpad.";
[email protected]fe819f52009-12-15 07:58:11162 DestructCrashReporter();
163 } else {
[email protected]593df612010-10-20 20:20:21164 VLOG(1) << "Breakpad not enabled; no clean-up needed.";
[email protected]fe819f52009-12-15 07:58:11165 }
166#endif // OS_MACOSX
167
[email protected]5fa1c542009-05-05 20:36:07168 _exit(0);
169 }
170};
171#endif
[email protected]40bd6582009-12-04 23:49:51172
[email protected]f85f0702010-01-30 09:31:01173class RenderViewContentSettingsSetter : public RenderViewVisitor {
174 public:
[email protected]0314ae02010-04-08 09:18:29175 RenderViewContentSettingsSetter(const GURL& url,
[email protected]f85f0702010-01-30 09:31:01176 const ContentSettings& content_settings)
[email protected]0314ae02010-04-08 09:18:29177 : url_(url),
[email protected]f85f0702010-01-30 09:31:01178 content_settings_(content_settings) {
179 }
180
181 virtual bool Visit(RenderView* render_view) {
[email protected]0314ae02010-04-08 09:18:29182 if (GURL(render_view->webview()->mainFrame()->url()) == url_)
[email protected]433819d2010-01-30 20:20:01183 render_view->SetContentSettings(content_settings_);
[email protected]f85f0702010-01-30 09:31:01184 return true;
185 }
186
187 private:
[email protected]0314ae02010-04-08 09:18:29188 GURL url_;
[email protected]f85f0702010-01-30 09:31:01189 ContentSettings content_settings_;
190
191 DISALLOW_COPY_AND_ASSIGN(RenderViewContentSettingsSetter);
192};
193
[email protected]40bd6582009-12-04 23:49:51194class RenderViewZoomer : public RenderViewVisitor {
195 public:
[email protected]b75b8292010-10-01 07:28:25196 RenderViewZoomer(const GURL& url, double zoom_level)
[email protected]9d797f32010-04-23 07:17:54197 : zoom_level_(zoom_level) {
198 host_ = net::GetHostOrSpecFromURL(url);
[email protected]40bd6582009-12-04 23:49:51199 }
200
201 virtual bool Visit(RenderView* render_view) {
202 WebView* webview = render_view->webview(); // Guaranteed non-NULL.
[email protected]b75b8292010-10-01 07:28:25203
204 // Don't set zoom level for full-page plugin since they don't use the same
205 // zoom settings.
206 if (webview->mainFrame()->document().isPluginDocument())
207 return true;
208
[email protected]9d797f32010-04-23 07:17:54209 if (net::GetHostOrSpecFromURL(GURL(webview->mainFrame()->url())) == host_)
[email protected]40bd6582009-12-04 23:49:51210 webview->setZoomLevel(false, zoom_level_);
211 return true;
212 }
213
214 private:
215 std::string host_;
[email protected]b75b8292010-10-01 07:28:25216 double zoom_level_;
[email protected]40bd6582009-12-04 23:49:51217
218 DISALLOW_COPY_AND_ASSIGN(RenderViewZoomer);
219};
[email protected]0478d0162010-08-28 08:29:40220
[email protected]3ead1322010-11-19 20:01:00221class RenderViewPhishingScorerSetter : public RenderViewVisitor {
222 public:
223 explicit RenderViewPhishingScorerSetter(const safe_browsing::Scorer* scorer)
224 : scorer_(scorer) {
225 }
226
227 virtual bool Visit(RenderView* render_view) {
228 safe_browsing::PhishingClassifierDelegate* delegate =
229 render_view->phishing_classifier_delegate();
230 if (delegate)
231 delegate->SetPhishingScorer(scorer_);
232 return true;
233 }
234
235 private:
236 const safe_browsing::Scorer* scorer_;
237
238 DISALLOW_COPY_AND_ASSIGN(RenderViewPhishingScorerSetter);
239};
240
[email protected]42f1d7822009-07-23 18:17:55241} // namespace
242
243// When we run plugins in process, we actually run them on the render thread,
244// which means that we need to make the render thread pump UI events.
245RenderThread::RenderThread() {
246 Init();
247}
248
249RenderThread::RenderThread(const std::string& channel_name)
250 : ChildThread(channel_name) {
251 Init();
252}
[email protected]5fa1c542009-05-05 20:36:07253
initial.commit09911bf2008-07-26 23:55:29254void RenderThread::Init() {
[email protected]a872ea1f2010-08-11 04:45:33255 TRACE_EVENT_BEGIN("RenderThread::Init", 0, "");
256
[email protected]94f9a0f682009-06-15 18:30:30257 lazy_tls.Pointer()->Set(this);
[email protected]2c62b562009-01-27 19:04:50258#if defined(OS_WIN)
[email protected]bdef78b52009-04-16 19:31:34259 // If you are running plugins in this thread you need COM active but in
260 // the normal case you don't.
[email protected]00c39612010-03-06 02:53:28261 if (RenderProcessImpl::InProcessPlugins())
[email protected]bdef78b52009-04-16 19:31:34262 CoInitialize(0);
[email protected]2c62b562009-01-27 19:04:50263#endif
initial.commit09911bf2008-07-26 23:55:29264
[email protected]71d6d852009-12-07 22:12:36265 std::string type_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
266 switches::kProcessType);
[email protected]31f87132010-04-21 23:36:21267 // In single process the single process is all there is.
268 is_extension_process_ = type_str == switches::kExtensionProcess ||
269 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess);
[email protected]b2a74ca2010-03-12 17:57:09270 is_incognito_process_ = false;
[email protected]47158302010-11-16 14:10:22271 is_speech_input_enabled_ = false;
[email protected]80fc08c52010-03-09 07:43:50272 suspend_webkit_shared_timer_ = true;
273 notify_webkit_of_modal_loop_ = true;
[email protected]42f1d7822009-07-23 18:17:55274 plugin_refresh_allowed_ = true;
[email protected]bee16aab2009-08-26 15:55:03275 cache_stats_task_pending_ = false;
276 widget_count_ = 0;
277 hidden_widget_count_ = 0;
[email protected]71d6d852009-12-07 22:12:36278 idle_notification_delay_in_s_ = is_extension_process_ ?
279 kInitialExtensionIdleHandlerDelayS : kInitialIdleHandlerDelayS;
[email protected]bee16aab2009-08-26 15:55:03280 task_factory_.reset(new ScopedRunnableMethodFactory<RenderThread>(this));
[email protected]3ead1322010-11-19 20:01:00281 callback_factory_.reset(new base::ScopedCallbackFactory<RenderThread>(this));
[email protected]8d86fce2009-02-26 23:37:55282
[email protected]8d86fce2009-02-26 23:37:55283 visited_link_slave_.reset(new VisitedLinkSlave());
[email protected]ee9080642010-04-07 00:23:06284 user_script_slave_.reset(new UserScriptSlave());
[email protected]74be069e82010-06-25 00:12:49285 renderer_net_predictor_.reset(new RendererNetPredictor());
[email protected]8d86fce2009-02-26 23:37:55286 histogram_snapshots_.reset(new RendererHistogramSnapshots());
[email protected]f430b5712009-08-21 21:46:31287 appcache_dispatcher_.reset(new AppCacheDispatcher(this));
[email protected]70c19a932010-05-14 12:59:11288 indexed_db_dispatcher_.reset(new IndexedDBDispatcher());
[email protected]dd9241932010-02-24 19:23:13289 spellchecker_.reset(new SpellCheck());
290
[email protected]a8624712009-04-17 00:51:35291 devtools_agent_filter_ = new DevToolsAgentFilter();
292 AddFilter(devtools_agent_filter_.get());
[email protected]dd9241932010-02-24 19:23:13293
[email protected]017022b2009-07-27 23:06:34294 db_message_filter_ = new DBMessageFilter();
295 AddFilter(db_message_filter_.get());
[email protected]dd9241932010-02-24 19:23:13296
297 cookie_message_filter_ = new CookieMessageFilter();
298 AddFilter(cookie_message_filter_.get());
[email protected]5fa1c542009-05-05 20:36:07299
300#if defined(OS_POSIX)
301 suicide_on_channel_error_filter_ = new SuicideOnChannelErrorFilter;
302 AddFilter(suicide_on_channel_error_filter_.get());
303#endif
[email protected]515c7162010-07-12 23:46:17304
305 // Establish a channel to the GPU process asynchronously if requested. If the
306 // channel is established in time, EstablishGpuChannelSync will not block when
[email protected]c53165ee2010-08-16 21:40:07307 // it is later called. Delays by a fixed period of time to avoid loading the
308 // GPU immediately in an attempt to not slow startup time.
[email protected]835d7c82010-10-14 04:38:38309 scoped_refptr<base::FieldTrial> prelaunch_trial(
310 new base::FieldTrial("PrelaunchGpuProcessExperiment", 100));
[email protected]c53165ee2010-08-16 21:40:07311 int prelaunch_group = prelaunch_trial->AppendGroup("prelaunch_gpu_process",
312 kPrelauchGpuPercentage);
313 if (prelaunch_group == prelaunch_trial->group() ||
314 CommandLine::ForCurrentProcess()->HasSwitch(
315 switches::kPrelaunchGpuProcess)) {
316 message_loop()->PostDelayedTask(FROM_HERE,
317 task_factory_->NewRunnableMethod(
318 &RenderThread::EstablishGpuChannel),
319 kPrelauchGpuProcessDelayMS);
[email protected]515c7162010-07-12 23:46:17320 }
[email protected]ee68378a2010-08-10 01:05:41321
[email protected]a872ea1f2010-08-11 04:45:33322 TRACE_EVENT_END("RenderThread::Init", 0, "");
initial.commit09911bf2008-07-26 23:55:29323}
324
[email protected]42f1d7822009-07-23 18:17:55325RenderThread::~RenderThread() {
[email protected]12cbfda32010-01-30 01:04:25326 // Wait for all databases to be closed.
[email protected]2b437e232010-04-02 01:30:08327 if (web_database_observer_impl_.get())
328 web_database_observer_impl_->WaitForAllDatabasesToClose();
[email protected]12cbfda32010-01-30 01:04:25329
[email protected]8d86fce2009-02-26 23:37:55330 // Shutdown in reverse of the initialization order.
[email protected]017022b2009-07-27 23:06:34331 RemoveFilter(db_message_filter_.get());
332 db_message_filter_ = NULL;
[email protected]2b437e232010-04-02 01:30:08333 RemoveFilter(devtools_agent_filter_.get());
[email protected]12cbfda32010-01-30 01:04:25334
[email protected]c6a7b862010-08-20 22:19:38335 // Shutdown the file thread if it's running.
336 if (file_thread_.get())
337 file_thread_->Stop();
338
[email protected]42f1d7822009-07-23 18:17:55339 if (webkit_client_.get())
[email protected]9291ed12009-07-23 17:33:22340 WebKit::shutdown();
[email protected]9291ed12009-07-23 17:33:22341
[email protected]94f9a0f682009-06-15 18:30:30342 lazy_tls.Pointer()->Set(NULL);
[email protected]8fd8de92008-08-12 23:50:30343
[email protected]8d86fce2009-02-26 23:37:55344 // TODO(port)
[email protected]2c62b562009-01-27 19:04:50345#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29346 // Clean up plugin channels before this thread goes away.
347 PluginChannelBase::CleanupChannels();
[email protected]bdef78b52009-04-16 19:31:34348 // Don't call COM if the renderer is in the sandbox.
[email protected]00c39612010-03-06 02:53:28349 if (RenderProcessImpl::InProcessPlugins())
[email protected]bdef78b52009-04-16 19:31:34350 CoUninitialize();
[email protected]2c62b562009-01-27 19:04:50351#endif
initial.commit09911bf2008-07-26 23:55:29352}
353
[email protected]42f1d7822009-07-23 18:17:55354RenderThread* RenderThread::current() {
355 return lazy_tls.Pointer()->Get();
356}
357
[email protected]c1f50aa2010-02-18 03:46:57358int32 RenderThread::RoutingIDForCurrentContext() {
359 int32 routing_id = MSG_ROUTING_CONTROL;
360 if (v8::Context::InContext()) {
[email protected]d5ddf9a2010-03-04 00:48:29361 WebFrame* frame = WebFrame::frameForCurrentContext();
362 if (frame) {
363 RenderView* view = RenderView::FromWebView(frame->view());
364 if (view)
365 routing_id = view->routing_id();
366 }
[email protected]c1f50aa2010-02-18 03:46:57367 } else {
368 DLOG(WARNING) << "Not called within a script context!";
369 }
370 return routing_id;
371}
372
373bool RenderThread::Send(IPC::Message* msg) {
[email protected]80fc08c52010-03-09 07:43:50374 // Certain synchronous messages can result in an app-modal cookie prompt.
375 // This could cause a complete hang of Chrome if a windowed plug-in is trying
376 // to communicate with the renderer thread since the browser's UI thread
377 // could be stuck (within a Windows API call) trying to synchronously
378 // communicate with the plug-in. The remedy is to pump messages on this
379 // thread while the cookie prompt is showing. This creates an opportunity
380 // for re-entrancy into WebKit, so we need to take care to disable callbacks,
381 // timers, and pending network loads that could trigger such callbacks.
[email protected]c1f50aa2010-02-18 03:46:57382
[email protected]80fc08c52010-03-09 07:43:50383 bool pumping_events = false, may_show_cookie_prompt = false;
384 if (msg->is_sync()) {
385 if (msg->is_caller_pumping_messages()) {
386 pumping_events = true;
387 } else {
388 switch (msg->type()) {
389 case ViewHostMsg_GetCookies::ID:
390 case ViewHostMsg_GetRawCookies::ID:
391 case ViewHostMsg_DOMStorageSetItem::ID:
392 case ViewHostMsg_SyncLoad::ID:
[email protected]0a1a45432010-03-31 08:09:45393 case ViewHostMsg_AllowDatabase::ID:
[email protected]80fc08c52010-03-09 07:43:50394 may_show_cookie_prompt = true;
395 pumping_events = true;
396 break;
397 }
398 }
[email protected]c1f50aa2010-02-18 03:46:57399 }
400
[email protected]80fc08c52010-03-09 07:43:50401 bool suspend_webkit_shared_timer = true; // default value
402 std::swap(suspend_webkit_shared_timer, suspend_webkit_shared_timer_);
[email protected]c1f50aa2010-02-18 03:46:57403
[email protected]80fc08c52010-03-09 07:43:50404 bool notify_webkit_of_modal_loop = true; // default value
405 std::swap(notify_webkit_of_modal_loop, notify_webkit_of_modal_loop_);
406
407 gfx::NativeViewId host_window = 0;
[email protected]c1f50aa2010-02-18 03:46:57408
409 if (pumping_events) {
[email protected]80fc08c52010-03-09 07:43:50410 // See ViewMsg_SignalCookiePromptEvent.
411 if (may_show_cookie_prompt) {
412 static_cast<IPC::SyncMessage*>(msg)->set_pump_messages_event(
413 cookie_message_filter_->pump_messages_event());
414 }
415
416 if (suspend_webkit_shared_timer)
[email protected]c1f50aa2010-02-18 03:46:57417 webkit_client_->SuspendSharedTimer();
418
[email protected]39065d012010-07-09 11:22:46419 if (notify_webkit_of_modal_loop)
[email protected]c1f50aa2010-02-18 03:46:57420 WebView::willEnterModalLoop();
[email protected]c1f50aa2010-02-18 03:46:57421
[email protected]80fc08c52010-03-09 07:43:50422 RenderWidget* widget =
423 static_cast<RenderWidget*>(ResolveRoute(msg->routing_id()));
424 if (widget) {
425 host_window = widget->host_window();
[email protected]c1f50aa2010-02-18 03:46:57426 PluginChannelHost::Broadcast(
427 new PluginMsg_SignalModalDialogEvent(host_window));
428 }
429 }
430
431 bool rv = ChildThread::Send(msg);
432
433 if (pumping_events) {
434 if (host_window) {
435 PluginChannelHost::Broadcast(
436 new PluginMsg_ResetModalDialogEvent(host_window));
437 }
438
[email protected]39065d012010-07-09 11:22:46439 if (notify_webkit_of_modal_loop)
[email protected]c1f50aa2010-02-18 03:46:57440 WebView::didExitModalLoop();
[email protected]c1f50aa2010-02-18 03:46:57441
[email protected]80fc08c52010-03-09 07:43:50442 if (suspend_webkit_shared_timer)
[email protected]c1f50aa2010-02-18 03:46:57443 webkit_client_->ResumeSharedTimer();
[email protected]80fc08c52010-03-09 07:43:50444
445 // We may end up nesting calls to Send, so we defer the reset until we
446 // return to the top-most message loop.
447 if (may_show_cookie_prompt &&
448 cookie_message_filter_->pump_messages_event()->IsSignaled()) {
449 MessageLoop::current()->PostNonNestableTask(FROM_HERE,
450 NewRunnableMethod(cookie_message_filter_.get(),
451 &CookieMessageFilter::ResetPumpMessagesEvent));
452 }
[email protected]c1f50aa2010-02-18 03:46:57453 }
454
455 return rv;
456}
457
458void RenderThread::AddRoute(int32 routing_id,
459 IPC::Channel::Listener* listener) {
460 widget_count_++;
[email protected]3231c2e2010-09-02 12:41:05461 child_process_logging::SetNumberOfViews(widget_count_);
[email protected]c1f50aa2010-02-18 03:46:57462 return ChildThread::AddRoute(routing_id, listener);
463}
464
465void RenderThread::RemoveRoute(int32 routing_id) {
466 widget_count_--;
[email protected]3231c2e2010-09-02 12:41:05467 child_process_logging::SetNumberOfViews(widget_count_);
[email protected]c1f50aa2010-02-18 03:46:57468 return ChildThread::RemoveRoute(routing_id);
469}
470
[email protected]42f1d7822009-07-23 18:17:55471void RenderThread::AddFilter(IPC::ChannelProxy::MessageFilter* filter) {
472 channel()->AddFilter(filter);
473}
474
475void RenderThread::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) {
476 channel()->RemoveFilter(filter);
477}
478
[email protected]bee16aab2009-08-26 15:55:03479void RenderThread::WidgetHidden() {
480 DCHECK(hidden_widget_count_ < widget_count_);
[email protected]4a3dab22009-11-11 17:36:50481 hidden_widget_count_++;
[email protected]b8f41a192010-04-19 18:25:04482 if (!is_extension_process_ &&
[email protected]71d6d852009-12-07 22:12:36483 widget_count_ && hidden_widget_count_ == widget_count_)
484 ScheduleIdleHandler(kInitialIdleHandlerDelayS);
[email protected]bee16aab2009-08-26 15:55:03485}
486
487void RenderThread::WidgetRestored() {
[email protected]61a9b2d82010-02-26 00:31:08488 DCHECK_GT(hidden_widget_count_, 0);
[email protected]bee16aab2009-08-26 15:55:03489 hidden_widget_count_--;
[email protected]b8f41a192010-04-19 18:25:04490 if (!is_extension_process_)
[email protected]71d6d852009-12-07 22:12:36491 idle_timer_.Stop();
[email protected]bee16aab2009-08-26 15:55:03492}
493
[email protected]c1f50aa2010-02-18 03:46:57494void RenderThread::DoNotSuspendWebKitSharedTimer() {
[email protected]80fc08c52010-03-09 07:43:50495 suspend_webkit_shared_timer_ = false;
[email protected]c1f50aa2010-02-18 03:46:57496}
497
498void RenderThread::DoNotNotifyWebKitOfModalLoop() {
[email protected]80fc08c52010-03-09 07:43:50499 notify_webkit_of_modal_loop_ = false;
[email protected]c1f50aa2010-02-18 03:46:57500}
501
[email protected]42f1d7822009-07-23 18:17:55502void RenderThread::Resolve(const char* name, size_t length) {
[email protected]74be069e82010-06-25 00:12:49503 return renderer_net_predictor_->Resolve(name, length);
[email protected]42f1d7822009-07-23 18:17:55504}
505
506void RenderThread::SendHistograms(int sequence_number) {
507 return histogram_snapshots_->SendHistograms(sequence_number);
508}
509
[email protected]176aa482008-11-14 03:25:15510void RenderThread::OnUpdateVisitedLinks(base::SharedMemoryHandle table) {
[email protected]5fe733de2009-02-11 18:59:20511 DCHECK(base::SharedMemory::IsHandleValid(table)) << "Bad table handle";
initial.commit09911bf2008-07-26 23:55:29512 visited_link_slave_->Init(table);
513}
514
[email protected]3e90d4a2009-07-03 17:38:39515void RenderThread::OnAddVisitedLinks(
516 const VisitedLinkSlave::Fingerprints& fingerprints) {
517 for (size_t i = 0; i < fingerprints.size(); ++i)
[email protected]50ae00ef2009-10-19 05:11:03518 WebView::updateVisitedLinkState(fingerprints[i]);
[email protected]3e90d4a2009-07-03 17:38:39519}
520
521void RenderThread::OnResetVisitedLinks() {
[email protected]50ae00ef2009-10-19 05:11:03522 WebView::resetVisitedLinkState();
[email protected]3e90d4a2009-07-03 17:38:39523}
524
[email protected]0314ae02010-04-08 09:18:29525void RenderThread::OnSetContentSettingsForCurrentURL(
526 const GURL& url,
[email protected]f85f0702010-01-30 09:31:01527 const ContentSettings& content_settings) {
[email protected]0314ae02010-04-08 09:18:29528 RenderViewContentSettingsSetter setter(url, content_settings);
[email protected]f85f0702010-01-30 09:31:01529 RenderView::ForEach(&setter);
530}
531
[email protected]9d797f32010-04-23 07:17:54532void RenderThread::OnSetZoomLevelForCurrentURL(const GURL& url,
[email protected]b75b8292010-10-01 07:28:25533 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:54534 RenderViewZoomer zoomer(url, zoom_level);
[email protected]40bd6582009-12-04 23:49:51535 RenderView::ForEach(&zoomer);
536}
537
[email protected]b2a74ca2010-03-12 17:57:09538void RenderThread::OnUpdateUserScripts(base::SharedMemoryHandle scripts) {
[email protected]5fe733de2009-02-11 18:59:20539 DCHECK(base::SharedMemory::IsHandleValid(scripts)) << "Bad scripts handle";
[email protected]ee9080642010-04-07 00:23:06540 user_script_slave_->UpdateScripts(scripts);
[email protected]c8865962009-12-16 07:47:39541 UpdateActiveExtensions();
[email protected]1e0f70402008-10-16 23:57:47542}
543
[email protected]703e807a2009-03-28 19:56:51544void RenderThread::OnSetExtensionFunctionNames(
545 const std::vector<std::string>& names) {
[email protected]a1a0df02009-04-09 08:18:04546 ExtensionProcessBindings::SetFunctionNames(names);
[email protected]703e807a2009-03-28 19:56:51547}
548
[email protected]5351dbc2010-08-27 15:22:11549void RenderThread::OnExtensionsUpdated(
550 const ViewMsg_ExtensionsUpdated_Params& params) {
551 ExtensionRendererInfo::UpdateExtensions(params);
[email protected]3a8eecb2010-04-22 23:56:30552}
553
[email protected]45776222009-07-15 20:21:58554void RenderThread::OnPageActionsUpdated(
555 const std::string& extension_id,
556 const std::vector<std::string>& page_actions) {
557 ExtensionProcessBindings::SetPageActions(extension_id, page_actions);
558}
559
[email protected]cccf90932009-08-23 17:56:25560void RenderThread::OnExtensionSetAPIPermissions(
[email protected]35506352009-08-07 18:58:19561 const std::string& extension_id,
[email protected]0df165f2010-09-28 16:49:40562 const std::set<std::string>& permissions) {
[email protected]cccf90932009-08-23 17:56:25563 ExtensionProcessBindings::SetAPIPermissions(extension_id, permissions);
[email protected]71d6d852009-12-07 22:12:36564
565 // This is called when starting a new extension page, so start the idle
566 // handler ticking.
[email protected]71d6d852009-12-07 22:12:36567 ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayS);
[email protected]c8865962009-12-16 07:47:39568
569 UpdateActiveExtensions();
[email protected]cccf90932009-08-23 17:56:25570}
571
572void RenderThread::OnExtensionSetHostPermissions(
573 const GURL& extension_url, const std::vector<URLPattern>& permissions) {
574 ExtensionProcessBindings::SetHostPermissions(extension_url, permissions);
[email protected]35506352009-08-07 18:58:19575}
576
[email protected]c61cc652009-11-04 05:44:40577void RenderThread::OnDOMStorageEvent(
578 const ViewMsg_DOMStorageEvent_Params& params) {
579 if (!dom_storage_event_dispatcher_.get())
[email protected]b7c7bcf2009-10-03 07:07:34580 dom_storage_event_dispatcher_.reset(WebStorageEventDispatcher::create());
[email protected]c61cc652009-11-04 05:44:40581 dom_storage_event_dispatcher_->dispatchStorageEvent(params.key_,
[email protected]ee2be5b32009-11-05 09:13:12582 params.old_value_, params.new_value_, params.origin_, params.url_,
[email protected]c61cc652009-11-04 05:44:40583 params.storage_type_ == DOM_STORAGE_LOCAL);
[email protected]b7c7bcf2009-10-03 07:07:34584}
585
[email protected]8930d472009-02-21 08:05:28586void RenderThread::OnControlMessageReceived(const IPC::Message& msg) {
[email protected]70c19a932010-05-14 12:59:11587 // Some messages are handled by delegates.
[email protected]f430b5712009-08-21 21:46:31588 if (appcache_dispatcher_->OnMessageReceived(msg))
[email protected]1edc16b82009-04-07 17:45:54589 return;
[email protected]70c19a932010-05-14 12:59:11590 if (indexed_db_dispatcher_->OnMessageReceived(msg))
591 return;
[email protected]1edc16b82009-04-07 17:45:54592
[email protected]8930d472009-02-21 08:05:28593 IPC_BEGIN_MESSAGE_MAP(RenderThread, msg)
594 IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_NewTable, OnUpdateVisitedLinks)
[email protected]3e90d4a2009-07-03 17:38:39595 IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_Add, OnAddVisitedLinks)
596 IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_Reset, OnResetVisitedLinks)
[email protected]0314ae02010-04-08 09:18:29597 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForCurrentURL,
598 OnSetContentSettingsForCurrentURL)
[email protected]9d797f32010-04-23 07:17:54599 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForCurrentURL,
600 OnSetZoomLevelForCurrentURL)
[email protected]b2a74ca2010-03-12 17:57:09601 IPC_MESSAGE_HANDLER(ViewMsg_SetIsIncognitoProcess, OnSetIsIncognitoProcess)
[email protected]8930d472009-02-21 08:05:28602 IPC_MESSAGE_HANDLER(ViewMsg_SetNextPageID, OnSetNextPageID)
[email protected]b9ab10c2009-08-07 18:09:55603 IPC_MESSAGE_HANDLER(ViewMsg_SetCSSColors, OnSetCSSColors)
[email protected]8930d472009-02-21 08:05:28604 // TODO(port): removed from render_messages_internal.h;
605 // is there a new non-windows message I should add here?
606 IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView)
607 IPC_MESSAGE_HANDLER(ViewMsg_SetCacheCapacities, OnSetCacheCapacities)
[email protected]163753f2010-10-01 20:59:03608 IPC_MESSAGE_HANDLER(ViewMsg_ClearCache, OnClearCache)
[email protected]55e57d42009-02-25 06:10:17609 IPC_MESSAGE_HANDLER(ViewMsg_GetRendererHistograms,
[email protected]c9a3ef82009-05-28 22:02:46610 OnGetRendererHistograms)
[email protected]d41041092009-10-08 06:56:57611#if defined(USE_TCMALLOC)
612 IPC_MESSAGE_HANDLER(ViewMsg_GetRendererTcmalloc,
613 OnGetRendererTcmalloc)
614#endif
[email protected]38b48a82009-11-11 01:51:32615 IPC_MESSAGE_HANDLER(ViewMsg_GetV8HeapStats, OnGetV8HeapStats)
[email protected]8930d472009-02-21 08:05:28616 IPC_MESSAGE_HANDLER(ViewMsg_GetCacheResourceStats,
617 OnGetCacheResourceStats)
[email protected]2f2243e2009-05-26 02:27:02618 IPC_MESSAGE_HANDLER(ViewMsg_UserScripts_UpdatedScripts,
[email protected]8930d472009-02-21 08:05:28619 OnUpdateUserScripts)
[email protected]b68d5ed2009-04-16 02:41:28620 // TODO(rafaelw): create an ExtensionDispatcher that handles extension
621 // messages seperates their handling from the RenderThread.
[email protected]dfcb62a2009-06-17 19:32:43622 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
623 OnExtensionMessageInvoke)
[email protected]703e807a2009-03-28 19:56:51624 IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetFunctionNames,
625 OnSetExtensionFunctionNames)
[email protected]5351dbc2010-08-27 15:22:11626 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionsUpdated,
627 OnExtensionsUpdated)
[email protected]fede6ca12009-10-08 18:24:26628 IPC_MESSAGE_HANDLER(ViewMsg_PurgeMemory, OnPurgeMemory)
[email protected]b547fd42009-04-23 23:16:27629 IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache,
630 OnPurgePluginListCache)
[email protected]45776222009-07-15 20:21:58631 IPC_MESSAGE_HANDLER(ViewMsg_Extension_UpdatePageActions,
632 OnPageActionsUpdated)
[email protected]cccf90932009-08-23 17:56:25633 IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetAPIPermissions,
634 OnExtensionSetAPIPermissions)
635 IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetHostPermissions,
636 OnExtensionSetHostPermissions)
[email protected]b7c7bcf2009-10-03 07:07:34637 IPC_MESSAGE_HANDLER(ViewMsg_DOMStorageEvent,
638 OnDOMStorageEvent)
[email protected]d55aaa132009-09-28 21:08:04639#if defined(IPC_MESSAGE_LOG_ENABLED)
[email protected]12636df2009-09-28 22:32:21640 IPC_MESSAGE_HANDLER(ViewMsg_SetIPCLoggingEnabled,
[email protected]d55aaa132009-09-28 21:08:04641 OnSetIPCLoggingEnabled)
642#endif
[email protected]85c55dc2009-11-06 03:05:46643 IPC_MESSAGE_HANDLER(ViewMsg_SpellChecker_Init,
644 OnInitSpellChecker)
645 IPC_MESSAGE_HANDLER(ViewMsg_SpellChecker_WordAdded,
646 OnSpellCheckWordAdded)
647 IPC_MESSAGE_HANDLER(ViewMsg_SpellChecker_EnableAutoSpellCorrect,
648 OnSpellCheckEnableAutoSpellCorrect)
[email protected]6217d392010-03-25 22:08:35649 IPC_MESSAGE_HANDLER(ViewMsg_GpuChannelEstablished, OnGpuChannelEstablished)
[email protected]31c90db2010-09-23 00:59:18650 IPC_MESSAGE_HANDLER(ViewMsg_SetPhishingModel, OnSetPhishingModel)
[email protected]47158302010-11-16 14:10:22651 IPC_MESSAGE_HANDLER(ViewMsg_SpeechInput_SetFeatureEnabled,
652 OnSetSpeechInputEnabled)
[email protected]8930d472009-02-21 08:05:28653 IPC_END_MESSAGE_MAP()
initial.commit09911bf2008-07-26 23:55:29654}
655
[email protected]47158302010-11-16 14:10:22656void RenderThread::OnSetSpeechInputEnabled(bool enabled) {
657 DCHECK(!webkit_client_.get());
658 is_speech_input_enabled_ = enabled;
659}
660
initial.commit09911bf2008-07-26 23:55:29661void RenderThread::OnSetNextPageID(int32 next_page_id) {
662 // This should only be called at process initialization time, so we shouldn't
663 // have to worry about thread-safety.
664 RenderView::SetNextPageID(next_page_id);
665}
666
[email protected]b9ab10c2009-08-07 18:09:55667// Called when to register CSS Color name->system color mappings.
668// We update the colors one by one and then tell WebKit to refresh all render
669// views.
670void RenderThread::OnSetCSSColors(
671 const std::vector<CSSColors::CSSColorMapping>& colors) {
[email protected]f5e4b9bf2009-10-08 00:59:59672 EnsureWebKitInitialized();
[email protected]b9ab10c2009-08-07 18:09:55673 size_t num_colors = colors.size();
674 scoped_array<WebKit::WebColorName> color_names(
675 new WebKit::WebColorName[num_colors]);
676 scoped_array<WebKit::WebColor> web_colors(new WebKit::WebColor[num_colors]);
677 size_t i = 0;
678 for (std::vector<CSSColors::CSSColorMapping>::const_iterator it =
679 colors.begin();
680 it != colors.end();
681 ++it, ++i) {
682 color_names[i] = it->first;
683 web_colors[i] = it->second;
684 }
685 WebKit::setNamedColors(color_names.get(), web_colors.get(), num_colors);
686}
687
[email protected]4e6419c2010-01-15 04:50:34688void RenderThread::OnCreateNewView(const ViewMsg_New_Params& params) {
[email protected]90a3fbb12009-02-28 01:13:47689 EnsureWebKitInitialized();
[email protected]be645db2009-02-06 20:36:33690 // When bringing in render_view, also bring in webkit's glue and jsbindings.
initial.commit09911bf2008-07-26 23:55:29691 RenderView::Create(
[email protected]8ab04652010-06-12 02:47:26692 this,
693 params.parent_window,
694 MSG_ROUTING_NONE,
695 params.renderer_preferences,
696 params.web_preferences,
697 new SharedRenderViewCounter(0),
698 params.view_id,
699 params.session_storage_namespace_id,
700 params.frame_name);
[email protected]7f874dec2009-02-06 01:48:27701}
[email protected]4274e582009-01-27 22:09:56702
initial.commit09911bf2008-07-26 23:55:29703void RenderThread::OnSetCacheCapacities(size_t min_dead_capacity,
704 size_t max_dead_capacity,
705 size_t capacity) {
[email protected]90a3fbb12009-02-28 01:13:47706 EnsureWebKitInitialized();
[email protected]2c434b32009-03-19 06:27:47707 WebCache::setCapacities(
708 min_dead_capacity, max_dead_capacity, capacity);
initial.commit09911bf2008-07-26 23:55:29709}
710
[email protected]163753f2010-10-01 20:59:03711void RenderThread::OnClearCache() {
712 EnsureWebKitInitialized();
713 WebCache::clear();
714}
715
initial.commit09911bf2008-07-26 23:55:29716void RenderThread::OnGetCacheResourceStats() {
[email protected]90a3fbb12009-02-28 01:13:47717 EnsureWebKitInitialized();
[email protected]2c434b32009-03-19 06:27:47718 WebCache::ResourceTypeStats stats;
719 WebCache::getResourceTypeStats(&stats);
initial.commit09911bf2008-07-26 23:55:29720 Send(new ViewHostMsg_ResourceTypeStats(stats));
721}
722
[email protected]c9a3ef82009-05-28 22:02:46723void RenderThread::OnGetRendererHistograms(int sequence_number) {
724 SendHistograms(sequence_number);
[email protected]55e57d42009-02-25 06:10:17725}
726
[email protected]d41041092009-10-08 06:56:57727#if defined(USE_TCMALLOC)
728void RenderThread::OnGetRendererTcmalloc() {
729 std::string result;
730 char buffer[1024 * 32];
[email protected]a4dc33f2009-10-20 15:09:55731 base::ProcessId pid = base::GetCurrentProcId();
[email protected]d41041092009-10-08 06:56:57732 MallocExtension::instance()->GetStats(buffer, sizeof(buffer));
733 result.append(buffer);
734 Send(new ViewHostMsg_RendererTcmalloc(pid, result));
735}
736#endif
737
[email protected]38b48a82009-11-11 01:51:32738void RenderThread::OnGetV8HeapStats() {
739 v8::HeapStatistics heap_stats;
740 v8::V8::GetHeapStatistics(&heap_stats);
741 Send(new ViewHostMsg_V8HeapStats(heap_stats.total_heap_size(),
742 heap_stats.used_heap_size()));
743}
744
initial.commit09911bf2008-07-26 23:55:29745void RenderThread::InformHostOfCacheStats() {
[email protected]90a3fbb12009-02-28 01:13:47746 EnsureWebKitInitialized();
[email protected]2c434b32009-03-19 06:27:47747 WebCache::UsageStats stats;
748 WebCache::getUsageStats(&stats);
initial.commit09911bf2008-07-26 23:55:29749 Send(new ViewHostMsg_UpdatedCacheStats(stats));
[email protected]bee16aab2009-08-26 15:55:03750 cache_stats_task_pending_ = false;
initial.commit09911bf2008-07-26 23:55:29751}
752
753void RenderThread::InformHostOfCacheStatsLater() {
754 // Rate limit informing the host of our cache stats.
[email protected]bee16aab2009-08-26 15:55:03755 if (cache_stats_task_pending_)
initial.commit09911bf2008-07-26 23:55:29756 return;
757
[email protected]bee16aab2009-08-26 15:55:03758 cache_stats_task_pending_ = true;
initial.commit09911bf2008-07-26 23:55:29759 MessageLoop::current()->PostDelayedTask(FROM_HERE,
[email protected]bee16aab2009-08-26 15:55:03760 task_factory_->NewRunnableMethod(
initial.commit09911bf2008-07-26 23:55:29761 &RenderThread::InformHostOfCacheStats),
762 kCacheStatsDelayMS);
763}
[email protected]90a3fbb12009-02-28 01:13:47764
[email protected]c40acc32010-01-14 01:02:53765void RenderThread::CloseCurrentConnections() {
766 Send(new ViewHostMsg_CloseCurrentConnections());
[email protected]b07f29092009-06-05 07:33:21767}
768
769void RenderThread::SetCacheMode(bool enabled) {
770 Send(new ViewHostMsg_SetCacheMode(enabled));
771}
772
[email protected]c5d79342010-06-05 01:27:34773void RenderThread::ClearCache() {
774 int rv;
775 Send(new ViewHostMsg_ClearCache(&rv));
776}
777
[email protected]12893c32010-08-19 17:30:54778void RenderThread::EnableSpdy(bool enable) {
779 Send(new ViewHostMsg_EnableSpdy(enable));
780}
781
[email protected]c8865962009-12-16 07:47:39782void RenderThread::UpdateActiveExtensions() {
783 // In single-process mode, the browser process reports the active extensions.
784 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
785 return;
786
787 std::set<std::string> active_extensions;
788 user_script_slave_->GetActiveExtensions(&active_extensions);
789 ExtensionProcessBindings::GetActiveExtensions(&active_extensions);
790 child_process_logging::SetActiveExtensions(active_extensions);
791}
792
[email protected]6217d392010-03-25 22:08:35793void RenderThread::EstablishGpuChannel() {
794 if (gpu_channel_.get()) {
[email protected]1082b1d2010-03-30 00:31:22795 // Do nothing if we already have a GPU channel or are already
796 // establishing one.
[email protected]e09cee42010-11-09 01:50:08797 if (gpu_channel_->state() == GpuChannelHost::kUnconnected ||
798 gpu_channel_->state() == GpuChannelHost::kConnected)
[email protected]6217d392010-03-25 22:08:35799 return;
800
801 // Recreate the channel if it has been lost.
[email protected]e09cee42010-11-09 01:50:08802 if (gpu_channel_->state() == GpuChannelHost::kLost)
[email protected]6217d392010-03-25 22:08:35803 gpu_channel_ = NULL;
804 }
805
806 if (!gpu_channel_.get())
807 gpu_channel_ = new GpuChannelHost;
808
809 // Ask the browser for the channel name.
810 Send(new ViewHostMsg_EstablishGpuChannel());
811}
812
[email protected]3bf4d532010-03-27 00:23:34813GpuChannelHost* RenderThread::EstablishGpuChannelSync() {
[email protected]f9a2b2fe2010-07-15 21:13:23814 EstablishGpuChannel();
815 Send(new ViewHostMsg_SynchronizeGpu());
816 return GetGpuChannel();
[email protected]3bf4d532010-03-27 00:23:34817}
818
[email protected]6217d392010-03-25 22:08:35819GpuChannelHost* RenderThread::GetGpuChannel() {
820 if (!gpu_channel_.get())
821 return NULL;
822
[email protected]e09cee42010-11-09 01:50:08823 if (gpu_channel_->state() != GpuChannelHost::kConnected)
[email protected]6217d392010-03-25 22:08:35824 return NULL;
825
826 return gpu_channel_.get();
827}
828
[email protected]3df0c202009-03-31 23:51:26829static void* CreateHistogram(
830 const char *name, int min, int max, size_t buckets) {
[email protected]e8829a192009-12-06 00:09:37831 if (min <= 0)
832 min = 1;
[email protected]835d7c82010-10-14 04:38:38833 scoped_refptr<base::Histogram> histogram = base::Histogram::FactoryGet(
834 name, min, max, buckets, base::Histogram::kUmaTargetedHistogramFlag);
[email protected]e8829a192009-12-06 00:09:37835 // We'll end up leaking these histograms, unless there is some code hiding in
836 // there to do the dec-ref.
[email protected]2753b392009-12-28 06:59:52837 // TODO(jar): Handle reference counting in webkit glue.
[email protected]e8829a192009-12-06 00:09:37838 histogram->AddRef();
839 return histogram.get();
[email protected]3df0c202009-03-31 23:51:26840}
841
842static void AddHistogramSample(void* hist, int sample) {
[email protected]835d7c82010-10-14 04:38:38843 base::Histogram* histogram = static_cast<base::Histogram*>(hist);
[email protected]3df0c202009-03-31 23:51:26844 histogram->Add(sample);
845}
846
[email protected]90a3fbb12009-02-28 01:13:47847void RenderThread::EnsureWebKitInitialized() {
848 if (webkit_client_.get())
849 return;
[email protected]da00a2882009-03-09 17:51:19850
[email protected]71d6d852009-12-07 22:12:36851 // For extensions, we want to ensure we call the IdleHandler every so often,
852 // even if the extension keeps up activity.
[email protected]b8f41a192010-04-19 18:25:04853 if (is_extension_process_) {
[email protected]71d6d852009-12-07 22:12:36854 forced_idle_timer_.Start(
855 base::TimeDelta::FromSeconds(kMaxExtensionIdleHandlerDelayS),
856 this, &RenderThread::IdleHandler);
857 }
858
[email protected]835d7c82010-10-14 04:38:38859 v8::V8::SetCounterFunction(base::StatsTable::FindLocation);
[email protected]3df0c202009-03-31 23:51:26860 v8::V8::SetCreateHistogramFunction(CreateHistogram);
861 v8::V8::SetAddHistogramSampleFunction(AddHistogramSample);
[email protected]da00a2882009-03-09 17:51:19862
[email protected]90a3fbb12009-02-28 01:13:47863 webkit_client_.reset(new RendererWebKitClientImpl);
864 WebKit::initialize(webkit_client_.get());
[email protected]8881eca82009-03-12 18:20:44865
[email protected]98d7127b2009-10-23 18:26:51866 WebScriptController::enableV8SingleThreadMode();
[email protected]4ea00e82009-07-30 22:59:34867
[email protected]60e448982009-05-06 04:21:16868 // chrome: pages should not be accessible by normal content, and should
[email protected]8881eca82009-03-12 18:20:44869 // also be unable to script anything but themselves (to help limit the damage
[email protected]60e448982009-05-06 04:21:16870 // that a corrupt chrome: page could cause).
[email protected]2c434b32009-03-19 06:27:47871 WebString chrome_ui_scheme(ASCIIToUTF16(chrome::kChromeUIScheme));
[email protected]204758c2009-10-22 03:56:30872 WebSecurityPolicy::registerURLSchemeAsLocal(chrome_ui_scheme);
873 WebSecurityPolicy::registerURLSchemeAsNoAccess(chrome_ui_scheme);
[email protected]da00a2882009-03-09 17:51:19874
[email protected]b4e75c12010-05-18 18:28:48875 // chrome-extension: resources shouldn't trigger insecure content warnings.
[email protected]37e5a9a2010-03-13 09:42:39876 WebString extension_scheme(ASCIIToUTF16(chrome::kExtensionScheme));
877 WebSecurityPolicy::registerURLSchemeAsSecure(extension_scheme);
878
[email protected]6cf8b1a22009-05-26 23:36:00879#if defined(OS_WIN)
880 // We don't yet support Gears on non-Windows, so don't tell pages that we do.
[email protected]af7eb3fb2010-09-23 21:31:06881 RegisterExtension(extensions_v8::GearsExtension::Get(), false);
[email protected]6cf8b1a22009-05-26 23:36:00882#endif
[email protected]af7eb3fb2010-09-23 21:31:06883 RegisterExtension(extensions_v8::LoadTimesExtension::Get(), false);
884 RegisterExtension(extensions_v8::ChromeAppExtension::Get(), false);
885 RegisterExtension(extensions_v8::ExternalExtension::Get(), false);
[email protected]ce833282010-11-04 15:48:39886 RegisterExtension(extensions_v8::SearchBoxExtension::Get(), false);
[email protected]15d9c0c2010-09-10 22:36:26887 v8::Extension* search_extension = extensions_v8::SearchExtension::Get();
888 // search_extension is null if not enabled.
889 if (search_extension)
[email protected]af7eb3fb2010-09-23 21:31:06890 RegisterExtension(search_extension, false);
[email protected]e2b2d4a2009-10-24 03:32:59891
[email protected]06533c0b2009-03-05 21:39:11892 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]a1a0df02009-04-09 08:18:04893
[email protected]af7eb3fb2010-09-23 21:31:06894 if (command_line.HasSwitch(switches::kEnableBenchmarking))
895 RegisterExtension(extensions_v8::BenchmarkingExtension::Get(), false);
[email protected]b07f29092009-06-05 07:33:21896
[email protected]06533c0b2009-03-05 21:39:11897 if (command_line.HasSwitch(switches::kPlaybackMode) ||
[email protected]ca12c842009-04-14 22:20:18898 command_line.HasSwitch(switches::kRecordMode) ||
899 command_line.HasSwitch(switches::kNoJsRandomness)) {
[email protected]af7eb3fb2010-09-23 21:31:06900 RegisterExtension(extensions_v8::PlaybackExtension::Get(), false);
[email protected]06533c0b2009-03-05 21:39:11901 }
[email protected]2cb82332009-03-18 17:24:55902
[email protected]af7eb3fb2010-09-23 21:31:06903 if (command_line.HasSwitch(switches::kDomAutomationController))
904 RegisterExtension(DomAutomationV8Extension::Get(), false);
905
906 // Add v8 extensions related to chrome extensions.
907 RegisterExtension(ExtensionProcessBindings::Get(), true);
908 RegisterExtension(BaseJsV8Extension::Get(), true);
909 RegisterExtension(JsonSchemaJsV8Extension::Get(), true);
910 RegisterExtension(EventBindings::Get(), true);
911 RegisterExtension(RendererExtensionBindings::Get(), true);
912 RegisterExtension(ExtensionApiTestV8Extension::Get(), true);
913
914 web_database_observer_impl_.reset(new WebDatabaseObserverImpl(this));
915 WebKit::WebDatabase::setObserver(web_database_observer_impl_.get());
[email protected]a9602de2010-03-18 23:43:11916
[email protected]b1b13212009-10-30 06:42:01917 WebRuntimeFeatures::enableMediaPlayer(
[email protected]00c39612010-03-06 02:53:28918 RenderProcess::current()->HasInitializedMediaLibrary());
[email protected]3553c6cc2009-10-20 05:51:55919
[email protected]b1b13212009-10-30 06:42:01920 WebRuntimeFeatures::enableSockets(
[email protected]cdf24782009-11-05 09:32:47921 !command_line.HasSwitch(switches::kDisableWebSockets));
[email protected]0afb9932009-10-24 00:37:58922
[email protected]b1b13212009-10-30 06:42:01923 WebRuntimeFeatures::enableDatabase(
[email protected]90a7ad522009-11-20 22:42:53924 !command_line.HasSwitch(switches::kDisableDatabases));
[email protected]bfa69d492009-10-31 03:27:19925
[email protected]13bc0d822009-11-07 01:17:14926 WebRuntimeFeatures::enableApplicationCache(
[email protected]425c270642010-01-26 20:42:37927 !command_line.HasSwitch(switches::kDisableApplicationCache));
[email protected]13bc0d822009-11-07 01:17:14928
[email protected]bfa69d492009-10-31 03:27:19929 WebRuntimeFeatures::enableNotifications(
[email protected]380f1862009-11-14 02:48:01930 !command_line.HasSwitch(switches::kDisableDesktopNotifications));
[email protected]7ee66e62009-11-05 09:16:30931
932 WebRuntimeFeatures::enableLocalStorage(
[email protected]5cf18362009-11-06 18:45:01933 !command_line.HasSwitch(switches::kDisableLocalStorage));
[email protected]7ee66e62009-11-05 09:16:30934 WebRuntimeFeatures::enableSessionStorage(
[email protected]03567802010-02-24 11:48:53935 !command_line.HasSwitch(switches::kDisableSessionStorage));
[email protected]2236bd1f2010-01-20 15:17:08936
[email protected]582fab732010-02-02 02:50:28937 WebRuntimeFeatures::enableIndexedDatabase(
[email protected]af1f9f32010-10-09 21:30:26938 !command_line.HasSwitch(switches::kDisableIndexedDatabase));
[email protected]582fab732010-02-02 02:50:28939
[email protected]2236bd1f2010-01-20 15:17:08940 WebRuntimeFeatures::enableGeolocation(
[email protected]d0569f42010-04-01 10:48:18941 !command_line.HasSwitch(switches::kDisableGeolocation));
[email protected]7a716c82010-03-03 10:33:44942
943 WebRuntimeFeatures::enableWebGL(
[email protected]11c4c812010-10-22 19:50:12944 !command_line.HasSwitch(switches::kDisableExperimentalWebGL));
[email protected]ccbe04e2010-03-17 17:58:43945
946 WebRuntimeFeatures::enablePushState(true);
[email protected]f2e3d6c2010-04-30 14:23:04947
948 WebRuntimeFeatures::enableTouch(
949 command_line.HasSwitch(switches::kEnableTouch));
[email protected]66249e22010-07-22 09:55:33950
[email protected]1f501972010-08-09 05:40:02951 WebRuntimeFeatures::enableDeviceMotion(
952 command_line.HasSwitch(switches::kEnableDeviceMotion));
953
[email protected]66249e22010-07-22 09:55:33954 WebRuntimeFeatures::enableDeviceOrientation(
[email protected]71453202010-08-27 15:47:37955 !command_line.HasSwitch(switches::kDisableDeviceOrientation));
[email protected]c8647272010-07-30 21:52:57956
[email protected]47158302010-11-16 14:10:22957 WebRuntimeFeatures::enableSpeechInput(is_speech_input_enabled_);
[email protected]4c56ef52010-09-03 01:56:04958
959 WebRuntimeFeatures::enableFileSystem(
[email protected]2a524d22010-10-16 01:16:23960 !command_line.HasSwitch(switches::kDisableFileSystem));
[email protected]90a3fbb12009-02-28 01:13:47961}
[email protected]75e5a872009-04-02 23:56:11962
[email protected]bee16aab2009-08-26 15:55:03963void RenderThread::IdleHandler() {
[email protected]61a9b2d82010-02-26 00:31:08964#if (defined(OS_WIN) || defined(OS_LINUX)) && defined(USE_TCMALLOC)
[email protected]e94afbb92009-10-01 00:25:41965 MallocExtension::instance()->ReleaseFreeMemory();
[email protected]05001182009-09-15 23:34:22966#endif
[email protected]bee16aab2009-08-26 15:55:03967
[email protected]f5e4b9bf2009-10-08 00:59:59968 v8::V8::IdleNotification();
[email protected]05001182009-09-15 23:34:22969
970 // Schedule next invocation.
971 // Dampen the delay using the algorithm:
972 // delay = delay + 1 / (delay + 2)
973 // Using floor(delay) has a dampening effect such as:
974 // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ...
975 // Note that idle_notification_delay_in_s_ would be reset to
976 // kInitialIdleHandlerDelayS in RenderThread::WidgetHidden.
[email protected]71d6d852009-12-07 22:12:36977 ScheduleIdleHandler(idle_notification_delay_in_s_ +
978 1.0 / (idle_notification_delay_in_s_ + 2.0));
[email protected]b8f41a192010-04-19 18:25:04979 if (is_extension_process_) {
[email protected]71d6d852009-12-07 22:12:36980 // Dampen the forced delay as well if the extension stays idle for long
981 // periods of time.
982 int64 forced_delay_s =
983 std::max(static_cast<int64>(idle_notification_delay_in_s_),
984 kMaxExtensionIdleHandlerDelayS);
985 forced_idle_timer_.Stop();
986 forced_idle_timer_.Start(
987 base::TimeDelta::FromSeconds(forced_delay_s),
988 this, &RenderThread::IdleHandler);
989 }
990}
[email protected]05001182009-09-15 23:34:22991
[email protected]71d6d852009-12-07 22:12:36992void RenderThread::ScheduleIdleHandler(double initial_delay_s) {
993 idle_notification_delay_in_s_ = initial_delay_s;
994 idle_timer_.Stop();
995 idle_timer_.Start(
996 base::TimeDelta::FromSeconds(static_cast<int64>(initial_delay_s)),
997 this, &RenderThread::IdleHandler);
[email protected]bee16aab2009-08-26 15:55:03998}
999
[email protected]a7ab1b782010-10-21 23:24:161000void RenderThread::OnExtensionMessageInvoke(const std::string& extension_id,
1001 const std::string& function_name,
[email protected]d7259472010-03-24 08:40:491002 const ListValue& args,
[email protected]a807bbe2010-04-14 10:51:191003 const GURL& event_url) {
1004 RendererExtensionBindings::Invoke(
[email protected]a7ab1b782010-10-21 23:24:161005 extension_id, function_name, args, NULL, event_url);
[email protected]71d6d852009-12-07 22:12:361006
1007 // Reset the idle handler each time there's any activity like event or message
1008 // dispatch, for which Invoke is the chokepoint.
[email protected]b8f41a192010-04-19 18:25:041009 if (is_extension_process_)
[email protected]71d6d852009-12-07 22:12:361010 ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayS);
[email protected]b68d5ed2009-04-16 02:41:281011}
[email protected]b547fd42009-04-23 23:16:271012
[email protected]fede6ca12009-10-08 18:24:261013void RenderThread::OnPurgeMemory() {
[email protected]85c55dc2009-11-06 03:05:461014 spellchecker_.reset(new SpellCheck());
[email protected]85c55dc2009-11-06 03:05:461015
[email protected]fede6ca12009-10-08 18:24:261016 EnsureWebKitInitialized();
1017
1018 // Clear the object cache (as much as possible; some live objects cannot be
1019 // freed).
1020 WebCache::clear();
1021
1022 // Clear the font/glyph cache.
1023 WebFontCache::clear();
1024
1025 // Clear the Cross-Origin Preflight cache.
1026 WebCrossOriginPreflightResultCache::clear();
1027
[email protected]adf00bc2009-11-02 18:35:001028 // Release all freeable memory from the SQLite process-global page cache (a
1029 // low-level object which backs the Connection-specific page caches).
[email protected]4a3dab22009-11-11 17:36:501030 while (sqlite3_release_memory(std::numeric_limits<int>::max()) > 0) {
1031 }
[email protected]adf00bc2009-11-02 18:35:001032
[email protected]fede6ca12009-10-08 18:24:261033 // Repeatedly call the V8 idle notification until it returns true ("nothing
1034 // more to free"). Note that it makes more sense to do this than to implement
1035 // a new "delete everything" pass because object references make it difficult
1036 // to free everything possible in just one pass.
[email protected]4a3dab22009-11-11 17:36:501037 while (!v8::V8::IdleNotification()) {
1038 }
[email protected]fede6ca12009-10-08 18:24:261039
[email protected]61a9b2d82010-02-26 00:31:081040#if (defined(OS_WIN) || defined(OS_LINUX)) && defined(USE_TCMALLOC)
[email protected]fede6ca12009-10-08 18:24:261041 // Tell tcmalloc to release any free pages it's still holding.
1042 MallocExtension::instance()->ReleaseFreeMemory();
1043#endif
1044}
1045
[email protected]b78e168b2009-09-21 22:05:451046void RenderThread::OnPurgePluginListCache(bool reload_pages) {
[email protected]f5e4b9bf2009-10-08 00:59:591047 EnsureWebKitInitialized();
[email protected]b547fd42009-04-23 23:16:271048 // The call below will cause a GetPlugins call with refresh=true, but at this
1049 // point we already know that the browser has refreshed its list, so disable
1050 // refresh temporarily to prevent each renderer process causing the list to be
1051 // regenerated.
1052 plugin_refresh_allowed_ = false;
[email protected]b78e168b2009-09-21 22:05:451053 WebKit::resetPluginCache(reload_pages);
[email protected]b547fd42009-04-23 23:16:271054 plugin_refresh_allowed_ = true;
1055}
[email protected]85c55dc2009-11-06 03:05:461056
[email protected]85c55dc2009-11-06 03:05:461057void RenderThread::OnInitSpellChecker(
[email protected]cb6037d2009-11-16 22:55:171058 IPC::PlatformFileForTransit bdict_file,
[email protected]85c55dc2009-11-06 03:05:461059 const std::vector<std::string>& custom_words,
1060 const std::string& language,
1061 bool auto_spell_correct) {
[email protected]cb6037d2009-11-16 22:55:171062 spellchecker_->Init(IPC::PlatformFileForTransitToPlatformFile(bdict_file),
1063 custom_words, language);
[email protected]85c55dc2009-11-06 03:05:461064 spellchecker_->EnableAutoSpellCorrect(auto_spell_correct);
1065}
1066
1067void RenderThread::OnSpellCheckWordAdded(const std::string& word) {
1068 spellchecker_->WordAdded(word);
1069}
1070
1071void RenderThread::OnSpellCheckEnableAutoSpellCorrect(bool enable) {
1072 spellchecker_->EnableAutoSpellCorrect(enable);
1073}
[email protected]b2a74ca2010-03-12 17:57:091074
1075void RenderThread::OnSetIsIncognitoProcess(bool is_incognito_process) {
1076 is_incognito_process_ = is_incognito_process;
1077}
[email protected]6217d392010-03-25 22:08:351078
1079void RenderThread::OnGpuChannelEstablished(
[email protected]4bce24e2010-09-07 20:45:011080 const IPC::ChannelHandle& channel_handle, const GPUInfo& gpu_info) {
[email protected]6217d392010-03-25 22:08:351081#if defined(OS_POSIX)
1082 // If we received a ChannelHandle, register it now.
1083 if (channel_handle.socket.fd >= 0)
1084 IPC::AddChannelSocket(channel_handle.name, channel_handle.socket.fd);
1085#endif
1086
[email protected]4bce24e2010-09-07 20:45:011087 gpu_channel_->set_gpu_info(gpu_info);
1088
[email protected]6217d392010-03-25 22:08:351089 if (channel_handle.name.size() != 0) {
1090 // Connect to the GPU process if a channel name was received.
1091 gpu_channel_->Connect(channel_handle.name);
1092 } else {
1093 // Otherwise cancel the connection.
1094 gpu_channel_ = NULL;
1095 }
1096}
[email protected]3a8eecb2010-04-22 23:56:301097
[email protected]31c90db2010-09-23 00:59:181098void RenderThread::OnSetPhishingModel(IPC::PlatformFileForTransit model_file) {
[email protected]3ead1322010-11-19 20:01:001099 safe_browsing::Scorer::CreateFromFile(
1100 IPC::PlatformFileForTransitToPlatformFile(model_file),
1101 GetFileThreadMessageLoopProxy(),
1102 callback_factory_->NewCallback(&RenderThread::PhishingScorerCreated));
1103}
1104
1105void RenderThread::PhishingScorerCreated(safe_browsing::Scorer* scorer) {
1106 if (!scorer) {
1107 DLOG(ERROR) << "Unable to create a PhishingScorer - corrupt model?";
1108 return;
1109 }
1110 phishing_scorer_.reset(scorer);
1111 RenderViewPhishingScorerSetter setter(phishing_scorer_.get());
1112 RenderView::ForEach(&setter);
[email protected]31c90db2010-09-23 00:59:181113}
1114
[email protected]c6a7b862010-08-20 22:19:381115scoped_refptr<base::MessageLoopProxy>
1116RenderThread::GetFileThreadMessageLoopProxy() {
1117 DCHECK(message_loop() == MessageLoop::current());
1118 if (!file_thread_.get()) {
1119 file_thread_.reset(new base::Thread("Renderer::FILE"));
1120 file_thread_->Start();
1121 }
1122 return file_thread_->message_loop_proxy();
1123}
[email protected]af7eb3fb2010-09-23 21:31:061124
1125bool RenderThread::AllowScriptExtension(const std::string& v8_extension_name,
1126 const GURL& url,
1127 int extension_group) {
1128 // If we don't know about it, it was added by WebCore, so we should allow it.
1129 if (v8_extensions_.find(v8_extension_name) == v8_extensions_.end())
1130 return true;
1131
1132 // If the V8 extension is not restricted, allow it to run anywhere.
1133 bool restrict_to_extensions = v8_extensions_[v8_extension_name];
1134 if (!restrict_to_extensions)
1135 return true;
1136
1137 // Extension-only bindings should be restricted to content scripts and
1138 // extension-blessed URLs.
1139 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS ||
1140 ExtensionRendererInfo::ExtensionBindingsAllowed(url)) {
1141 return true;
1142 }
1143
1144 return false;
1145}
1146
1147void RenderThread::RegisterExtension(v8::Extension* extension,
1148 bool restrict_to_extensions) {
1149 WebScriptController::registerExtension(extension);
1150 v8_extensions_[extension->name()] = restrict_to_extensions;
1151}