summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-30 11:29:16 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-30 11:29:16 +0000
commit11a65b697e1eca3e0a0c64164ee114b287125cf5 (patch)
treeccaa46ed78056ba6cc319e38ab89990e43155d79 /content
parent5ca728fd925b34561624c618ba72cb61beb16523 (diff)
downloadchromium_src-11a65b697e1eca3e0a0c64164ee114b287125cf5.zip
chromium_src-11a65b697e1eca3e0a0c64164ee114b287125cf5.tar.gz
chromium_src-11a65b697e1eca3e0a0c64164ee114b287125cf5.tar.bz2
Add methods to close individual or all open windows to Shell
BUG=111316 TEST=none Review URL: https://chromiumcodereview.appspot.com/9909015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@129828 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/shell/shell.cc14
-rw-r--r--content/shell/shell.h8
-rw-r--r--content/shell/shell_browser_context.cc8
-rw-r--r--content/shell/shell_browser_context.h3
-rw-r--r--content/shell/shell_browser_main.cc10
-rw-r--r--content/shell/shell_gtk.cc11
-rw-r--r--content/shell/shell_mac.mm4
-rw-r--r--content/shell/shell_win.cc7
8 files changed, 49 insertions, 16 deletions
diff --git a/content/shell/shell.cc b/content/shell/shell.cc
index dff406f..55c9ad8 100644
--- a/content/shell/shell.cc
+++ b/content/shell/shell.cc
@@ -4,6 +4,7 @@
#include "content/shell/shell.h"
+#include "base/auto_reset.h"
#include "base/command_line.h"
#include "base/message_loop.h"
#include "base/path_service.h"
@@ -24,6 +25,8 @@ namespace content {
std::vector<Shell*> Shell::windows_;
+bool Shell::quit_message_loop_ = true;
+
Shell::Shell(WebContents* web_contents)
: WebContentsObserver(web_contents),
wait_until_done_(false),
@@ -45,6 +48,9 @@ Shell::~Shell() {
break;
}
}
+
+ if (windows_.empty() && quit_message_loop_)
+ MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
}
Shell* Shell::CreateShell(WebContents* web_contents) {
@@ -60,6 +66,14 @@ Shell* Shell::CreateShell(WebContents* web_contents) {
return shell;
}
+void Shell::CloseAllWindows() {
+ AutoReset<bool> auto_reset(&quit_message_loop_, false);
+ std::vector<Shell*> open_windows(windows_);
+ for (size_t i = 0; i < open_windows.size(); ++i)
+ open_windows[i]->Close();
+ MessageLoop::current()->RunAllPending();
+}
+
Shell* Shell::FromRenderViewHost(RenderViewHost* rvh) {
for (size_t i = 0; i < windows_.size(); ++i) {
if (windows_[i]->web_contents() &&
diff --git a/content/shell/shell.h b/content/shell/shell.h
index 0beb6dd..1fc519a 100644
--- a/content/shell/shell.h
+++ b/content/shell/shell.h
@@ -44,6 +44,7 @@ class Shell : public WebContentsDelegate,
void Reload();
void Stop();
void UpdateNavigationControls();
+ void Close();
// Do one time initialization at application startup.
static void PlatformInitialize();
@@ -60,6 +61,9 @@ class Shell : public WebContentsDelegate,
// Returns the Shell object corresponding to the given RenderViewHost.
static Shell* FromRenderViewHost(RenderViewHost* rvh);
+ // Closes all windows and returns. This runs a message loop.
+ static void CloseAllWindows();
+
// Closes all windows and exits.
static void PlatformExit();
@@ -177,6 +181,10 @@ class Shell : public WebContentsDelegate,
// A container of all the open windows. We use a vector so we can keep track
// of ordering.
static std::vector<Shell*> windows_;
+
+ // True if the destructur of Shell should post a quit closure on the current
+ // message loop if the destructed Shell object was the last one.
+ static bool quit_message_loop_;
};
} // namespace content
diff --git a/content/shell/shell_browser_context.cc b/content/shell/shell_browser_context.cc
index ae3526f..4765860 100644
--- a/content/shell/shell_browser_context.cc
+++ b/content/shell/shell_browser_context.cc
@@ -87,6 +87,7 @@ class ShellSpeechRecognitionPreferences : public SpeechRecognitionPreferences {
ShellBrowserContext::ShellBrowserContext(
ShellBrowserMainParts* shell_main_parts)
: shell_main_parts_(shell_main_parts) {
+ InitWhileIOAllowed();
}
ShellBrowserContext::~ShellBrowserContext() {
@@ -96,10 +97,7 @@ ShellBrowserContext::~ShellBrowserContext() {
}
}
-FilePath ShellBrowserContext::GetPath() {
- if (!path_.empty())
- return path_;
-
+void ShellBrowserContext::InitWhileIOAllowed() {
#if defined(OS_WIN)
CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA, &path_));
path_ = path_.Append(std::wstring(L"content_shell"));
@@ -118,7 +116,9 @@ FilePath ShellBrowserContext::GetPath() {
if (!file_util::PathExists(path_))
file_util::CreateDirectory(path_);
+}
+FilePath ShellBrowserContext::GetPath() {
return path_;
}
diff --git a/content/shell/shell_browser_context.h b/content/shell/shell_browser_context.h
index 581febb..11220b0 100644
--- a/content/shell/shell_browser_context.h
+++ b/content/shell/shell_browser_context.h
@@ -43,6 +43,9 @@ class ShellBrowserContext : public BrowserContext {
virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
private:
+ // Performs initialization of the ShellBrowserContext while IO is still
+ // allowed on the current thread.
+ void InitWhileIOAllowed();
FilePath path_;
scoped_ptr<ResourceContext> resource_context_;
diff --git a/content/shell/shell_browser_main.cc b/content/shell/shell_browser_main.cc
index 5a1755a..f1343d9 100644
--- a/content/shell/shell_browser_main.cc
+++ b/content/shell/shell_browser_main.cc
@@ -6,6 +6,7 @@
#include "base/command_line.h"
#include "base/memory/scoped_ptr.h"
+#include "base/threading/thread_restrictions.h"
#include "content/public/browser/browser_main_runner.h"
#include "content/shell/shell.h"
#include "content/shell/shell_browser_context.h"
@@ -31,7 +32,11 @@ GURL GetURLForLayoutTest(const char* test_name) {
}
// TODO(jochen): use pixel_hash and timeout.
GURL test_url = webkit_support::CreateURLForPathOrURL(path_or_url);
- webkit_support::SetCurrentDirectoryForFileURL(test_url);
+ {
+ // We're outside of the message loop here, and this is a test.
+ base::ThreadRestrictions::ScopedAllowIO allow_io;
+ webkit_support::SetCurrentDirectoryForFileURL(test_url);
+ }
return test_url;
}
@@ -69,7 +74,8 @@ int ShellBrowserMain(const content::MainFunctionParams& parameters) {
MSG_ROUTING_NONE,
NULL);
main_runner_->Run();
- // TODO(jochen): Figure out a way to close shell.
+
+ content::Shell::CloseAllWindows();
}
exit_code = 0;
} else {
diff --git a/content/shell/shell_gtk.cc b/content/shell/shell_gtk.cc
index 5854091..31d5baa 100644
--- a/content/shell/shell_gtk.cc
+++ b/content/shell/shell_gtk.cc
@@ -8,7 +8,6 @@
#include <gtk/gtk.h>
#include "base/logging.h"
-#include "base/message_loop.h"
#include "base/string_piece.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/native_web_keyboard_event.h"
@@ -178,6 +177,10 @@ void Shell::PlatformResizeSubViews() {
SizeTo(content_width_, content_height_);
}
+void Shell::Close() {
+ gtk_widget_destroy(GTK_WIDGET(window_));
+}
+
void Shell::OnBackButtonClicked(GtkWidget* widget) {
GoBackOrForward(-1);
}
@@ -205,12 +208,6 @@ void Shell::OnURLEntryActivate(GtkWidget* entry) {
// Callback for when the main window is destroyed.
gboolean Shell::OnWindowDestroyed(GtkWidget* window) {
delete this;
-
- if (windows_.empty()) {
- MessageLoop::current()->PostTask(FROM_HERE,
- MessageLoop::QuitClosure());
- }
-
return FALSE; // Don't stop this message.
}
diff --git a/content/shell/shell_mac.mm b/content/shell/shell_mac.mm
index 2e561b3..63e6211 100644
--- a/content/shell/shell_mac.mm
+++ b/content/shell/shell_mac.mm
@@ -215,6 +215,10 @@ void Shell::PlatformResizeSubViews() {
// Not needed; subviews are bound.
}
+void Shell::Close() {
+ [window_ performClose:nil];
+}
+
void Shell::ActionPerformed(int control) {
switch (control) {
case IDC_NAV_BACK:
diff --git a/content/shell/shell_win.cc b/content/shell/shell_win.cc
index 20fe1a0..d69e00b 100644
--- a/content/shell/shell_win.cc
+++ b/content/shell/shell_win.cc
@@ -7,7 +7,6 @@
#include <windows.h>
#include <commctrl.h>
-#include "base/message_loop.h"
#include "base/string_piece.h"
#include "base/utf_string_conversions.h"
#include "base/win/resource_util.h"
@@ -182,6 +181,10 @@ void Shell::PlatformResizeSubViews() {
rc.bottom - kURLBarHeight, TRUE);
}
+void Shell::Close() {
+ DestroyWindow(window_);
+}
+
ATOM Shell::RegisterWindowClass() {
WNDCLASSEX wcex = {
sizeof(WNDCLASSEX),
@@ -236,8 +239,6 @@ LRESULT CALLBACK Shell::WndProc(HWND hwnd, UINT message, WPARAM wParam,
}
case WM_DESTROY: {
delete shell;
- if (windows_.empty())
- MessageLoop::current()->Quit();
return 0;
}