diff options
author | beng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-13 19:40:50 +0000 |
---|---|---|
committer | beng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-13 19:40:50 +0000 |
commit | fb8f5e9fe66c66122b14fc3de2e9a97b786dd787 (patch) | |
tree | 1dcbf497a86aa56d96dfeeead9ccb2ac4d40415b /chrome/browser/views | |
parent | 5e41359d62d6742eecc04cf8cf487ff8c896bfbb (diff) | |
download | chromium_src-fb8f5e9fe66c66122b14fc3de2e9a97b786dd787.zip chromium_src-fb8f5e9fe66c66122b14fc3de2e9a97b786dd787.tar.gz chromium_src-fb8f5e9fe66c66122b14fc3de2e9a97b786dd787.tar.bz2 |
Move more UI stuff into browser/views
B=2205
Review URL: http://codereview.chromium.org/2825
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2169 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
46 files changed, 1645 insertions, 37 deletions
diff --git a/chrome/browser/views/about_chrome_view.cc b/chrome/browser/views/about_chrome_view.cc index 6766a9b..02eb5ce 100644 --- a/chrome/browser/views/about_chrome_view.cc +++ b/chrome/browser/views/about_chrome_view.cc @@ -12,9 +12,9 @@ #include "chrome/app/locales/locale_settings.h" #include "chrome/app/theme/theme_resources.h" #include "chrome/common/gfx/color_utils.h" -#include "chrome/browser/standard_layout.h" #include "chrome/browser/user_metrics.h" #include "chrome/browser/views/restart_message_box.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/common/l10n_util.h" #include "chrome/common/resource_bundle.h" #include "chrome/common/chrome_constants.h" diff --git a/chrome/browser/views/bookmark_bubble_view.cc b/chrome/browser/views/bookmark_bubble_view.cc index 476391e..12dd987 100644 --- a/chrome/browser/views/bookmark_bubble_view.cc +++ b/chrome/browser/views/bookmark_bubble_view.cc @@ -8,10 +8,10 @@ #include "chrome/app/theme/theme_resources.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/profile.h" -#include "chrome/browser/standard_layout.h" #include "chrome/browser/user_metrics.h" #include "chrome/browser/views/bookmark_editor_view.h" #include "chrome/browser/views/info_bubble.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/l10n_util.h" #include "chrome/common/notification_service.h" diff --git a/chrome/browser/views/bookmark_editor_view.cc b/chrome/browser/views/bookmark_editor_view.cc index 549474c..2d777b3 100644 --- a/chrome/browser/views/bookmark_editor_view.cc +++ b/chrome/browser/views/bookmark_editor_view.cc @@ -10,8 +10,8 @@ #include "chrome/app/locales/locale_settings.h" #include "chrome/browser/history/history.h" #include "chrome/browser/profile.h" -#include "chrome/browser/standard_layout.h" #include "chrome/browser/url_fixer_upper.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/common/l10n_util.h" #include "chrome/views/background.h" #include "chrome/views/focus_manager.h" diff --git a/chrome/browser/views/browser_views.vcproj b/chrome/browser/views/browser_views.vcproj index 15054b5..6a36ee7 100644 --- a/chrome/browser/views/browser_views.vcproj +++ b/chrome/browser/views/browser_views.vcproj @@ -562,6 +562,14 @@ > </File> <File + RelativePath=".\external_protocol_dialog.cc" + > + </File> + <File + RelativePath=".\external_protocol_dialog.h" + > + </File> + <File RelativePath=".\first_run_bubble.cc" > </File> @@ -602,6 +610,14 @@ > </File> <File + RelativePath=".\html_dialog_view.cc" + > + </File> + <File + RelativePath=".\html_dialog_view.h" + > + </File> + <File RelativePath=".\hung_renderer_view.cc" > </File> @@ -682,6 +698,14 @@ > </File> <File + RelativePath=".\page_info_window.cc" + > + </File> + <File + RelativePath=".\page_info_window.h" + > + </File> + <File RelativePath=".\password_manager_view.cc" > </File> @@ -714,6 +738,14 @@ > </File> <File + RelativePath=".\restart_message_box.cc" + > + </File> + <File + RelativePath=".\restart_message_box.h" + > + </File> + <File RelativePath=".\sad_tab_view.cc" > </File> @@ -734,6 +766,10 @@ > </File> <File + RelativePath=".\standard_layout.h" + > + </File> + <File RelativePath=".\star_toggle.cc" > </File> @@ -750,6 +786,14 @@ > </File> <File + RelativePath=".\tab_contents_container_view.cc" + > + </File> + <File + RelativePath=".\tab_contents_container_view.h" + > + </File> + <File RelativePath=".\theme_helpers.cc" > </File> @@ -774,6 +818,14 @@ > </File> <File + RelativePath=".\user_data_dir_dialog.cc" + > + </File> + <File + RelativePath=".\user_data_dir_dialog.h" + > + </File> + <File RelativePath=".\window_resources.cc" > </File> diff --git a/chrome/browser/views/bug_report_view.cc b/chrome/browser/views/bug_report_view.cc index cbc592c..b1dfacb 100644 --- a/chrome/browser/views/bug_report_view.cc +++ b/chrome/browser/views/bug_report_view.cc @@ -15,7 +15,7 @@ #include "chrome/browser/safe_browsing/safe_browsing_util.h" #include "chrome/browser/tab_contents.h" #include "chrome/browser/url_fetcher.h" -#include "chrome/browser/standard_layout.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/common/l10n_util.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" diff --git a/chrome/browser/views/clear_browsing_data.cc b/chrome/browser/views/clear_browsing_data.cc index c8e3ea6..c81b63d 100644 --- a/chrome/browser/views/clear_browsing_data.cc +++ b/chrome/browser/views/clear_browsing_data.cc @@ -6,8 +6,8 @@ #include "chrome/app/locales/locale_settings.h" #include "chrome/browser/profile.h" -#include "chrome/browser/standard_layout.h" #include "chrome/browser/template_url_model.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/common/l10n_util.h" #include "chrome/views/background.h" #include "chrome/views/checkbox.h" diff --git a/chrome/browser/views/edit_keyword_controller.cc b/chrome/browser/views/edit_keyword_controller.cc index 63cffaa..ba9fcbb 100644 --- a/chrome/browser/views/edit_keyword_controller.cc +++ b/chrome/browser/views/edit_keyword_controller.cc @@ -7,12 +7,12 @@ #include "base/string_util.h" #include "chrome/app/theme/theme_resources.h" #include "chrome/browser/profile.h" -#include "chrome/browser/standard_layout.h" #include "chrome/browser/template_url.h" #include "chrome/browser/template_url_model.h" #include "chrome/browser/url_fixer_upper.h" #include "chrome/browser/user_metrics.h" #include "chrome/browser/views/keyword_editor_view.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/common/l10n_util.h" #include "chrome/common/resource_bundle.h" #include "chrome/views/label.h" diff --git a/chrome/browser/views/external_protocol_dialog.cc b/chrome/browser/views/external_protocol_dialog.cc new file mode 100644 index 0000000..cc85b0e --- /dev/null +++ b/chrome/browser/views/external_protocol_dialog.cc @@ -0,0 +1,142 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/views/external_protocol_dialog.h" + +#include "base/registry.h" +#include "base/string_util.h" +#include "base/thread.h" +#include "chrome/browser/browser_process.h" +#include "chrome/browser/external_protocol_handler.h" +#include "chrome/browser/tab_util.h" +#include "chrome/browser/tab_contents.h" +#include "chrome/common/l10n_util.h" +#include "chrome/views/message_box_view.h" +#include "chrome/views/window.h" + +#include "chromium_strings.h" +#include "generated_resources.h" + +namespace { + +const int kMessageWidth = 400; + +} // namespace + +/////////////////////////////////////////////////////////////////////////////// +// ExternalProtocolDialog, public: + +// static +void ExternalProtocolDialog::RunExternalProtocolDialog( + const GURL& url, const std::wstring& command, int render_process_host_id, + int routing_id) { + TabContents* tab_contents = tab_util::GetTabContentsByID( + render_process_host_id, routing_id); + ExternalProtocolDialog* handler = + new ExternalProtocolDialog(tab_contents, url, command); +} + +ExternalProtocolDialog::~ExternalProtocolDialog() { +} + +////////////////////////////////////////////////////////////////////////////// +// ExternalProtocolDialog, ChromeViews::DialogDelegate implementation: + +int ExternalProtocolDialog::GetDialogButtons() const { + return DIALOGBUTTON_OK | DIALOGBUTTON_CANCEL; +} + +int ExternalProtocolDialog::GetDefaultDialogButton() const { + return DIALOGBUTTON_CANCEL; +} + +std::wstring ExternalProtocolDialog::GetDialogButtonLabel( + DialogButton button) const { + if (button == DIALOGBUTTON_OK) + return l10n_util::GetString(IDS_EXTERNAL_PROTOCOL_OK_BUTTON_TEXT); + + // Set the button to have a default name. + return L""; +} + +std::wstring ExternalProtocolDialog::GetWindowTitle() const { + return l10n_util::GetString(IDS_EXTERNAL_PROTOCOL_TITLE); +} + +void ExternalProtocolDialog::WindowClosing() { + delete this; +} + +bool ExternalProtocolDialog::Accept() { + MessageLoop* io_loop = g_browser_process->io_thread()->message_loop(); + if (io_loop == NULL) { + // Returning true closes the dialog. + return true; + } + + // Attempt to launch the application on the IO loop. + io_loop->PostTask(FROM_HERE, + NewRunnableFunction( + &ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck, url_)); + return true; +} + +ChromeViews::View* ExternalProtocolDialog::GetContentsView() { + return message_box_view_; +} + +/////////////////////////////////////////////////////////////////////////////// +// ExternalProtocolDialog, private: + +ExternalProtocolDialog::ExternalProtocolDialog(TabContents* tab_contents, + const GURL& url, + const std::wstring& command) + : tab_contents_(tab_contents), + url_(url) { + std::wstring message_text = l10n_util::GetStringF( + IDS_EXTERNAL_PROTOCOL_INFORMATION, + ASCIIToWide(url.scheme() + ":"), + ASCIIToWide(url.possibly_invalid_spec())) + L"\n\n"; + + message_text += l10n_util::GetStringF( + IDS_EXTERNAL_PROTOCOL_APPLICATION_TO_LAUNCH, command) + L"\n\n"; + + message_text += l10n_util::GetString(IDS_EXTERNAL_PROTOCOL_WARNING); + + message_box_view_ = new MessageBoxView(MessageBoxView::kIsConfirmMessageBox, + message_text, + L"", + kMessageWidth); + HWND root_hwnd; + if (tab_contents_) { + root_hwnd = GetAncestor(tab_contents_->GetContentHWND(), GA_ROOT); + } else { + // Dialog is top level if we don't have a tab_contents associated with us. + root_hwnd = NULL; + } + + ChromeViews::Window::CreateChromeWindow(root_hwnd, gfx::Rect(), this)->Show(); +} + +/* static */ +std::wstring ExternalProtocolDialog::GetApplicationForProtocol( + const GURL& url) { + std::wstring url_spec = ASCIIToWide(url.possibly_invalid_spec()); + std::wstring cmd_key_path = + ASCIIToWide(url.scheme() + "\\shell\\open\\command"); + RegKey cmd_key(HKEY_CLASSES_ROOT, cmd_key_path.c_str(), KEY_READ); + size_t split_offset = url_spec.find(L':'); + if (split_offset == std::wstring::npos) + return std::wstring(); + std::wstring parameters = url_spec.substr(split_offset + 1, + url_spec.length() - 1); + std::wstring application_to_launch; + if (cmd_key.ReadValue(NULL, &application_to_launch)) { + ReplaceSubstringsAfterOffset(&application_to_launch, 0, L"%1", parameters); + return application_to_launch; + } else { + return std::wstring(); + } +} + diff --git a/chrome/browser/views/external_protocol_dialog.h b/chrome/browser/views/external_protocol_dialog.h new file mode 100644 index 0000000..0c48e34 --- /dev/null +++ b/chrome/browser/views/external_protocol_dialog.h @@ -0,0 +1,69 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_EXTERNAL_PROTOCOL_DIALOG_H__ +#define CHROME_BROWSER_EXTERNAL_PROTOCOL_DIALOG_H__ + +#include "chrome/views/dialog_delegate.h" +#include "googleurl/src/gurl.h" + +class MessageBoxView; +class TabContents; + +class ExternalProtocolDialog : public ChromeViews::DialogDelegate { + public: + // Creates and runs a External Protocol dialog box. + // |url| - The url of the request. + // |command| - the command that ShellExecute will run. + // |render_process_host_id| and |routing_id| are used by + // tab_util::GetTabContentsByID to aquire the tab contents associated with + // this dialog. + // NOTE: There is a race between the Time of Check and the Time Of Use for + // the command line. Since the caller (web page) does not have access + // to change the command line by itself, we do not do anything special + // to protect against this scenario. + static void RunExternalProtocolDialog(const GURL& url, + const std::wstring& command, + int render_process_host_id, + int routing_id); + + // Returns the path of the application to be launched given the protocol + // of the requested url. Returns an empty string on failure. + static std::wstring GetApplicationForProtocol(const GURL& url); + + virtual ~ExternalProtocolDialog(); + + // ChromeViews::DialogDelegate Methods: + virtual int GetDialogButtons() const; + virtual int GetDefaultDialogButton() const; + virtual std::wstring GetDialogButtonLabel(DialogButton button) const; + virtual std::wstring GetWindowTitle() const; + virtual void WindowClosing(); + virtual bool Accept(); + virtual ChromeViews::View* GetContentsView(); + + // ChromeViews::WindowDelegate Methods: + virtual bool IsAlwaysOnTop() const { return false; } + virtual bool IsModal() const { return false; } + + private: + // RunExternalProtocolDialog calls this private constructor. + ExternalProtocolDialog(TabContents* tab_contents, + const GURL& url, + const std::wstring& command); + + // The message box view whose commands we handle. + MessageBoxView* message_box_view_; + + // The associated TabContents. + TabContents* tab_contents_; + + // URL of the external protocol request. + GURL url_; + + DISALLOW_EVIL_CONSTRUCTORS(ExternalProtocolDialog); +}; + +#endif // CHROME_BROWSER_EXTERNAL_PROTOCOL_DIALOG_H__ + diff --git a/chrome/browser/views/first_run_bubble.cc b/chrome/browser/views/first_run_bubble.cc index 0221814..6696e55 100644 --- a/chrome/browser/views/first_run_bubble.cc +++ b/chrome/browser/views/first_run_bubble.cc @@ -9,8 +9,8 @@ #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_window.h" #include "chrome/browser/options_window.h" -#include "chrome/browser/standard_layout.h" #include "chrome/browser/template_url_model.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/common/l10n_util.h" #include "chrome/common/resource_bundle.h" #include "chrome/views/event.h" diff --git a/chrome/browser/views/first_run_customize_view.cc b/chrome/browser/views/first_run_customize_view.cc index d5c91351..1109ac9 100644 --- a/chrome/browser/views/first_run_customize_view.cc +++ b/chrome/browser/views/first_run_customize_view.cc @@ -9,8 +9,8 @@ #include "chrome/browser/importer/importer.h" #include "chrome/browser/first_run.h" #include "chrome/browser/shell_integration.h" -#include "chrome/browser/standard_layout.h" #include "chrome/browser/user_metrics.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/common/l10n_util.h" #include "chrome/common/resource_bundle.h" #include "chrome/views/checkbox.h" diff --git a/chrome/browser/views/first_run_view.cc b/chrome/browser/views/first_run_view.cc index e4fc454..9e581e3 100644 --- a/chrome/browser/views/first_run_view.cc +++ b/chrome/browser/views/first_run_view.cc @@ -8,8 +8,8 @@ #include "chrome/app/theme/theme_resources.h" #include "chrome/browser/importer/importer.h" #include "chrome/browser/first_run.h" -#include "chrome/browser/standard_layout.h" #include "chrome/browser/views/first_run_customize_view.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/browser/user_metrics.h" #include "chrome/common/l10n_util.h" #include "chrome/common/resource_bundle.h" diff --git a/chrome/browser/views/first_run_view_base.cc b/chrome/browser/views/first_run_view_base.cc index fcb5cce..e6aa69d 100644 --- a/chrome/browser/views/first_run_view_base.cc +++ b/chrome/browser/views/first_run_view_base.cc @@ -11,8 +11,8 @@ #include "chrome/app/theme/theme_resources.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/standard_layout.h" #include "chrome/browser/first_run.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/l10n_util.h" #include "chrome/common/pref_names.h" diff --git a/chrome/browser/views/frame/browser_view2.cc b/chrome/browser/views/frame/browser_view2.cc index af274ff..e72ec22 100644 --- a/chrome/browser/views/frame/browser_view2.cc +++ b/chrome/browser/views/frame/browser_view2.cc @@ -10,12 +10,12 @@ #include "chrome/browser/browser.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/encoding_menu_controller_delegate.h" -#include "chrome/browser/tab_contents_container_view.h" #include "chrome/browser/view_ids.h" #include "chrome/browser/views/bookmark_bar_view.h" #include "chrome/browser/views/download_shelf_view.h" #include "chrome/browser/views/frame/browser_frame.h" #include "chrome/browser/views/status_bubble.h" +#include "chrome/browser/views/tab_contents_container_view.h" #include "chrome/browser/views/tabs/tab_strip.h" #include "chrome/browser/views/toolbar_view.h" #include "chrome/common/drag_drop_types.h" diff --git a/chrome/browser/views/hung_renderer_view.cc b/chrome/browser/views/hung_renderer_view.cc index fa1691d..8138cc6 100644 --- a/chrome/browser/views/hung_renderer_view.cc +++ b/chrome/browser/views/hung_renderer_view.cc @@ -8,7 +8,7 @@ #include "chrome/app/theme/theme_resources.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/render_view_host.h" -#include "chrome/browser/standard_layout.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/browser/web_contents.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/gfx/chrome_canvas.h" diff --git a/chrome/browser/views/importer_lock_view.cc b/chrome/browser/views/importer_lock_view.cc index dc1c36b..2b8dc58 100644 --- a/chrome/browser/views/importer_lock_view.cc +++ b/chrome/browser/views/importer_lock_view.cc @@ -6,7 +6,7 @@ #include "chrome/app/locales/locale_settings.h" #include "chrome/browser/importer/importer.h" -#include "chrome/browser/standard_layout.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/common/l10n_util.h" #include "chrome/views/label.h" #include "chrome/views/window.h" diff --git a/chrome/browser/views/importer_view.cc b/chrome/browser/views/importer_view.cc index afa8eb2..b8ee784 100644 --- a/chrome/browser/views/importer_view.cc +++ b/chrome/browser/views/importer_view.cc @@ -6,7 +6,7 @@ #include "chrome/app/locales/locale_settings.h" #include "chrome/browser/browser_list.h" -#include "chrome/browser/standard_layout.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/common/l10n_util.h" #include "chrome/views/checkbox.h" #include "chrome/views/grid_layout.h" diff --git a/chrome/browser/views/importing_progress_view.cc b/chrome/browser/views/importing_progress_view.cc index 8dbc8ec..77f842f 100644 --- a/chrome/browser/views/importing_progress_view.cc +++ b/chrome/browser/views/importing_progress_view.cc @@ -5,7 +5,7 @@ #include "chrome/browser/views/importing_progress_view.h" #include "chrome/app/locales/locale_settings.h" -#include "chrome/browser/standard_layout.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/common/l10n_util.h" #include "chrome/views/grid_layout.h" #include "chrome/views/label.h" diff --git a/chrome/browser/views/info_bar_alternate_nav_url_view.cc b/chrome/browser/views/info_bar_alternate_nav_url_view.cc index 7237914..24477f3 100644 --- a/chrome/browser/views/info_bar_alternate_nav_url_view.cc +++ b/chrome/browser/views/info_bar_alternate_nav_url_view.cc @@ -5,10 +5,10 @@ #include "chrome/browser/views/info_bar_alternate_nav_url_view.h" #include "chrome/app/theme/theme_resources.h" -#include "chrome/browser/standard_layout.h" #include "chrome/browser/web_contents.h" #include "chrome/browser/views/event_utils.h" #include "chrome/browser/views/info_bar_view.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/common/l10n_util.h" #include "chrome/common/page_transition_types.h" #include "chrome/common/resource_bundle.h" diff --git a/chrome/browser/views/info_bar_confirm_view.cc b/chrome/browser/views/info_bar_confirm_view.cc index 7a4728a..57ffc53 100644 --- a/chrome/browser/views/info_bar_confirm_view.cc +++ b/chrome/browser/views/info_bar_confirm_view.cc @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/standard_layout.h" #include "chrome/browser/views/info_bar_confirm_view.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/common/l10n_util.h" #include "generated_resources.h" diff --git a/chrome/browser/views/info_bar_item_view.cc b/chrome/browser/views/info_bar_item_view.cc index 0d111d0..d5b7411 100644 --- a/chrome/browser/views/info_bar_item_view.cc +++ b/chrome/browser/views/info_bar_item_view.cc @@ -3,8 +3,8 @@ // found in the LICENSE file. #include "chrome/app/theme/theme_resources.h" -#include "chrome/browser/standard_layout.h" #include "chrome/browser/views/info_bar_item_view.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/common/l10n_util.h" #include "chrome/common/resource_bundle.h" #include "chrome/views/external_focus_tracker.h" diff --git a/chrome/browser/views/input_window.cc b/chrome/browser/views/input_window.cc index c7d9698..77d7901 100644 --- a/chrome/browser/views/input_window.cc +++ b/chrome/browser/views/input_window.cc @@ -4,7 +4,7 @@ #include "chrome/browser/views/input_window.h" -#include "chrome/browser/standard_layout.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/common/l10n_util.h" #include "chrome/views/grid_layout.h" #include "chrome/views/label.h" diff --git a/chrome/browser/views/keyword_editor_view.cc b/chrome/browser/views/keyword_editor_view.cc index 3532d86..a4e446d 100644 --- a/chrome/browser/views/keyword_editor_view.cc +++ b/chrome/browser/views/keyword_editor_view.cc @@ -12,11 +12,11 @@ #include "chrome/app/theme/theme_resources.h" #include "chrome/browser/history/history.h" #include "chrome/browser/profile.h" -#include "chrome/browser/standard_layout.h" #include "chrome/browser/template_url.h" #include "chrome/browser/template_url_model.h" #include "chrome/browser/user_metrics.h" #include "chrome/browser/views/edit_keyword_controller.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/common/l10n_util.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" diff --git a/chrome/browser/views/location_bar_view.cc b/chrome/browser/views/location_bar_view.cc index ce9da67..d5eba49 100644 --- a/chrome/browser/views/location_bar_view.cc +++ b/chrome/browser/views/location_bar_view.cc @@ -13,13 +13,13 @@ #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/navigation_entry.h" -#include "chrome/browser/page_info_window.h" #include "chrome/browser/profile.h" #include "chrome/browser/template_url.h" #include "chrome/browser/template_url_model.h" #include "chrome/browser/view_ids.h" #include "chrome/browser/views/info_bubble.h" #include "chrome/browser/views/first_run_bubble.h" +#include "chrome/browser/views/page_info_window.h" #include "chrome/common/l10n_util.h" #include "chrome/common/resource_bundle.h" #include "chrome/common/gfx/chrome_canvas.h" diff --git a/chrome/browser/views/login_view.cc b/chrome/browser/views/login_view.cc index bb5eb86..ccbad1f 100644 --- a/chrome/browser/views/login_view.cc +++ b/chrome/browser/views/login_view.cc @@ -7,7 +7,7 @@ #include "chrome/browser/views/login_view.h" #include "base/message_loop.h" -#include "chrome/browser/standard_layout.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/common/l10n_util.h" #include "chrome/views/grid_layout.h" #include "chrome/views/label.h" diff --git a/chrome/browser/views/old_frames/simple_vista_frame.cc b/chrome/browser/views/old_frames/simple_vista_frame.cc index fc25e6a..c7090d7 100644 --- a/chrome/browser/views/old_frames/simple_vista_frame.cc +++ b/chrome/browser/views/old_frames/simple_vista_frame.cc @@ -8,7 +8,7 @@ #include "chrome/browser/browser.h" #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents.h" -#include "chrome/browser/tab_contents_container_view.h" +#include "chrome/browser/views/tab_contents_container_view.h" #include "chrome/browser/web_app.h" #include "chrome/browser/web_app_icon_manager.h" #include "chrome/browser/web_contents.h" diff --git a/chrome/browser/views/old_frames/simple_xp_frame.cc b/chrome/browser/views/old_frames/simple_xp_frame.cc index 4c4d506..d4bf51a 100644 --- a/chrome/browser/views/old_frames/simple_xp_frame.cc +++ b/chrome/browser/views/old_frames/simple_xp_frame.cc @@ -9,8 +9,8 @@ #include "chrome/browser/browser.h" #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents.h" -#include "chrome/browser/tab_contents_container_view.h" #include "chrome/browser/views/location_bar_view.h" +#include "chrome/browser/views/tab_contents_container_view.h" #include "chrome/browser/views/tabs/tab.h" #include "chrome/browser/web_app.h" #include "chrome/browser/web_app_icon_manager.h" diff --git a/chrome/browser/views/old_frames/vista_frame.cc b/chrome/browser/views/old_frames/vista_frame.cc index faa1213..ef531c0 100644 --- a/chrome/browser/views/old_frames/vista_frame.cc +++ b/chrome/browser/views/old_frames/vista_frame.cc @@ -20,11 +20,11 @@ #include "chrome/browser/frame_util.h" #include "chrome/browser/suspend_controller.h" #include "chrome/browser/tab_contents.h" -#include "chrome/browser/tab_contents_container_view.h" #include "chrome/browser/view_ids.h" #include "chrome/browser/views/bookmark_bar_view.h" #include "chrome/browser/views/download_shelf_view.h" #include "chrome/browser/views/frame/browser_view.h" +#include "chrome/browser/views/tab_contents_container_view.h" #include "chrome/browser/views/tabs/tab_strip.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/gfx/chrome_canvas.h" diff --git a/chrome/browser/views/old_frames/xp_frame.cc b/chrome/browser/views/old_frames/xp_frame.cc index 6a33d77..1a02f3a 100644 --- a/chrome/browser/views/old_frames/xp_frame.cc +++ b/chrome/browser/views/old_frames/xp_frame.cc @@ -15,13 +15,13 @@ #include "chrome/browser/frame_util.h" #include "chrome/browser/suspend_controller.h" #include "chrome/browser/tab_contents.h" -#include "chrome/browser/tab_contents_container_view.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/view_ids.h" #include "chrome/browser/views/bookmark_bar_view.h" #include "chrome/browser/views/download_shelf_view.h" #include "chrome/browser/views/frame/browser_view.h" #include "chrome/browser/views/old_frames/point_buffer.h" +#include "chrome/browser/views/tab_contents_container_view.h" #include "chrome/browser/views/tabs/tab_strip.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" diff --git a/chrome/browser/views/options/advanced_contents_view.cc b/chrome/browser/views/options/advanced_contents_view.cc index 569ca31..fe00d42 100644 --- a/chrome/browser/views/options/advanced_contents_view.cc +++ b/chrome/browser/views/options/advanced_contents_view.cc @@ -25,10 +25,10 @@ #include "chrome/browser/net/dns_global.h" #include "chrome/browser/resource_dispatcher_host.h" #include "chrome/browser/safe_browsing/safe_browsing_service.h" -#include "chrome/browser/standard_layout.h" -#include "chrome/browser/views/restart_message_box.h" #include "chrome/browser/views/options/cookies_view.h" #include "chrome/browser/views/options/language_combobox_model.h" +#include "chrome/browser/views/restart_message_box.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/common/filter_policy.h" #include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/pref_member.h" diff --git a/chrome/browser/views/options/advanced_page_view.cc b/chrome/browser/views/options/advanced_page_view.cc index 3476134..2865882 100644 --- a/chrome/browser/views/options/advanced_page_view.cc +++ b/chrome/browser/views/options/advanced_page_view.cc @@ -7,8 +7,8 @@ #include "base/string_util.h" #include "base/values.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/standard_layout.h" #include "chrome/browser/views/options/advanced_contents_view.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/l10n_util.h" #include "chrome/common/pref_names.h" diff --git a/chrome/browser/views/options/content_page_view.cc b/chrome/browser/views/options/content_page_view.cc index b5d01dd..d138840a 100644 --- a/chrome/browser/views/options/content_page_view.cc +++ b/chrome/browser/views/options/content_page_view.cc @@ -15,10 +15,10 @@ #include "chrome/app/theme/theme_resources.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/shell_dialogs.h" -#include "chrome/browser/standard_layout.h" #include "chrome/browser/views/options/fonts_languages_window_view.h" #include "chrome/browser/views/options/options_group_view.h" #include "chrome/browser/views/password_manager_view.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/l10n_util.h" #include "chrome/common/pref_names.h" diff --git a/chrome/browser/views/options/cookies_view.cc b/chrome/browser/views/options/cookies_view.cc index 564fd83..5ba17fd 100644 --- a/chrome/browser/views/options/cookies_view.cc +++ b/chrome/browser/views/options/cookies_view.cc @@ -10,8 +10,8 @@ #include "base/time_format.h" #include "chrome/app/locales/locale_settings.h" #include "chrome/app/theme/theme_resources.h" -#include "chrome/browser/standard_layout.h" #include "chrome/browser/profile.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/common/gfx/color_utils.h" #include "chrome/common/l10n_util.h" #include "chrome/common/resource_bundle.h" diff --git a/chrome/browser/views/options/fonts_page_view.cc b/chrome/browser/views/options/fonts_page_view.cc index 09a82cf..0d9c559b 100644 --- a/chrome/browser/views/options/fonts_page_view.cc +++ b/chrome/browser/views/options/fonts_page_view.cc @@ -17,8 +17,8 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/character_encoding.h" #include "chrome/browser/shell_dialogs.h" -#include "chrome/browser/standard_layout.h" #include "chrome/browser/views/password_manager_view.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/gfx/chrome_font.h" #include "chrome/common/l10n_util.h" diff --git a/chrome/browser/views/options/general_page_view.cc b/chrome/browser/views/options/general_page_view.cc index a231872..6f178ef 100644 --- a/chrome/browser/views/options/general_page_view.cc +++ b/chrome/browser/views/options/general_page_view.cc @@ -17,12 +17,12 @@ #include "chrome/browser/profile.h" #include "chrome/browser/shell_integration.h" #include "chrome/browser/session_startup_pref.h" -#include "chrome/browser/standard_layout.h" #include "chrome/browser/template_url.h" #include "chrome/browser/template_url_model.h" #include "chrome/browser/url_fixer_upper.h" #include "chrome/browser/views/keyword_editor_view.h" #include "chrome/browser/views/options/options_group_view.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/l10n_util.h" #include "chrome/common/pref_names.h" diff --git a/chrome/browser/views/options/languages_page_view.cc b/chrome/browser/views/options/languages_page_view.cc index 485e35b..aa0e3b3 100644 --- a/chrome/browser/views/options/languages_page_view.cc +++ b/chrome/browser/views/options/languages_page_view.cc @@ -16,10 +16,10 @@ #include "chrome/app/theme/theme_resources.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/shell_dialogs.h" -#include "chrome/browser/standard_layout.h" #include "chrome/browser/views/options/language_combobox_model.h" #include "chrome/browser/views/password_manager_view.h" #include "chrome/browser/views/restart_message_box.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/gfx/chrome_font.h" #include "chrome/common/l10n_util.h" diff --git a/chrome/browser/views/options/options_group_view.cc b/chrome/browser/views/options/options_group_view.cc index 1046f75..d905d2b 100644 --- a/chrome/browser/views/options/options_group_view.cc +++ b/chrome/browser/views/options/options_group_view.cc @@ -10,7 +10,7 @@ #include "base/gfx/native_theme.h" #include "base/gfx/skia_utils.h" #include "chrome/app/locales/locale_settings.h" -#include "chrome/browser/standard_layout.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/common/gfx/chrome_font.h" #include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/l10n_util.h" diff --git a/chrome/browser/views/page_info_window.cc b/chrome/browser/views/page_info_window.cc new file mode 100644 index 0000000..2d80ded --- /dev/null +++ b/chrome/browser/views/page_info_window.cc @@ -0,0 +1,678 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/views/page_info_window.h" + +#include <cryptuiapi.h> +#pragma comment(lib, "cryptui.lib") + +#include "base/string_util.h" +#include "base/time_format.h" +#include "chrome/app/locales/locale_settings.h" +#include "chrome/app/theme/theme_resources.h" +#include "chrome/browser/browser_process.h" +#include "chrome/browser/cert_store.h" +#include "chrome/browser/history/history.h" +#include "chrome/browser/navigation_entry.h" +#include "chrome/browser/profile.h" +#include "chrome/browser/ssl_manager.h" +#include "chrome/browser/views/standard_layout.h" +#include "chrome/common/l10n_util.h" +#include "chrome/common/pref_names.h" +#include "chrome/common/pref_service.h" +#include "chrome/common/resource_bundle.h" +#include "chrome/common/win_util.h" +#include "chrome/views/background.h" +#include "chrome/views/grid_layout.h" +#include "chrome/views/image_view.h" +#include "chrome/views/label.h" +#include "chrome/views/native_button.h" +#include "chrome/views/separator.h" +#include "net/base/cert_status_flags.h" +#include "net/base/x509_certificate.h" +#include "skia/include/SkColor.h" +#include "generated_resources.h" + +const int kVerticalPadding = 10; +const int kHorizontalPadding = 10; + +//////////////////////////////////////////////////////////////////////////////// +// SecurityTabView +class SecurityTabView : public ChromeViews::View { + public: + SecurityTabView(Profile* profile, NavigationEntry* navigation_entry); + virtual ~SecurityTabView(); + + virtual void Layout(); + + // Add a section. + virtual void AddSection(const std::wstring& title, + bool state, + const std::wstring& head_line, + const std::wstring& description); + + private: + // A section contains an image that shows a status (good or bad), a title, + // an optional head-line (in bold) and a description. + class Section : public ChromeViews::View { + public: + Section(const std::wstring& title, + bool state, + const std::wstring& head_line, + const std::wstring& description); + virtual ~Section(); + + virtual int GetHeightForWidth(int w); + virtual void Layout(); + + private: + // The text placed on top of the section (on the left of the separator bar). + std::wstring title_; + + // Whether to show the good/bad icon. + bool state_; + + // The first line of the description, show in bold. + std::wstring head_line_; + + // The description, displayed below the head line. + std::wstring description_; + + static SkBitmap* good_state_icon_; + static SkBitmap* bad_state_icon_; + + ChromeViews::Label* title_label_; + ChromeViews::Separator* separator_; + ChromeViews::ImageView* status_image_; + ChromeViews::Label* head_line_label_; + ChromeViews::Label* description_label_; + + DISALLOW_EVIL_CONSTRUCTORS(Section); + }; + + // Returns a name that can be used to represent the issuer. It tries in this + // order CN, O and OU and returns the first non-empty one found. + static std::string GetIssuerName( + const net::X509Certificate::Principal& issuer); + + // Callback from history service with number of visits to url. + void OnGotVisitCountToHost(HistoryService::Handle handle, + bool found_visits, + int count, + Time first_visit); + + std::vector<Section*> sections_; + + // Used to request number of visits. + CancelableRequestConsumer request_consumer_; + + DISALLOW_EVIL_CONSTRUCTORS(SecurityTabView); +}; + +// static +SkBitmap* SecurityTabView::Section::good_state_icon_ = NULL; +SkBitmap* SecurityTabView::Section::bad_state_icon_ = NULL; + +// Layout constants. +static const int kHGapToBorder = 6; +static const int kVGapToBorder = 6; +static const int kHGapTitleToSeparator = 2; +static const int kVGapTitleToImage = 6; +static const int kHGapImageToDescription = 6; +static const int kVGapHeadLineToDescription = 2; +static const int kVGapBetweenSections = 20; +static const int kHExtraSeparatorPadding = 2; + +SecurityTabView::Section::Section(const std::wstring& title, bool state, + const std::wstring& head_line, + const std::wstring& description) + : title_(title), + state_(state), + head_line_(head_line), + description_(description) { + if (!good_state_icon_) { + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + good_state_icon_ = rb.GetBitmapNamed(IDR_PAGEINFO_GOOD); + bad_state_icon_ = rb.GetBitmapNamed(IDR_PAGEINFO_BAD); + } + title_label_ = new ChromeViews::Label(title); + title_label_->SetHorizontalAlignment(ChromeViews::Label::ALIGN_LEFT); + AddChildView(title_label_); + + separator_ = new ChromeViews::Separator(); + AddChildView(separator_); + + status_image_ = new ChromeViews::ImageView(); + status_image_->SetImage(state ? good_state_icon_ : bad_state_icon_); + AddChildView(status_image_); + + head_line_label_ = new ChromeViews::Label(head_line); + head_line_label_->SetFont( + head_line_label_->GetFont().DeriveFont(0, ChromeFont::BOLD)); + head_line_label_->SetHorizontalAlignment(ChromeViews::Label::ALIGN_LEFT); + AddChildView(head_line_label_); + + description_label_ = new ChromeViews::Label(description); + description_label_->SetMultiLine(true); + description_label_->SetHorizontalAlignment(ChromeViews::Label::ALIGN_LEFT); + AddChildView(description_label_); +} + +SecurityTabView::Section::~Section() { +} + +int SecurityTabView::Section::GetHeightForWidth(int width) { + // The height of the section depends on the height of the description label + // (multi-line). We need to know the width of the description label to know + // its height. + int height = 0; + CSize size; + title_label_->GetPreferredSize(&size); + height += size.cy + kVGapTitleToImage; + + CSize image_size; + status_image_->GetPreferredSize(&image_size); + + int text_height = 0; + if (!head_line_label_->GetText().empty()) { + head_line_label_->GetPreferredSize(&size); + text_height = size.cy + kVGapHeadLineToDescription; + } + + int description_width = width - image_size.cx - kHGapImageToDescription - + kHGapToBorder; + text_height += description_label_->GetHeightForWidth(description_width); + + height += std::max(static_cast<int>(image_size.cy), text_height); + + return height; +} + +void SecurityTabView::Section::Layout() { + // First, layout the title and separator. + int x = 0; + int y = 0; + CSize size; + title_label_->GetPreferredSize(&size); + title_label_->SetBounds(x, y, size.cx, size.cy); + x += size.cx + kHGapTitleToSeparator; + separator_->SetBounds(x + kHExtraSeparatorPadding, y, + GetWidth() - x - 2 * kHExtraSeparatorPadding, size.cy); + + // Then the image, head-line and description. + x = kHGapToBorder; + y += title_label_->GetHeight() + kVGapTitleToImage; + status_image_->GetPreferredSize(&size); + status_image_->SetBounds(x, y, size.cx, size.cy); + x += size.cx + kHGapImageToDescription; + int w = GetWidth() - x; + if (!head_line_label_->GetText().empty()) { + head_line_label_->GetPreferredSize(&size); + head_line_label_->SetBounds(x, y, w > 0 ? w : 0, size.cy); + y += size.cy + kVGapHeadLineToDescription; + } else { + head_line_label_->SetBounds(x, y, 0, 0); + } + if (w > 0) { + description_label_->SetBounds(x, y, w, + description_label_->GetHeightForWidth(w)); + } else { + description_label_->SetBounds(x, y, 0, 0); + } +} + +SecurityTabView::SecurityTabView(Profile* profile, + NavigationEntry* navigation_entry) { + bool identity_ok = true; + bool connection_ok = true; + std::wstring identity_title; + std::wstring identity_msg; + std::wstring connection_msg; + scoped_refptr<net::X509Certificate> cert; + const NavigationEntry::SSLStatus& ssl = navigation_entry->ssl(); + + // Identity section. + std::wstring subject_name(UTF8ToWide(navigation_entry->url().host())); + bool empty_subject_name = false; + if (subject_name.empty()) { + subject_name.assign( + l10n_util::GetString(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY)); + empty_subject_name = true; + } + if (navigation_entry->page_type() == NavigationEntry::NORMAL_PAGE && + ssl.cert_id() && + CertStore::GetSharedInstance()->RetrieveCert(ssl.cert_id(), &cert) && + !net::IsCertStatusError(ssl.cert_status())) { + // OK HTTPS page. + if ((ssl.cert_status() & net::CERT_STATUS_IS_EV) != 0) { + DCHECK(!cert->subject().organization_names.empty()); + identity_title = + l10n_util::GetStringF(IDS_PAGE_INFO_EV_IDENTITY_TITLE, + UTF8ToWide(cert->subject().organization_names[0]), + UTF8ToWide(navigation_entry->url().host())); + // An EV Cert is required to have a city (localityName) and country but + // state is "if any". + DCHECK(!cert->subject().locality_name.empty()); + DCHECK(!cert->subject().country_name.empty()); + std::wstring locality; + if (!cert->subject().state_or_province_name.empty()) { + locality = l10n_util::GetStringF( + IDS_PAGEINFO_ADDRESS, + UTF8ToWide(cert->subject().locality_name), + UTF8ToWide(cert->subject().state_or_province_name), + UTF8ToWide(cert->subject().country_name)); + } else { + locality = l10n_util::GetStringF( + IDS_PAGEINFO_PARTIAL_ADDRESS, + UTF8ToWide(cert->subject().locality_name), + UTF8ToWide(cert->subject().country_name)); + } + DCHECK(!cert->subject().organization_names.empty()); + identity_msg.assign(l10n_util::GetStringF( + IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV, + UTF8ToWide(cert->subject().organization_names[0]), + locality, + UTF8ToWide(GetIssuerName(cert->issuer())))); + } else { + // Non EV OK HTTPS. + if (empty_subject_name) + identity_title.clear(); // Don't display any title. + else + identity_title.assign(subject_name); + std::wstring issuer_name(UTF8ToWide(GetIssuerName(cert->issuer()))); + if (issuer_name.empty()) { + issuer_name.assign( + l10n_util::GetString(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY)); + } else { + identity_msg.assign( + l10n_util::GetStringF(IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, + issuer_name)); + } + } + } else { + // Bad HTTPS. + identity_msg.assign( + l10n_util::GetString(IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY)); + identity_ok = false; + } + + // Connection section. + // We consider anything less than 80 bits encryption to be weak encryption. + // TODO(wtc): Bug 1198735: report mixed/unsafe content for unencrypted and + // weakly encrypted connections. + if (ssl.security_bits() <= 0) { + connection_ok = false; + connection_msg.assign( + l10n_util::GetStringF( + IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT, + subject_name)); + } else if (ssl.security_bits() < 80) { + connection_ok = false; + connection_msg.assign( + l10n_util::GetStringF( + IDS_PAGE_INFO_SECURITY_TAB_WEAK_ENCRYPTION_CONNECTION_TEXT, + subject_name)); + } else { + connection_msg.assign( + l10n_util::GetStringF( + IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT, + subject_name, + IntToWString(ssl.security_bits()))); + if (ssl.has_mixed_content()) { + connection_ok = false; + connection_msg.assign( + l10n_util::GetStringF( + IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK, + connection_msg, + l10n_util::GetString( + IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_MIXED_CONTENT_WARNING))); + } else if (ssl.has_unsafe_content()) { + connection_ok = false; + connection_msg.assign( + l10n_util::GetStringF( + IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK, + connection_msg, + l10n_util::GetString( + IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_BAD_HTTPS_WARNING))); + } + } + + // Let's add the different sections. + AddSection(l10n_util::GetString(IDS_PAGE_INFO_SECURITY_TAB_IDENTITY_TITLE), + identity_ok, identity_title, identity_msg); + AddSection(l10n_util::GetString(IDS_PAGE_INFO_SECURITY_TAB_CONNECTION_TITLE), + connection_ok, std::wstring(), connection_msg); + + // Request the number of visits. + HistoryService* history = profile->GetHistoryService( + Profile::EXPLICIT_ACCESS); + if (history) { + history->GetVisitCountToHost( + navigation_entry->url(), + &request_consumer_, + NewCallback(this, &SecurityTabView::OnGotVisitCountToHost)); + } +} + +SecurityTabView::~SecurityTabView() { +} + +void SecurityTabView::AddSection(const std::wstring& title, + bool state, + const std::wstring& head_line, + const std::wstring& description) { + Section* section = new Section(title, state, head_line, description); + sections_.push_back(section); + AddChildView(section); +} + +void SecurityTabView::Layout() { + int width = GetWidth() - 2 * kHGapToBorder; + int x = kHGapToBorder; + int y = kVGapToBorder; + for (std::vector<Section*>::const_iterator iter = sections_.begin(); + iter != sections_.end(); ++iter) { + Section* section = *iter; + int h = section->GetHeightForWidth(width); + section->SetBounds(x, y, width, h); + section->Layout(); + y += h + kVGapBetweenSections; + } +} + +// static +std::string SecurityTabView::GetIssuerName( + const net::X509Certificate::Principal& issuer) { + if (!issuer.common_name.empty()) + return issuer.common_name; + if (!issuer.organization_names.empty()) + return issuer.organization_names[0]; + if (!issuer.organization_unit_names.empty()) + return issuer.organization_unit_names[0]; + + return std::string(); +} + +void SecurityTabView::OnGotVisitCountToHost(HistoryService::Handle handle, + bool found_visits, + int count, + Time first_visit) { + if (!found_visits) { + // This indicates an error, such as the page wasn't http/https; do nothing. + return; + } + + bool visited_before_today = false; + if (count) { + Time today = Time::Now().LocalMidnight(); + Time first_visit_midnight = first_visit.LocalMidnight(); + visited_before_today = (first_visit_midnight < today); + } + + if (!visited_before_today) { + AddSection( + l10n_util::GetString(IDS_PAGE_INFO_SECURITY_TAB_PERSONAL_HISTORY_TITLE), + false, std::wstring(), + l10n_util::GetString(IDS_PAGE_INFO_SECURITY_TAB_FIRST_VISITED_TODAY)); + } else { + AddSection( + l10n_util::GetString(IDS_PAGE_INFO_SECURITY_TAB_PERSONAL_HISTORY_TITLE), + true, std::wstring(), + l10n_util::GetStringF(IDS_PAGE_INFO_SECURITY_TAB_VISITED_BEFORE_TODAY, + base::TimeFormatShortDate(first_visit))); + } + Layout(); + SchedulePaint(); +} + +//////////////////////////////////////////////////////////////////////////////// +// PageInfoContentView +class PageInfoContentView : public ChromeViews::View { + public: + PageInfoContentView() : cert_viewer_button_(NULL) {} + + void set_cert_viewer_button(ChromeViews::NativeButton* cert_viewer_button) { + cert_viewer_button_ = cert_viewer_button; + } + + // ChromeViews::View overrides: + virtual void GetPreferredSize(CSize *out) { + DCHECK(out); + *out = ChromeViews::Window::GetLocalizedContentsSize( + IDS_PAGEINFO_DIALOG_WIDTH_CHARS, + IDS_PAGEINFO_DIALOG_HEIGHT_LINES).ToSIZE(); + } + + virtual void Layout() { + if (cert_viewer_button_) { + CSize ps; + cert_viewer_button_->GetPreferredSize(&ps); + + CRect parent_bounds; + GetParent()->GetLocalBounds(&parent_bounds, false); + int y_buttons = parent_bounds.bottom - ps.cy - kButtonVEdgeMargin; + cert_viewer_button_->SetBounds(kPanelHorizMargin, y_buttons, ps.cx, + ps.cy); + } + View::Layout(); + } + + private: + ChromeViews::NativeButton* cert_viewer_button_; + + DISALLOW_EVIL_CONSTRUCTORS(PageInfoContentView); +}; + +//////////////////////////////////////////////////////////////////////////////// +// PageInfoWindow + +int PageInfoWindow::opened_window_count_ = 0; + +// static +void PageInfoWindow::Create(Profile* profile, + NavigationEntry* nav_entry, + HWND parent_hwnd, + PageInfoWindow::TabID tab) { + PageInfoWindow* window = new PageInfoWindow(); + window->Init(profile, nav_entry, parent_hwnd); + window->Show(); +} + +// static +void PageInfoWindow::RegisterPrefs(PrefService* prefs) { + prefs->RegisterDictionaryPref(prefs::kPageInfoWindowPlacement); +} + +PageInfoWindow::PageInfoWindow() : cert_id_(0), contents_(NULL) { +} + +PageInfoWindow::~PageInfoWindow() { + DCHECK(opened_window_count_ > 0); + opened_window_count_--; +} + +void PageInfoWindow::Init(Profile* profile, + NavigationEntry* navigation_entry, + HWND parent) { + cert_id_ = navigation_entry->ssl().cert_id(); + + cert_info_button_ = new ChromeViews::NativeButton( + l10n_util::GetString(IDS_PAGEINFO_CERT_INFO_BUTTON)); + cert_info_button_->SetListener(this); + + contents_ = new PageInfoContentView(); + DWORD sys_color = ::GetSysColor(COLOR_3DFACE); + SkColor color = SkColorSetRGB(GetRValue(sys_color), GetGValue(sys_color), + GetBValue(sys_color)); + contents_->SetBackground( + ChromeViews::Background::CreateSolidBackground(color)); + + ChromeViews::GridLayout* layout = new ChromeViews::GridLayout(contents_); + contents_->SetLayoutManager(layout); + ChromeViews::ColumnSet* columns = layout->AddColumnSet(0); + columns->AddPaddingColumn(0, kHorizontalPadding); + columns->AddColumn(ChromeViews::GridLayout::FILL, // Horizontal resize. + ChromeViews::GridLayout::FILL, // Vertical resize. + 1, // Resize weight. + ChromeViews::GridLayout::USE_PREF, // Size type. + 0, // Ignored for USE_PREF. + 0); // Minimum size. + columns->AddColumn(ChromeViews::GridLayout::FILL, // Horizontal resize. + ChromeViews::GridLayout::FILL, // Vertical resize. + 1, // Resize weight. + ChromeViews::GridLayout::USE_PREF, // Size type. + 0, // Ignored for USE_PREF. + 0); // Minimum size. + columns->AddPaddingColumn(0, kHorizontalPadding); + + layout->AddPaddingRow(0, kHorizontalPadding); + layout->StartRow(1, 0); + layout->AddView(CreateSecurityTabView(profile, navigation_entry), 2, 1); + + layout->AddPaddingRow(0, kHorizontalPadding); + + if (opened_window_count_ > 0) { + // There already is a PageInfo window opened. Let's shift the location of + // the new PageInfo window so they don't overlap entirely. + // Window::Init will position the window from the stored location. + CRect bounds; + bool maximized, always_on_top; + if (RestoreWindowPosition(&bounds, &maximized, &always_on_top)) { + CalculateWindowBounds(&bounds); + SaveWindowPosition(bounds, maximized, always_on_top); + } + } + + ChromeViews::Window::CreateChromeWindow(parent, gfx::Rect(), this); + // TODO(beng): (Cleanup) - cert viewer button should use GetExtraView. + + if (cert_id_) { + scoped_refptr<net::X509Certificate> cert; + CertStore::GetSharedInstance()->RetrieveCert(cert_id_, &cert); + // When running with Gears, we have no os certificate, so there is no cert + // to show. Don't bother showing the cert info button in that case. + if (cert.get() && cert->os_cert_handle()) { + contents_->GetParent()->AddChildView(cert_info_button_); + contents_->set_cert_viewer_button(cert_info_button_); + contents_->Layout(); + } + } +} + +ChromeViews::View* PageInfoWindow::CreateGeneralTabView() { + return new ChromeViews::View(); +} + +ChromeViews::View* PageInfoWindow::CreateSecurityTabView( + Profile* profile, + NavigationEntry* navigation_entry) { + return new SecurityTabView(profile, navigation_entry); +} + +void PageInfoWindow::Show() { + window()->Show(); + opened_window_count_++; +} + +int PageInfoWindow::GetDialogButtons() const { + return DIALOGBUTTON_CANCEL; +} + +std::wstring PageInfoWindow::GetWindowTitle() const { + return l10n_util::GetString(IDS_PAGEINFO_WINDOW_TITLE); +} + +void PageInfoWindow::SaveWindowPosition(const CRect& bounds, + bool maximized, + bool always_on_top) { + window()->SaveWindowPositionToPrefService(g_browser_process->local_state(), + prefs::kPageInfoWindowPlacement, + bounds, maximized, always_on_top); +} + +bool PageInfoWindow::RestoreWindowPosition(CRect* bounds, + bool* maximized, + bool* always_on_top) { + return window()->RestoreWindowPositionFromPrefService( + g_browser_process->local_state(), + prefs::kPageInfoWindowPlacement, + bounds, maximized, always_on_top); +} + +ChromeViews::View* PageInfoWindow::GetContentsView() { + return contents_; +} + +void PageInfoWindow::ButtonPressed(ChromeViews::NativeButton* sender) { + if (sender == cert_info_button_) { + DCHECK(cert_id_ != 0); + ShowCertDialog(cert_id_); + } else { + NOTREACHED(); + } +} + +void PageInfoWindow::CalculateWindowBounds(CRect* bounds) { + const int kDefaultOffset = 15; + + gfx::Rect window_bounds(*bounds); + gfx::Rect monitor_bounds(win_util::GetMonitorBoundsForRect(window_bounds)); + + // If necessary, move the window so it is visible on the screen. + gfx::Rect adjusted_bounds = window_bounds.AdjustToFit(monitor_bounds); + if (adjusted_bounds != window_bounds) { + // The bounds have moved, we are done. + RECT rect = adjusted_bounds.ToRECT(); + bounds->CopyRect(&rect); + return; + } + + // Move the window from its specified position, trying to keep it entirely + // visible. + int x_offset, y_offset; + if (window_bounds.right() + kDefaultOffset >= monitor_bounds.right() && + abs(monitor_bounds.x() - window_bounds.x()) >= kDefaultOffset) { + x_offset = -kDefaultOffset; + } else { + x_offset = kDefaultOffset; + } + + if (window_bounds.bottom() + kDefaultOffset >= monitor_bounds.bottom() && + abs(monitor_bounds.y() - window_bounds.y()) >= kDefaultOffset) { + y_offset = -kDefaultOffset; + } else { + y_offset = kDefaultOffset; + } + + bounds->OffsetRect(x_offset, y_offset); +} + +void PageInfoWindow::ShowCertDialog(int cert_id) { + scoped_refptr<net::X509Certificate> cert; + CertStore::GetSharedInstance()->RetrieveCert(cert_id, &cert); + if (!cert.get()) { + // The certificate was not found. Could be that the renderer crashed before + // we displayed the page info. + return; + } + + CRYPTUI_VIEWCERTIFICATE_STRUCT view_info = { 0 }; + view_info.dwSize = sizeof(view_info); + // We set our parent to the tab window. This makes the cert dialog created + // in CryptUIDlgViewCertificate modal to the browser. + view_info.hwndParent = window()->owning_window(); + view_info.dwFlags = CRYPTUI_DISABLE_EDITPROPERTIES | + CRYPTUI_DISABLE_ADDTOSTORE; + view_info.pCertContext = cert->os_cert_handle(); + // Search the cert store that 'cert' is in when building the cert chain. + HCERTSTORE cert_store = view_info.pCertContext->hCertStore; + view_info.cStores = 1; + view_info.rghStores = &cert_store; + BOOL properties_changed; + + // This next call blocks but keeps processing windows messages, making it + // modal to the browser window. + BOOL rv = ::CryptUIDlgViewCertificate(&view_info, &properties_changed); +} + diff --git a/chrome/browser/views/page_info_window.h b/chrome/browser/views/page_info_window.h new file mode 100644 index 0000000..f2e998c --- /dev/null +++ b/chrome/browser/views/page_info_window.h @@ -0,0 +1,92 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_VIEWS_PAGE_INFO_WINDOW_H__ +#define CHROME_BROWSER_VIEWS_PAGE_INFO_WINDOW_H__ + +#include "chrome/views/dialog_delegate.h" +#include "chrome/views/native_button.h" +#include "chrome/views/window.h" + +// The page info window displays information regarding the current page, +// including security information. + +namespace ChromeViews { +class TabbedPane; +} + +class NavigationEntry; +class PageInfoContentView; +class PrefService; +class Profile; +class X509Certificate; + +class PageInfoWindow : public ChromeViews::DialogDelegate, + public ChromeViews::NativeButton::Listener { + public: + enum TabID { + GENERAL = 0, + SECURITY, + + }; + + // Creates and shows a new PageInfoWindow. + static void Create(Profile* profile, + NavigationEntry* nav_entry, + HWND parent_hwnd, + TabID tab); + + static void RegisterPrefs(PrefService* prefs); + + PageInfoWindow(); + virtual ~PageInfoWindow(); + + virtual void Init(Profile* profile, + NavigationEntry* navigation_entry, + HWND parent); + + // ChromeViews::Window overridden method. + void Show(); + + // ChromeViews::NativeButton::Listener method. + virtual void ButtonPressed(ChromeViews::NativeButton* sender); + + // ChromeViews::DialogDelegate methods: + virtual int GetDialogButtons() const; + virtual std::wstring GetWindowTitle() const; + virtual void SaveWindowPosition(const CRect& bounds, + bool maximized, + bool always_on_top); + virtual bool RestoreWindowPosition(CRect* bounds, + bool* maximized, + bool* always_on_top); + virtual ChromeViews::View* GetContentsView(); + + private: + ChromeViews::View* CreateGeneralTabView(); + ChromeViews::View* CreateSecurityTabView(Profile* profile, + NavigationEntry* navigation_entry); + + // Offsets the specified rectangle so it is showing on the screen and shifted + // from its original location. + void CalculateWindowBounds(CRect* bounds); + + // Shows various information for the specified certificate in a new dialog. + void ShowCertDialog(int cert_id); + + ChromeViews::NativeButton* cert_info_button_; + + // The id of the server cert for this page (0 means no cert). + int cert_id_; + + // The page info contents. + PageInfoContentView* contents_; + + // A counter of how many page info windows are currently opened. + static int opened_window_count_; + + DISALLOW_EVIL_CONSTRUCTORS(PageInfoWindow); +}; + +#endif // #define CHROME_BROWSER_VIEWS_PAGE_INFO_WINDOW_H__ diff --git a/chrome/browser/views/password_manager_view.cc b/chrome/browser/views/password_manager_view.cc index cee8b3d..678b036 100644 --- a/chrome/browser/views/password_manager_view.cc +++ b/chrome/browser/views/password_manager_view.cc @@ -5,8 +5,8 @@ #include "base/string_util.h" #include "chrome/common/l10n_util.h" #include "chrome/browser/profile.h" -#include "chrome/browser/standard_layout.h" #include "chrome/browser/views/password_manager_view.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/views/background.h" #include "chrome/views/grid_layout.h" #include "chrome/views/native_button.h" diff --git a/chrome/browser/views/shelf_item_dialog.cc b/chrome/browser/views/shelf_item_dialog.cc index 8566cdb..f08ccb3 100644 --- a/chrome/browser/views/shelf_item_dialog.cc +++ b/chrome/browser/views/shelf_item_dialog.cc @@ -9,9 +9,9 @@ #include "chrome/app/locales/locale_settings.h" #include "chrome/app/theme/theme_resources.h" #include "chrome/browser/profile.h" -#include "chrome/browser/standard_layout.h" #include "chrome/browser/tab_contents.h" #include "chrome/browser/url_fixer_upper.h" +#include "chrome/browser/views/standard_layout.h" #include "chrome/common/gfx/url_elider.h" #include "chrome/common/l10n_util.h" #include "chrome/common/pref_names.h" diff --git a/chrome/browser/views/standard_layout.h b/chrome/browser/views/standard_layout.h new file mode 100644 index 0000000..37e239bc --- /dev/null +++ b/chrome/browser/views/standard_layout.h @@ -0,0 +1,78 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_VIEWS_STANDARD_LAYOUT_H__ +#define CHROME_BROWSER_VIEWS_STANDARD_LAYOUT_H__ + +#include "chrome/views/grid_layout.h" + +// +// This file contains some constants we use to implement our standard panel +// layout. +// see: spec 21/4 + +// Left or right margin. +const int kPanelHorizMargin = 13; + +// Top or bottom margin. +const int kPanelVertMargin = 13; + +// If some UI has some sub UI. Indent horizontally by the following value. +const int kPanelHorizIndentation = 24; + +// When several controls are aligned vertically, the baseline should be spaced +// by the following number of pixels. +const int kPanelVerticalSpacing = 32; + +// Vertical spacing between sub UI. +const int kPanelSubVerticalSpacing = 24; + +// Vertical spacing between a label and some control. +const int kLabelToControlVerticalSpacing = 8; + +// Vertical spacing between controls that are logically related. +const int kRelatedControlVerticalSpacing = 8; + +// Small vertical spacing between controls that are logically related. +const int kRelatedControlSmallVerticalSpacing = 4; + +// Vertical spacing between controls that are logically unrelated. +const int kUnrelatedControlVerticalSpacing = 20; + +// Larger vertical spacing between unrelated controls. +const int kUnrelatedControlLargeVerticalSpacing = 30; + +// Small horizontal spacing between controls that are logically related. +const int kRelatedControlSmallHorizontalSpacing = 8; + +// Horizontal spacing between controls that are logically related. +const int kRelatedControlHorizontalSpacing = 8; + +// Horizontal spacing between controls that are logically unrelated. +const int kUnrelatedControlHorizontalSpacing = 12; + +// Larger horizontal spacing between unrelated controls. +const int kUnrelatedControlLargeHorizontalSpacing = 20; + +// Vertical spacing between the edge of the window and the +// top or bottom of a button. +const int kButtonVEdgeMargin = 6; + +// Vertical spacing between the edge of the window and the +// left or right of a button. +const int kButtonHEdgeMargin = 7; + +// Horizontal spacing between buttons that are logically related. +const int kRelatedButtonHSpacing = 6; + +// Creates a GridLayout with kPanel*Margin insets. +static ChromeViews::GridLayout* CreatePanelGridLayout(ChromeViews::View* host) { + ChromeViews::GridLayout* layout = new ChromeViews::GridLayout(host); + layout->SetInsets(kPanelVertMargin, kPanelHorizMargin, + kPanelVertMargin, kPanelHorizMargin); + return layout; +} + +#endif // CHROME_BROWSER_VIEWS_STANDARD_LAYOUT_H__ + diff --git a/chrome/browser/views/tab_contents_container_view.cc b/chrome/browser/views/tab_contents_container_view.cc new file mode 100644 index 0000000..582726a --- /dev/null +++ b/chrome/browser/views/tab_contents_container_view.cc @@ -0,0 +1,243 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include <algorithm> + +#include "chrome/browser/views/tab_contents_container_view.h" + +#include "base/logging.h" +#include "chrome/browser/render_view_host.h" +#include "chrome/browser/render_view_host_manager.h" +#include "chrome/browser/render_widget_host_view.h" +#include "chrome/browser/tab_contents.h" +#include "chrome/browser/view_ids.h" +#include "chrome/browser/web_contents.h" +#include "chrome/views/root_view.h" + +using ChromeViews::FocusTraversable; +using ChromeViews::FocusManager; +using ChromeViews::View; + +TabContentsContainerView::TabContentsContainerView() : tab_contents_(NULL) { + SetID(VIEW_ID_TAB_CONTAINER); +} + +TabContentsContainerView::~TabContentsContainerView() { + if (tab_contents_) + RemoveObservers(); +} + +void TabContentsContainerView::SetTabContents(TabContents* tab_contents) { + if (tab_contents_) { + // TODO(beng): (Cleanup) We want to call the _base_ class' version here. + // WebContents' WM_WINDOWPOSCHANGED handler will ensure its + // version is called. The correct thing to do here is to + // rationalize all TabContents Hide/Show/Size etc into a single + // API, but that's too complex for this first phase. + tab_contents_->TabContents::HideContents(); + + // Unregister the tab contents window from the FocusManager. + HWND hwnd = tab_contents_->GetContentHWND(); + if (hwnd) { + // We may not have an HWND anymore, if the renderer crashed and we are + // displaying the sad tab for example. + FocusManager::UninstallFocusSubclass(hwnd); + } + + ChromeViews::RootView* root_view = tab_contents_->GetContentsRootView(); + if (root_view) { + // Unlink the RootViews as a clean-up. + root_view->SetFocusTraversableParent(NULL); + root_view->SetFocusTraversableParentView(NULL); + } + + // Now detach the TabContents. + Detach(); + + RemoveObservers(); + } + + tab_contents_ = tab_contents; + + if (!tab_contents_) { + // When detaching the last tab of the browser SetTabContents is invoked + // with NULL. Don't attempt to do anything in that case. + return; + } + + // We need to register the tab contents window with the BrowserContainer so + // that the BrowserContainer is the focused view when the focus is on the + // TabContents window (for the WebContents case). + SetAssociatedFocusView(this); + + Attach(tab_contents->GetContainerHWND()); + HWND contents_hwnd = tab_contents_->GetContentHWND(); + if (contents_hwnd) + FocusManager::InstallFocusSubclass(contents_hwnd, this); + + AddObservers(); + + ChromeViews::RootView* root_view = tab_contents_->GetContentsRootView(); + if (root_view) { + // Link the RootViews for proper focus traversal (note that we skip the + // TabContentsContainerView as it acts as a FocusTraversable proxy). + root_view->SetFocusTraversableParent(GetRootView()); + root_view->SetFocusTraversableParentView(this); + } +} + +ChromeViews::FocusTraversable* TabContentsContainerView::GetFocusTraversable() { + if (tab_contents_ && tab_contents_->GetContentsRootView()) + return tab_contents_->GetContentsRootView(); + return NULL; +} + +bool TabContentsContainerView::IsFocusable() const { + // We need to be focusable when our contents is not a view hierarchy, as + // clicking on the contents needs to focus us. + if (tab_contents_ && !tab_contents_->GetContentsRootView()) + return true; + + // If we do contain views, then we should just act as a regular container by + // not being focusable. + return false; +} + +void TabContentsContainerView::AboutToRequestFocusFromTabTraversal( + bool reverse) { + if (!tab_contents_) + return; + // Give an opportunity to the tab to reset its focus. + tab_contents_->SetInitialFocus(reverse); +} + +bool TabContentsContainerView::CanProcessTabKeyEvents() { + // TabContents with no RootView are supposed to deal with the focus traversal + // explicitly. For that reason, they receive tab key events as is. + return tab_contents_ && !tab_contents_->GetContentsRootView(); +} + +ChromeViews::FocusTraversable* + TabContentsContainerView::GetFocusTraversableParent() { + if (tab_contents_ && tab_contents_->GetContentsRootView()) { + // Since we link the RootView of the TabContents to the RootView that + // contains us, this should not be invoked. + NOTREACHED(); + return NULL; + } + return GetRootView(); +} + +ChromeViews::View* + TabContentsContainerView::GetFocusTraversableParentView() { + if (tab_contents_ && tab_contents_->GetContentsRootView()) { + // Since we link the RootView of the TabContents to the RootView that + // contains us, this should not be invoked. + NOTREACHED(); + return NULL; + } + return this; +} + +void TabContentsContainerView::Focus() { + if (tab_contents_ && !tab_contents_->GetContentsRootView()) { + // Set the native focus on the actual content of the tab. + ::SetFocus(tab_contents_->GetContentHWND()); + } +} + +void TabContentsContainerView::RequestFocus() { + // This is a hack to circumvent the fact that a view does not explicitly get + // a call to set the focus if it already has the focus. This causes a problem + // with tabs such as the WebContents that instruct the RenderView that it got + // focus when they actually get the focus. When switching from one WebContents + // tab that has focus to another WebContents tab that had focus, since the + // TabContentsContainerView already has focus, Focus() would not be called and + // the RenderView would not get notified it got focused. + // By clearing the focused view before-hand, we ensure Focus() will be called. + GetRootView()->FocusView(NULL); + View::RequestFocus(); +} + +bool TabContentsContainerView::GetAccessibleRole(VARIANT* role) { + DCHECK(role); + + role->vt = VT_I4; + role->lVal = ROLE_SYSTEM_GROUPING; + return true; +} + +bool TabContentsContainerView::ShouldLookupAccelerators( + const ChromeViews::KeyEvent& e) { + if (tab_contents_ && !tab_contents_->IsCrashed() && + tab_contents_->AsWebContents()) + return false; + return true; +} + +void TabContentsContainerView::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + if (type == NOTIFY_RENDER_VIEW_HOST_CHANGED) { + RenderViewHostSwitchedDetails* switched_details = + Details<RenderViewHostSwitchedDetails>(details).ptr(); + RenderViewHostChanged(switched_details->old_host, + switched_details->new_host); + } else if (type == NOTIFY_TAB_CONTENTS_DESTROYED) { + TabContentsDestroyed(Source<TabContents>(source).ptr()); + } else { + NOTREACHED(); + } +} + +void TabContentsContainerView::AddObservers() { + DCHECK(tab_contents_); + if (tab_contents_->AsWebContents()) { + // WebContents can change their RenderViewHost and hence the HWND that is + // shown and getting focused. We need to keep track of that so we install + // the focus subclass on the shown HWND so we intercept focus change events. + NotificationService::current()->AddObserver( + this, NOTIFY_RENDER_VIEW_HOST_CHANGED, + Source<NavigationController>(tab_contents_->controller())); + } + NotificationService::current()->AddObserver( + this, NOTIFY_TAB_CONTENTS_DESTROYED, + Source<TabContents>(tab_contents_)); +} + +void TabContentsContainerView::RemoveObservers() { + DCHECK(tab_contents_); + if (tab_contents_->AsWebContents()) { + NotificationService::current()->RemoveObserver( + this, NOTIFY_RENDER_VIEW_HOST_CHANGED, + Source<NavigationController>(tab_contents_->controller())); + } + NotificationService::current()->RemoveObserver( + this, NOTIFY_TAB_CONTENTS_DESTROYED, + Source<TabContents>(tab_contents_)); +} + +void TabContentsContainerView::RenderViewHostChanged(RenderViewHost* old_host, + RenderViewHost* new_host) { + if (old_host && old_host->view()) + FocusManager::UninstallFocusSubclass(old_host->view()->GetPluginHWND()); + + if (new_host && new_host->view()) + FocusManager::InstallFocusSubclass(new_host->view()->GetPluginHWND(), this); + + // If we are focused, we need to pass the focus to the new RenderViewHost. + FocusManager* focus_manager = + FocusManager::GetFocusManager(GetRootView()->GetViewContainer()-> + GetHWND()); + if (focus_manager->GetFocusedView() == this) + Focus(); +} + +void TabContentsContainerView::TabContentsDestroyed(TabContents* contents) { + // Sometimes, a TabContents is destroyed before we know about it. This allows + // us to clean up our state in case this happens. + DCHECK(contents == tab_contents_); + SetTabContents(NULL); +} + diff --git a/chrome/browser/views/tab_contents_container_view.h b/chrome/browser/views/tab_contents_container_view.h new file mode 100644 index 0000000..c904b73 --- /dev/null +++ b/chrome/browser/views/tab_contents_container_view.h @@ -0,0 +1,80 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_VIEWS_TAB_CONTENTS_CONTAINER_VIEW_H__ +#define CHROME_BROWSER_VIEWS_TAB_CONTENTS_CONTAINER_VIEW_H__ + +namespace ChromeView { +class KeyEvent; +class View; +} +class RenderViewHost; +class TabContents; + +#include "chrome/common/notification_service.h" +#include "chrome/views/focus_manager.h" +#include "chrome/views/hwnd_view.h" + +// This View contains the TabContents. +// It takes care of linking the TabContents to the browser RootView so that the +// focus can traverse from one to the other when pressing Tab/Shift-Tab. +class TabContentsContainerView : public ChromeViews::HWNDView, + public NotificationObserver { + public: + TabContentsContainerView(); + virtual ~TabContentsContainerView(); + + // Make the specified tab visible. + void SetTabContents(TabContents* tab_contents); + TabContents* GetTabContents() const { return tab_contents_; } + + // Overridden from View. + virtual ChromeViews::FocusTraversable* GetFocusTraversable(); + virtual bool IsFocusable() const; + virtual void Focus(); + virtual void RequestFocus(); + virtual void AboutToRequestFocusFromTabTraversal(bool reverse); + virtual bool CanProcessTabKeyEvents(); + + // Overridden from HWNDView. + virtual ChromeViews::FocusTraversable* GetFocusTraversableParent(); + virtual ChromeViews::View* GetFocusTraversableParentView(); + + // NotificationObserver implementation. + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + + // Returns the MSAA role of the current view. The role is what assistive + // technologies (ATs) use to determine what behavior to expect from a given + // control. + bool GetAccessibleRole(VARIANT* role); + + protected: + // Web content should be given first crack at accelerators. This function + // returns false if the current tab is a webcontents. + virtual bool ShouldLookupAccelerators(const ChromeViews::KeyEvent& e); + + private: + // Add or remove observers for events that we care about. + void AddObservers(); + void RemoveObservers(); + + // Called when the RenderViewHost of the hosted TabContents has changed, e.g. + // to show an interstitial page. + void RenderViewHostChanged(RenderViewHost* old_host, + RenderViewHost* new_host); + + // Called when a TabContents is destroyed. This gives us a chance to clean + // up our internal state if the TabContents is somehow destroyed before we + // get notified. + void TabContentsDestroyed(TabContents* contents); + + // The current TabContents shown. + TabContents* tab_contents_; + + DISALLOW_EVIL_CONSTRUCTORS(TabContentsContainerView); +}; + +#endif // #ifndef CHROME_BROWSER_VIEWS_TAB_CONTENTS_CONTAINER_VIEW_H__ diff --git a/chrome/browser/views/user_data_dir_dialog.cc b/chrome/browser/views/user_data_dir_dialog.cc new file mode 100644 index 0000000..90460fb --- /dev/null +++ b/chrome/browser/views/user_data_dir_dialog.cc @@ -0,0 +1,103 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/logging.h" +#include "chrome/browser/views/user_data_dir_dialog.h" +#include "chrome/common/l10n_util.h" +#include "chrome/views/message_box_view.h" +#include "chrome/views/window.h" + +#include "chromium_strings.h" +#include "generated_resources.h" + +// static +std::wstring UserDataDirDialog::RunUserDataDirDialog( + const std::wstring& user_data_dir) { + // When the window closes, it will delete itself. + UserDataDirDialog* dlg = new UserDataDirDialog(user_data_dir); + MessageLoopForUI::current()->Run(dlg); + return dlg->user_data_dir(); +} + +UserDataDirDialog::UserDataDirDialog(const std::wstring& user_data_dir) + : select_file_dialog_(SelectFileDialog::Create(this)), + is_blocking_(true) { + std::wstring message_text = l10n_util::GetStringF( + IDS_CANT_WRITE_USER_DIRECTORY_SUMMARY, user_data_dir); + const int kDialogWidth = 400; + message_box_view_ = new MessageBoxView(MessageBoxView::kIsConfirmMessageBox, + message_text.c_str(), std::wstring(), kDialogWidth); + + ChromeViews::Window::CreateChromeWindow(NULL, gfx::Rect(), this)->Show(); +} + +UserDataDirDialog::~UserDataDirDialog() { + select_file_dialog_->ListenerDestroyed(); +} + +int UserDataDirDialog::GetDialogButtons() const { + return DIALOGBUTTON_OK | DIALOGBUTTON_CANCEL; + +} + +std::wstring UserDataDirDialog::GetDialogButtonLabel( + DialogButton button) const { + + switch (button) { + case DIALOGBUTTON_OK: + return l10n_util::GetString( + IDS_CANT_WRITE_USER_DIRECTORY_CHOOSE_DIRECTORY_BUTTON); + case DIALOGBUTTON_CANCEL: + return l10n_util::GetString(IDS_CANT_WRITE_USER_DIRECTORY_EXIT_BUTTON); + default: + NOTREACHED(); + } + + return std::wstring(); +} + +std::wstring UserDataDirDialog::GetWindowTitle() const { + return l10n_util::GetString(IDS_CANT_WRITE_USER_DIRECTORY_TITLE); +} + +void UserDataDirDialog::WindowClosing() { + delete this; +} + +bool UserDataDirDialog::Accept() { + // Directory picker + std::wstring dialog_title = l10n_util::GetString( + IDS_CANT_WRITE_USER_DIRECTORY_CHOOSE_DIRECTORY_BUTTON); + HWND owning_hwnd = + GetAncestor(message_box_view_->GetViewContainer()->GetHWND(), GA_ROOT); + select_file_dialog_->SelectFile(SelectFileDialog::SELECT_FOLDER, + dialog_title, std::wstring(), owning_hwnd, + NULL); + return false; +} + +bool UserDataDirDialog::Cancel() { + is_blocking_ = false; + return true; +} + +ChromeViews::View* UserDataDirDialog::GetContentsView() { + return message_box_view_; +} + +bool UserDataDirDialog::Dispatch(const MSG& msg) { + TranslateMessage(&msg); + DispatchMessage(&msg); + return is_blocking_; +} + +void UserDataDirDialog::FileSelected(const std::wstring& path, void* params) { + user_data_dir_ = path; + is_blocking_ = false; + window()->Close(); +} + +void UserDataDirDialog::FileSelectionCanceled(void* params) { +} + diff --git a/chrome/browser/views/user_data_dir_dialog.h b/chrome/browser/views/user_data_dir_dialog.h new file mode 100644 index 0000000..d9811a8 --- /dev/null +++ b/chrome/browser/views/user_data_dir_dialog.h @@ -0,0 +1,71 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// A dialog box that tells the user that we can't write to the specified user +// data directory. Provides the user a chance to pick a different directory. + +#ifndef CHROME_BROWSER_USER_DATA_DIR_DIALOG_H__ +#define CHROME_BROWSER_USER_DATA_DIR_DIALOG_H__ + +#include "base/basictypes.h" +#include "base/message_loop.h" +#include "chrome/browser/shell_dialogs.h" +#include "chrome/views/dialog_delegate.h" + +class MessageBoxView; +namespace ChromeViews { +class Window; +} + +class UserDataDirDialog : public ChromeViews::DialogDelegate, + public MessageLoopForUI::Dispatcher, + public SelectFileDialog::Listener { + public: + // Creates and runs a user data directory picker dialog. The method blocks + // while the dialog is showing. If the user picks a directory, this method + // returns the chosen directory. |user_data_dir| is the value of the + // directory we were not able to use. + static std::wstring RunUserDataDirDialog(const std::wstring& user_data_dir); + virtual ~UserDataDirDialog(); + + std::wstring user_data_dir() { return user_data_dir_; } + + // ChromeViews::DialogDelegate Methods: + virtual int GetDialogButtons() const; + virtual std::wstring GetDialogButtonLabel(DialogButton button) const; + virtual std::wstring GetWindowTitle() const; + virtual void WindowClosing(); + virtual bool Accept(); + virtual bool Cancel(); + + // ChromeViews::WindowDelegate Methods: + virtual bool IsAlwaysOnTop() const { return false; } + virtual bool IsModal() const { return false; } + virtual ChromeViews::View* GetContentsView(); + + // MessageLoop::Dispatcher Method: + virtual bool Dispatch(const MSG& msg); + + // SelectFileDialog::Listener Methods: + virtual void FileSelected(const std::wstring& path, void* params); + virtual void FileSelectionCanceled(void* params); + + private: + explicit UserDataDirDialog(const std::wstring& user_data_dir); + + // Empty until the user picks a directory. + std::wstring user_data_dir_; + + MessageBoxView* message_box_view_; + scoped_refptr<SelectFileDialog> select_file_dialog_; + + // Used to keep track of whether or not to block the message loop (still + // waiting for the user to dismiss the dialog). + bool is_blocking_; + + DISALLOW_EVIL_CONSTRUCTORS(UserDataDirDialog); +}; + +#endif // CHROME_BROWSER_USER_DATA_DIR_DIALOG_H__ + |