Skip to content

Commit

Permalink
Add a new switch: --allow-scripts-to-close-windows.
Browse files Browse the repository at this point in the history
With this switch, window.close() will always be enabled.

Currently the switch is only available in test_shell.
Review URL: http://codereview.chromium.org/2915

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2333 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
patrick@chromium.org committed Sep 17, 2008
1 parent cbbe217 commit 1de1aa6
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 2 deletions.
4 changes: 3 additions & 1 deletion webkit/glue/webpreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct WebPreferences {
bool text_areas_are_resizable;
bool dashboard_compatibility_mode;
bool java_enabled;
bool allow_scripts_to_close_windows;

// TODO(tc): User style sheets will not work in chrome because it tries to
// load the style sheet using a request without a frame.
Expand Down Expand Up @@ -71,7 +72,8 @@ struct WebPreferences {
text_areas_are_resizable(true),
dashboard_compatibility_mode(false),
java_enabled(true),
user_style_sheet_enabled(false) {
user_style_sheet_enabled(false),
allow_scripts_to_close_windows(false) {
}
};

Expand Down
2 changes: 2 additions & 0 deletions webkit/glue/webview_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,8 @@ void WebViewImpl::SetPreferences(const WebPreferences& preferences) {
preferences.shrinks_standalone_images_to_fit);
settings->setUsesUniversalDetector(preferences.uses_universal_detector);
settings->setTextAreasAreResizable(preferences.text_areas_are_resizable);
settings->setAllowScriptsToCloseWindows(
preferences.allow_scripts_to_close_windows);
if (preferences.user_style_sheet_enabled) {
settings->setUserStyleSheetLocation(webkit_glue::GURLToKURL(
preferences.user_style_sheet_location));
Expand Down
9 changes: 8 additions & 1 deletion webkit/pending/DOMWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "PlatformScreen.h"
#include "PlatformString.h"
#include "Screen.h"
#include "Settings.h"
#include <algorithm>
#include <wtf/MathExtras.h>

Expand Down Expand Up @@ -345,7 +346,13 @@ void DOMWindow::close()
if (!m_frame)
return;

if (m_frame->loader()->openedByDOM() || m_frame->loader()->getHistoryLength() <= 1)
Settings* settings = m_frame->settings();
bool allow_scripts_to_close_windows =
(settings && settings->allowScriptsToCloseWindows());

if (m_frame->loader()->openedByDOM()
|| m_frame->loader()->getHistoryLength() <= 1
|| allow_scripts_to_close_windows)
m_frame->scheduleClose();
}

Expand Down
6 changes: 6 additions & 0 deletions webkit/pending/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Settings::Settings(Page* page)
, m_needsSiteSpecificQuirks(false)
, m_fontRenderingMode(0)
, m_usesEncodingDetector(false)
, m_allow_scripts_to_close_windows(false)
{
// A Frame may not have been created yet, so we initialize the AtomicString
// hash before trying to use it.
Expand Down Expand Up @@ -329,4 +330,9 @@ void Settings::setUsesUniversalDetector(bool usesEncodingDetector)
m_usesEncodingDetector = usesEncodingDetector;
}

void Settings::setAllowScriptsToCloseWindows(bool allow_scripts_to_close_windows)
{
m_allow_scripts_to_close_windows = allow_scripts_to_close_windows;
}

} // namespace WebCore
4 changes: 4 additions & 0 deletions webkit/pending/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ namespace WebCore {
void setNeedsSiteSpecificQuirks(bool);
bool needsSiteSpecificQuirks() const { return m_needsSiteSpecificQuirks; }

void setAllowScriptsToCloseWindows(bool);
bool allowScriptsToCloseWindows() const { return m_allow_scripts_to_close_windows; }

private:
Page* m_page;

Expand Down Expand Up @@ -191,6 +194,7 @@ namespace WebCore {
bool m_needsSiteSpecificQuirks : 1;
unsigned m_fontRenderingMode : 1;
bool m_usesEncodingDetector : 1;
bool m_allow_scripts_to_close_windows : 1;
};

} // namespace WebCore
Expand Down
7 changes: 7 additions & 0 deletions webkit/tools/test_shell/test_shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ void TestShell::CleanupLogging() {
logging::CloseLogFile();
}

// static
void TestShell::SetAllowScriptsToCloseWindows() {
if (web_prefs_)
web_prefs_->allow_scripts_to_close_windows = true;
}

// static
void TestShell::InitializeTestShell(bool interactive) {
// Start COM stuff.
Expand Down Expand Up @@ -244,6 +250,7 @@ void TestShell::ResetWebPreferences() {
web_prefs_->user_agent = webkit_glue::GetDefaultUserAgent();
web_prefs_->dashboard_compatibility_mode = false;
web_prefs_->java_enabled = true;
web_prefs_->allow_scripts_to_close_windows = false;
}
}

Expand Down
2 changes: 2 additions & 0 deletions webkit/tools/test_shell/test_shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ class TestShell {

static void ResetWebPreferences();

static void SetAllowScriptsToCloseWindows();

WebPreferences* GetWebPreferences() { return web_prefs_; }

// Some layout tests hardcode a file:///tmp/LayoutTests URL. We get around
Expand Down
3 changes: 3 additions & 0 deletions webkit/tools/test_shell/test_shell_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ int main(int argc, char* argv[])
bool interactive = !layout_test_mode;
TestShell::InitializeTestShell(interactive);

if (parsed_command_line.HasSwitch(test_shell::kAllowScriptsToCloseWindows))
TestShell::SetAllowScriptsToCloseWindows();

// Disable user themes for layout tests so pixel tests are consistent.
if (!interactive)
gfx::NativeTheme::instance()->DisableTheming();
Expand Down
3 changes: 3 additions & 0 deletions webkit/tools/test_shell/test_shell_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,8 @@ const wchar_t kUseNewHttp[] = L"new-http";
// Enable tracing events (see base/trace_event.h)
const wchar_t kEnableTracing[] = L"enable-tracing";

// Allow scripts to close windows in all cases.
const wchar_t kAllowScriptsToCloseWindows[] = L"allow-scripts-to-close-windows";

} // namespace test_shell

1 change: 1 addition & 0 deletions webkit/tools/test_shell/test_shell_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ extern const wchar_t kDebugMemoryInUse[];
extern const wchar_t kEnableFileCookies[];
extern const wchar_t kUseNewHttp[];
extern const wchar_t kEnableTracing[];
extern const wchar_t kAllowScriptsToCloseWindows[];

} // namespace test_shell

Expand Down

0 comments on commit 1de1aa6

Please sign in to comment.