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/chromeos/login/webui_login_view.h" | 5 #include "chrome/browser/chromeos/login/webui_login_view.h" |
6 | 6 |
7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/utf_string_conversions.h" |
| 9 #include "base/values.h" |
8 #include "chrome/browser/chromeos/accessibility_util.h" | 10 #include "chrome/browser/chromeos/accessibility_util.h" |
9 #include "chrome/browser/chromeos/login/proxy_settings_dialog.h" | 11 #include "chrome/browser/chromeos/login/proxy_settings_dialog.h" |
10 #include "chrome/browser/chromeos/login/webui_login_display.h" | 12 #include "chrome/browser/chromeos/login/webui_login_display.h" |
11 #include "chrome/browser/chromeos/status/clock_menu_button.h" | 13 #include "chrome/browser/chromeos/status/clock_menu_button.h" |
12 #include "chrome/browser/chromeos/status/input_method_menu_button.h" | 14 #include "chrome/browser/chromeos/status/input_method_menu_button.h" |
13 #include "chrome/browser/chromeos/status/network_menu_button.h" | 15 #include "chrome/browser/chromeos/status/network_menu_button.h" |
14 #include "chrome/browser/chromeos/status/status_area_view.h" | 16 #include "chrome/browser/chromeos/status/status_area_view.h" |
15 #include "chrome/browser/chromeos/wm_ipc.h" | 17 #include "chrome/browser/chromeos/wm_ipc.h" |
16 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
17 #include "chrome/browser/ui/views/dom_view.h" | 19 #include "chrome/browser/ui/views/dom_view.h" |
| 20 #include "chrome/common/render_messages.h" |
| 21 #include "content/browser/renderer_host/render_view_host_observer.h" |
18 #include "content/browser/tab_contents/tab_contents.h" | 22 #include "content/browser/tab_contents/tab_contents.h" |
19 #include "ui/gfx/rect.h" | 23 #include "ui/gfx/rect.h" |
20 #include "ui/gfx/size.h" | 24 #include "ui/gfx/size.h" |
21 #include "views/widget/native_widget_gtk.h" | 25 #include "views/widget/native_widget_gtk.h" |
22 #include "views/widget/widget.h" | 26 #include "views/widget/widget.h" |
23 | 27 |
24 #if defined(TOUCH_UI) | 28 #if defined(TOUCH_UI) |
25 #include "chrome/browser/ui/touch/keyboard/keyboard_manager.h" | 29 #include "chrome/browser/ui/touch/keyboard/keyboard_manager.h" |
26 #endif | 30 #endif |
27 | 31 |
28 namespace { | 32 namespace { |
29 | 33 |
30 const char kViewClassName[] = "browser/chromeos/login/WebUILoginView"; | 34 const char kViewClassName[] = "browser/chromeos/login/WebUILoginView"; |
31 | 35 |
32 // These strings must be kept in sync with handleAccelerator() in oobe.js. | 36 // These strings must be kept in sync with handleAccelerator() in oobe.js. |
33 const char kAccelNameAccessibility[] = "accessibility"; | 37 const char kAccelNameAccessibility[] = "accessibility"; |
34 const char kAccelNameEnrollment[] = "enrollment"; | 38 const char kAccelNameEnrollment[] = "enrollment"; |
35 | 39 |
| 40 // Observes IPC messages from the FrameSniffer and notifies JS if error |
| 41 // appears. |
| 42 class SnifferObserver : public RenderViewHostObserver { |
| 43 public: |
| 44 SnifferObserver(RenderViewHost* host, WebUI* webui) |
| 45 : RenderViewHostObserver(host), webui_(webui) { |
| 46 DCHECK(webui_); |
| 47 Send(new ChromeViewMsg_StartFrameSniffer(routing_id(), |
| 48 UTF8ToUTF16("gaia-frame"))); |
| 49 } |
| 50 |
| 51 virtual ~SnifferObserver() {} |
| 52 |
| 53 // IPC::Channel::Listener implementation. |
| 54 virtual bool OnMessageReceived(const IPC::Message& message) { |
| 55 bool handled = true; |
| 56 IPC_BEGIN_MESSAGE_MAP(SnifferObserver, message) |
| 57 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_FrameLoadingError, OnError) |
| 58 IPC_MESSAGE_UNHANDLED(handled = false) |
| 59 IPC_END_MESSAGE_MAP() |
| 60 return handled; |
| 61 } |
| 62 |
| 63 private: |
| 64 void OnError(int error) { |
| 65 base::FundamentalValue error_value(error); |
| 66 webui_->CallJavascriptFunction("login.OfflineMessageScreen.onFrameError", |
| 67 error_value); |
| 68 } |
| 69 |
| 70 WebUI* webui_; |
| 71 }; |
| 72 |
36 // A View class which places its first child at the right most position. | 73 // A View class which places its first child at the right most position. |
37 class RightAlignedView : public views::View { | 74 class RightAlignedView : public views::View { |
38 public: | 75 public: |
39 virtual void Layout() OVERRIDE; | 76 virtual void Layout() OVERRIDE; |
40 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; | 77 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; |
41 }; | 78 }; |
42 | 79 |
43 void RightAlignedView::Layout() { | 80 void RightAlignedView::Layout() { |
44 if (has_children()) { | 81 if (has_children()) { |
45 views::View* child = child_at(0); | 82 views::View* child = child_at(0); |
46 gfx::Size preferred_size = child->GetPreferredSize(); | 83 gfx::Size preferred_size = child->GetPreferredSize(); |
47 child->SetBounds(width() - preferred_size.width(), | 84 child->SetBounds(width() - preferred_size.width(), |
48 0, preferred_size.width(), preferred_size.height()); | 85 0, preferred_size.width(), preferred_size.height()); |
49 } | 86 } |
50 } | 87 } |
51 | 88 |
52 void RightAlignedView::ChildPreferredSizeChanged(View* child) { | 89 void RightAlignedView::ChildPreferredSizeChanged(View* child) { |
53 Layout(); | 90 Layout(); |
54 } | 91 } |
55 | 92 |
56 | |
57 } // namespace | 93 } // namespace |
58 | 94 |
59 namespace chromeos { | 95 namespace chromeos { |
60 | 96 |
61 // static | 97 // static |
62 const int WebUILoginView::kStatusAreaCornerPadding = 5; | 98 const int WebUILoginView::kStatusAreaCornerPadding = 5; |
63 | 99 |
64 // WebUILoginView public: ------------------------------------------------------ | 100 // WebUILoginView public: ------------------------------------------------------ |
65 | 101 |
66 WebUILoginView::WebUILoginView() | 102 WebUILoginView::WebUILoginView() |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 | 255 |
220 void WebUILoginView::OnDialogClosed() { | 256 void WebUILoginView::OnDialogClosed() { |
221 } | 257 } |
222 | 258 |
223 void WebUILoginView::OnLocaleChanged() { | 259 void WebUILoginView::OnLocaleChanged() { |
224 // Proxy settings dialog contains localized strings. | 260 // Proxy settings dialog contains localized strings. |
225 proxy_settings_dialog_.reset(); | 261 proxy_settings_dialog_.reset(); |
226 SchedulePaint(); | 262 SchedulePaint(); |
227 } | 263 } |
228 | 264 |
| 265 void WebUILoginView::OnRenderHostCreated(RenderViewHost* host) { |
| 266 new SnifferObserver(host, GetWebUI()); |
| 267 } |
| 268 |
229 void WebUILoginView::OnTabMainFrameLoaded() { | 269 void WebUILoginView::OnTabMainFrameLoaded() { |
230 } | 270 } |
231 | 271 |
232 void WebUILoginView::OnTabMainFrameFirstRender() { | 272 void WebUILoginView::OnTabMainFrameFirstRender() { |
233 InitStatusArea(); | 273 InitStatusArea(); |
234 | 274 |
235 if (host_window_frozen_) { | 275 if (host_window_frozen_) { |
236 host_window_frozen_ = false; | 276 host_window_frozen_ = false; |
237 | 277 |
238 // Unfreezes the host window since tab is rendereed now. | 278 // Unfreezes the host window since tab is rendereed now. |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 GetFocusManager()); | 353 GetFocusManager()); |
314 | 354 |
315 // Make sure error bubble is cleared on keyboard event. This is needed | 355 // Make sure error bubble is cleared on keyboard event. This is needed |
316 // when the focus is inside an iframe. | 356 // when the focus is inside an iframe. |
317 WebUI* web_ui = GetWebUI(); | 357 WebUI* web_ui = GetWebUI(); |
318 if (web_ui) | 358 if (web_ui) |
319 web_ui->CallJavascriptFunction("cr.ui.Oobe.clearErrors"); | 359 web_ui->CallJavascriptFunction("cr.ui.Oobe.clearErrors"); |
320 } | 360 } |
321 | 361 |
322 } // namespace chromeos | 362 } // namespace chromeos |
OLD | NEW |