| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/first_run/first_run.h" | 5 #include "chrome/browser/first_run/first_run.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <shellapi.h> | 8 #include <shellapi.h> |
| 9 #include <shlobj.h> | 9 #include <shlobj.h> |
| 10 | 10 |
| (...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 kill_chrome_(NULL), | 615 kill_chrome_(NULL), |
| 616 result_(Upgrade::TD_LAST_ENUM) { | 616 result_(Upgrade::TD_LAST_ENUM) { |
| 617 } | 617 } |
| 618 | 618 |
| 619 virtual ~TryChromeDialog() { | 619 virtual ~TryChromeDialog() { |
| 620 }; | 620 }; |
| 621 | 621 |
| 622 // Shows the modal dialog asking the user to try chrome. Note that the dialog | 622 // Shows the modal dialog asking the user to try chrome. Note that the dialog |
| 623 // has no parent and it will position itself in a lower corner of the screen. | 623 // has no parent and it will position itself in a lower corner of the screen. |
| 624 // The dialog does not steal focus and does not have an entry in the taskbar. | 624 // The dialog does not steal focus and does not have an entry in the taskbar. |
| 625 Upgrade::TryResult ShowModal() { | 625 Upgrade::TryResult ShowModal(ProcessSingleton* process_singleton) { |
| 626 using views::GridLayout; | 626 using views::GridLayout; |
| 627 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 627 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 628 | 628 |
| 629 views::ImageView* icon = new views::ImageView(); | 629 views::ImageView* icon = new views::ImageView(); |
| 630 icon->SetImage(*rb.GetBitmapNamed(IDR_PRODUCT_ICON_32)); | 630 icon->SetImage(*rb.GetBitmapNamed(IDR_PRODUCT_ICON_32)); |
| 631 gfx::Size icon_size = icon->GetPreferredSize(); | 631 gfx::Size icon_size = icon->GetPreferredSize(); |
| 632 | 632 |
| 633 // An approximate window size. After Layout() we'll get better bounds. | 633 // An approximate window size. After Layout() we'll get better bounds. |
| 634 gfx::Rect pos(310, 160); | 634 gfx::Rect pos(310, 160); |
| 635 views::WidgetWin* popup = new views::WidgetWin(); | 635 views::WidgetWin* popup = new views::WidgetWin(); |
| 636 if (!popup) { | 636 if (!popup) { |
| 637 NOTREACHED(); | 637 NOTREACHED(); |
| 638 return Upgrade::TD_DIALOG_ERROR; | 638 return Upgrade::TD_DIALOG_ERROR; |
| 639 } | 639 } |
| 640 |
| 640 popup->set_delete_on_destroy(true); | 641 popup->set_delete_on_destroy(true); |
| 641 popup->set_window_style(WS_POPUP | WS_CLIPCHILDREN); | 642 popup->set_window_style(WS_POPUP | WS_CLIPCHILDREN); |
| 642 popup->set_window_ex_style(WS_EX_TOOLWINDOW); | 643 popup->set_window_ex_style(WS_EX_TOOLWINDOW); |
| 643 popup->Init(NULL, pos); | 644 popup->Init(NULL, pos); |
| 644 | 645 |
| 645 views::RootView* root_view = popup->GetRootView(); | 646 views::RootView* root_view = popup->GetRootView(); |
| 646 // The window color is a tiny bit off-white. | 647 // The window color is a tiny bit off-white. |
| 647 root_view->set_background( | 648 root_view->set_background( |
| 648 views::Background::CreateSolidBackground(0xfc, 0xfc, 0xfc)); | 649 views::Background::CreateSolidBackground(0xfc, 0xfc, 0xfc)); |
| 649 | 650 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 // account the differences between XP and Vista fonts and buttons. | 761 // account the differences between XP and Vista fonts and buttons. |
| 761 layout->Layout(root_view); | 762 layout->Layout(root_view); |
| 762 gfx::Size preferred = layout->GetPreferredSize(root_view); | 763 gfx::Size preferred = layout->GetPreferredSize(root_view); |
| 763 pos = ComputeWindowPosition(preferred.width(), preferred.height(), | 764 pos = ComputeWindowPosition(preferred.width(), preferred.height(), |
| 764 base::i18n::IsRTL()); | 765 base::i18n::IsRTL()); |
| 765 popup->SetBounds(pos); | 766 popup->SetBounds(pos); |
| 766 | 767 |
| 767 // Carve the toast shape into the window. | 768 // Carve the toast shape into the window. |
| 768 SetToastRegion(popup->GetNativeView(), | 769 SetToastRegion(popup->GetNativeView(), |
| 769 preferred.width(), preferred.height()); | 770 preferred.width(), preferred.height()); |
| 770 // Time to show the window in a modal loop. | |
| 771 popup_ = popup; | 771 popup_ = popup; |
| 772 |
| 773 // Time to show the window in a modal loop. We don't want this chrome |
| 774 // instance trying to serve WM_COPYDATA requests, as we'll surely crash. |
| 775 process_singleton->Lock(popup->GetNativeView()); |
| 772 popup_->Show(); | 776 popup_->Show(); |
| 773 MessageLoop::current()->Run(); | 777 MessageLoop::current()->Run(); |
| 778 process_singleton->Unlock(); |
| 774 return result_; | 779 return result_; |
| 775 } | 780 } |
| 776 | 781 |
| 777 protected: | 782 protected: |
| 778 // Overridden from ButtonListener. We have two buttons and according to | 783 // Overridden from ButtonListener. We have two buttons and according to |
| 779 // what the user clicked we set |result_| and we should always close and | 784 // what the user clicked we set |result_| and we should always close and |
| 780 // end the modal loop. | 785 // end the modal loop. |
| 781 virtual void ButtonPressed(views::Button* sender, const views::Event& event) { | 786 virtual void ButtonPressed(views::Button* sender, const views::Event& event) { |
| 782 if (sender->tag() == BT_CLOSE_BUTTON) { | 787 if (sender->tag() == BT_CLOSE_BUTTON) { |
| 783 // The user pressed cancel or the [x] button. | 788 // The user pressed cancel or the [x] button. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 views::WidgetWin* popup_; | 857 views::WidgetWin* popup_; |
| 853 views::RadioButton* try_chrome_; | 858 views::RadioButton* try_chrome_; |
| 854 views::RadioButton* kill_chrome_; | 859 views::RadioButton* kill_chrome_; |
| 855 Upgrade::TryResult result_; | 860 Upgrade::TryResult result_; |
| 856 | 861 |
| 857 DISALLOW_COPY_AND_ASSIGN(TryChromeDialog); | 862 DISALLOW_COPY_AND_ASSIGN(TryChromeDialog); |
| 858 }; | 863 }; |
| 859 | 864 |
| 860 } // namespace | 865 } // namespace |
| 861 | 866 |
| 862 Upgrade::TryResult Upgrade::ShowTryChromeDialog(size_t version) { | 867 Upgrade::TryResult Upgrade::ShowTryChromeDialog( |
| 868 size_t version, |
| 869 ProcessSingleton* process_singleton) { |
| 863 if (version > 10000) { | 870 if (version > 10000) { |
| 864 // This is a test value. We want to make sure we exercise | 871 // This is a test value. We want to make sure we exercise |
| 865 // returning this early. See EarlyReturnTest test harness. | 872 // returning this early. See EarlyReturnTest test harness. |
| 866 return Upgrade::TD_NOT_NOW; | 873 return Upgrade::TD_NOT_NOW; |
| 867 } | 874 } |
| 868 TryChromeDialog td(version); | 875 TryChromeDialog td(version); |
| 869 return td.ShowModal(); | 876 return td.ShowModal(process_singleton); |
| 870 } | 877 } |
| OLD | NEW |