| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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.h" | 5 #include "chrome/browser/first_run.h" |
| 6 | 6 |
| 7 #include <atlbase.h> | 7 #include <atlbase.h> |
| 8 #include <atlcom.h> | 8 #include <atlcom.h> |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 #include <shellapi.h> | 10 #include <shellapi.h> |
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 } | 619 } |
| 620 return true; | 620 return true; |
| 621 } | 621 } |
| 622 | 622 |
| 623 ////////////////////////////////////////////////////////////////////////// | 623 ////////////////////////////////////////////////////////////////////////// |
| 624 | 624 |
| 625 namespace { | 625 namespace { |
| 626 | 626 |
| 627 // These strings are used by TryChromeDialog. They will need to be localized | 627 // These strings are used by TryChromeDialog. They will need to be localized |
| 628 // if we use it for other locales. | 628 // if we use it for other locales. |
| 629 const wchar_t kHeading[] = | 629 const wchar_t* kHeading[] = { |
| 630 L"You stopped using Google Chrome. Would you like to ..."; | 630 L"You stopped using Google Chrome. Would you like to ...", |
| 631 const wchar_t kGiveChromeATry[] = | 631 L"Google Chrome misses you.", |
| 632 L"Give the new version a try (already installed)"; | 632 L"There is a new version of Google Chrome available.", |
| 633 const wchar_t kNahUninstallIt[] = L"Uninstall Google Chrome"; | 633 L"Google Chrome has been updated, but you haven't tried it yet" |
| 634 }; |
| 635 |
| 636 const wchar_t* kGiveChromeATry[] = { |
| 637 L"Give the new version a try (already installed)", |
| 638 L"Give it a second chance", |
| 639 L"Try it out (already installed)" |
| 640 }; |
| 641 |
| 642 const wchar_t* kNahUninstallIt[] = { |
| 643 L"Uninstall Google Chrome", |
| 644 L"Uninstall Google Chrome, it had its chance" |
| 645 }; |
| 646 |
| 647 const wchar_t* kOKButn[] = { |
| 648 L"OK", |
| 649 L"Try it" |
| 650 }; |
| 651 |
| 634 const wchar_t kDontBugMe[] = L"Don't bug me"; | 652 const wchar_t kDontBugMe[] = L"Don't bug me"; |
| 635 const wchar_t kOKButn[] = L"OK"; | |
| 636 const wchar_t kWhyThis[] = L"Why am I seeing this?"; | 653 const wchar_t kWhyThis[] = L"Why am I seeing this?"; |
| 637 const wchar_t kHelpCenterUrl[] = | 654 const wchar_t kHelpCenterUrl[] = |
| 638 L"http://www.google.com/support/chrome/bin/answer.py?hl=en&answer=150752"; | 655 L"http://www.google.com/support/chrome/bin/answer.py?hl=en&answer=150752"; |
| 639 | 656 |
| 657 // This structure and the following constant defines how the dialog looks with |
| 658 // respect of buttons and text, but does not fundamentally change the behavior. |
| 659 struct VersionConfig { |
| 660 int heading_index; |
| 661 int try_index; |
| 662 int uninstall_index; |
| 663 int ok_button_index; |
| 664 }; |
| 665 |
| 666 const VersionConfig kDialogVersion[] = { |
| 667 {0, 0, 0, 0}, // 0 is classic. |
| 668 {1, 1, 1, 0}, // 1 is humorous. |
| 669 {2, 2, 0, 0}, // 2 is update-focused. |
| 670 {3, -1, -1, 1} // 3 is simpler (no radio buttons). |
| 671 }; |
| 640 | 672 |
| 641 // This class displays a modal dialog using the views system. The dialog asks | 673 // This class displays a modal dialog using the views system. The dialog asks |
| 642 // the user to give chrome another try. This class only handles the UI so the | 674 // the user to give chrome another try. This class only handles the UI so the |
| 643 // resulting actions are up to the caller. It looks like this: | 675 // resulting actions are up to the caller. One version looks like this: |
| 644 // | 676 // |
| 645 // /----------------------------------------\ | 677 // /----------------------------------------\ |
| 646 // | |icon| You stopped using Google [x] | | 678 // | |icon| You stopped using Google [x] | |
| 647 // | |icon| Chrome. Would you like to.. | | 679 // | |icon| Chrome. Would you like to.. | |
| 648 // | [o] Give the new version a try | | 680 // | [o] Give the new version a try | |
| 649 // | [ ] Uninstall Google Chrome | | 681 // | [ ] Uninstall Google Chrome | |
| 650 // | [ OK ] [Don't bug me] | | 682 // | [ OK ] [Don't bug me] | |
| 651 // | _why_am_I_seeign this?__ | | 683 // | _why_am_I_seeign this?__ | |
| 652 // ------------------------------------------ | 684 // ------------------------------------------ |
| 653 class TryChromeDialog : public views::ButtonListener, | 685 class TryChromeDialog : public views::ButtonListener, |
| 654 public views::LinkController { | 686 public views::LinkController { |
| 655 public: | 687 public: |
| 656 TryChromeDialog() | 688 TryChromeDialog(size_t version) |
| 657 : popup_(NULL), | 689 : version_(version), |
| 690 popup_(NULL), |
| 658 try_chrome_(NULL), | 691 try_chrome_(NULL), |
| 659 kill_chrome_(NULL), | 692 kill_chrome_(NULL), |
| 660 result_(Upgrade::TD_LAST_ENUM) { | 693 result_(Upgrade::TD_LAST_ENUM) { |
| 694 // In case of doubt, use the first version of the dialog. |
| 695 if (version_ >= arraysize(kHeading)) |
| 696 version_ = 0; |
| 661 } | 697 } |
| 662 | 698 |
| 663 virtual ~TryChromeDialog() { | 699 virtual ~TryChromeDialog() { |
| 664 }; | 700 }; |
| 665 | 701 |
| 666 // Shows the modal dialog asking the user to try chrome. Note that the dialog | 702 // Shows the modal dialog asking the user to try chrome. Note that the dialog |
| 667 // has no parent and it will position itself in a lower corner of the screen. | 703 // has no parent and it will position itself in a lower corner of the screen. |
| 668 // The dialog does not steal focus and does not have an entry in the taskbar. | 704 // The dialog does not steal focus and does not have an entry in the taskbar. |
| 669 Upgrade::TryResult ShowModal() { | 705 Upgrade::TryResult ShowModal() { |
| 670 using views::GridLayout; | 706 using views::GridLayout; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 GridLayout::USE_PREF, 0, 0); | 768 GridLayout::USE_PREF, 0, 0); |
| 733 // Fifth row: [pad][pad][link]. | 769 // Fifth row: [pad][pad][link]. |
| 734 columns = layout->AddColumnSet(4); | 770 columns = layout->AddColumnSet(4); |
| 735 columns->AddPaddingColumn(0, icon_size.width()); | 771 columns->AddPaddingColumn(0, icon_size.width()); |
| 736 columns->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); | 772 columns->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
| 737 columns->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, | 773 columns->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, |
| 738 GridLayout::USE_PREF, 0, 0); | 774 GridLayout::USE_PREF, 0, 0); |
| 739 // First row views. | 775 // First row views. |
| 740 layout->StartRow(0, 0); | 776 layout->StartRow(0, 0); |
| 741 layout->AddView(icon); | 777 layout->AddView(icon); |
| 742 views::Label* label = new views::Label(kHeading); | 778 views::Label* label = |
| 779 new views::Label(kHeading[kDialogVersion[version_].heading_index]); |
| 743 label->SetFont(rb.GetFont(ResourceBundle::MediumBoldFont)); | 780 label->SetFont(rb.GetFont(ResourceBundle::MediumBoldFont)); |
| 744 label->SetMultiLine(true); | 781 label->SetMultiLine(true); |
| 745 label->SizeToFit(200); | 782 label->SizeToFit(200); |
| 746 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 783 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 747 layout->AddView(label); | 784 layout->AddView(label); |
| 748 views::ImageButton* close_button = new views::ImageButton(this); | 785 views::ImageButton* close_button = new views::ImageButton(this); |
| 749 close_button->SetImage(views::CustomButton::BS_NORMAL, | 786 close_button->SetImage(views::CustomButton::BS_NORMAL, |
| 750 rb.GetBitmapNamed(IDR_CLOSE_BAR)); | 787 rb.GetBitmapNamed(IDR_CLOSE_BAR)); |
| 751 close_button->SetImage(views::CustomButton::BS_HOT, | 788 close_button->SetImage(views::CustomButton::BS_HOT, |
| 752 rb.GetBitmapNamed(IDR_CLOSE_BAR_H)); | 789 rb.GetBitmapNamed(IDR_CLOSE_BAR_H)); |
| 753 close_button->SetImage(views::CustomButton::BS_PUSHED, | 790 close_button->SetImage(views::CustomButton::BS_PUSHED, |
| 754 rb.GetBitmapNamed(IDR_CLOSE_BAR_P)); | 791 rb.GetBitmapNamed(IDR_CLOSE_BAR_P)); |
| 755 close_button->set_tag(BT_CLOSE_BUTTON); | 792 close_button->set_tag(BT_CLOSE_BUTTON); |
| 756 layout->AddView(close_button); | 793 layout->AddView(close_button); |
| 757 // Second row views. | 794 // Second row views. |
| 758 layout->StartRowWithPadding(0, 1, 0, 10); | 795 if (kDialogVersion[version_].try_index >= 0) { |
| 759 try_chrome_ = new views::RadioButton(kGiveChromeATry, 1); | 796 layout->StartRowWithPadding(0, 1, 0, 10); |
| 760 try_chrome_->SetChecked(true); | 797 try_chrome_ = new views::RadioButton( |
| 761 layout->AddView(try_chrome_); | 798 kGiveChromeATry[kDialogVersion[version_].try_index], 1); |
| 799 try_chrome_->SetChecked(true); |
| 800 layout->AddView(try_chrome_); |
| 801 } |
| 762 // Third row views. | 802 // Third row views. |
| 763 layout->StartRow(0, 2); | 803 if (kDialogVersion[version_].try_index >= 0) { |
| 764 kill_chrome_ = new views::RadioButton(kNahUninstallIt, 1); | 804 layout->StartRow(0, 2); |
| 765 layout->AddView(kill_chrome_); | 805 kill_chrome_ = new views::RadioButton( |
| 806 kNahUninstallIt[kDialogVersion[version_].uninstall_index], 1); |
| 807 layout->AddView(kill_chrome_); |
| 808 } |
| 766 // Fourth row views. | 809 // Fourth row views. |
| 767 layout->StartRowWithPadding(0, 3, 0, 10); | 810 layout->StartRowWithPadding(0, 3, 0, 10); |
| 768 views::Button* accept_button = new views::NativeButton(this, kOKButn); | 811 views::Button* accept_button = new views::NativeButton(this, |
| 812 kOKButn[kDialogVersion[version_].ok_button_index]); |
| 769 accept_button->set_tag(BT_OK_BUTTON); | 813 accept_button->set_tag(BT_OK_BUTTON); |
| 770 layout->AddView(accept_button); | 814 layout->AddView(accept_button); |
| 771 views::Button* cancel_button = new views::NativeButton(this, kDontBugMe); | 815 views::Button* cancel_button = new views::NativeButton(this, kDontBugMe); |
| 772 cancel_button->set_tag(BT_CLOSE_BUTTON); | 816 cancel_button->set_tag(BT_CLOSE_BUTTON); |
| 773 layout->AddView(cancel_button); | 817 layout->AddView(cancel_button); |
| 774 // Fifth row views. | 818 // Fifth row views. |
| 775 layout->StartRowWithPadding(0, 4, 0, 10); | 819 layout->StartRowWithPadding(0, 4, 0, 10); |
| 776 views::Link* link = new views::Link(kWhyThis); | 820 views::Link* link = new views::Link(kWhyThis); |
| 777 link->SetController(this); | 821 link->SetController(this); |
| 778 layout->AddView(link); | 822 layout->AddView(link); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 793 MessageLoop::current()->Run(); | 837 MessageLoop::current()->Run(); |
| 794 return result_; | 838 return result_; |
| 795 } | 839 } |
| 796 | 840 |
| 797 protected: | 841 protected: |
| 798 // Overridden from ButtonListener. We have two buttons and according to | 842 // Overridden from ButtonListener. We have two buttons and according to |
| 799 // what the user clicked we set |result_| and we should always close and | 843 // what the user clicked we set |result_| and we should always close and |
| 800 // end the modal loop. | 844 // end the modal loop. |
| 801 virtual void ButtonPressed(views::Button* sender) { | 845 virtual void ButtonPressed(views::Button* sender) { |
| 802 if (sender->tag() == BT_CLOSE_BUTTON) { | 846 if (sender->tag() == BT_CLOSE_BUTTON) { |
| 847 // The user pressed cancel or the [x] button. |
| 803 result_ = Upgrade::TD_NOT_NOW; | 848 result_ = Upgrade::TD_NOT_NOW; |
| 849 } else if (!try_chrome_) { |
| 850 // We don't have radio buttons, the user pressed ok. |
| 851 result_ = Upgrade::TD_TRY_CHROME; |
| 804 } else { | 852 } else { |
| 853 // The outcome is according to the selected ratio button. |
| 805 result_ = try_chrome_->checked() ? Upgrade::TD_TRY_CHROME : | 854 result_ = try_chrome_->checked() ? Upgrade::TD_TRY_CHROME : |
| 806 Upgrade::TD_UNINSTALL_CHROME; | 855 Upgrade::TD_UNINSTALL_CHROME; |
| 807 } | 856 } |
| 808 popup_->Close(); | 857 popup_->Close(); |
| 809 MessageLoop::current()->Quit(); | 858 MessageLoop::current()->Quit(); |
| 810 } | 859 } |
| 811 | 860 |
| 812 // Overridden from LinkController. If the user selects the link we need to | 861 // Overridden from LinkController. If the user selects the link we need to |
| 813 // fire off the default browser that by some convoluted logic should not be | 862 // fire off the default browser that by some convoluted logic should not be |
| 814 // chrome. | 863 // chrome. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 void SetToastRegion(HWND window, int w, int h) { | 899 void SetToastRegion(HWND window, int w, int h) { |
| 851 static const POINT polygon[] = { | 900 static const POINT polygon[] = { |
| 852 {0, 4}, {1, 2}, {2, 1}, {4, 0}, // Left side. | 901 {0, 4}, {1, 2}, {2, 1}, {4, 0}, // Left side. |
| 853 {w-4, 0}, {w-2, 1}, {w-1, 2}, {w, 4}, // Right side. | 902 {w-4, 0}, {w-2, 1}, {w-1, 2}, {w, 4}, // Right side. |
| 854 {w, h}, {0, h} | 903 {w, h}, {0, h} |
| 855 }; | 904 }; |
| 856 HRGN region = ::CreatePolygonRgn(polygon, arraysize(polygon), WINDING); | 905 HRGN region = ::CreatePolygonRgn(polygon, arraysize(polygon), WINDING); |
| 857 ::SetWindowRgn(window, region, FALSE); | 906 ::SetWindowRgn(window, region, FALSE); |
| 858 } | 907 } |
| 859 | 908 |
| 909 // controls which version of the text to use. |
| 910 size_t version_; |
| 911 |
| 860 // We don't own any of this pointers. The |popup_| owns itself and owns | 912 // We don't own any of this pointers. The |popup_| owns itself and owns |
| 861 // the other views. | 913 // the other views. |
| 862 views::WidgetWin* popup_; | 914 views::WidgetWin* popup_; |
| 863 views::RadioButton* try_chrome_; | 915 views::RadioButton* try_chrome_; |
| 864 views::RadioButton* kill_chrome_; | 916 views::RadioButton* kill_chrome_; |
| 865 Upgrade::TryResult result_; | 917 Upgrade::TryResult result_; |
| 866 | 918 |
| 867 DISALLOW_COPY_AND_ASSIGN(TryChromeDialog); | 919 DISALLOW_COPY_AND_ASSIGN(TryChromeDialog); |
| 868 }; | 920 }; |
| 869 | 921 |
| 870 } // namespace | 922 } // namespace |
| 871 | 923 |
| 872 Upgrade::TryResult Upgrade::ShowTryChromeDialog() { | 924 Upgrade::TryResult Upgrade::ShowTryChromeDialog(size_t version) { |
| 873 TryChromeDialog td; | 925 TryChromeDialog td(version); |
| 874 return td.ShowModal(); | 926 return td.ShowModal(); |
| 875 } | 927 } |
| OLD | NEW |