- add sources.
[platform/framework/web/crosswalk.git] / src / chrome_frame / ready_mode / internal / ready_prompt_window.cc
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.
4
5 #include "chrome_frame/ready_mode/internal/ready_prompt_window.h"
6
7 #include <atlctrls.h>
8 #include <Shellapi.h>
9
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"
18
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
22 // file.
23 #include <minmax.h>  // NOLINT
24 #include <atlctrlx.h>  // NOLINT
25
26 ReadyPromptWindow::ReadyPromptWindow(
27     InfobarContent::Frame* frame, ReadyModeState* ready_mode_state,
28     UrlLauncher* url_launcher)
29     : frame_(frame),
30       ready_mode_state_(ready_mode_state),
31       url_launcher_(url_launcher),
32       icon_(NULL),
33       weak_ptr_factory_(this) {
34 }
35 ReadyPromptWindow::~ReadyPromptWindow() {
36   if (icon_)
37     ::DestroyIcon(icon_);
38 }
39
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);
46
47   base::WeakPtr<ReadyPromptWindow> instance((new ReadyPromptWindow(
48       frame, ready_mode_state, url_launcher))->weak_ptr_factory_.GetWeakPtr());
49
50   DCHECK(!instance->IsWindow());
51
52   if (instance->Create(frame->GetFrameWindow()) == NULL) {
53     DPLOG(ERROR) << "Failed to create HWND for ReadyPromptWindow.";
54     return base::WeakPtr<ReadyPromptWindow>();
55   }
56
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,
63                                              HLINK_NOTIFYBUTTON);
64
65   CStatic icon_control(instance->GetDlgItem(IDC_PROMPT_ICON));
66
67   instance->icon_ = static_cast<HICON>(
68       ::LoadImage(_AtlBaseModule.GetResourceInstance(),
69                   MAKEINTRESOURCE(IDI_CHROME_FRAME_ICON),
70                   IMAGE_ICON, 16, 16, 0));
71
72   if (instance->icon_)
73     icon_control.SetIcon(instance->icon_);
74
75   return instance;
76 }
77
78 void ReadyPromptWindow::OnDestroy() {
79   frame_ = NULL;
80 }
81
82 BOOL ReadyPromptWindow::OnInitDialog(CWindow wndFocus, LPARAM lInitParam) {
83   DlgResize_Init(false);  // false => 'no gripper'
84   return TRUE;
85 }
86
87 LRESULT ReadyPromptWindow::OnYes(WORD /*wNotifyCode*/,
88                                  WORD /*wID*/,
89                                  HWND /*hWndCtl*/,
90                                  BOOL& /*bHandled*/) {
91   frame_->CloseInfobar();
92   ready_mode_state_->AcceptChromeFrame();
93   return 0;
94 }
95
96 LRESULT ReadyPromptWindow::OnRemindMeLater(WORD /*wNotifyCode*/,
97                                            WORD /*wID*/,
98                                            HWND /*hWndCtl*/,
99                                            BOOL& /*bHandled*/) {
100   frame_->CloseInfobar();
101   ready_mode_state_->TemporarilyDeclineChromeFrame();
102   return 0;
103 }
104
105 LRESULT ReadyPromptWindow::OnNo(WORD /*wNotifyCode*/,
106                                 WORD /*wID*/,
107                                 HWND /*hWndCtl*/,
108                                 BOOL& /*bHandled*/) {
109   frame_->CloseInfobar();
110   ready_mode_state_->PermanentlyDeclineChromeFrame();
111   return 0;
112 }
113
114 LRESULT ReadyPromptWindow::OnLearnMore(WORD /*wParam*/,
115                                        LPNMHDR /*lParam*/,
116                                        BOOL& /*bHandled*/) {
117   url_launcher_->LaunchUrl(SimpleResourceLoader::Get(
118       IDS_CHROME_FRAME_READY_MODE_LEARN_MORE_URL));
119   return 0;
120 }
121
122 void ReadyPromptWindow::OnFinalMessage(HWND) {
123   delete this;
124 }