OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/try_chrome_dialog_view.h" | 5 #include "chrome/browser/first_run/try_chrome_dialog_view.h" |
6 | 6 |
7 #include <shellapi.h> | 7 #include <shellapi.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 BT_DONT_BUG_RADIO | 48 BT_DONT_BUG_RADIO |
49 }; | 49 }; |
50 | 50 |
51 const int kRadioGroupID = 1; | 51 const int kRadioGroupID = 1; |
52 | 52 |
53 } // namespace | 53 } // namespace |
54 | 54 |
55 // static | 55 // static |
56 TryChromeDialogView::Result TryChromeDialogView::Show( | 56 TryChromeDialogView::Result TryChromeDialogView::Show( |
57 size_t flavor, | 57 size_t flavor, |
58 ProcessSingleton* process_singleton) { | 58 const ActiveModalDialogListener& listener) { |
59 if (flavor > 10000) { | 59 if (flavor > 10000) { |
60 // This is a test value. We want to make sure we exercise | 60 // This is a test value. We want to make sure we exercise |
61 // returning this early. See TryChromeDialogBrowserTest test. | 61 // returning this early. See TryChromeDialogBrowserTest test. |
62 return NOT_NOW; | 62 return NOT_NOW; |
63 } | 63 } |
64 TryChromeDialogView dialog(flavor); | 64 TryChromeDialogView dialog(flavor); |
65 return dialog.ShowModal(process_singleton); | 65 return dialog.ShowModal(listener); |
66 } | 66 } |
67 | 67 |
68 TryChromeDialogView::TryChromeDialogView(size_t flavor) | 68 TryChromeDialogView::TryChromeDialogView(size_t flavor) |
69 : flavor_(flavor), | 69 : flavor_(flavor), |
70 popup_(NULL), | 70 popup_(NULL), |
71 try_chrome_(NULL), | 71 try_chrome_(NULL), |
72 kill_chrome_(NULL), | 72 kill_chrome_(NULL), |
73 dont_try_chrome_(NULL), | 73 dont_try_chrome_(NULL), |
74 make_default_(NULL), | 74 make_default_(NULL), |
75 result_(COUNT) { | 75 result_(COUNT) { |
76 } | 76 } |
77 | 77 |
78 TryChromeDialogView::~TryChromeDialogView() { | 78 TryChromeDialogView::~TryChromeDialogView() { |
79 } | 79 } |
80 | 80 |
81 TryChromeDialogView::Result TryChromeDialogView::ShowModal( | 81 TryChromeDialogView::Result TryChromeDialogView::ShowModal( |
82 ProcessSingleton* process_singleton) { | 82 const ActiveModalDialogListener& listener) { |
83 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 83 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
84 | 84 |
85 views::ImageView* icon = new views::ImageView(); | 85 views::ImageView* icon = new views::ImageView(); |
86 icon->SetImage(rb.GetNativeImageNamed(IDR_PRODUCT_LOGO_32).ToImageSkia()); | 86 icon->SetImage(rb.GetNativeImageNamed(IDR_PRODUCT_LOGO_32).ToImageSkia()); |
87 gfx::Size icon_size = icon->GetPreferredSize(); | 87 gfx::Size icon_size = icon->GetPreferredSize(); |
88 | 88 |
89 popup_ = new views::Widget; | 89 popup_ = new views::Widget; |
90 if (!popup_) { | 90 if (!popup_) { |
91 NOTREACHED(); | 91 NOTREACHED(); |
92 return DIALOG_ERROR; | 92 return DIALOG_ERROR; |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 // Carve the toast shape into the window. | 288 // Carve the toast shape into the window. |
289 HWND toast_window; | 289 HWND toast_window; |
290 #if defined(USE_AURA) | 290 #if defined(USE_AURA) |
291 toast_window = | 291 toast_window = |
292 popup_->GetNativeView()->GetRootWindow()->GetAcceleratedWidget(); | 292 popup_->GetNativeView()->GetRootWindow()->GetAcceleratedWidget(); |
293 #else | 293 #else |
294 toast_window = popup_->GetNativeView(); | 294 toast_window = popup_->GetNativeView(); |
295 #endif | 295 #endif |
296 SetToastRegion(toast_window, preferred.width(), preferred.height()); | 296 SetToastRegion(toast_window, preferred.width(), preferred.height()); |
297 | 297 |
298 // Time to show the window in a modal loop. The ProcessSingleton should | 298 // Time to show the window in a modal loop. |
299 // already be locked and it will not process WM_COPYDATA requests. Change the | |
300 // window to bring to foreground if a request arrives. | |
301 CHECK(process_singleton->locked()); | |
302 process_singleton->SetForegroundWindow(popup_->GetNativeView()); | |
303 popup_->Show(); | 299 popup_->Show(); |
300 if (!listener.is_null()) | |
301 listener.Run(popup_->GetNativeView()); | |
304 MessageLoop::current()->Run(); | 302 MessageLoop::current()->Run(); |
gab
2013/03/27 18:03:26
We shouldn't run the MessageLoop before the end of
erikwright (departed)
2013/03/28 03:16:34
I'm sure a way could be found to do that, but keep
| |
305 process_singleton->SetForegroundWindow(NULL); | 303 if (!listener.is_null()) |
304 listener.Run(NULL); | |
306 return result_; | 305 return result_; |
307 } | 306 } |
308 | 307 |
309 gfx::Rect TryChromeDialogView::ComputeWindowPosition(int width, | 308 gfx::Rect TryChromeDialogView::ComputeWindowPosition(int width, |
310 int height, | 309 int height, |
311 bool is_RTL) { | 310 bool is_RTL) { |
312 // The 'Shell_TrayWnd' is the taskbar. We like to show our window in that | 311 // The 'Shell_TrayWnd' is the taskbar. We like to show our window in that |
313 // monitor if we can. This code works even if such window is not found. | 312 // monitor if we can. This code works even if such window is not found. |
314 HWND taskbar = ::FindWindowW(L"Shell_TrayWnd", NULL); | 313 HWND taskbar = ::FindWindowW(L"Shell_TrayWnd", NULL); |
315 HMONITOR monitor = ::MonitorFromWindow(taskbar, MONITOR_DEFAULTTOPRIMARY); | 314 HMONITOR monitor = ::MonitorFromWindow(taskbar, MONITOR_DEFAULTTOPRIMARY); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
372 result_ = TRY_CHROME_AS_DEFAULT; | 371 result_ = TRY_CHROME_AS_DEFAULT; |
373 } | 372 } |
374 | 373 |
375 popup_->Close(); | 374 popup_->Close(); |
376 MessageLoop::current()->Quit(); | 375 MessageLoop::current()->Quit(); |
377 } | 376 } |
378 | 377 |
379 void TryChromeDialogView::LinkClicked(views::Link* source, int event_flags) { | 378 void TryChromeDialogView::LinkClicked(views::Link* source, int event_flags) { |
380 ::ShellExecuteW(NULL, L"open", kHelpCenterUrl, NULL, NULL, SW_SHOW); | 379 ::ShellExecuteW(NULL, L"open", kHelpCenterUrl, NULL, NULL, SW_SHOW); |
381 } | 380 } |
OLD | NEW |