chrome_render_message_filter.cc revision cedac228d2dd51db4b79ea1e72c7f249408ee061
14ee2ad04344446e610172a0e73949212923014dfSebastian Redl// Copyright (c) 2012 The Chromium Authors. All rights reserved.
22cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor// Use of this source code is governed by a BSD-style license that can be
32cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor// found in the LICENSE file.
42cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
52cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
62cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
72cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include <string>
82cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
92cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "base/bind.h"
10a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl#include "base/bind_helpers.h"
112cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "base/metrics/histogram.h"
122cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "chrome/browser/chrome_notification_types.h"
132cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "chrome/browser/content_settings/cookie_settings.h"
147faa2ec03a7ef120ac165bb45b6c70a8b20c9f1cSebastian Redl#include "chrome/browser/content_settings/tab_specific_content_settings.h"
1589d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor#include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
160eca89e9890db4d8336ce762a5b359a1d58ca02bArgyrios Kyrtzidis#include "chrome/browser/net/chrome_url_request_context.h"
17e737f5041a36d0befb39ffeed8d50ba15916d3daDouglas Gregor#include "chrome/browser/net/predictor.h"
18e737f5041a36d0befb39ffeed8d50ba15916d3daDouglas Gregor#include "chrome/browser/profiles/profile_manager.h"
192cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "chrome/browser/renderer_host/web_cache_manager.h"
202cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "chrome/common/extensions/api/i18n/default_locale_handler.h"
212cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "chrome/common/render_messages.h"
222a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall#include "content/public/browser/notification_service.h"
2389eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis#include "content/public/browser/render_process_host.h"
240b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
257a1fad38256eb4c5129359be85ba1ea1678eb5c9John McCall#if defined(ENABLE_EXTENSIONS)
262cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "base/strings/utf_string_conversions.h"
27a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall#include "chrome/browser/browser_process.h"
286ab7cd853e9c15cf986a8a7c3db1f8d20e275409Sebastian Redl#include "chrome/browser/extensions/activity_log/activity_action_constants.h"
297c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner#include "chrome/browser/extensions/activity_log/activity_actions.h"
306a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor#include "chrome/browser/extensions/activity_log/activity_log.h"
317c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner#include "chrome/browser/extensions/api/activity_log_private/activity_log_private_api.h"
3283d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff#include "chrome/browser/extensions/api/messaging/message_service.h"
3314f79002e58556798e86168c63e48d533287eda5Douglas Gregor#include "extensions/browser/extension_system.h"
3410e286aa8d39fb51a21412850265d9dae74613eeChris Lattner#include "extensions/common/constants.h"
353251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor#include "extensions/common/extension_messages.h"
3614f79002e58556798e86168c63e48d533287eda5Douglas Gregor#include "extensions/common/file_util.h"
37bd94500d3aa60092fb0f1e90f53fb0d03fa502a8Douglas Gregor#include "extensions/common/message_bundle.h"
382bec0410d268779f601bd509e0302a500af7ac6aDouglas Gregor#endif
39ab41e63821dc60ad144d0684df8d79a9eef86b75Douglas Gregor
400a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor#if defined(ENABLE_TASK_MANAGER)
4117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor#include "chrome/browser/task_manager/task_manager.h"
4217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor#endif
432596e429a61602312bdd149786045b8a90cd2d10Daniel Dunbar
442cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#if defined(USE_TCMALLOC)
45fbfd180495e7800975c6d9bdc6d24e706ef70e34Michael J. Spencer#include "chrome/browser/browser_about_handler.h"
4614f79002e58556798e86168c63e48d533287eda5Douglas Gregor#endif
4703013fa9a0bf1ef4b907f5fec006c8f4000fdd21Michael J. Spencer
48f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregorusing content::BrowserThread;
493c304bd9ec2b4611572d4cbae9e1727bbecb5dc9Chris Lattnerusing extensions::APIPermission;
50cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregorusing blink::WebCache;
51f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor
522cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregornamespace {
538538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl
542cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorconst uint32 kFilteredMessageClasses[] = {
55ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl  ChromeMsgStart,
565f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner#if defined(ENABLE_EXTENSIONS)
575f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner  ExtensionMsgStart,
585f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner#endif
596e089c687cc2b914c46859ab7e46fe4c3c6b0afbBenjamin Kramer};
60ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl
616e089c687cc2b914c46859ab7e46fe4c3c6b0afbBenjamin Kramer#if defined(ENABLE_EXTENSIONS)
626e089c687cc2b914c46859ab7e46fe4c3c6b0afbBenjamin Kramer// Logs an action to the extension activity log for the specified profile.  Can
635f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner// be called from any thread.
645f9e272e632e951b1efe824cd16acb4d96077930Chris Lattnervoid AddActionToExtensionActivityLog(
656e089c687cc2b914c46859ab7e46fe4c3c6b0afbBenjamin Kramer    Profile* profile,
66ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl    scoped_refptr<extensions::Action> action) {
67ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl  // The ActivityLog can only be accessed from the main (UI) thread.  If we're
682cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  // running on the wrong thread, re-dispatch from the main thread.
692cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
702cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    BrowserThread::PostTask(
7112b1c7615d4f9a2edc544be499f895f16ac100edChris Lattner        BrowserThread::UI, FROM_HERE,
722cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor        base::Bind(&AddActionToExtensionActivityLog, profile, action));
733397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  } else {
74a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl    if (!g_browser_process->profile_manager()->IsValidProfile(profile))
7589eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis      return;
762cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    // If the action included a URL, check whether it is for an incognito
772cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    // profile.  The check is performed here so that it can safely be done from
782cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    // the UI thread.
798538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl    if (action->page_url().is_valid() || !action->page_title().empty())
802cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor      action->set_page_incognito(profile->IsOffTheRecord());
8189eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis    extensions::ActivityLog* activity_log =
828538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl        extensions::ActivityLog::GetInstance(profile);
832cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    activity_log->LogAction(action);
842cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  }
852cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
862cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#endif
872cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
882cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}  // namespace
892cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
902cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas GregorChromeRenderMessageFilter::ChromeRenderMessageFilter(
912cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    int render_process_id,
922cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    Profile* profile,
932cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    net::URLRequestContextGetter* request_context)
943397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl    : BrowserMessageFilter(kFilteredMessageClasses,
952cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor                           arraysize(kFilteredMessageClasses)),
962cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor      render_process_id_(render_process_id),
972cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor      profile_(profile),
983397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl      off_the_record_(profile_->IsOffTheRecord()),
992cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor      predictor_(profile_->GetNetworkPredictor()),
1008538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl      request_context_(request_context),
1012cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#if defined(ENABLE_EXTENSIONS)
1022cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor      extension_info_map_(
1033397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl          extensions::ExtensionSystem::Get(profile)->info_map()),
1042cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#endif
1058538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl      cookie_settings_(CookieSettings::Factory::GetForProfile(profile)) {}
1062cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1072cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas GregorChromeRenderMessageFilter::~ChromeRenderMessageFilter() {
1083397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl}
1091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1108538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redlbool ChromeRenderMessageFilter::OnMessageReceived(const IPC::Message& message) {
1112cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  bool handled = true;
1122cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  IPC_BEGIN_MESSAGE_MAP(ChromeRenderMessageFilter, message)
1133397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl    IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DnsPrefetch, OnDnsPrefetch)
114df1550fc59b51681d37225934fe4e3acac321621Richard Smith    IPC_MESSAGE_HANDLER(ChromeViewHostMsg_Preconnect, OnPreconnect)
115df1550fc59b51681d37225934fe4e3acac321621Richard Smith    IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ResourceTypeStats,
1168538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl                        OnResourceTypeStats)
1172cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    IPC_MESSAGE_HANDLER(ChromeViewHostMsg_UpdatedCacheStats,
1182cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor                        OnUpdatedCacheStats)
1193397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl    IPC_MESSAGE_HANDLER(ChromeViewHostMsg_FPS, OnFPS)
120df1550fc59b51681d37225934fe4e3acac321621Richard Smith    IPC_MESSAGE_HANDLER(ChromeViewHostMsg_V8HeapStats, OnV8HeapStats)
1218538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl#if defined(ENABLE_EXTENSIONS)
1222cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenChannelToExtension,
1232cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor                        OnOpenChannelToExtension)
1243397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl    IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenChannelToTab, OnOpenChannelToTab)
1251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenChannelToNativeApp,
1261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                        OnOpenChannelToNativeApp)
1278538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl    IPC_MESSAGE_HANDLER_DELAY_REPLY(ExtensionHostMsg_GetMessageBundle,
1282cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor                                    OnGetExtensionMessageBundle)
1292cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    IPC_MESSAGE_HANDLER(ExtensionHostMsg_CloseChannel, OnExtensionCloseChannel)
1303397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl    IPC_MESSAGE_HANDLER(ExtensionHostMsg_AddAPIActionToActivityLog,
1312cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor                        OnAddAPIActionToExtensionActivityLog);
1322cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    IPC_MESSAGE_HANDLER(ExtensionHostMsg_AddDOMActionToActivityLog,
1330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall                        OnAddDOMActionToExtensionActivityLog);
1342cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    IPC_MESSAGE_HANDLER(ExtensionHostMsg_AddEventToActivityLog,
1352cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor                        OnAddEventToExtensionActivityLog);
1363397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl#endif
1372cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    IPC_MESSAGE_HANDLER(ChromeViewHostMsg_AllowDatabase, OnAllowDatabase)
1382cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    IPC_MESSAGE_HANDLER(ChromeViewHostMsg_AllowDOMStorage, OnAllowDOMStorage)
1398538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl    IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RequestFileSystemAccessSync,
1402cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor                        OnRequestFileSystemAccessSync)
1412cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RequestFileSystemAccessAsync,
1423397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl                        OnRequestFileSystemAccessAsync)
1432cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    IPC_MESSAGE_HANDLER(ChromeViewHostMsg_AllowIndexedDB, OnAllowIndexedDB)
1448538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl#if defined(ENABLE_EXTENSIONS)
1452cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    IPC_MESSAGE_HANDLER(ChromeViewHostMsg_CanTriggerClipboardRead,
1462cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor                        OnCanTriggerClipboardRead)
1473397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl    IPC_MESSAGE_HANDLER(ChromeViewHostMsg_CanTriggerClipboardWrite,
1482cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor                        OnCanTriggerClipboardWrite)
1497e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor#endif
1507e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor#if defined(ENABLE_PLUGINS)
151c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor    IPC_MESSAGE_HANDLER(ChromeViewHostMsg_IsCrashReportingEnabled,
1528538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl                        OnIsCrashReportingEnabled)
1532cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#endif
1542cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    IPC_MESSAGE_UNHANDLED(handled = false)
1553397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  IPC_END_MESSAGE_MAP()
1562cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1572cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  return handled;
158e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson}
1598538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl
1602cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorvoid ChromeRenderMessageFilter::OverrideThreadForMessage(
1612cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    const IPC::Message& message, BrowserThread::ID* thread) {
1623397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  switch (message.type()) {
1632cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    case ChromeViewHostMsg_ResourceTypeStats::ID:
1648538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl#if defined(ENABLE_EXTENSIONS)
1652cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    case ExtensionHostMsg_CloseChannel::ID:
1662cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#endif
1673397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl    case ChromeViewHostMsg_UpdatedCacheStats::ID:
1682cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor      *thread = BrowserThread::UI;
169264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola      break;
170264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    default:
171a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman      break;
172425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  }
173ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor}
174264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
175f85e193739c953358c865005855253af4f68a497John McCallnet::HostResolver* ChromeRenderMessageFilter::GetHostResolver() {
1762cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  return request_context_->GetURLRequestContext()->host_resolver();
1772cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
1783397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl
1792cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorvoid ChromeRenderMessageFilter::OnDnsPrefetch(
1808538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl    const std::vector<std::string>& hostnames) {
1812cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  if (predictor_)
1822cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    predictor_->DnsPrefetchList(hostnames);
1833397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl}
1842cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1852cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorvoid ChromeRenderMessageFilter::OnPreconnect(const GURL& url) {
1862cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  if (predictor_)
1872cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    predictor_->PreconnectUrl(
1882cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor        url, GURL(), chrome_browser_net::UrlInfo::MOUSE_OVER_MOTIVATED, 1);
1892cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
190c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor
19160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redlvoid ChromeRenderMessageFilter::OnResourceTypeStats(
19260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    const WebCache::ResourceTypeStats& stats) {
19360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  HISTOGRAM_COUNTS("WebCoreCache.ImagesSizeKB",
19460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl                   static_cast<int>(stats.images.size / 1024));
19560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  HISTOGRAM_COUNTS("WebCoreCache.CSSStylesheetsSizeKB",
19660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl                   static_cast<int>(stats.cssStyleSheets.size / 1024));
19760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  HISTOGRAM_COUNTS("WebCoreCache.ScriptsSizeKB",
19860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl                   static_cast<int>(stats.scripts.size / 1024));
1998538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  HISTOGRAM_COUNTS("WebCoreCache.XSLStylesheetsSizeKB",
2002cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor                   static_cast<int>(stats.xslStyleSheets.size / 1024));
2012cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  HISTOGRAM_COUNTS("WebCoreCache.FontsSizeKB",
2023397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl                   static_cast<int>(stats.fonts.size / 1024));
203ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2048538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
205ed97649e9574b9d854fa4d6109c9333ae0993554John McCall#if defined(ENABLE_TASK_MANAGER)
206ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  TaskManager::GetInstance()->model()->NotifyResourceTypeStats(peer_pid(),
2073397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl                                                               stats);
2082cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#endif  // defined(ENABLE_TASK_MANAGER)
2099763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis}
2109763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis
2118538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redlvoid ChromeRenderMessageFilter::OnUpdatedCacheStats(
2122cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    const WebCache::UsageStats& stats) {
2132cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  WebCacheManager::GetInstance()->ObserveStats(render_process_id_, stats);
2143397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl}
215c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor
2168538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redlvoid ChromeRenderMessageFilter::OnFPS(int routing_id, float fps) {
2172cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
2182cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    BrowserThread::PostTask(
2193397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl        BrowserThread::UI, FROM_HERE,
2202cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor        base::Bind(
2218538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl            &ChromeRenderMessageFilter::OnFPS, this,
2222cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor            routing_id, fps));
2232cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    return;
2243397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  }
225395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson
2268538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl#if defined(ENABLE_TASK_MANAGER)
227395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  TaskManager::GetInstance()->model()->NotifyFPS(
228395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson      peer_pid(), routing_id, fps);
229ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt#endif  // defined(ENABLE_TASK_MANAGER)
230ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt}
231ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
232ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntvoid ChromeRenderMessageFilter::OnV8HeapStats(int v8_memory_allocated,
233ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                              int v8_memory_used) {
234ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
235ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    BrowserThread::PostTask(
23634b41d939a1328f484511c6002ba2456db879a29Richard Smith        BrowserThread::UI, FROM_HERE,
23734b41d939a1328f484511c6002ba2456db879a29Richard Smith        base::Bind(&ChromeRenderMessageFilter::OnV8HeapStats, this,
23834b41d939a1328f484511c6002ba2456db879a29Richard Smith                   v8_memory_allocated, v8_memory_used));
23934b41d939a1328f484511c6002ba2456db879a29Richard Smith    return;
24034b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
2413397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl
242be191100e034b23a3e13053757a57b7f5068c24aArgyrios Kyrtzidis  base::ProcessId renderer_id = peer_pid();
2432cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
2441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump#if defined(ENABLE_TASK_MANAGER)
2452cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  TaskManager::GetInstance()->model()->NotifyV8HeapStats(
2462cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor      renderer_id,
2472cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor      static_cast<size_t>(v8_memory_allocated),
2483397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl      static_cast<size_t>(v8_memory_used));
2492cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#endif  // defined(ENABLE_TASK_MANAGER)
2508538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl
2512cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  V8HeapStatsDetails details(v8_memory_allocated, v8_memory_used);
2522cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  content::NotificationService::current()->Notify(
2533397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl      chrome::NOTIFICATION_RENDERER_V8_HEAP_STATS_COMPUTED,
2542cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor      content::Source<const base::ProcessId>(&renderer_id),
2558538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl      content::Details<const V8HeapStatsDetails>(&details));
2562cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
2572cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
2589d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall#if defined(ENABLE_EXTENSIONS)
2599d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallvoid ChromeRenderMessageFilter::OnOpenChannelToExtension(
2609d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    int routing_id,
2619d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    const ExtensionMsg_ExternalConnectionInfo& info,
2629d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    const std::string& channel_name,
2639d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    bool include_tls_channel_id,
2649d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    int* port_id) {
2651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  int port2_id;
2663397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  extensions::MessageService::AllocatePortIdPair(port_id, &port2_id);
26749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
26849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  BrowserThread::PostTask(
26949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall      BrowserThread::UI, FROM_HERE,
2708538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl      base::Bind(&ChromeRenderMessageFilter::OpenChannelToExtensionOnUIThread,
27149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall                 this, render_process_id_, routing_id, port2_id, info,
27249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall                 channel_name, include_tls_channel_id));
27349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall}
274c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
275c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorvoid ChromeRenderMessageFilter::OpenChannelToExtensionOnUIThread(
276c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor    int source_process_id, int source_routing_id,
277c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor    int receiver_port_id,
278c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor    const ExtensionMsg_ExternalConnectionInfo& info,
279c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor    const std::string& channel_name,
280c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor    bool include_tls_channel_id) {
281c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2823397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  extensions::MessageService::Get(profile_)->OpenChannelToExtension(
2832cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor      source_process_id, source_routing_id, receiver_port_id,
284be191100e034b23a3e13053757a57b7f5068c24aArgyrios Kyrtzidis      info.source_id, info.target_id, info.source_url, channel_name,
28590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis      include_tls_channel_id);
28690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis}
28790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis
28890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidisvoid ChromeRenderMessageFilter::OnOpenChannelToNativeApp(
28990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis    int routing_id,
2903e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    const std::string& source_extension_id,
2913e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    const std::string& native_app_name,
2929763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis    int* port_id) {
2939763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis  int port2_id;
2948538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  extensions::MessageService::AllocatePortIdPair(port_id, &port2_id);
29590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis
29690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis  BrowserThread::PostTask(
29790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis      BrowserThread::UI, FROM_HERE,
2983397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl      base::Bind(&ChromeRenderMessageFilter::OpenChannelToNativeAppOnUIThread,
299ae8b17f1d5d303af53db5a4f4a375ea6b9356566Argyrios Kyrtzidis                 this, routing_id, port2_id, source_extension_id,
300ae8b17f1d5d303af53db5a4f4a375ea6b9356566Argyrios Kyrtzidis                 native_app_name));
301ae8b17f1d5d303af53db5a4f4a375ea6b9356566Argyrios Kyrtzidis}
3028538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl
30390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidisvoid ChromeRenderMessageFilter::OpenChannelToNativeAppOnUIThread(
30490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis    int source_routing_id,
30590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis    int receiver_port_id,
3063397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl    const std::string& source_extension_id,
30790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis    const std::string& native_app_name) {
30890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
30990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis  extensions::MessageService::Get(profile_)->OpenChannelToNativeApp(
31090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis      render_process_id_, source_routing_id, receiver_port_id,
31190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis      source_extension_id, native_app_name);
31290b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis}
3133397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl
31490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidisvoid ChromeRenderMessageFilter::OnOpenChannelToTab(
31590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis    int routing_id, int tab_id, const std::string& extension_id,
31690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis    const std::string& channel_name, int* port_id) {
3174fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  int port2_id;
3188538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  extensions::MessageService::AllocatePortIdPair(port_id, &port2_id);
31990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis
32090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis  BrowserThread::PostTask(
32190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis      BrowserThread::UI, FROM_HERE,
3223397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl      base::Bind(&ChromeRenderMessageFilter::OpenChannelToTabOnUIThread, this,
3238dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis                 render_process_id_, routing_id, port2_id, tab_id, extension_id,
3248dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis                 channel_name));
3258dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis}
326f48d45e3e36c132bdee3373beec4e8b19ae3f9c4Argyrios Kyrtzidis
327f48d45e3e36c132bdee3373beec4e8b19ae3f9c4Argyrios Kyrtzidisvoid ChromeRenderMessageFilter::OpenChannelToTabOnUIThread(
328f48d45e3e36c132bdee3373beec4e8b19ae3f9c4Argyrios Kyrtzidis    int source_process_id, int source_routing_id,
3298538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl    int receiver_port_id,
33090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis    int tab_id,
33190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis    const std::string& extension_id,
33290b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis    const std::string& channel_name) {
3333397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
33490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis  extensions::MessageService::Get(profile_)->OpenChannelToTab(
3353acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis      source_process_id, source_routing_id, receiver_port_id,
3363acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis      tab_id, extension_id, channel_name);
3373acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis}
3383acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis
3393acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidisvoid ChromeRenderMessageFilter::OnGetExtensionMessageBundle(
3403acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis    const std::string& extension_id, IPC::Message* reply_msg) {
3413acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis  const extensions::Extension* extension =
3428538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl      extension_info_map_->extensions().GetByID(extension_id);
3432cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  base::FilePath extension_path;
3442cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  std::string default_locale;
3457536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  if (extension) {
3467536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    extension_path = extension->path();
347cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    default_locale = extensions::LocaleInfo::GetDefaultLocale(extension);
348cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  }
349cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor
350cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  BrowserThread::PostTask(
3517536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor      BrowserThread::FILE, FROM_HERE,
3527536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor      base::Bind(
3537536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor          &ChromeRenderMessageFilter::OnGetExtensionMessageBundleOnFileThread,
354075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara          this, extension_path, extension_id, default_locale, reply_msg));
355075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara}
356075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
357075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaravoid ChromeRenderMessageFilter::OnGetExtensionMessageBundleOnFileThread(
358075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    const base::FilePath& extension_path,
3593397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl    const std::string& extension_id,
360465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    const std::string& default_locale,
3613acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis    IPC::Message* reply_msg) {
3623acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
3638538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl
3642cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  scoped_ptr<extensions::MessageBundle::SubstitutionMap> dictionary_map(
3652cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor      extensions::file_util::LoadMessageBundleSubstitutionMap(
3663397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl          extension_path, extension_id, default_locale));
3673cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
36831f17ecbef57b5679c017c375db330546b7b5145John McCall  ExtensionHostMsg_GetMessageBundle::WriteReplyParams(reply_msg,
3698538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl                                                      *dictionary_map);
3703cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  Send(reply_msg);
3713cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall}
3723397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl
373deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregorvoid ChromeRenderMessageFilter::OnExtensionCloseChannel(
3748538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl    int port_id,
375c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    const std::string& error_message) {
376c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  if (!content::RenderProcessHost::FromID(render_process_id_))
3773397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl    return;  // To guard against crash in browser_tests shutdown.
378c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3792cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  extensions::MessageService* message_service =
380c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      extensions::MessageService::Get(profile_);
381446ee4eb4fc4c705a59365252df7a5c253daafa1Steve Naroff  if (message_service)
382446ee4eb4fc4c705a59365252df7a5c253daafa1Steve Naroff    message_service->CloseChannel(port_id, error_message);
3838538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl}
3842cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
3852cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorvoid ChromeRenderMessageFilter::OnAddAPIActionToExtensionActivityLog(
386d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff    const std::string& extension_id,
3873397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl    const ExtensionHostMsg_APIActionOrEvent_Params& params) {
3881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  scoped_refptr<extensions::Action> action = new extensions::Action(
3898538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl      extension_id, base::Time::Now(), extensions::Action::ACTION_API_CALL,
3902cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor      params.api_call);
3912cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  action->set_args(make_scoped_ptr(params.arguments.DeepCopy()));
392a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall  if (!params.extra.empty()) {
393a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall    action->mutable_other()->SetString(
394a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall        activity_log_constants::kActionExtra, params.extra);
395a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl  }
39689eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis  AddActionToExtensionActivityLog(profile_, action);
397a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall}
398a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall
39989eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ChromeRenderMessageFilter::OnAddDOMActionToExtensionActivityLog(
400a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall    const std::string& extension_id,
401a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall    const ExtensionHostMsg_DOMAction_Params& params) {
40251bd803fbdade51d674598ed45da3d54190a656cJohn McCall  scoped_refptr<extensions::Action> action = new extensions::Action(
403a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall      extension_id, base::Time::Now(), extensions::Action::ACTION_DOM_ACCESS,
40451bd803fbdade51d674598ed45da3d54190a656cJohn McCall      params.api_call);
405a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall  action->set_args(make_scoped_ptr(params.arguments.DeepCopy()));
406a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall  action->set_page_url(params.url);
40751bd803fbdade51d674598ed45da3d54190a656cJohn McCall  action->set_page_title(base::UTF16ToUTF8(params.url_title));
40851bd803fbdade51d674598ed45da3d54190a656cJohn McCall  action->mutable_other()->SetInteger(activity_log_constants::kActionDomVerb,
409a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall                                      params.call_type);
410a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall  AddActionToExtensionActivityLog(profile_, action);
411a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall}
412a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall
41351bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid ChromeRenderMessageFilter::OnAddEventToExtensionActivityLog(
41451bd803fbdade51d674598ed45da3d54190a656cJohn McCall    const std::string& extension_id,
41551bd803fbdade51d674598ed45da3d54190a656cJohn McCall    const ExtensionHostMsg_APIActionOrEvent_Params& params) {
41651bd803fbdade51d674598ed45da3d54190a656cJohn McCall  scoped_refptr<extensions::Action> action = new extensions::Action(
417ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      extension_id, base::Time::Now(), extensions::Action::ACTION_API_EVENT,
418ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      params.api_call);
419ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  action->set_args(make_scoped_ptr(params.arguments.DeepCopy()));
420ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  if (!params.extra.empty()) {
421ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    action->mutable_other()->SetString(activity_log_constants::kActionExtra,
422ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor                                       params.extra);
423ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
42451bd803fbdade51d674598ed45da3d54190a656cJohn McCall  AddActionToExtensionActivityLog(profile_, action);
42551bd803fbdade51d674598ed45da3d54190a656cJohn McCall}
42651bd803fbdade51d674598ed45da3d54190a656cJohn McCall#endif  // defined(ENABLE_EXTENSIONS)
42751bd803fbdade51d674598ed45da3d54190a656cJohn McCall
42851bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid ChromeRenderMessageFilter::OnAllowDatabase(
42951bd803fbdade51d674598ed45da3d54190a656cJohn McCall    int render_frame_id,
43051bd803fbdade51d674598ed45da3d54190a656cJohn McCall    const GURL& origin_url,
43151bd803fbdade51d674598ed45da3d54190a656cJohn McCall    const GURL& top_origin_url,
43251bd803fbdade51d674598ed45da3d54190a656cJohn McCall    const base::string16& name,
43351bd803fbdade51d674598ed45da3d54190a656cJohn McCall    const base::string16& display_name,
43451bd803fbdade51d674598ed45da3d54190a656cJohn McCall    bool* allowed) {
43551bd803fbdade51d674598ed45da3d54190a656cJohn McCall  *allowed =
43651bd803fbdade51d674598ed45da3d54190a656cJohn McCall      cookie_settings_->IsSettingCookieAllowed(origin_url, top_origin_url);
43751bd803fbdade51d674598ed45da3d54190a656cJohn McCall  BrowserThread::PostTask(
43851bd803fbdade51d674598ed45da3d54190a656cJohn McCall      BrowserThread::UI, FROM_HERE,
43951bd803fbdade51d674598ed45da3d54190a656cJohn McCall      base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
44051bd803fbdade51d674598ed45da3d54190a656cJohn McCall                 render_process_id_, render_frame_id, origin_url, name,
44151bd803fbdade51d674598ed45da3d54190a656cJohn McCall                 display_name, !*allowed));
442b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara}
44351bd803fbdade51d674598ed45da3d54190a656cJohn McCall
44451bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid ChromeRenderMessageFilter::OnAllowDOMStorage(int render_frame_id,
44551bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                                  const GURL& origin_url,
44651bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                                  const GURL& top_origin_url,
44751bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                                  bool local,
44851bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                                  bool* allowed) {
44951bd803fbdade51d674598ed45da3d54190a656cJohn McCall  *allowed =
45051bd803fbdade51d674598ed45da3d54190a656cJohn McCall      cookie_settings_->IsSettingCookieAllowed(origin_url, top_origin_url);
45151bd803fbdade51d674598ed45da3d54190a656cJohn McCall  // Record access to DOM storage for potential display in UI.
45251bd803fbdade51d674598ed45da3d54190a656cJohn McCall  BrowserThread::PostTask(
45351bd803fbdade51d674598ed45da3d54190a656cJohn McCall      BrowserThread::UI, FROM_HERE,
45451bd803fbdade51d674598ed45da3d54190a656cJohn McCall      base::Bind(&TabSpecificContentSettings::DOMStorageAccessed,
45551bd803fbdade51d674598ed45da3d54190a656cJohn McCall                 render_process_id_, render_frame_id, origin_url, local,
45651bd803fbdade51d674598ed45da3d54190a656cJohn McCall                 !*allowed));
45751bd803fbdade51d674598ed45da3d54190a656cJohn McCall}
45851bd803fbdade51d674598ed45da3d54190a656cJohn McCall
45951bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid ChromeRenderMessageFilter::OnRequestFileSystemAccessSync(
46051bd803fbdade51d674598ed45da3d54190a656cJohn McCall    int render_frame_id,
46151bd803fbdade51d674598ed45da3d54190a656cJohn McCall    const GURL& origin_url,
46251bd803fbdade51d674598ed45da3d54190a656cJohn McCall    const GURL& top_origin_url,
46351bd803fbdade51d674598ed45da3d54190a656cJohn McCall    bool* allowed) {
46451bd803fbdade51d674598ed45da3d54190a656cJohn McCall  *allowed =
46551bd803fbdade51d674598ed45da3d54190a656cJohn McCall      cookie_settings_->IsSettingCookieAllowed(origin_url, top_origin_url);
46651bd803fbdade51d674598ed45da3d54190a656cJohn McCall  // Record access to file system for potential display in UI.
46751bd803fbdade51d674598ed45da3d54190a656cJohn McCall  BrowserThread::PostTask(
46851bd803fbdade51d674598ed45da3d54190a656cJohn McCall      BrowserThread::UI, FROM_HERE,
46951bd803fbdade51d674598ed45da3d54190a656cJohn McCall      base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
47051bd803fbdade51d674598ed45da3d54190a656cJohn McCall                 render_process_id_, render_frame_id, origin_url, !*allowed));
47151bd803fbdade51d674598ed45da3d54190a656cJohn McCall}
47251bd803fbdade51d674598ed45da3d54190a656cJohn McCall
47351bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid ChromeRenderMessageFilter::OnRequestFileSystemAccessAsync(
47451bd803fbdade51d674598ed45da3d54190a656cJohn McCall    int render_frame_id,
475796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara    int request_id,
476796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara    const GURL& origin_url,
477dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    const GURL& top_origin_url) {
47851bd803fbdade51d674598ed45da3d54190a656cJohn McCall  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
47951bd803fbdade51d674598ed45da3d54190a656cJohn McCall
48051bd803fbdade51d674598ed45da3d54190a656cJohn McCall  bool allowed =
48151bd803fbdade51d674598ed45da3d54190a656cJohn McCall      cookie_settings_->IsSettingCookieAllowed(origin_url, top_origin_url);
48251bd803fbdade51d674598ed45da3d54190a656cJohn McCall  // Record access to file system for potential display in UI.
48351bd803fbdade51d674598ed45da3d54190a656cJohn McCall  BrowserThread::PostTask(
48451bd803fbdade51d674598ed45da3d54190a656cJohn McCall      BrowserThread::UI, FROM_HERE,
48551bd803fbdade51d674598ed45da3d54190a656cJohn McCall      base::Bind(
48651bd803fbdade51d674598ed45da3d54190a656cJohn McCall          &TabSpecificContentSettings::FileSystemAccessed,
487ed97649e9574b9d854fa4d6109c9333ae0993554John McCall          render_process_id_,
488ed97649e9574b9d854fa4d6109c9333ae0993554John McCall          render_frame_id,
489ed97649e9574b9d854fa4d6109c9333ae0993554John McCall          origin_url,
49051bd803fbdade51d674598ed45da3d54190a656cJohn McCall          !allowed));
49151bd803fbdade51d674598ed45da3d54190a656cJohn McCall
49251bd803fbdade51d674598ed45da3d54190a656cJohn McCall  Send(new ChromeViewMsg_RequestFileSystemAccessAsyncResponse(
49351bd803fbdade51d674598ed45da3d54190a656cJohn McCall      render_frame_id,
494cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall      request_id,
495cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall      allowed));
496cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall}
49751bd803fbdade51d674598ed45da3d54190a656cJohn McCall
49851bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid ChromeRenderMessageFilter::OnAllowIndexedDB(int render_frame_id,
499cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall                                                 const GURL& origin_url,
500cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall                                                 const GURL& top_origin_url,
501cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall                                                 const base::string16& name,
502cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall                                                 bool* allowed) {
50351bd803fbdade51d674598ed45da3d54190a656cJohn McCall  *allowed =
50451bd803fbdade51d674598ed45da3d54190a656cJohn McCall      cookie_settings_->IsSettingCookieAllowed(origin_url, top_origin_url);
50551bd803fbdade51d674598ed45da3d54190a656cJohn McCall  BrowserThread::PostTask(
506a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall      BrowserThread::UI, FROM_HERE,
507ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt      base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
508ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                 render_process_id_, render_frame_id, origin_url, name,
509ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                 !*allowed));
510ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt}
511ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
512ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt#if defined(ENABLE_EXTENSIONS)
51334b41d939a1328f484511c6002ba2456db879a29Richard Smithvoid ChromeRenderMessageFilter::OnCanTriggerClipboardRead(
51434b41d939a1328f484511c6002ba2456db879a29Richard Smith    const GURL& origin, bool* allowed) {
51534b41d939a1328f484511c6002ba2456db879a29Richard Smith  *allowed = extension_info_map_->SecurityOriginHasAPIPermission(
51651bd803fbdade51d674598ed45da3d54190a656cJohn McCall      origin, render_process_id_, APIPermission::kClipboardRead);
51751bd803fbdade51d674598ed45da3d54190a656cJohn McCall}
518a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall
51951bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid ChromeRenderMessageFilter::OnCanTriggerClipboardWrite(
52051bd803fbdade51d674598ed45da3d54190a656cJohn McCall    const GURL& origin, bool* allowed) {
521a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall  // Since all extensions could historically write to the clipboard, preserve it
5229d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  // for compatibility.
5239d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  *allowed = (origin.SchemeIs(extensions::kExtensionScheme) ||
5249d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      extension_info_map_->SecurityOriginHasAPIPermission(
5259d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall          origin, render_process_id_, APIPermission::kClipboardWrite));
5269d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall}
5279d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall#endif
5289d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
5299d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall#if defined(ENABLE_PLUGINS)
5309d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallvoid ChromeRenderMessageFilter::OnIsCrashReportingEnabled(bool* enabled) {
5319d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  *enabled = ChromeMetricsServiceAccessor::IsCrashReportingEnabled();
5329d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall}
5339d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall#endif
5349d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall