summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-07 01:51:06 +0000
committermmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-07 01:51:06 +0000
commitb09f76d6cf6649e652ad255eba9631af787b9a09 (patch)
treeb4dfe7f2190464f17d3ea06ac6e81d7cdfec3f91
parent5f493d90d856263bd00992b03931cd4f20a39c16 (diff)
downloadchromium_src-b09f76d6cf6649e652ad255eba9631af787b9a09.zip
chromium_src-b09f76d6cf6649e652ad255eba9631af787b9a09.tar.gz
chromium_src-b09f76d6cf6649e652ad255eba9631af787b9a09.tar.bz2
Clear DNS cache and passive log collector on incognito close.
The call that used to do this was made from the predictor, and was accidentally removed during a predictor refactoring (http://codereview.chromium.org/7467012/) BUG=69732 TEST=open incognito window, go somewhere, close the window, open net-internals, and check that no hints of what was done during incognito mode remain. Review URL: http://codereview.chromium.org/8775067 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113324 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/io_thread.cc22
-rw-r--r--chrome/browser/io_thread.h5
-rw-r--r--chrome/browser/profiles/off_the_record_profile_impl.cc5
-rw-r--r--chrome/browser/ui/webui/net_internals_ui_browsertest.cc227
-rw-r--r--chrome/test/data/webui/net_internals/dns_view.js11
-rw-r--r--chrome/test/data/webui/net_internals/net_internals_test.js22
6 files changed, 198 insertions, 94 deletions
diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc
index 130a932..9c3b997 100644
--- a/chrome/browser/io_thread.cc
+++ b/chrome/browser/io_thread.cc
@@ -395,6 +395,15 @@ ChromeNetLog* IOThread::net_log() {
return net_log_;
}
+void IOThread::ChangedToOnTheRecord() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ BrowserThread::PostTask(
+ BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(&IOThread::ChangedToOnTheRecordOnIOThread,
+ base::Unretained(this)));
+}
+
net::URLRequestContextGetter* IOThread::system_url_request_context_getter() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (!system_url_request_context_getter_) {
@@ -593,6 +602,19 @@ net::SSLConfigService* IOThread::GetSSLConfigService() {
return ssl_config_service_manager_->Get();
}
+void IOThread::ChangedToOnTheRecordOnIOThread() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+
+ // Clear the host cache to avoid showing entries from the OTR session
+ // in about:net-internals.
+ ClearHostCache();
+
+ // Clear all of the passively logged data.
+ // TODO(eroman): this is a bit heavy handed, really all we need to do is
+ // clear the data pertaining to incognito context.
+ net_log_->ClearAllPassivelyCapturedEvents();
+}
+
void IOThread::InitSystemRequestContext() {
if (system_url_request_context_getter_)
return;
diff --git a/chrome/browser/io_thread.h b/chrome/browser/io_thread.h
index 207257a..974dab4 100644
--- a/chrome/browser/io_thread.h
+++ b/chrome/browser/io_thread.h
@@ -106,6 +106,9 @@ class IOThread : public content::BrowserThreadDelegate {
ChromeNetLog* net_log();
+ // Handles changing to On The Record mode, discarding confidential data.
+ void ChangedToOnTheRecord();
+
// Returns a getter for the URLRequestContext. Only called on the UI thread.
net::URLRequestContextGetter* system_url_request_context_getter();
@@ -143,6 +146,8 @@ class IOThread : public content::BrowserThreadDelegate {
// Returns an SSLConfigService instance.
net::SSLConfigService* GetSSLConfigService();
+ void ChangedToOnTheRecordOnIOThread();
+
// The NetLog is owned by the browser process, to allow logging from other
// threads during shutdown, but is used most frequently on the IOThread.
ChromeNetLog* net_log_;
diff --git a/chrome/browser/profiles/off_the_record_profile_impl.cc b/chrome/browser/profiles/off_the_record_profile_impl.cc
index 619d835..9442345 100644
--- a/chrome/browser/profiles/off_the_record_profile_impl.cc
+++ b/chrome/browser/profiles/off_the_record_profile_impl.cc
@@ -26,6 +26,7 @@
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_special_storage_policy.h"
#include "chrome/browser/extensions/extension_webrequest_api.h"
+#include "chrome/browser/io_thread.h"
#include "chrome/browser/net/proxy_service_factory.h"
#include "chrome/browser/plugin_prefs.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h"
@@ -154,6 +155,10 @@ OffTheRecordProfileImpl::~OffTheRecordProfileImpl() {
ExtensionPrefs* extension_prefs = extension_service->extension_prefs();
extension_prefs->ClearIncognitoSessionOnlyContentSettings();
}
+
+ // Clears any data the network stack contains that may be related to the
+ // OTR session.
+ g_browser_process->io_thread()->ChangedToOnTheRecord();
}
std::string OffTheRecordProfileImpl::GetProfileName() {
diff --git a/chrome/browser/ui/webui/net_internals_ui_browsertest.cc b/chrome/browser/ui/webui/net_internals_ui_browsertest.cc
index 258e60b..96fedfc 100644
--- a/chrome/browser/ui/webui/net_internals_ui_browsertest.cc
+++ b/chrome/browser/ui/webui/net_internals_ui_browsertest.cc
@@ -73,97 +73,6 @@ void AddCacheEntryOnIOThread(net::URLRequestContextGetter* context_getter,
expires);
}
-// Class to handle messages from the renderer needed by certain tests.
-class NetInternalsTestMessageHandler : public WebUIMessageHandler {
- public:
- NetInternalsTestMessageHandler();
-
- void set_browser(Browser* browser) {
- ASSERT_TRUE(browser);
- browser_ = browser;
- }
-
- private:
- virtual void RegisterMessages() OVERRIDE;
-
- // Opens the given URL in a new background tab.
- void OpenNewTab(const ListValue* list_value);
-
- // Adds a new entry to the host cache. Takes in hostname, ip address,
- // net error code, and expiration time (as number of days from now).
- void AddCacheEntry(const ListValue* list_value);
-
- // Navigates to the prerender in the background tab. This assumes that
- // there is a "Click()" function in the background tab which will navigate
- // there, and that the background tab exists at slot 1.
- void NavigateToPrerender(const ListValue* list_value);
-
- Browser* browser_;
-
- DISALLOW_COPY_AND_ASSIGN(NetInternalsTestMessageHandler);
-};
-
-NetInternalsTestMessageHandler::NetInternalsTestMessageHandler()
- : browser_(NULL) {
-}
-
-void NetInternalsTestMessageHandler::RegisterMessages() {
- web_ui_->RegisterMessageCallback(
- "openNewTab",
- base::Bind(&NetInternalsTestMessageHandler::OpenNewTab,
- base::Unretained(this)));
- web_ui_->RegisterMessageCallback(
- "addCacheEntry",
- base::Bind(&NetInternalsTestMessageHandler::AddCacheEntry,
- base::Unretained(this)));
- web_ui_->RegisterMessageCallback("navigateToPrerender",
- base::Bind(&NetInternalsTestMessageHandler::NavigateToPrerender,
- base::Unretained(this)));
-}
-
-void NetInternalsTestMessageHandler::OpenNewTab(const ListValue* list_value) {
- std::string url;
- ASSERT_TRUE(list_value->GetString(0, &url));
- ASSERT_TRUE(browser_);
- ui_test_utils::NavigateToURLWithDisposition(
- browser_,
- GURL(url),
- NEW_BACKGROUND_TAB,
- ui_test_utils::BROWSER_TEST_NONE);
-}
-
-// Called on UI thread. Adds an entry to the cache for the specified hostname
-// by posting a task to the IO thread. Takes the host name, ip address, net
-// error code, and expiration time in days from now as parameters. If the error
-// code indicates failure, the ip address must be an empty string.
-void NetInternalsTestMessageHandler::AddCacheEntry(
- const ListValue* list_value) {
- std::string hostname;
- std::string ip_literal;
- double net_error;
- double expire_days_from_now;
- ASSERT_TRUE(list_value->GetString(0, &hostname));
- ASSERT_TRUE(list_value->GetString(1, &ip_literal));
- ASSERT_TRUE(list_value->GetDouble(2, &net_error));
- ASSERT_TRUE(list_value->GetDouble(3, &expire_days_from_now));
- ASSERT_TRUE(browser_);
-
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::Bind(&AddCacheEntryOnIOThread,
- make_scoped_refptr(browser_->profile()->GetRequestContext()),
- hostname,
- ip_literal,
- static_cast<int>(net_error),
- static_cast<int>(expire_days_from_now)));
-}
-
-void NetInternalsTestMessageHandler::NavigateToPrerender(
- const ListValue* list_value) {
- RenderViewHost* host = browser_->GetTabContentsAt(1)->render_view_host();
- host->ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16("Click()"));
-}
-
class NetInternalsTest : public WebUIBrowserTest {
public:
NetInternalsTest();
@@ -189,17 +98,56 @@ class NetInternalsTest : public WebUIBrowserTest {
}
private:
+ // Class to handle messages from the renderer needed by certain tests.
+ class MessageHandler : public WebUIMessageHandler {
+ public:
+ explicit MessageHandler(NetInternalsTest* net_internals_test);
+
+ private:
+ virtual void RegisterMessages() OVERRIDE;
+
+ // Opens the given URL in a new background tab.
+ void OpenNewTab(const ListValue* list_value);
+
+ // Called on UI thread. Adds an entry to the cache for the specified
+ // hostname by posting a task to the IO thread. Takes the host name,
+ // ip address, net error code, and expiration time in days from now
+ // as parameters. If the error code indicates failure, the ip address
+ // must be an empty string.
+ void AddCacheEntry(const ListValue* list_value);
+
+ // Navigates to the prerender in the background tab. This assumes that
+ // there is a "Click()" function in the background tab which will navigate
+ // there, and that the background tab exists at slot 1.
+ void NavigateToPrerender(const ListValue* list_value);
+
+ // Creates an incognito browser.
+ void CreateIncognitoBrowser(const ListValue* list_value);
+
+ // Closes an incognito browser created with CreateIncognitoBrowser.
+ void CloseIncognitoBrowser(const ListValue* list_value);
+
+ Browser* browser() {
+ return net_internals_test_->browser();
+ }
+
+ NetInternalsTest* net_internals_test_;
+ Browser* incognito_browser_;
+
+ DISALLOW_COPY_AND_ASSIGN(MessageHandler);
+ };
+
virtual WebUIMessageHandler* GetMockMessageHandler() OVERRIDE {
- message_handler_.set_browser(browser());
return &message_handler_;
}
- NetInternalsTestMessageHandler message_handler_;
+ MessageHandler message_handler_;
DISALLOW_COPY_AND_ASSIGN(NetInternalsTest);
};
-NetInternalsTest::NetInternalsTest() {
+NetInternalsTest::NetInternalsTest()
+ : ALLOW_THIS_IN_INITIALIZER_LIST(message_handler_(this)) {
}
NetInternalsTest::~NetInternalsTest() {
@@ -244,6 +192,90 @@ void NetInternalsTest::SetUpOnMainThread() {
}
////////////////////////////////////////////////////////////////////////////////
+// NetInternalsTest::MessageHandler
+////////////////////////////////////////////////////////////////////////////////
+
+NetInternalsTest::MessageHandler::MessageHandler(
+ NetInternalsTest* net_internals_test)
+ : net_internals_test_(net_internals_test),
+ incognito_browser_(NULL) {
+}
+
+void NetInternalsTest::MessageHandler::RegisterMessages() {
+ web_ui_->RegisterMessageCallback(
+ "openNewTab",
+ base::Bind(&NetInternalsTest::MessageHandler::OpenNewTab,
+ base::Unretained(this)));
+ web_ui_->RegisterMessageCallback(
+ "addCacheEntry",
+ base::Bind(&NetInternalsTest::MessageHandler::AddCacheEntry,
+ base::Unretained(this)));
+ web_ui_->RegisterMessageCallback("navigateToPrerender",
+ base::Bind(&NetInternalsTest::MessageHandler::NavigateToPrerender,
+ base::Unretained(this)));
+ web_ui_->RegisterMessageCallback("createIncognitoBrowser",
+ base::Bind(&NetInternalsTest::MessageHandler::CreateIncognitoBrowser,
+ base::Unretained(this)));
+ web_ui_->RegisterMessageCallback("closeIncognitoBrowser",
+ base::Bind(&NetInternalsTest::MessageHandler::CloseIncognitoBrowser,
+ base::Unretained(this)));
+}
+
+void NetInternalsTest::MessageHandler::OpenNewTab(
+ const ListValue* list_value) {
+ std::string url;
+ ASSERT_TRUE(list_value->GetString(0, &url));
+ ui_test_utils::NavigateToURLWithDisposition(
+ browser(),
+ GURL(url),
+ NEW_BACKGROUND_TAB,
+ ui_test_utils::BROWSER_TEST_NONE);
+}
+
+void NetInternalsTest::MessageHandler::AddCacheEntry(
+ const ListValue* list_value) {
+ std::string hostname;
+ std::string ip_literal;
+ double net_error;
+ double expire_days_from_now;
+ ASSERT_TRUE(list_value->GetString(0, &hostname));
+ ASSERT_TRUE(list_value->GetString(1, &ip_literal));
+ ASSERT_TRUE(list_value->GetDouble(2, &net_error));
+ ASSERT_TRUE(list_value->GetDouble(3, &expire_days_from_now));
+ ASSERT_TRUE(browser());
+
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&AddCacheEntryOnIOThread,
+ make_scoped_refptr(browser()->profile()->GetRequestContext()),
+ hostname,
+ ip_literal,
+ static_cast<int>(net_error),
+ static_cast<int>(expire_days_from_now)));
+}
+
+void NetInternalsTest::MessageHandler::NavigateToPrerender(
+ const ListValue* list_value) {
+ RenderViewHost* host = browser()->GetTabContentsAt(1)->render_view_host();
+ host->ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16("Click()"));
+}
+
+void NetInternalsTest::MessageHandler::CreateIncognitoBrowser(
+ const ListValue* list_value) {
+ ASSERT_FALSE(incognito_browser_);
+ incognito_browser_ = net_internals_test_->CreateIncognitoBrowser();
+}
+
+void NetInternalsTest::MessageHandler::CloseIncognitoBrowser(
+ const ListValue* list_value) {
+ ASSERT_TRUE(incognito_browser_);
+ incognito_browser_->CloseAllTabs();
+ // Closing all a Browser's tabs will ultimately result in its destruction,
+ // thought it may not have been destroyed yet.
+ incognito_browser_ = NULL;
+}
+
+////////////////////////////////////////////////////////////////////////////////
// net_internals_ui.js
////////////////////////////////////////////////////////////////////////////////
@@ -368,6 +400,13 @@ IN_PROC_BROWSER_TEST_F(NetInternalsTest, NetInternalsDnsViewAddTwoTwice) {
EXPECT_TRUE(RunJavascriptAsyncTest("netInternalsDnsViewAddTwoTwice"));
}
+// Makes sure that openning and then closing an incognito window clears the
+// DNS cache. To keep things simple, we add a fake cache entry ourselves,
+// rather than having the incognito browser create one.
+IN_PROC_BROWSER_TEST_F(NetInternalsTest, NetInternalsDnsViewIncognitoClears) {
+ EXPECT_TRUE(RunJavascriptAsyncTest("netInternalsDnsViewIncognitoClears"));
+}
+
////////////////////////////////////////////////////////////////////////////////
// test_view.js
////////////////////////////////////////////////////////////////////////////////
diff --git a/chrome/test/data/webui/net_internals/dns_view.js b/chrome/test/data/webui/net_internals/dns_view.js
index e8ac7ee..d9c2416 100644
--- a/chrome/test/data/webui/net_internals/dns_view.js
+++ b/chrome/test/data/webui/net_internals/dns_view.js
@@ -255,4 +255,15 @@ netInternalsTest.test('netInternalsDnsViewAddTwoTwice', function() {
taskQueue.run(true);
});
+netInternalsTest.test('netInternalsDnsViewIncognitoClears', function() {
+ netInternalsTest.switchToView('dns');
+ var taskQueue = new netInternalsTest.TaskQueue(true);
+ taskQueue.addTask(netInternalsTest.getCreateIncognitoBrowserTask());
+ taskQueue.addTask(new AddCacheEntryTask(
+ 'somewhere.com', '1.2.3.4', 0, true));
+ taskQueue.addTask(netInternalsTest.getCloseIncognitoBrowserTask());
+ taskQueue.addTask(new WaitForEntryDestructionTask('somewhere.com'));
+ taskQueue.run(true);
+});
+
})(); // Anonymous namespace
diff --git a/chrome/test/data/webui/net_internals/net_internals_test.js b/chrome/test/data/webui/net_internals/net_internals_test.js
index 1b86a6e..90c598a 100644
--- a/chrome/test/data/webui/net_internals/net_internals_test.js
+++ b/chrome/test/data/webui/net_internals/net_internals_test.js
@@ -424,6 +424,25 @@ var netInternalsTest = (function() {
}
};
+ // Creates an incognito window. May not be called if there already is an
+ // incognito in exitence. Returns immediately.
+ function getCreateIncognitoBrowserTask() {
+ return new CallFunctionTask(
+ function() {
+ chrome.send('createIncognitoBrowser');
+ });
+ };
+
+ // Closes an incognito window created with the task above. May only be
+ // called if there's an incognito window created by the above function
+ // that has yet to be closed. Returns immediately.
+ function getCloseIncognitoBrowserTask() {
+ return new CallFunctionTask(
+ function() {
+ chrome.send('closeIncognitoBrowser');
+ });
+ };
+
/**
* Returns true if a node does not have a 'display' property of 'none'.
* @param {node}: node The node to check.
@@ -510,6 +529,9 @@ var netInternalsTest = (function() {
switchToView: switchToView,
TaskQueue: TaskQueue,
Task: Task,
+ CallFunctionTask: CallFunctionTask,
+ getCreateIncognitoBrowserTask: getCreateIncognitoBrowserTask,
+ getCloseIncognitoBrowserTask: getCloseIncognitoBrowserTask,
Source: Source,
Event: Event,
CreateBeginEvent: CreateBeginEvent,