Chromium Code Reviews| Index: chrome/browser/chromeos/enrollment_dialog_view.cc |
| diff --git a/chrome/browser/chromeos/enrollment_dialog_view.cc b/chrome/browser/chromeos/enrollment_dialog_view.cc |
| index 28eb08772fd3f7a757a995540242fc508e3fcbcb..56feaab1573da4a5d43009be45cfb6bf2e8adda5 100644 |
| --- a/chrome/browser/chromeos/enrollment_dialog_view.cc |
| +++ b/chrome/browser/chromeos/enrollment_dialog_view.cc |
| @@ -6,8 +6,12 @@ |
| #include "base/bind.h" |
| #include "chrome/browser/chromeos/cros/network_library.h" |
| +#include "chrome/browser/extensions/extension_host.h" |
| #include "chrome/browser/profiles/profile_manager.h" |
| #include "chrome/browser/themes/theme_service.h" |
| +#include "chrome/browser/ui/views/extensions/extension_dialog.h" |
| +#include "chrome/browser/ui/views/extensions/extension_dialog_observer.h" |
| +#include "content/public/common/page_transition_types.h" |
| #include "grit/generated_resources.h" |
| #include "ui/base/l10n/l10n_util.h" |
| #include "ui/base/resource/resource_bundle.h" |
| @@ -30,120 +34,70 @@ namespace chromeos { |
| namespace { |
| // Default width/height of the dialog. |
| -const int kDefaultWidth = 640; |
| -const int kDefaultHeight = 480; |
| +const int kDefaultWidth = 400; |
| +const int kDefaultHeight = 200; |
| -// Border around the WebView |
| -const int kWebViewBorderSize = 1; |
| - |
| -// TODO(gspencer): Move this into ui/views/layout, perhaps just adding insets |
| -// to FillLayout. |
| -class BorderLayout : public LayoutManager { |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// Dialog for certificate enrollment. This displays the content from the |
| +// certificate enrollment URI. |
| +class EnrollmentDialogView : public views::DialogDelegateView { |
| public: |
| - explicit BorderLayout(const gfx::Insets& insets) : insets_(insets) {} |
| - virtual ~BorderLayout() {} |
| - |
| - // Overridden from LayoutManager: |
| - virtual void Layout(View* host) OVERRIDE { |
| - if (!host->has_children()) |
| - return; |
| + virtual ~EnrollmentDialogView(); |
| - View* frame_view = host->child_at(0); |
| - frame_view->SetBounds(insets_.left(), |
| - insets_.top(), |
| - host->width() - insets_.right() - insets_.left(), |
| - host->height() - insets_.bottom() - insets_.top()); |
| - } |
| + static void ShowDialog(gfx::NativeWindow owning_window, |
| + Profile* profile, |
| + const GURL& target_uri, |
| + const base::Closure& connect); |
| + void Close(); |
| - virtual gfx::Size GetPreferredSize(View* host) OVERRIDE { |
| - DCHECK_EQ(1, host->child_count()); |
| - gfx::Size child_size = host->child_at(0)->GetPreferredSize(); |
| - child_size.Enlarge(insets_.left() + insets_.right(), |
| - insets_.top() + insets_.bottom()); |
| - return child_size; |
| - } |
| + // views::DialogDelegateView overrides |
| + virtual int GetDialogButtons() const OVERRIDE; |
| + bool Accept(); |
|
stevenjb
2012/05/02 00:31:23
move Accept() and Close() below virtual overrides.
Greg Spencer (Chromium)
2012/05/02 21:08:59
Actually they are overrides too. Fixed their sign
|
| - private: |
| - gfx::Insets insets_; |
| - DISALLOW_COPY_AND_ASSIGN(BorderLayout); |
| -}; |
| + // views::WidgetDelegate overrides |
| + virtual ui::ModalType GetModalType() const OVERRIDE; |
| + virtual string16 GetWindowTitle() const OVERRIDE; |
| -// Handler for certificate enrollment. This displays the content from the |
| -// certificate enrollment URI and listens for a certificate to be added. If a |
| -// certificate is added, then it invokes the closure to allow the network to |
| -// continue to connect. |
| -class DialogEnrollmentDelegate : public EnrollmentDelegate { |
| - public: |
| - // |owning_window| is the window that will own the dialog. |
| - explicit DialogEnrollmentDelegate(gfx::NativeWindow owning_window); |
| - virtual ~DialogEnrollmentDelegate(); |
| + // views::View overrides |
| + virtual gfx::Size GetPreferredSize() OVERRIDE; |
| - // EnrollmentDelegate overrides |
| - virtual void Enroll(const std::vector<std::string>& uri_list, |
| - const base::Closure& connect) OVERRIDE; |
| + // views::Widget overrides |
| + virtual views::View* GetContentsView() OVERRIDE; |
| private: |
| - gfx::NativeWindow owning_window_; |
| - |
| - DISALLOW_COPY_AND_ASSIGN(DialogEnrollmentDelegate); |
| + EnrollmentDialogView(Profile* profile, |
| + const GURL& target_uri, |
| + const base::Closure& connect); |
| + void InitDialog(); |
| + |
| + Profile* profile_; |
| + GURL target_uri_; |
| + base::Closure connect_; |
| + bool added_cert_; |
| }; |
| -DialogEnrollmentDelegate::DialogEnrollmentDelegate( |
| - gfx::NativeWindow owning_window) |
| - : owning_window_(owning_window) {} |
| - |
| -DialogEnrollmentDelegate::~DialogEnrollmentDelegate() {} |
| - |
| -void DialogEnrollmentDelegate::Enroll(const std::vector<std::string>& uri_list, |
| - const base::Closure& connect) { |
| - // Keep the closure for later activation if we notice that |
| - // a certificate has been added. |
| - for (std::vector<std::string>::const_iterator iter = uri_list.begin(); |
| - iter != uri_list.end(); ++iter) { |
| - GURL uri(*iter); |
| - if (uri.IsStandard() || uri.scheme() == "chrome-extension") { |
| - // If this is a "standard" scheme, like http, ftp, etc., then open that in |
| - // the enrollment dialog. If this is a chrome extension, then just open |
| - // that extension in a tab and let it provide any UI that it needs to |
| - // complete. |
| - EnrollmentDialogView::ShowDialog(owning_window_, uri, connect); |
| - return; |
| - } |
| - } |
| - // If we didn't find a scheme we could handle, then don't continue connecting. |
| - // TODO(gspencer): provide a path to display this failure to the user. |
| - VLOG(1) << "Couldn't find usable scheme in enrollment URI(s)"; |
| -} |
| - |
| -} // namespace |
| - |
| //////////////////////////////////////////////////////////////////////////////// |
| // EnrollmentDialogView implementation. |
| -EnrollmentDialogView::EnrollmentDialogView(const GURL& target_uri, |
| +EnrollmentDialogView::EnrollmentDialogView(Profile* profile, |
| + const GURL& target_uri, |
| const base::Closure& connect) |
| - : target_uri_(target_uri), |
| + : profile_(profile), |
| + target_uri_(target_uri), |
| connect_(connect), |
| added_cert_(false) { |
| - net::CertDatabase::AddObserver(this); |
| } |
| EnrollmentDialogView::~EnrollmentDialogView() { |
| - net::CertDatabase::RemoveObserver(this); |
| -} |
| - |
| -// static |
| -EnrollmentDelegate* EnrollmentDialogView::CreateEnrollmentDelegate( |
| - gfx::NativeWindow owning_window) { |
| - return new DialogEnrollmentDelegate(owning_window); |
| } |
| // static |
| void EnrollmentDialogView::ShowDialog(gfx::NativeWindow owning_window, |
| + Profile* profile, |
| const GURL& target_uri, |
| const base::Closure& connect) { |
| EnrollmentDialogView* dialog_view = |
| - new EnrollmentDialogView(target_uri, connect); |
| + new EnrollmentDialogView(profile, target_uri, connect); |
| views::Widget::CreateWindowWithParent(dialog_view, owning_window); |
| dialog_view->InitDialog(); |
| views::Widget* widget = dialog_view->GetWidget(); |
| @@ -156,12 +110,21 @@ void EnrollmentDialogView::Close() { |
| } |
| int EnrollmentDialogView::GetDialogButtons() const { |
| - return ui::DIALOG_BUTTON_CANCEL; |
| + return ui::DIALOG_BUTTON_CANCEL | ui::DIALOG_BUTTON_OK; |
| } |
| -void EnrollmentDialogView::OnClose() { |
| - if (added_cert_) |
| - connect_.Run(); |
| +bool EnrollmentDialogView::Accept() { |
| + // Navigate to the target URI in a browser tab. |
| + Browser* browser = BrowserList::FindTabbedBrowser(profile_, false); |
| + if (!browser) { |
| + // Couldn't find a tabbed browser: create one. |
| + browser = Browser::Create(profile_); |
| + } |
| + DCHECK(browser); |
| + browser->AddSelectedTabWithURL( |
| + target_uri_, |
| + content::PAGE_TRANSITION_LINK); |
| + return true; |
| } |
| ui::ModalType EnrollmentDialogView::GetModalType() const { |
| @@ -180,42 +143,17 @@ views::View* EnrollmentDialogView::GetContentsView() { |
| return this; |
| } |
| -void EnrollmentDialogView::OnUserCertAdded( |
| - const net::X509Certificate* cert) { |
| - added_cert_ = true; |
| - Close(); |
| -} |
| - |
| void EnrollmentDialogView::InitDialog() { |
| added_cert_ = false; |
| // Create the views and layout manager and set them up. |
| Label* label = new Label( |
| - l10n_util::GetStringUTF16( |
| - IDS_NETWORK_ENROLLMENT_HANDLER_EMBEDDED_ENROLL)); |
| + l10n_util::GetStringUTF16(IDS_NETWORK_ENROLLMENT_HANDLER_TAB_ENROLL)); |
| label->SetFont( |
| ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont)); |
| label->SetHorizontalAlignment(Label::ALIGN_LEFT); |
| label->SetMultiLine(true); |
| label->SetAllowCharacterBreak(true); |
| - // In order to get a border that shows around the WebView, we need to embed it |
| - // into another view because it hosts a native window that fills the view. |
| - View* web_view_border_view = new View(); |
| - web_view_border_view->SetLayoutManager( |
| - new BorderLayout(gfx::Insets(kWebViewBorderSize, |
| - kWebViewBorderSize, |
| - kWebViewBorderSize, |
| - kWebViewBorderSize))); |
| - SkColor frame_color = ThemeService::GetDefaultColor( |
| - ThemeService::COLOR_FRAME); |
| - Border* border = views::Border::CreateSolidBorder(kWebViewBorderSize, |
| - frame_color); |
| - web_view_border_view->set_border(border); |
| - views::WebView* web_view = |
| - new views::WebView(ProfileManager::GetLastUsedProfile()); |
| - web_view_border_view->AddChildView(web_view); |
| - web_view->SetVisible(true); |
| - |
| GridLayout* grid_layout = GridLayout::CreatePanel(this); |
| SetLayoutManager(grid_layout); |
| @@ -226,8 +164,6 @@ void EnrollmentDialogView::InitDialog() { |
| views::GridLayout::USE_PREF, // Size type. |
| 0, // Ignored for USE_PREF. |
| 0); // Minimum size. |
| - // Add a column set for aligning the text when it has no icons (such as the |
| - // help center link). |
| columns = grid_layout->AddColumnSet(1); |
| columns->AddPaddingColumn( |
| 0, views::kUnrelatedControlHorizontalSpacing); |
| @@ -241,11 +177,69 @@ void EnrollmentDialogView::InitDialog() { |
| grid_layout->StartRow(0, 0); |
| grid_layout->AddView(label); |
| grid_layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); |
| - grid_layout->StartRow(100.0f, 0); |
| - grid_layout->AddView(web_view_border_view); |
| - grid_layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); |
| grid_layout->Layout(this); |
| - web_view->LoadInitialURL(target_uri_); |
| +} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// Handler for certificate enrollment. |
| + |
| +class DialogEnrollmentDelegate : public EnrollmentDelegate { |
| + public: |
| + // |owning_window| is the window that will own the dialog. |
| + explicit DialogEnrollmentDelegate(gfx::NativeWindow owning_window, |
| + Profile* profile); |
| + virtual ~DialogEnrollmentDelegate(); |
| + |
| + // EnrollmentDelegate overrides |
| + virtual void Enroll(const std::vector<std::string>& uri_list, |
| + const base::Closure& connect) OVERRIDE; |
| + |
| + private: |
| + gfx::NativeWindow owning_window_; |
| + Profile* profile_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DialogEnrollmentDelegate); |
| +}; |
| + |
| +DialogEnrollmentDelegate::DialogEnrollmentDelegate( |
| + gfx::NativeWindow owning_window, |
| + Profile* profile) : owning_window_(owning_window), profile_(profile) {} |
| + |
| +DialogEnrollmentDelegate::~DialogEnrollmentDelegate() {} |
| + |
| +void DialogEnrollmentDelegate::Enroll(const std::vector<std::string>& uri_list, |
| + const base::Closure& connect) { |
| + // Keep the closure for later activation if we notice that |
| + // a certificate has been added. |
| + |
| + // TODO(gspencer): Do something smart with the closure. At the moment it is |
| + // being ignored because we don't know when the enrollment tab is closed. |
|
stevenjb
2012/05/02 00:31:23
This sounds like something we should have an issue
Greg Spencer (Chromium)
2012/05/02 21:08:59
Done. http://crosbug.com/30422
|
| + for (std::vector<std::string>::const_iterator iter = uri_list.begin(); |
| + iter != uri_list.end(); ++iter) { |
| + GURL uri(*iter); |
| + if (uri.IsStandard() || uri.scheme() == "chrome-extension") { |
|
stevenjb
2012/05/02 00:31:23
Is there a constant for "chrome-extension"?
Greg Spencer (Chromium)
2012/05/02 21:08:59
Not that I could find: mostly we just use raw stri
stevenjb
2012/05/02 21:12:44
Yeah, we should change that, but if that's the cur
Mihai Parparita -not on Chrome
2012/05/02 21:30:14
There is chrome::kExtensionScheme (from chrome/com
Greg Spencer (Chromium)
2012/05/02 21:44:26
Huh, I guess I just didn't see it in the search re
|
| + // If this is a "standard" scheme, like http, ftp, etc., then open that in |
| + // the enrollment dialog. |
| + EnrollmentDialogView::ShowDialog(owning_window_, profile_, uri, connect); |
| + return; |
| + } |
| + } |
| + |
| + // If we didn't find a scheme we could handle, then don't continue connecting. |
| + // TODO(gspencer): provide a path to display this failure to the user. (but |
| + // for the most part they won't know what it means, since it's probably coming |
| + // from a policy-pushed ONC file). |
| + VLOG(1) << "Couldn't find usable scheme in enrollment URI(s)"; |
| +} |
| + |
| +} // namespace |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// Factory function. |
| + |
| +EnrollmentDelegate* CreateEnrollmentDelegate(gfx::NativeWindow owning_window, |
| + Profile* profile) { |
| + return new DialogEnrollmentDelegate(owning_window, profile); |
| } |
| } // namespace chromeos |