OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "athena/content/web_activity.h" | 5 #include "athena/content/web_activity.h" |
6 | 6 |
7 #include "athena/activity/public/activity_factory.h" | 7 #include "athena/activity/public/activity_factory.h" |
8 #include "athena/activity/public/activity_manager.h" | 8 #include "athena/activity/public/activity_manager.h" |
9 #include "athena/input/public/accelerator_manager.h" | 9 #include "athena/input/public/accelerator_manager.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "content/public/browser/native_web_keyboard_event.h" | 11 #include "content/public/browser/native_web_keyboard_event.h" |
12 #include "content/public/browser/navigation_controller.h" | 12 #include "content/public/browser/navigation_controller.h" |
13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
14 #include "content/public/browser/web_contents_delegate.h" | 14 #include "content/public/browser/web_contents_delegate.h" |
15 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" | 15 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" |
16 #include "ui/views/controls/webview/webview.h" | 16 #include "ui/views/controls/webview/webview.h" |
17 #include "ui/views/focus/focus_manager.h" | 17 #include "ui/views/focus/focus_manager.h" |
18 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
19 | 19 |
20 namespace athena { | 20 namespace athena { |
21 namespace { | 21 namespace { |
22 | 22 |
23 class WebActivityController : public AcceleratorHandler { | 23 class WebActivityController : public AcceleratorHandler { |
24 public: | 24 public: |
25 enum Command { | 25 enum Command { |
26 CMD_BACK, | 26 CMD_BACK, |
27 CMD_FORWARD, | 27 CMD_FORWARD, |
28 CMD_RELOAD, | 28 CMD_RELOAD, |
29 CMD_RELOAD_IGNORE_CACHE, | 29 CMD_RELOAD_IGNORE_CACHE, |
| 30 CMD_CLOSE, |
30 }; | 31 }; |
31 | 32 |
32 explicit WebActivityController(views::WebView* web_view) | 33 explicit WebActivityController(views::WebView* web_view) |
33 : web_view_(web_view), reserved_accelerator_enabled_(true) {} | 34 : web_view_(web_view), reserved_accelerator_enabled_(true) {} |
34 virtual ~WebActivityController() {} | 35 virtual ~WebActivityController() {} |
35 | 36 |
36 // Installs accelerators for web activity. | 37 // Installs accelerators for web activity. |
37 void InstallAccelerators() { | 38 void InstallAccelerators() { |
38 accelerator_manager_ = AcceleratorManager::CreateForFocusManager( | 39 accelerator_manager_ = AcceleratorManager::CreateForFocusManager( |
39 web_view_->GetFocusManager()).Pass(); | 40 web_view_->GetFocusManager()).Pass(); |
40 const AcceleratorData accelerator_data[] = { | 41 const AcceleratorData accelerator_data[] = { |
41 {TRIGGER_ON_PRESS, ui::VKEY_R, ui::EF_CONTROL_DOWN, CMD_RELOAD, | 42 {TRIGGER_ON_PRESS, ui::VKEY_R, ui::EF_CONTROL_DOWN, CMD_RELOAD, |
42 AF_NONE}, | 43 AF_NONE}, |
43 {TRIGGER_ON_PRESS, ui::VKEY_BROWSER_REFRESH, ui::EF_NONE, CMD_RELOAD, | 44 {TRIGGER_ON_PRESS, ui::VKEY_BROWSER_REFRESH, ui::EF_NONE, CMD_RELOAD, |
44 AF_NONE}, | 45 AF_NONE}, |
45 {TRIGGER_ON_PRESS, ui::VKEY_BROWSER_REFRESH, ui::EF_CONTROL_DOWN, | 46 {TRIGGER_ON_PRESS, ui::VKEY_BROWSER_REFRESH, ui::EF_CONTROL_DOWN, |
46 CMD_RELOAD_IGNORE_CACHE, AF_NONE}, | 47 CMD_RELOAD_IGNORE_CACHE, AF_NONE}, |
47 {TRIGGER_ON_PRESS, ui::VKEY_BROWSER_FORWARD, ui::EF_NONE, CMD_FORWARD, | 48 {TRIGGER_ON_PRESS, ui::VKEY_BROWSER_FORWARD, ui::EF_NONE, CMD_FORWARD, |
48 AF_NONE}, | 49 AF_NONE}, |
49 {TRIGGER_ON_PRESS, ui::VKEY_BROWSER_BACK, ui::EF_NONE, CMD_BACK, | 50 {TRIGGER_ON_PRESS, ui::VKEY_BROWSER_BACK, ui::EF_NONE, CMD_BACK, |
50 AF_NONE}, | 51 AF_NONE}, |
| 52 {TRIGGER_ON_PRESS, ui::VKEY_W, ui::EF_CONTROL_DOWN, CMD_CLOSE, AF_NONE}, |
51 }; | 53 }; |
52 accelerator_manager_->RegisterAccelerators( | 54 accelerator_manager_->RegisterAccelerators( |
53 accelerator_data, arraysize(accelerator_data), this); | 55 accelerator_data, arraysize(accelerator_data), this); |
54 } | 56 } |
55 | 57 |
56 // Methods that are called before and after key events are consumed by the web | 58 // Methods that are called before and after key events are consumed by the web |
57 // contents. | 59 // contents. |
58 // See the documentation in WebContentsDelegate: for more details. | 60 // See the documentation in WebContentsDelegate: for more details. |
59 bool PreHandleKeyboardEvent(content::WebContents* source, | 61 bool PreHandleKeyboardEvent(content::WebContents* source, |
60 const content::NativeWebKeyboardEvent& event, | 62 const content::NativeWebKeyboardEvent& event, |
(...skipping 17 matching lines...) Expand all Loading... |
78 const content::NativeWebKeyboardEvent& event) { | 80 const content::NativeWebKeyboardEvent& event) { |
79 unhandled_keyboard_event_handler_.HandleKeyboardEvent( | 81 unhandled_keyboard_event_handler_.HandleKeyboardEvent( |
80 event, web_view_->GetFocusManager()); | 82 event, web_view_->GetFocusManager()); |
81 } | 83 } |
82 | 84 |
83 private: | 85 private: |
84 // AcceleratorHandler: | 86 // AcceleratorHandler: |
85 virtual bool IsCommandEnabled(int command_id) const OVERRIDE { | 87 virtual bool IsCommandEnabled(int command_id) const OVERRIDE { |
86 switch (command_id) { | 88 switch (command_id) { |
87 case CMD_RELOAD: | 89 case CMD_RELOAD: |
| 90 case CMD_RELOAD_IGNORE_CACHE: |
88 return true; | 91 return true; |
89 case CMD_BACK: | 92 case CMD_BACK: |
90 return web_view_->GetWebContents()->GetController().CanGoBack(); | 93 return web_view_->GetWebContents()->GetController().CanGoBack(); |
91 case CMD_FORWARD: | 94 case CMD_FORWARD: |
92 return web_view_->GetWebContents()->GetController().CanGoForward(); | 95 return web_view_->GetWebContents()->GetController().CanGoForward(); |
| 96 case CMD_CLOSE: |
| 97 // TODO(oshima): check onbeforeunload handler. |
| 98 return true; |
93 } | 99 } |
94 return false; | 100 return false; |
95 } | 101 } |
96 | 102 |
97 virtual bool OnAcceleratorFired(int command_id, | 103 virtual bool OnAcceleratorFired(int command_id, |
98 const ui::Accelerator& accelerator) OVERRIDE { | 104 const ui::Accelerator& accelerator) OVERRIDE { |
99 switch (command_id) { | 105 switch (command_id) { |
100 case CMD_RELOAD: | 106 case CMD_RELOAD: |
101 web_view_->GetWebContents()->GetController().Reload(false); | 107 web_view_->GetWebContents()->GetController().Reload(false); |
102 return true; | 108 return true; |
103 case CMD_RELOAD_IGNORE_CACHE: | 109 case CMD_RELOAD_IGNORE_CACHE: |
104 web_view_->GetWebContents()->GetController().ReloadIgnoringCache(false); | 110 web_view_->GetWebContents()->GetController().ReloadIgnoringCache(false); |
105 return true; | 111 return true; |
106 case CMD_BACK: | 112 case CMD_BACK: |
107 web_view_->GetWebContents()->GetController().GoBack(); | 113 web_view_->GetWebContents()->GetController().GoBack(); |
108 return true; | 114 return true; |
109 case CMD_FORWARD: | 115 case CMD_FORWARD: |
110 web_view_->GetWebContents()->GetController().GoForward(); | 116 web_view_->GetWebContents()->GetController().GoForward(); |
111 return true; | 117 return true; |
| 118 case CMD_CLOSE: |
| 119 web_view_->GetWidget()->Close(); |
| 120 return true; |
112 } | 121 } |
113 return false; | 122 return false; |
114 } | 123 } |
115 | 124 |
116 views::WebView* web_view_; | 125 views::WebView* web_view_; |
117 bool reserved_accelerator_enabled_; | 126 bool reserved_accelerator_enabled_; |
118 scoped_ptr<AcceleratorManager> accelerator_manager_; | 127 scoped_ptr<AcceleratorManager> accelerator_manager_; |
119 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_; | 128 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_; |
120 | 129 |
121 DISALLOW_COPY_AND_ASSIGN(WebActivityController); | 130 DISALLOW_COPY_AND_ASSIGN(WebActivityController); |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 void WebActivity::DidUpdateFaviconURL( | 407 void WebActivity::DidUpdateFaviconURL( |
399 const std::vector<content::FaviconURL>& candidates) { | 408 const std::vector<content::FaviconURL>& candidates) { |
400 ActivityManager::Get()->UpdateActivity(this); | 409 ActivityManager::Get()->UpdateActivity(this); |
401 } | 410 } |
402 | 411 |
403 void WebActivity::DidChangeThemeColor(SkColor theme_color) { | 412 void WebActivity::DidChangeThemeColor(SkColor theme_color) { |
404 title_color_ = theme_color; | 413 title_color_ = theme_color; |
405 } | 414 } |
406 | 415 |
407 } // namespace athena | 416 } // namespace athena |
OLD | NEW |