1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome_frame/ready_mode/internal/ready_prompt_window.h"
10 #include "base/compiler_specific.h"
11 #include "base/win/scoped_bstr.h"
12 #include "base/win/scoped_comptr.h"
13 #include "chrome_frame/ready_mode/internal/ready_mode_state.h"
14 #include "chrome_frame/ready_mode/internal/url_launcher.h"
15 #include "chrome_frame/simple_resource_loader.h"
16 #include "grit/chrome_frame_dialogs.h"
17 #include "grit/chromium_strings.h"
19 // atlctrlx.h requires 'min' and 'max' macros, the definition of which conflicts
20 // with STL headers. Hence we include them out of the order defined by style
21 // guidelines. As a result you may not refer to std::min or std::max in this
23 #include <minmax.h> // NOLINT
24 #include <atlctrlx.h> // NOLINT
26 ReadyPromptWindow::ReadyPromptWindow(
27 InfobarContent::Frame* frame, ReadyModeState* ready_mode_state,
28 UrlLauncher* url_launcher)
30 ready_mode_state_(ready_mode_state),
31 url_launcher_(url_launcher),
33 weak_ptr_factory_(this) {
35 ReadyPromptWindow::~ReadyPromptWindow() {
40 base::WeakPtr<ReadyPromptWindow> ReadyPromptWindow::CreateInstance(
41 InfobarContent::Frame* frame, ReadyModeState* ready_mode_state,
42 UrlLauncher* url_launcher) {
43 DCHECK(frame != NULL);
44 DCHECK(ready_mode_state != NULL);
45 DCHECK(url_launcher != NULL);
47 base::WeakPtr<ReadyPromptWindow> instance((new ReadyPromptWindow(
48 frame, ready_mode_state, url_launcher))->weak_ptr_factory_.GetWeakPtr());
50 DCHECK(!instance->IsWindow());
52 if (instance->Create(frame->GetFrameWindow()) == NULL) {
53 DPLOG(ERROR) << "Failed to create HWND for ReadyPromptWindow.";
54 return base::WeakPtr<ReadyPromptWindow>();
57 // Subclass the "Learn more." text to make it behave like a link. Clicks are
58 // routed to OnLearnMore().
59 CWindow rte = instance->GetDlgItem(IDC_PROMPT_LINK);
60 instance->link_.reset(new CHyperLink());
61 instance->link_->SubclassWindow(rte);
62 instance->link_->SetHyperLinkExtendedStyle(HLINK_NOTIFYBUTTON,
65 CStatic icon_control(instance->GetDlgItem(IDC_PROMPT_ICON));
67 instance->icon_ = static_cast<HICON>(
68 ::LoadImage(_AtlBaseModule.GetResourceInstance(),
69 MAKEINTRESOURCE(IDI_CHROME_FRAME_ICON),
70 IMAGE_ICON, 16, 16, 0));
73 icon_control.SetIcon(instance->icon_);
78 void ReadyPromptWindow::OnDestroy() {
82 BOOL ReadyPromptWindow::OnInitDialog(CWindow wndFocus, LPARAM lInitParam) {
83 DlgResize_Init(false); // false => 'no gripper'
87 LRESULT ReadyPromptWindow::OnYes(WORD /*wNotifyCode*/,
91 frame_->CloseInfobar();
92 ready_mode_state_->AcceptChromeFrame();
96 LRESULT ReadyPromptWindow::OnRemindMeLater(WORD /*wNotifyCode*/,
100 frame_->CloseInfobar();
101 ready_mode_state_->TemporarilyDeclineChromeFrame();
105 LRESULT ReadyPromptWindow::OnNo(WORD /*wNotifyCode*/,
108 BOOL& /*bHandled*/) {
109 frame_->CloseInfobar();
110 ready_mode_state_->PermanentlyDeclineChromeFrame();
114 LRESULT ReadyPromptWindow::OnLearnMore(WORD /*wParam*/,
116 BOOL& /*bHandled*/) {
117 url_launcher_->LaunchUrl(SimpleResourceLoader::Get(
118 IDS_CHROME_FRAME_READY_MODE_LEARN_MORE_URL));
122 void ReadyPromptWindow::OnFinalMessage(HWND) {