diff options
-rw-r--r-- | chrome/browser/download/download_manager.cc | 4 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_browsertest.cc (renamed from chrome/browser/extensions/extension_view_unittest.cc) | 47 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_shelf_model.cc | 3 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_ui.cc | 5 | ||||
-rw-r--r-- | chrome/browser/extensions/test_extension_loader.cc | 21 | ||||
-rw-r--r-- | chrome/browser/extensions/test_extension_loader.h | 6 | ||||
-rw-r--r-- | chrome/browser/net/chrome_url_request_context.cc | 10 | ||||
-rw-r--r-- | chrome/browser/profile.cc | 9 | ||||
-rw-r--r-- | chrome/browser/utility_process_host.cc | 9 | ||||
-rw-r--r-- | chrome/browser/views/location_bar_view.cc | 2 | ||||
-rw-r--r-- | chrome/chrome.gyp | 2 |
11 files changed, 91 insertions, 27 deletions
diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc index c18d08d..de48b90 100644 --- a/chrome/browser/download/download_manager.cc +++ b/chrome/browser/download/download_manager.cc @@ -1228,8 +1228,8 @@ void DownloadManager::OpenDownload(const DownloadItem* download, } void DownloadManager::OpenChromeExtension(const FilePath& full_path) { - ExtensionsService* extensions_service = profile_->GetExtensionsService(); - extensions_service->InstallExtension(full_path); + profile_->GetOriginalProfile()->GetExtensionsService()-> + InstallExtension(full_path); } void DownloadManager::OpenDownloadInShell(const DownloadItem* download, diff --git a/chrome/browser/extensions/extension_view_unittest.cc b/chrome/browser/extensions/extension_browsertest.cc index 2f5abf8..c61c59d 100644 --- a/chrome/browser/extensions/extension_view_unittest.cc +++ b/chrome/browser/extensions/extension_browsertest.cc @@ -4,6 +4,7 @@ #include "base/ref_counted.h" #include "chrome/browser/browser.h" +#include "chrome/browser/browser_list.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/extensions/extension_shelf.h" #include "chrome/browser/extensions/extension_host.h" @@ -15,6 +16,7 @@ #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension_error_reporter.h" +#include "chrome/common/url_constants.h" #include "chrome/test/in_process_browser_test.h" #include "chrome/test/ui_test_utils.h" @@ -24,8 +26,9 @@ namespace { // up. const int kAlertTimeoutMs = 20000; -// The extension we're using as our test case. -const char* kExtensionId = "00123456789abcdef0123456789abcdef0123456"; +// The extensions we're using as our test case. +const char* kGoodExtension1Id = "00123456789abcdef0123456789abcdef0123456"; +const char* kGoodCrxId = "00123456789abcdef0123456789abcdef0123456"; }; // namespace @@ -88,8 +91,8 @@ class ExtensionViewTest : public InProcessBrowserTest { }; // Tests that ExtensionView starts an extension process and runs the script -// contained in the extension's "index.html" file. -IN_PROC_BROWSER_TEST_F(ExtensionViewTest, Index) { +// contained in the extension's toolstrip. +IN_PROC_BROWSER_TEST_F(ExtensionViewTest, Toolstrip) { // Get the path to our extension. FilePath path; ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); @@ -99,7 +102,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionViewTest, Index) { // Wait for the extension to load and grab a pointer to it. TestExtensionLoader loader(browser()->profile()); - Extension* extension = loader.Load(kExtensionId, path); + Extension* extension = loader.Load(kGoodExtension1Id, path); ASSERT_TRUE(extension); GURL url = Extension::GetResourceURL(extension->url(), "toolstrip1.html"); @@ -129,12 +132,42 @@ IN_PROC_BROWSER_TEST_F(ExtensionViewTest, Shelf) { // Wait for the extension to load and grab a pointer to it. TestExtensionLoader loader(browser()->profile()); - Extension* extension = loader.Load(kExtensionId, path); + Extension* extension = loader.Load(kGoodExtension1Id, path); ASSERT_TRUE(extension); - GURL url = Extension::GetResourceURL(extension->url(), "toolstrip1.html"); // There should now be two extension views and preferred height of the view // should be non-zero. EXPECT_EQ(shelf->GetChildViewCount(), 2); EXPECT_NE(shelf->GetPreferredSize().height(), 0); } + +// Tests that installing and uninstalling extensions don't crash with an +// incognito window open. +IN_PROC_BROWSER_TEST_F(ExtensionViewTest, Incognito) { + // Open an incognito window to the extensions management page. We just + // want to make sure that we don't crash while playing with extensions when + // this guy is around. + Browser::OpenURLOffTheRecord(browser()->profile(), + GURL(chrome::kChromeUIExtensionsURL)); + + // Get the path to our extension. + FilePath path; + ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); + path = path.AppendASCII("extensions").AppendASCII("good.crx"); + ASSERT_TRUE(file_util::PathExists(path)); // sanity check + + // Wait for the extension to load and grab a pointer to it. + TestExtensionLoader loader(browser()->profile()); + Extension* extension = loader.Install(kGoodCrxId, path); + ASSERT_TRUE(extension); + + // TODO(mpcomplete): wait for uninstall to complete? + browser()->profile()->GetExtensionsService()->UninstallExtension(kGoodCrxId); + + // Close our incognito window. + Browser* otr_browser = BrowserList::FindBrowserWithType( + browser()->profile()->GetOffTheRecordProfile(), + Browser::TYPE_NORMAL); + if (otr_browser) + otr_browser->CloseAllTabs(); +} diff --git a/chrome/browser/extensions/extension_shelf_model.cc b/chrome/browser/extensions/extension_shelf_model.cc index 37d3eb6..6af45c6 100644 --- a/chrome/browser/extensions/extension_shelf_model.cc +++ b/chrome/browser/extensions/extension_shelf_model.cc @@ -107,6 +107,9 @@ void ExtensionShelfModel::Observe(NotificationType type, void ExtensionShelfModel::AddExtensions(const ExtensionList* extensions) { ExtensionProcessManager* manager = browser_->profile()->GetExtensionProcessManager(); + if (!manager) + return; + for (ExtensionList::const_iterator extension = extensions->begin(); extension != extensions->end(); ++extension) { for (std::vector<std::string>::const_iterator toolstrip_path = diff --git a/chrome/browser/extensions/extensions_ui.cc b/chrome/browser/extensions/extensions_ui.cc index c23dcb6..af69ec6 100644 --- a/chrome/browser/extensions/extensions_ui.cc +++ b/chrome/browser/extensions/extensions_ui.cc @@ -224,7 +224,7 @@ std::vector<ExtensionPage> ExtensionsDOMHandler::GetActivePagesForExtension( std::vector<ExtensionPage> result; ExtensionMessageService* ems = ExtensionMessageService::GetInstance( - dom_ui_->GetProfile()->GetRequestContext()); + dom_ui_->GetProfile()->GetOriginalProfile()->GetRequestContext()); RenderProcessHost* process_host = ems->GetProcessForExtension(extension_id); if (!process_host) return result; @@ -260,7 +260,8 @@ void ExtensionsDOMHandler::Init() { } ExtensionsUI::ExtensionsUI(TabContents* contents) : DOMUI(contents) { - ExtensionsService *exstension_service = GetProfile()->GetExtensionsService(); + ExtensionsService *exstension_service = + GetProfile()->GetOriginalProfile()->GetExtensionsService(); ExtensionsDOMHandler* handler = new ExtensionsDOMHandler(this, exstension_service); diff --git a/chrome/browser/extensions/test_extension_loader.cc b/chrome/browser/extensions/test_extension_loader.cc index d8bacb7..d17f557 100644 --- a/chrome/browser/extensions/test_extension_loader.cc +++ b/chrome/browser/extensions/test_extension_loader.cc @@ -15,6 +15,7 @@ namespace { // How long to wait for the extension to load before giving up. const int kLoadTimeoutMs = 5000; +const int kInstallTimeoutMs = 10000; } // namespace @@ -25,7 +26,8 @@ TestExtensionLoader::TestExtensionLoader(Profile* profile) NotificationService::AllSources()); profile_->GetExtensionsService()->Init(); - DCHECK(profile_->GetExtensionsService()->extensions()->empty()); + profile_->GetExtensionsService()->set_show_extensions_prompts(false); + DCHECK(profile_->GetExtensionsService()->extensions()->empty()); } Extension* TestExtensionLoader::Load(const char* extension_id, @@ -45,6 +47,23 @@ Extension* TestExtensionLoader::Load(const char* extension_id, return extension_; } +Extension* TestExtensionLoader::Install(const char* extension_id, + const FilePath& path) { + loading_extension_id_ = extension_id; + + // Install the extension. When installed, the extension will automatically + // be loaded. + profile_->GetExtensionsService()->InstallExtension(path); + + // Wait for the load to complete. + extension_ = NULL; + MessageLoop::current()->PostDelayedTask(FROM_HERE, + new MessageLoop::QuitTask, kInstallTimeoutMs); + ui_test_utils::RunMessageLoop(); + + return extension_; +} + void TestExtensionLoader::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { diff --git a/chrome/browser/extensions/test_extension_loader.h b/chrome/browser/extensions/test_extension_loader.h index 60ca84f..e0ef193 100644 --- a/chrome/browser/extensions/test_extension_loader.h +++ b/chrome/browser/extensions/test_extension_loader.h @@ -17,8 +17,14 @@ class TestExtensionLoader : public NotificationObserver { public: explicit TestExtensionLoader(Profile* profile); + // Tells the extension service to load the extension at the given path. It + // waits for the extension with the expected ID to load, then returns a + // handle to it. Extension* Load(const char* extension_id, const FilePath& path); + // Same as above, but installs from a CRX first. + Extension* Install(const char* extension_id, const FilePath& path); + virtual void Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details); diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index 304b506..0a1fb13 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -294,10 +294,12 @@ ChromeURLRequestContext::ChromeURLRequestContext(Profile* profile) prefs_->AddPrefObserver(prefs::kAcceptLanguages, this); prefs_->AddPrefObserver(prefs::kCookieBehavior, this); - registrar_.Add(this, NotificationType::EXTENSIONS_LOADED, - NotificationService::AllSources()); - registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, - NotificationService::AllSources()); + if (!is_off_the_record_) { + registrar_.Add(this, NotificationType::EXTENSIONS_LOADED, + NotificationService::AllSources()); + registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, + NotificationService::AllSources()); + } } // NotificationObserver implementation. diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index b7bd98d..1aed4ee 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -120,8 +120,6 @@ class OffTheRecordProfileImpl : public Profile, request_context_ = ChromeURLRequestContext::CreateOffTheRecord(this); request_context_->AddRef(); - extension_process_manager_.reset(new ExtensionProcessManager(this)); - // Register for browser close notifications so we can detect when the last // off-the-record window is closed, in which case we can clean our states // (cookies, downloads...). @@ -160,7 +158,7 @@ class OffTheRecordProfileImpl : public Profile, } virtual ExtensionsService* GetExtensionsService() { - return profile_->GetExtensionsService(); + return NULL; } virtual UserScriptMaster* GetUserScriptMaster() { @@ -168,7 +166,7 @@ class OffTheRecordProfileImpl : public Profile, } virtual ExtensionProcessManager* GetExtensionProcessManager() { - return extension_process_manager_.get(); + return NULL; } virtual SSLHostState* GetSSLHostState() { @@ -401,9 +399,6 @@ class OffTheRecordProfileImpl : public Profile, // The ForceTLSState that only stores enabled sites in memory. scoped_ptr<net::ForceTLSState> force_tls_state_; - // Extensions run in a different context in incognito mode. - scoped_ptr<ExtensionProcessManager> extension_process_manager_; - // Time we were started. Time start_time_; diff --git a/chrome/browser/utility_process_host.cc b/chrome/browser/utility_process_host.cc index 2be419e..5dad2c5 100644 --- a/chrome/browser/utility_process_host.cc +++ b/chrome/browser/utility_process_host.cc @@ -41,9 +41,12 @@ bool UtilityProcessHost::StartProcess(const FilePath& exposed_dir) { if (!CreateChannel()) return false; - std::wstring exe_path; - if (!PathService::Get(base::FILE_EXE, &exe_path)) - return false; + std::wstring exe_path = CommandLine::ForCurrentProcess()->GetSwitchValue( + switches::kBrowserSubprocessPath); + if (exe_path.empty()) { + if (!PathService::Get(base::FILE_EXE, &exe_path)) + return false; + } CommandLine cmd_line(exe_path); cmd_line.AppendSwitchWithValue(switches::kProcessType, diff --git a/chrome/browser/views/location_bar_view.cc b/chrome/browser/views/location_bar_view.cc index e514043..4fff35b 100644 --- a/chrome/browser/views/location_bar_view.cc +++ b/chrome/browser/views/location_bar_view.cc @@ -601,6 +601,8 @@ void LocationBarView::DeletePageActionViews() { std::vector<PageAction*> LocationBarView::GetPageActions() { std::vector<PageAction*> result; + if (!profile_->GetExtensionsService()) + return result; // Query the extension system to see how many page actions we have. // TODO(finnur): Sort the page icons in some meaningful way. diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index f077006..bec31eb 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -26,7 +26,7 @@ ], 'browser_tests_sources_win_specific': [ 'browser/extensions/extension_shelf_model_unittest.cc', - 'browser/extensions/extension_view_unittest.cc', + 'browser/extensions/extension_browsertest.cc', 'browser/extensions/test_extension_loader.cc', 'browser/extensions/test_extension_loader.h', 'browser/views/find_bar_win_browsertest.cc', |