Home | History | Annotate | Download | only in chrome_frame
      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 // Implementation of DeleteChromeHistory
      6 #include "chrome_frame/delete_chrome_history.h"
      7 
      8 #include "chrome/browser/browsing_data/browsing_data_remover.h"
      9 
     10 #include "base/win/windows_version.h"
     11 #include "chrome_frame/chrome_frame_activex.h"
     12 #include "chrome_frame/utils.h"
     13 
     14 // Below other header to avoid symbol pollution.
     15 #define INITGUID
     16 #include <deletebrowsinghistory.h>
     17 
     18 DeleteChromeHistory::DeleteChromeHistory()
     19   : remove_mask_(0) {
     20   DVLOG(1) << __FUNCTION__;
     21 }
     22 
     23 DeleteChromeHistory::~DeleteChromeHistory() {
     24 }
     25 
     26 
     27 HRESULT DeleteChromeHistory::FinalConstruct() {
     28   DVLOG(1) << __FUNCTION__;
     29   Initialize();
     30   return S_OK;
     31 }
     32 
     33 void DeleteChromeHistory::OnAutomationServerReady() {
     34   DVLOG(1) << __FUNCTION__;
     35   automation_client_->RemoveBrowsingData(remove_mask_);
     36   loop_.Quit();
     37 }
     38 
     39 void DeleteChromeHistory::OnAutomationServerLaunchFailed(
     40       AutomationLaunchResult reason, const std::string& server_version) {
     41   DLOG(WARNING) << __FUNCTION__;
     42   loop_.Quit();
     43 }
     44 
     45 void DeleteChromeHistory::GetProfilePath(const std::wstring& profile_name,
     46                                          base::FilePath* profile_path) {
     47   ChromeFramePlugin::GetProfilePath(kIexploreProfileName, profile_path);
     48 }
     49 
     50 STDMETHODIMP DeleteChromeHistory::DeleteBrowsingHistory(DWORD flags) {
     51   DVLOG(1) << __FUNCTION__;
     52   // Usually called inside a quick startup/tear-down routine by RunDLL32. You
     53   // can simulate the process by calling:
     54   //    RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255
     55   // Since automation setup isn't synchronous, we can be tearing down while
     56   // being only partially set-up, causing even synchronous IPCs to be dropped.
     57   // Since the *Chrome* startup/tear-down occurs synchronously from the
     58   // perspective of automation, we can add a flag to the chrome.exe invocation
     59   // in lieu of sending an IPC when it seems appropriate. Since we assume this
     60   // happens in one-off fashion, don't attempt to pack REMOVE_* arguments.
     61   // Instead, have the browser process clobber all history.
     62   //
     63   // IE8 on Vista launches us twice when the user asks to delete browsing data -
     64   // once in low integrity and once in medium integrity. The low integrity
     65   // instance will fail to connect to the automation server and restart it in an
     66   // effort to connect. Thus, we detect if we are in that circumstance and exit
     67   // silently.
     68   base::IntegrityLevel integrity_level;
     69   if (base::win::GetVersion() >= base::win::VERSION_VISTA &&
     70       !base::GetProcessIntegrityLevel(base::GetCurrentProcessHandle(),
     71                                       &integrity_level)) {
     72     return E_UNEXPECTED;
     73   }
     74   if (integrity_level == base::LOW_INTEGRITY) {
     75     return S_OK;
     76   }
     77   if (!InitializeAutomation(GetHostProcessName(false), false, false,
     78                             GURL(), GURL(), true)) {
     79     return E_UNEXPECTED;
     80   }
     81 
     82   if (flags & DELETE_BROWSING_HISTORY_COOKIES)
     83     remove_mask_ |= BrowsingDataRemover::REMOVE_SITE_DATA;
     84   if (flags & DELETE_BROWSING_HISTORY_TIF)
     85     remove_mask_ |= BrowsingDataRemover::REMOVE_CACHE;
     86   if (flags & DELETE_BROWSING_HISTORY_FORMDATA)
     87     remove_mask_ |= BrowsingDataRemover::REMOVE_FORM_DATA;
     88   if (flags & DELETE_BROWSING_HISTORY_PASSWORDS)
     89     remove_mask_ |= BrowsingDataRemover::REMOVE_PASSWORDS;
     90   if (flags & DELETE_BROWSING_HISTORY_HISTORY)
     91     remove_mask_ |= BrowsingDataRemover::REMOVE_HISTORY;
     92 
     93   loop_.PostDelayedTask(FROM_HERE,
     94       base::MessageLoop::QuitClosure(), base::TimeDelta::FromMinutes(10));
     95   loop_.base::MessageLoop::Run();
     96 
     97   return S_OK;
     98 }
     99 
    100 
    101