diff options
-rw-r--r-- | chrome/browser/browser_process.h | 10 | ||||
-rw-r--r-- | chrome/browser/browser_process_impl.cc | 43 | ||||
-rw-r--r-- | chrome/browser/browser_process_impl.h | 9 | ||||
-rw-r--r-- | chrome/browser/renderer_host/browser_render_process_host.cc | 39 | ||||
-rw-r--r-- | chrome/browser/renderer_host/browser_render_process_host.h | 13 | ||||
-rw-r--r-- | chrome/common/chrome_constants.cc | 2 | ||||
-rw-r--r-- | chrome/common/chrome_constants.h | 1 | ||||
-rw-r--r-- | chrome/common/chrome_switches.cc | 5 | ||||
-rw-r--r-- | chrome/test/testing_browser_process.h | 5 |
9 files changed, 124 insertions, 3 deletions
diff --git a/chrome/browser/browser_process.h b/chrome/browser/browser_process.h index ecf3003..b9510a8 100644 --- a/chrome/browser/browser_process.h +++ b/chrome/browser/browser_process.h @@ -18,6 +18,11 @@ #include "ipc/ipc_message.h" class AutomationProviderList; + +namespace safe_browsing { +class ClientSideDetectionService; +} + class Clipboard; class DevToolsManager; class DownloadRequestLimiter; @@ -140,6 +145,11 @@ class BrowserProcess { // Returns the object that watches for changes in the closeable state of tab. virtual TabCloseableStateWatcher* tab_closeable_state_watcher() = 0; + // Returns an object which handles communication with the SafeBrowsing + // client-side detection servers. + virtual safe_browsing::ClientSideDetectionService* + safe_browsing_detection_service() = 0; + // Trigger an asynchronous check to see if we have the inspector's files on // disk. virtual void CheckForInspectorFiles() = 0; diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc index 9a1201e..ea52797 100644 --- a/chrome/browser/browser_process_impl.cc +++ b/chrome/browser/browser_process_impl.cc @@ -44,6 +44,7 @@ #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/renderer_host/resource_dispatcher_host.h" +#include "chrome/browser/safe_browsing/client_side_detection_service.h" #include "chrome/browser/safe_browsing/safe_browsing_service.h" #include "chrome/browser/sidebar/sidebar_manager.h" #include "chrome/browser/tab_closeable_state_watcher.h" @@ -98,6 +99,7 @@ BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line) created_devtools_manager_(false), created_sidebar_manager_(false), created_notification_ui_manager_(false), + created_safe_browsing_detection_service_(false), module_ref_count_(0), did_start_(false), checked_for_new_frames_(false), @@ -483,6 +485,15 @@ TabCloseableStateWatcher* BrowserProcessImpl::tab_closeable_state_watcher() { return tab_closeable_state_watcher_.get(); } +safe_browsing::ClientSideDetectionService* + BrowserProcessImpl::safe_browsing_detection_service() { + DCHECK(CalledOnValidThread()); + if (!created_safe_browsing_detection_service_) { + CreateSafeBrowsingDetectionService(); + } + return safe_browsing_detection_service_.get(); +} + void BrowserProcessImpl::CheckForInspectorFiles() { file_thread()->message_loop()->PostTask (FROM_HERE, @@ -712,6 +723,38 @@ void BrowserProcessImpl::CreatePrintPreviewTabController() { print_preview_tab_controller_ = new printing::PrintPreviewTabController(); } +void BrowserProcessImpl::CreateSafeBrowsingDetectionService() { + DCHECK(safe_browsing_detection_service_.get() == NULL); + // Set this flag to true so that we don't retry indefinitely to + // create the service class if there was an error. + created_safe_browsing_detection_service_ = true; + + FilePath model_file_path; + Profile* profile = profile_manager() ? + profile_manager()->GetDefaultProfile() : NULL; + if (IsSafeBrowsingDetectionServiceEnabled() && + PathService::Get(chrome::DIR_USER_DATA, &model_file_path) && + profile && profile->GetRequestContext()) { + safe_browsing_detection_service_.reset( + safe_browsing::ClientSideDetectionService::Create( + model_file_path.Append(chrome::kSafeBrowsingPhishingModelFilename), + profile->GetRequestContext())); + } +} + +bool BrowserProcessImpl::IsSafeBrowsingDetectionServiceEnabled() { + // The safe browsing client-side detection is enabled only if the switch is + // enabled, the user has opted in to UMA usage stats and SafeBrowsing + // is enabled. + Profile* profile = profile_manager() ? + profile_manager()->GetDefaultProfile() : NULL; + return (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableClientSidePhishingDetection) && + metrics_service() && metrics_service()->reporting_active() && + profile && profile->GetPrefs() && + profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)); +} + // The BrowserProcess object must outlive the file thread so we use traits // which don't do any management. DISABLE_RUNNABLE_METHOD_REFCOUNT(BrowserProcessImpl); diff --git a/chrome/browser/browser_process_impl.h b/chrome/browser/browser_process_impl.h index ba91c10..cc9d60c 100644 --- a/chrome/browser/browser_process_impl.h +++ b/chrome/browser/browser_process_impl.h @@ -71,6 +71,8 @@ class BrowserProcessImpl : public BrowserProcess, public NonThreadSafe { virtual DownloadStatusUpdater* download_status_updater(); virtual base::WaitableEvent* shutdown_event(); virtual TabCloseableStateWatcher* tab_closeable_state_watcher(); + virtual safe_browsing::ClientSideDetectionService* + safe_browsing_detection_service(); virtual void CheckForInspectorFiles(); #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) @@ -113,6 +115,9 @@ class BrowserProcessImpl : public BrowserProcess, public NonThreadSafe { void CreateStatusTrayManager(); void CreateTabCloseableStateWatcher(); void CreatePrintPreviewTabController(); + void CreateSafeBrowsingDetectionService(); + + bool IsSafeBrowsingDetectionServiceEnabled(); #if defined(IPC_MESSAGE_LOG_ENABLED) void SetIPCLoggingEnabledForChildProcesses(bool enabled); @@ -179,6 +184,10 @@ class BrowserProcessImpl : public BrowserProcess, public NonThreadSafe { scoped_ptr<TabCloseableStateWatcher> tab_closeable_state_watcher_; + bool created_safe_browsing_detection_service_; + scoped_ptr<safe_browsing::ClientSideDetectionService> + safe_browsing_detection_service_; + unsigned int module_ref_count_; bool did_start_; diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc index 8b8889d9..5af2e6f 100644 --- a/chrome/browser/renderer_host/browser_render_process_host.cc +++ b/chrome/browser/renderer_host/browser_render_process_host.cc @@ -49,6 +49,7 @@ #include "chrome/browser/renderer_host/render_widget_host.h" #include "chrome/browser/renderer_host/resource_message_filter.h" #include "chrome/browser/renderer_host/web_cache_manager.h" +#include "chrome/browser/safe_browsing/client_side_detection_service.h" #include "chrome/browser/spellcheck_host.h" #include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/visitedlink/visitedlink_master.h" @@ -215,7 +216,8 @@ BrowserRenderProcessHost::BrowserRenderProcessHost(Profile* profile) base::TimeDelta::FromSeconds(5), this, &BrowserRenderProcessHost::ClearTransportDIBCache)), accessibility_enabled_(false), - extension_process_(false) { + extension_process_(false), + callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { widget_helper_ = new RenderWidgetHelper(); registrar_.Add(this, NotificationType::USER_SCRIPTS_UPDATED, @@ -626,7 +628,6 @@ void BrowserRenderProcessHost::PropagateBrowserCommandLineToRenderer( switches::kDisableFileSystem, switches::kPpapiOutOfProcess, switches::kEnablePrintPreview, - switches::kEnableClientSidePhishingDetection, switches::kEnableCrxlessWebApps }; renderer_cmd->CopySwitchesFrom(browser_cmd, kSwitchNames, @@ -637,6 +638,12 @@ void BrowserRenderProcessHost::PropagateBrowserCommandLineToRenderer( !browser_cmd.HasSwitch(switches::kDisableDatabases)) { renderer_cmd->AppendSwitch(switches::kDisableDatabases); } + + // Only enable client-side phishing detection in the renderer if it is enabled + // in the browser process. + if (g_browser_process->safe_browsing_detection_service()) { + renderer_cmd->AppendSwitch(switches::kEnableClientSidePhishingDetection); + } } base::ProcessHandle BrowserRenderProcessHost::GetHandle() { @@ -1087,6 +1094,8 @@ void BrowserRenderProcessHost::OnProcessLaunched() { if (profile()->GetSpellCheckHost()) InitSpellChecker(); + InitClientSidePhishingDetection(); + if (max_page_id_ != -1) Send(new ViewMsg_SetNextPageID(max_page_id_ + 1)); @@ -1178,3 +1187,29 @@ void BrowserRenderProcessHost::InitSpellChecker() { void BrowserRenderProcessHost::EnableAutoSpellCorrect(bool enable) { Send(new ViewMsg_SpellChecker_EnableAutoSpellCorrect(enable)); } + +void BrowserRenderProcessHost::InitClientSidePhishingDetection() { + if (g_browser_process->safe_browsing_detection_service()) { + // The BrowserRenderProcessHost object might get deleted before the + // safe browsing client-side detection service class is done with opening + // the model file. To avoid crashing we use the callback factory which will + // cancel the callback if |this| is destroyed. + g_browser_process->safe_browsing_detection_service()->GetModelFile( + callback_factory_.NewCallback( + &BrowserRenderProcessHost::OpenPhishingModelDone)); + } +} + +void BrowserRenderProcessHost::OpenPhishingModelDone( + base::PlatformFile model_file) { + if (model_file != base::kInvalidPlatformFileValue) { + IPC::PlatformFileForTransit file; +#if defined(OS_POSIX) + file = base::FileDescriptor(model_file, false); +#elif defined(OS_WIN) + ::DuplicateHandle(::GetCurrentProcess(), model_file, GetHandle(), &file, 0, + false, DUPLICATE_SAME_ACCESS); +#endif + Send(new ViewMsg_SetPhishingModel(file)); + } +} diff --git a/chrome/browser/renderer_host/browser_render_process_host.h b/chrome/browser/renderer_host/browser_render_process_host.h index 0b3a78a..469fd12 100644 --- a/chrome/browser/renderer_host/browser_render_process_host.h +++ b/chrome/browser/renderer_host/browser_render_process_host.h @@ -13,7 +13,9 @@ #include <string> #include "app/surface/transport_dib.h" +#include "base/platform_file.h" #include "base/process.h" +#include "base/scoped_callback_factory.h" #include "base/scoped_ptr.h" #include "base/timer.h" #include "chrome/browser/child_process_launcher.h" @@ -170,6 +172,15 @@ class BrowserRenderProcessHost : public RenderProcessHost, // Tell the renderer that auto spell correction has been enabled/disabled. void EnableAutoSpellCorrect(bool enable); + // Initializes client-side phishing detection. Starts reading the phishing + // model from the client-side detection service class. Once the model is read + // OpenPhishingModelDone() is invoked. + void InitClientSidePhishingDetection(); + + // Called once the client-side detection service class is done with opening + // the model file. + void OpenPhishingModelDone(base::PlatformFile model_file); + NotificationRegistrar registrar_; // The count of currently visible widgets. Since the host can be a container @@ -220,6 +231,8 @@ class BrowserRenderProcessHost : public RenderProcessHost, // because the queued messages may have dependencies on the init messages. std::queue<IPC::Message*> queued_messages_; + base::ScopedCallbackFactory<BrowserRenderProcessHost> callback_factory_; + DISALLOW_COPY_AND_ASSIGN(BrowserRenderProcessHost); }; diff --git a/chrome/common/chrome_constants.cc b/chrome/common/chrome_constants.cc index 9b3a9ba..778db36 100644 --- a/chrome/common/chrome_constants.cc +++ b/chrome/common/chrome_constants.cc @@ -92,6 +92,8 @@ const FilePath::CharType kHistoryFilename[] = FPL("History"); const FilePath::CharType kLocalStateFilename[] = FPL("Local State"); const FilePath::CharType kPreferencesFilename[] = FPL("Preferences"); const FilePath::CharType kSafeBrowsingFilename[] = FPL("Safe Browsing Bloom"); +const FilePath::CharType kSafeBrowsingPhishingModelFilename[] = + FPL("Safe Browsing Phishing Model"); const FilePath::CharType kSingletonCookieFilename[] = FPL("SingletonCookie"); const FilePath::CharType kSingletonSocketFilename[] = FPL("SingletonSocket"); const FilePath::CharType kSingletonLockFilename[] = FPL("SingletonLock"); diff --git a/chrome/common/chrome_constants.h b/chrome/common/chrome_constants.h index ee82ff54..688bdc1 100644 --- a/chrome/common/chrome_constants.h +++ b/chrome/common/chrome_constants.h @@ -53,6 +53,7 @@ extern const FilePath::CharType kHistoryFilename[]; extern const FilePath::CharType kLocalStateFilename[]; extern const FilePath::CharType kPreferencesFilename[]; extern const FilePath::CharType kSafeBrowsingFilename[]; +extern const FilePath::CharType kSafeBrowsingPhishingModelFilename[]; extern const FilePath::CharType kSingletonCookieFilename[]; extern const FilePath::CharType kSingletonSocketFilename[]; extern const FilePath::CharType kSingletonLockFilename[]; diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index 22acc46..bddc032 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -416,7 +416,10 @@ const char kEnableBenchmarking[] = "enable-benchmarking"; // blocked pop-ups only. const char kEnableBlockContentAnimation[] = "enable-blocked-content-animation"; -// Enable experimental client-side detection of phishing pages. +// In the browser process this switch is used to enable or disable the +// client-side phishing detection. In the renderer this switch is only enabled +// if this switch is enabled in the browser and the user has opted in to UMA +// stats and SafeBrowsing is enabled in the preferences. const char kEnableClientSidePhishingDetection[] = "enable-client-side-phishing-detection"; diff --git a/chrome/test/testing_browser_process.h b/chrome/test/testing_browser_process.h index ef92396..6c9d52d1 100644 --- a/chrome/test/testing_browser_process.h +++ b/chrome/test/testing_browser_process.h @@ -98,6 +98,11 @@ class TestingBrowserProcess : public BrowserProcess { return NULL; } + virtual safe_browsing::ClientSideDetectionService* + safe_browsing_detection_service() { + return NULL; + } + virtual Clipboard* clipboard() { if (!clipboard_.get()) { // Note that we need a MessageLoop for the next call to work. |