chrome_render_message_filter.cc revision 5821806d5e7f356e8fa4b058a389a808ea183019
1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
6
7#include "base/bind.h"
8#include "base/command_line.h"
9#include "base/file_util.h"
10#include "base/metrics/histogram.h"
11#include "chrome/browser/automation/automation_resource_message_filter.h"
12#include "chrome/browser/browser_process.h"
13#include "chrome/browser/content_settings/cookie_settings.h"
14#include "chrome/browser/content_settings/tab_specific_content_settings.h"
15#include "chrome/browser/extensions/api/messaging/message_service.h"
16#include "chrome/browser/extensions/event_router.h"
17#include "chrome/browser/extensions/extension_function_dispatcher.h"
18#include "chrome/browser/extensions/extension_info_map.h"
19#include "chrome/browser/extensions/extension_process_manager.h"
20#include "chrome/browser/extensions/extension_service.h"
21#include "chrome/browser/extensions/extension_system.h"
22#include "chrome/browser/nacl_host/nacl_process_host.h"
23#include "chrome/browser/nacl_host/pnacl_file_host.h"
24#include "chrome/browser/net/chrome_url_request_context.h"
25#include "chrome/browser/net/predictor.h"
26#include "chrome/browser/profiles/profile.h"
27#include "chrome/browser/task_manager/task_manager.h"
28#include "chrome/common/chrome_notification_types.h"
29#include "chrome/common/chrome_switches.h"
30#include "chrome/common/extensions/extension.h"
31#include "chrome/common/extensions/extension_file_util.h"
32#include "chrome/common/extensions/extension_messages.h"
33#include "chrome/common/extensions/message_bundle.h"
34#include "chrome/common/render_messages.h"
35#include "chrome/common/url_constants.h"
36#include "content/public/browser/notification_service.h"
37#include "content/public/browser/render_process_host.h"
38#include "content/public/browser/resource_dispatcher_host.h"
39#include "content/public/common/process_type.h"
40#include "googleurl/src/gurl.h"
41#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
42#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
43#include "webkit/plugins/npapi/plugin_list.h"
44
45#if defined(USE_TCMALLOC)
46#include "chrome/browser/browser_about_handler.h"
47#endif
48
49using content::BrowserThread;
50using extensions::APIPermission;
51using WebKit::WebCache;
52using WebKit::WebSecurityOrigin;
53
54ChromeRenderMessageFilter::ChromeRenderMessageFilter(
55    int render_process_id,
56    Profile* profile,
57    net::URLRequestContextGetter* request_context)
58    : render_process_id_(render_process_id),
59      profile_(profile),
60      off_the_record_(profile_->IsOffTheRecord()),
61      request_context_(request_context),
62      extension_info_map_(
63          extensions::ExtensionSystem::Get(profile)->info_map()),
64      cookie_settings_(CookieSettings::Factory::GetForProfile(profile)),
65      weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
66}
67
68ChromeRenderMessageFilter::~ChromeRenderMessageFilter() {
69}
70
71bool ChromeRenderMessageFilter::OnMessageReceived(const IPC::Message& message,
72                                                  bool* message_was_ok) {
73  bool handled = true;
74  IPC_BEGIN_MESSAGE_MAP_EX(ChromeRenderMessageFilter, message, *message_was_ok)
75#if !defined(DISABLE_NACL)
76    IPC_MESSAGE_HANDLER_DELAY_REPLY(ChromeViewHostMsg_LaunchNaCl, OnLaunchNaCl)
77    IPC_MESSAGE_HANDLER_DELAY_REPLY(ChromeViewHostMsg_GetReadonlyPnaclFD,
78                                    OnGetReadonlyPnaclFd)
79    IPC_MESSAGE_HANDLER_DELAY_REPLY(ChromeViewHostMsg_NaClCreateTemporaryFile,
80                                    OnNaClCreateTemporaryFile)
81#endif
82    IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DnsPrefetch, OnDnsPrefetch)
83    IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ResourceTypeStats,
84                        OnResourceTypeStats)
85    IPC_MESSAGE_HANDLER(ChromeViewHostMsg_UpdatedCacheStats,
86                        OnUpdatedCacheStats)
87    IPC_MESSAGE_HANDLER(ChromeViewHostMsg_FPS, OnFPS)
88    IPC_MESSAGE_HANDLER(ChromeViewHostMsg_V8HeapStats, OnV8HeapStats)
89    IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenChannelToExtension,
90                        OnOpenChannelToExtension)
91    IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenChannelToTab, OnOpenChannelToTab)
92    IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenChannelToNativeApp,
93                        OnOpenChannelToNativeApp)
94    IPC_MESSAGE_HANDLER_DELAY_REPLY(ExtensionHostMsg_GetMessageBundle,
95                                    OnGetExtensionMessageBundle)
96    IPC_MESSAGE_HANDLER(ExtensionHostMsg_AddListener, OnExtensionAddListener)
97    IPC_MESSAGE_HANDLER(ExtensionHostMsg_RemoveListener,
98                        OnExtensionRemoveListener)
99    IPC_MESSAGE_HANDLER(ExtensionHostMsg_AddLazyListener,
100                        OnExtensionAddLazyListener)
101    IPC_MESSAGE_HANDLER(ExtensionHostMsg_RemoveLazyListener,
102                        OnExtensionRemoveLazyListener)
103    IPC_MESSAGE_HANDLER(ExtensionHostMsg_AddFilteredListener,
104                        OnExtensionAddFilteredListener)
105    IPC_MESSAGE_HANDLER(ExtensionHostMsg_RemoveFilteredListener,
106                        OnExtensionRemoveFilteredListener)
107    IPC_MESSAGE_HANDLER(ExtensionHostMsg_CloseChannel, OnExtensionCloseChannel)
108    IPC_MESSAGE_HANDLER(ExtensionHostMsg_RequestForIOThread,
109                        OnExtensionRequestForIOThread)
110    IPC_MESSAGE_HANDLER(ExtensionHostMsg_ShouldUnloadAck,
111                        OnExtensionShouldUnloadAck)
112    IPC_MESSAGE_HANDLER(ExtensionHostMsg_GenerateUniqueID,
113                        OnExtensionGenerateUniqueID)
114    IPC_MESSAGE_HANDLER(ExtensionHostMsg_UnloadAck, OnExtensionUnloadAck)
115    IPC_MESSAGE_HANDLER(ExtensionHostMsg_ResumeRequests,
116                        OnExtensionResumeRequests);
117    IPC_MESSAGE_HANDLER(ChromeViewHostMsg_AllowDatabase, OnAllowDatabase)
118    IPC_MESSAGE_HANDLER(ChromeViewHostMsg_AllowDOMStorage, OnAllowDOMStorage)
119    IPC_MESSAGE_HANDLER(ChromeViewHostMsg_AllowFileSystem, OnAllowFileSystem)
120    IPC_MESSAGE_HANDLER(ChromeViewHostMsg_AllowIndexedDB, OnAllowIndexedDB)
121    IPC_MESSAGE_HANDLER(ChromeViewHostMsg_CanTriggerClipboardRead,
122                        OnCanTriggerClipboardRead)
123    IPC_MESSAGE_HANDLER(ChromeViewHostMsg_CanTriggerClipboardWrite,
124                        OnCanTriggerClipboardWrite)
125    IPC_MESSAGE_UNHANDLED(handled = false)
126  IPC_END_MESSAGE_MAP()
127
128#if defined(ENABLE_AUTOMATION)
129  if ((message.type() == ChromeViewHostMsg_GetCookies::ID ||
130       message.type() == ChromeViewHostMsg_SetCookie::ID) &&
131    AutomationResourceMessageFilter::ShouldFilterCookieMessages(
132        render_process_id_, message.routing_id())) {
133    // ChromeFrame then we need to get/set cookies from the external host.
134    IPC_BEGIN_MESSAGE_MAP_EX(ChromeRenderMessageFilter, message,
135                             *message_was_ok)
136      IPC_MESSAGE_HANDLER_DELAY_REPLY(ChromeViewHostMsg_GetCookies,
137                                      OnGetCookies)
138      IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetCookie, OnSetCookie)
139    IPC_END_MESSAGE_MAP()
140    handled = true;
141  }
142#endif
143
144  return handled;
145}
146
147void ChromeRenderMessageFilter::OverrideThreadForMessage(
148    const IPC::Message& message, BrowserThread::ID* thread) {
149  switch (message.type()) {
150    case ChromeViewHostMsg_ResourceTypeStats::ID:
151    case ExtensionHostMsg_AddListener::ID:
152    case ExtensionHostMsg_RemoveListener::ID:
153    case ExtensionHostMsg_AddLazyListener::ID:
154    case ExtensionHostMsg_RemoveLazyListener::ID:
155    case ExtensionHostMsg_AddFilteredListener::ID:
156    case ExtensionHostMsg_RemoveFilteredListener::ID:
157    case ExtensionHostMsg_CloseChannel::ID:
158    case ExtensionHostMsg_ShouldUnloadAck::ID:
159    case ExtensionHostMsg_UnloadAck::ID:
160    case ChromeViewHostMsg_UpdatedCacheStats::ID:
161      *thread = BrowserThread::UI;
162      break;
163    default:
164      break;
165  }
166}
167
168net::HostResolver* ChromeRenderMessageFilter::GetHostResolver() {
169  return request_context_->GetURLRequestContext()->host_resolver();
170}
171
172#if !defined(DISABLE_NACL)
173void ChromeRenderMessageFilter::OnLaunchNaCl(const GURL& manifest_url,
174                                             int render_view_id,
175                                             uint32 permission_bits,
176                                             int socket_count,
177                                             IPC::Message* reply_msg) {
178  NaClProcessHost* host = new NaClProcessHost(manifest_url,
179                                              render_view_id,
180                                              permission_bits,
181                                              off_the_record_);
182  host->Launch(this, socket_count, reply_msg, extension_info_map_);
183}
184
185void ChromeRenderMessageFilter::OnGetReadonlyPnaclFd(
186    const std::string& filename, IPC::Message* reply_msg) {
187  // This posts a task to another thread, but the renderer will
188  // block until the reply is sent.
189  pnacl_file_host::GetReadonlyPnaclFd(this, filename, reply_msg);
190}
191
192void ChromeRenderMessageFilter::OnNaClCreateTemporaryFile(
193    IPC::Message* reply_msg) {
194  pnacl_file_host::CreateTemporaryFile(this, reply_msg);
195}
196#endif
197
198void ChromeRenderMessageFilter::OnDnsPrefetch(
199    const std::vector<std::string>& hostnames) {
200  if (profile_->GetNetworkPredictor())
201    profile_->GetNetworkPredictor()->DnsPrefetchList(hostnames);
202}
203
204void ChromeRenderMessageFilter::OnResourceTypeStats(
205    const WebCache::ResourceTypeStats& stats) {
206  HISTOGRAM_COUNTS("WebCoreCache.ImagesSizeKB",
207                   static_cast<int>(stats.images.size / 1024));
208  HISTOGRAM_COUNTS("WebCoreCache.CSSStylesheetsSizeKB",
209                   static_cast<int>(stats.cssStyleSheets.size / 1024));
210  HISTOGRAM_COUNTS("WebCoreCache.ScriptsSizeKB",
211                   static_cast<int>(stats.scripts.size / 1024));
212  HISTOGRAM_COUNTS("WebCoreCache.XSLStylesheetsSizeKB",
213                   static_cast<int>(stats.xslStyleSheets.size / 1024));
214  HISTOGRAM_COUNTS("WebCoreCache.FontsSizeKB",
215                   static_cast<int>(stats.fonts.size / 1024));
216
217  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
218#if defined(ENABLE_TASK_MANAGER)
219  TaskManager::GetInstance()->model()->NotifyResourceTypeStats(
220      base::GetProcId(peer_handle()), stats);
221#endif  // defined(ENABLE_TASK_MANAGER)
222}
223
224void ChromeRenderMessageFilter::OnUpdatedCacheStats(
225    const WebCache::UsageStats& stats) {
226  WebCacheManager::GetInstance()->ObserveStats(render_process_id_, stats);
227}
228
229void ChromeRenderMessageFilter::OnFPS(int routing_id, float fps) {
230  if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
231    BrowserThread::PostTask(
232        BrowserThread::UI, FROM_HERE,
233        base::Bind(
234            &ChromeRenderMessageFilter::OnFPS, this,
235            routing_id, fps));
236    return;
237  }
238
239  base::ProcessId renderer_id = base::GetProcId(peer_handle());
240
241#if defined(ENABLE_TASK_MANAGER)
242  TaskManager::GetInstance()->model()->NotifyFPS(
243      renderer_id, routing_id, fps);
244#endif  // defined(ENABLE_TASK_MANAGER)
245
246  FPSDetails details(routing_id, fps);
247  content::NotificationService::current()->Notify(
248      chrome::NOTIFICATION_RENDERER_FPS_COMPUTED,
249      content::Source<const base::ProcessId>(&renderer_id),
250      content::Details<const FPSDetails>(&details));
251}
252
253void ChromeRenderMessageFilter::OnV8HeapStats(int v8_memory_allocated,
254                                              int v8_memory_used) {
255  if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
256    BrowserThread::PostTask(
257        BrowserThread::UI, FROM_HERE,
258        base::Bind(
259            &ChromeRenderMessageFilter::OnV8HeapStats, this,
260            v8_memory_allocated, v8_memory_used));
261    return;
262  }
263
264  base::ProcessId renderer_id = base::GetProcId(peer_handle());
265
266#if defined(ENABLE_TASK_MANAGER)
267  TaskManager::GetInstance()->model()->NotifyV8HeapStats(
268      renderer_id,
269      static_cast<size_t>(v8_memory_allocated),
270      static_cast<size_t>(v8_memory_used));
271#endif  // defined(ENABLE_TASK_MANAGER)
272
273  V8HeapStatsDetails details(v8_memory_allocated, v8_memory_used);
274  content::NotificationService::current()->Notify(
275      chrome::NOTIFICATION_RENDERER_V8_HEAP_STATS_COMPUTED,
276      content::Source<const base::ProcessId>(&renderer_id),
277      content::Details<const V8HeapStatsDetails>(&details));
278}
279
280void ChromeRenderMessageFilter::OnOpenChannelToExtension(
281    int routing_id, const std::string& source_extension_id,
282    const std::string& target_extension_id,
283    const std::string& channel_name, int* port_id) {
284  int port2_id;
285  extensions::MessageService::AllocatePortIdPair(port_id, &port2_id);
286
287  BrowserThread::PostTask(
288      BrowserThread::UI, FROM_HERE,
289      base::Bind(&ChromeRenderMessageFilter::OpenChannelToExtensionOnUIThread,
290                 this, render_process_id_, routing_id, port2_id,
291                 source_extension_id, target_extension_id, channel_name));
292}
293
294void ChromeRenderMessageFilter::OpenChannelToExtensionOnUIThread(
295    int source_process_id, int source_routing_id,
296    int receiver_port_id,
297    const std::string& source_extension_id,
298    const std::string& target_extension_id,
299    const std::string& channel_name) {
300  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
301  extensions::ExtensionSystem::Get(profile_)->message_service()->
302      OpenChannelToExtension(
303          source_process_id, source_routing_id, receiver_port_id,
304          source_extension_id, target_extension_id, channel_name);
305}
306
307void ChromeRenderMessageFilter::OnOpenChannelToNativeApp(
308    int routing_id, const std::string& source_extension_id,
309    const std::string& native_app_name,
310    const std::string& channel_name,
311    const std::string& connect_message, int* port_id) {
312  int port2_id;
313  extensions::MessageService::AllocatePortIdPair(port_id, &port2_id);
314
315  BrowserThread::PostTask(
316      BrowserThread::UI, FROM_HERE,
317      base::Bind(&ChromeRenderMessageFilter::OpenChannelToNativeAppOnUIThread,
318                 this,
319                 routing_id,
320                 port2_id,
321                 source_extension_id,
322                 native_app_name,
323                 channel_name,
324                 connect_message));
325}
326
327void ChromeRenderMessageFilter::OpenChannelToNativeAppOnUIThread(
328    int source_routing_id,
329    int receiver_port_id,
330    const std::string& source_extension_id,
331    const std::string& native_app_name,
332    const std::string& channel_name,
333    const std::string& connect_message) {
334  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
335  extensions::ExtensionSystem::Get(profile_)->message_service()->
336      OpenChannelToNativeApp(
337          render_process_id_, source_routing_id, receiver_port_id,
338          source_extension_id, native_app_name, channel_name, connect_message);
339}
340
341void ChromeRenderMessageFilter::OnOpenChannelToTab(
342    int routing_id, int tab_id, const std::string& extension_id,
343    const std::string& channel_name, int* port_id) {
344  int port2_id;
345  extensions::MessageService::AllocatePortIdPair(port_id, &port2_id);
346
347  BrowserThread::PostTask(
348      BrowserThread::UI, FROM_HERE,
349      base::Bind(&ChromeRenderMessageFilter::OpenChannelToTabOnUIThread, this,
350                 render_process_id_, routing_id, port2_id, tab_id, extension_id,
351                 channel_name));
352}
353
354void ChromeRenderMessageFilter::OpenChannelToTabOnUIThread(
355    int source_process_id, int source_routing_id,
356    int receiver_port_id,
357    int tab_id,
358    const std::string& extension_id,
359    const std::string& channel_name) {
360  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
361  extensions::ExtensionSystem::Get(profile_)->message_service()->
362      OpenChannelToTab(
363          source_process_id, source_routing_id, receiver_port_id,
364          tab_id, extension_id, channel_name);
365}
366
367void ChromeRenderMessageFilter::OnGetExtensionMessageBundle(
368    const std::string& extension_id, IPC::Message* reply_msg) {
369  const extensions::Extension* extension =
370      extension_info_map_->extensions().GetByID(extension_id);
371  FilePath extension_path;
372  std::string default_locale;
373  if (extension) {
374    extension_path = extension->path();
375    default_locale = extension->default_locale();
376  }
377
378  BrowserThread::PostTask(
379      BrowserThread::FILE, FROM_HERE,
380      base::Bind(
381          &ChromeRenderMessageFilter::OnGetExtensionMessageBundleOnFileThread,
382          this, extension_path, extension_id, default_locale, reply_msg));
383}
384
385void ChromeRenderMessageFilter::OnGetExtensionMessageBundleOnFileThread(
386    const FilePath& extension_path,
387    const std::string& extension_id,
388    const std::string& default_locale,
389    IPC::Message* reply_msg) {
390  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
391
392  scoped_ptr<extensions::MessageBundle::SubstitutionMap> dictionary_map(
393      extension_file_util::LoadMessageBundleSubstitutionMap(
394          extension_path,
395          extension_id,
396          default_locale));
397
398  ExtensionHostMsg_GetMessageBundle::WriteReplyParams(
399      reply_msg, *dictionary_map);
400  Send(reply_msg);
401}
402
403void ChromeRenderMessageFilter::OnExtensionAddListener(
404    const std::string& extension_id,
405    const std::string& event_name) {
406  content::RenderProcessHost* process =
407      content::RenderProcessHost::FromID(render_process_id_);
408  if (!process ||
409      !extensions::ExtensionSystem::Get(profile_)->event_router())
410    return;
411
412  extensions::ExtensionSystem::Get(profile_)->event_router()->
413      AddEventListener(event_name, process, extension_id);
414}
415
416void ChromeRenderMessageFilter::OnExtensionRemoveListener(
417    const std::string& extension_id,
418    const std::string& event_name) {
419  content::RenderProcessHost* process =
420      content::RenderProcessHost::FromID(render_process_id_);
421  if (!process ||
422      !extensions::ExtensionSystem::Get(profile_)->event_router())
423    return;
424
425  extensions::ExtensionSystem::Get(profile_)->event_router()->
426      RemoveEventListener(event_name, process, extension_id);
427}
428
429void ChromeRenderMessageFilter::OnExtensionAddLazyListener(
430    const std::string& extension_id, const std::string& event_name) {
431  if (extensions::ExtensionSystem::Get(profile_)->event_router()) {
432    extensions::ExtensionSystem::Get(profile_)->event_router()->
433        AddLazyEventListener(event_name, extension_id);
434  }
435}
436
437void ChromeRenderMessageFilter::OnExtensionRemoveLazyListener(
438    const std::string& extension_id, const std::string& event_name) {
439  if (extensions::ExtensionSystem::Get(profile_)->event_router()) {
440    extensions::ExtensionSystem::Get(profile_)->event_router()->
441        RemoveLazyEventListener(event_name, extension_id);
442  }
443}
444
445void ChromeRenderMessageFilter::OnExtensionAddFilteredListener(
446    const std::string& extension_id,
447    const std::string& event_name,
448    const base::DictionaryValue& filter,
449    bool lazy) {
450  content::RenderProcessHost* process =
451      content::RenderProcessHost::FromID(render_process_id_);
452  if (!process ||
453      !extensions::ExtensionSystem::Get(profile_)->event_router())
454    return;
455
456  extensions::ExtensionSystem::Get(profile_)->event_router()->
457      AddFilteredEventListener(event_name, process, extension_id, filter, lazy);
458}
459
460void ChromeRenderMessageFilter::OnExtensionRemoveFilteredListener(
461    const std::string& extension_id,
462    const std::string& event_name,
463    const base::DictionaryValue& filter,
464    bool lazy) {
465  content::RenderProcessHost* process =
466      content::RenderProcessHost::FromID(render_process_id_);
467  if (!process ||
468      !extensions::ExtensionSystem::Get(profile_)->event_router())
469    return;
470
471  extensions::ExtensionSystem::Get(profile_)->event_router()->
472      RemoveFilteredEventListener(event_name, process, extension_id, filter,
473                                  lazy);
474}
475
476void ChromeRenderMessageFilter::OnExtensionCloseChannel(int port_id,
477                                                        bool connection_error) {
478  if (!content::RenderProcessHost::FromID(render_process_id_))
479    return;  // To guard against crash in browser_tests shutdown.
480
481  extensions::MessageService* message_service =
482      extensions::ExtensionSystem::Get(profile_)->message_service();
483  if (message_service)
484    message_service->CloseChannel(port_id, connection_error);
485}
486
487void ChromeRenderMessageFilter::OnExtensionRequestForIOThread(
488    int routing_id,
489    const ExtensionHostMsg_Request_Params& params) {
490  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
491
492  ExtensionFunctionDispatcher::DispatchOnIOThread(
493      extension_info_map_, profile_, render_process_id_,
494      weak_ptr_factory_.GetWeakPtr(), routing_id, params);
495}
496
497void ChromeRenderMessageFilter::OnExtensionShouldUnloadAck(
498     const std::string& extension_id, int sequence_id) {
499  if (extensions::ExtensionSystem::Get(profile_)->process_manager()) {
500    extensions::ExtensionSystem::Get(profile_)->process_manager()->
501        OnShouldUnloadAck(extension_id, sequence_id);
502  }
503}
504
505void ChromeRenderMessageFilter::OnExtensionUnloadAck(
506     const std::string& extension_id) {
507  if (extensions::ExtensionSystem::Get(profile_)->process_manager()) {
508    extensions::ExtensionSystem::Get(profile_)->process_manager()->
509        OnUnloadAck(extension_id);
510  }
511}
512
513void ChromeRenderMessageFilter::OnExtensionGenerateUniqueID(int* unique_id) {
514  static int next_unique_id = 1;
515  *unique_id = next_unique_id++;
516}
517
518void ChromeRenderMessageFilter::OnExtensionResumeRequests(int route_id) {
519  content::ResourceDispatcherHost::Get()->ResumeBlockedRequestsForRoute(
520      render_process_id_, route_id);
521}
522
523void ChromeRenderMessageFilter::OnAllowDatabase(int render_view_id,
524                                                const GURL& origin_url,
525                                                const GURL& top_origin_url,
526                                                const string16& name,
527                                                const string16& display_name,
528                                                bool* allowed) {
529  *allowed = cookie_settings_->IsSettingCookieAllowed(origin_url,
530                                                      top_origin_url);
531  BrowserThread::PostTask(
532      BrowserThread::UI, FROM_HERE,
533      base::Bind(
534          &TabSpecificContentSettings::WebDatabaseAccessed,
535          render_process_id_, render_view_id, origin_url, name, display_name,
536          !*allowed));
537}
538
539void ChromeRenderMessageFilter::OnAllowDOMStorage(int render_view_id,
540                                                  const GURL& origin_url,
541                                                  const GURL& top_origin_url,
542                                                  bool local,
543                                                  bool* allowed) {
544  *allowed = cookie_settings_->IsSettingCookieAllowed(origin_url,
545                                                      top_origin_url);
546  // Record access to DOM storage for potential display in UI.
547  BrowserThread::PostTask(
548      BrowserThread::UI, FROM_HERE,
549      base::Bind(
550          &TabSpecificContentSettings::DOMStorageAccessed,
551          render_process_id_, render_view_id, origin_url, local, !*allowed));
552}
553
554void ChromeRenderMessageFilter::OnAllowFileSystem(int render_view_id,
555                                                  const GURL& origin_url,
556                                                  const GURL& top_origin_url,
557                                                  bool* allowed) {
558  *allowed = cookie_settings_->IsSettingCookieAllowed(origin_url,
559                                                      top_origin_url);
560  // Record access to file system for potential display in UI.
561  BrowserThread::PostTask(
562      BrowserThread::UI, FROM_HERE,
563      base::Bind(
564          &TabSpecificContentSettings::FileSystemAccessed,
565          render_process_id_, render_view_id, origin_url, !*allowed));
566}
567
568void ChromeRenderMessageFilter::OnAllowIndexedDB(int render_view_id,
569                                                 const GURL& origin_url,
570                                                 const GURL& top_origin_url,
571                                                 const string16& name,
572                                                 bool* allowed) {
573  *allowed = cookie_settings_->IsSettingCookieAllowed(origin_url,
574                                                      top_origin_url);
575  BrowserThread::PostTask(
576      BrowserThread::UI, FROM_HERE,
577      base::Bind(
578          &TabSpecificContentSettings::IndexedDBAccessed,
579          render_process_id_, render_view_id, origin_url, name, !*allowed));
580}
581
582void ChromeRenderMessageFilter::OnCanTriggerClipboardRead(
583    const GURL& origin, bool* allowed) {
584  *allowed = extension_info_map_->SecurityOriginHasAPIPermission(
585      origin, render_process_id_, APIPermission::kClipboardRead);
586}
587
588void ChromeRenderMessageFilter::OnCanTriggerClipboardWrite(
589    const GURL& origin, bool* allowed) {
590  // Since all extensions could historically write to the clipboard, preserve it
591  // for compatibility.
592  *allowed = (origin.SchemeIs(chrome::kExtensionScheme) ||
593      extension_info_map_->SecurityOriginHasAPIPermission(
594          origin, render_process_id_, APIPermission::kClipboardWrite));
595}
596
597void ChromeRenderMessageFilter::OnGetCookies(
598    const GURL& url,
599    const GURL& first_party_for_cookies,
600    IPC::Message* reply_msg) {
601#if defined(ENABLE_AUTOMATION)
602  AutomationResourceMessageFilter::GetCookiesForUrl(
603      this, request_context_->GetURLRequestContext(), render_process_id_,
604      reply_msg, url);
605#endif
606}
607
608void ChromeRenderMessageFilter::OnSetCookie(const IPC::Message& message,
609                                            const GURL& url,
610                                            const GURL& first_party_for_cookies,
611                                            const std::string& cookie) {
612#if defined(ENABLE_AUTOMATION)
613  AutomationResourceMessageFilter::SetCookiesForUrl(
614      render_process_id_, message.routing_id(), url, cookie);
615#endif
616}
617