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" |
(...skipping 11 matching lines...) Expand all Loading... |
22 namespace { | 22 namespace { |
23 | 23 |
24 class WebActivityController : public AcceleratorHandler { | 24 class WebActivityController : public AcceleratorHandler { |
25 public: | 25 public: |
26 enum Command { | 26 enum Command { |
27 CMD_BACK, | 27 CMD_BACK, |
28 CMD_FORWARD, | 28 CMD_FORWARD, |
29 CMD_RELOAD, | 29 CMD_RELOAD, |
30 CMD_RELOAD_IGNORE_CACHE, | 30 CMD_RELOAD_IGNORE_CACHE, |
31 CMD_CLOSE, | 31 CMD_CLOSE, |
| 32 CMD_STOP, |
32 }; | 33 }; |
33 | 34 |
34 explicit WebActivityController(views::WebView* web_view) | 35 explicit WebActivityController(views::WebView* web_view) |
35 : web_view_(web_view), reserved_accelerator_enabled_(true) {} | 36 : web_view_(web_view), reserved_accelerator_enabled_(true) {} |
36 virtual ~WebActivityController() {} | 37 virtual ~WebActivityController() {} |
37 | 38 |
38 // Installs accelerators for web activity. | 39 // Installs accelerators for web activity. |
39 void InstallAccelerators() { | 40 void InstallAccelerators() { |
40 accelerator_manager_ = AcceleratorManager::CreateForFocusManager( | 41 accelerator_manager_ = AcceleratorManager::CreateForFocusManager( |
41 web_view_->GetFocusManager()).Pass(); | 42 web_view_->GetFocusManager()).Pass(); |
42 const AcceleratorData accelerator_data[] = { | 43 const AcceleratorData accelerator_data[] = { |
43 {TRIGGER_ON_PRESS, ui::VKEY_R, ui::EF_CONTROL_DOWN, CMD_RELOAD, | 44 {TRIGGER_ON_PRESS, ui::VKEY_R, ui::EF_CONTROL_DOWN, CMD_RELOAD, |
44 AF_NONE}, | 45 AF_NONE}, |
45 {TRIGGER_ON_PRESS, ui::VKEY_BROWSER_REFRESH, ui::EF_NONE, CMD_RELOAD, | 46 {TRIGGER_ON_PRESS, ui::VKEY_BROWSER_REFRESH, ui::EF_NONE, CMD_RELOAD, |
46 AF_NONE}, | 47 AF_NONE}, |
47 {TRIGGER_ON_PRESS, ui::VKEY_BROWSER_REFRESH, ui::EF_CONTROL_DOWN, | 48 {TRIGGER_ON_PRESS, ui::VKEY_BROWSER_REFRESH, ui::EF_CONTROL_DOWN, |
48 CMD_RELOAD_IGNORE_CACHE, AF_NONE}, | 49 CMD_RELOAD_IGNORE_CACHE, AF_NONE}, |
49 {TRIGGER_ON_PRESS, ui::VKEY_BROWSER_FORWARD, ui::EF_NONE, CMD_FORWARD, | 50 {TRIGGER_ON_PRESS, ui::VKEY_BROWSER_FORWARD, ui::EF_NONE, CMD_FORWARD, |
50 AF_NONE}, | 51 AF_NONE}, |
51 {TRIGGER_ON_PRESS, ui::VKEY_BROWSER_BACK, ui::EF_NONE, CMD_BACK, | 52 {TRIGGER_ON_PRESS, ui::VKEY_BROWSER_BACK, ui::EF_NONE, CMD_BACK, |
52 AF_NONE}, | 53 AF_NONE}, |
53 {TRIGGER_ON_PRESS, ui::VKEY_W, ui::EF_CONTROL_DOWN, CMD_CLOSE, AF_NONE}, | 54 {TRIGGER_ON_PRESS, ui::VKEY_W, ui::EF_CONTROL_DOWN, CMD_CLOSE, AF_NONE}, |
| 55 {TRIGGER_ON_PRESS, ui::VKEY_ESCAPE, ui::EF_NONE, CMD_STOP, AF_NONE}, |
54 }; | 56 }; |
55 accelerator_manager_->RegisterAccelerators( | 57 accelerator_manager_->RegisterAccelerators( |
56 accelerator_data, arraysize(accelerator_data), this); | 58 accelerator_data, arraysize(accelerator_data), this); |
57 } | 59 } |
58 | 60 |
59 // Methods that are called before and after key events are consumed by the web | 61 // Methods that are called before and after key events are consumed by the web |
60 // contents. | 62 // contents. |
61 // See the documentation in WebContentsDelegate: for more details. | 63 // See the documentation in WebContentsDelegate: for more details. |
62 bool PreHandleKeyboardEvent(content::WebContents* source, | 64 bool PreHandleKeyboardEvent(content::WebContents* source, |
63 const content::NativeWebKeyboardEvent& event, | 65 const content::NativeWebKeyboardEvent& event, |
(...skipping 26 matching lines...) Expand all Loading... |
90 case CMD_RELOAD: | 92 case CMD_RELOAD: |
91 case CMD_RELOAD_IGNORE_CACHE: | 93 case CMD_RELOAD_IGNORE_CACHE: |
92 return true; | 94 return true; |
93 case CMD_BACK: | 95 case CMD_BACK: |
94 return web_view_->GetWebContents()->GetController().CanGoBack(); | 96 return web_view_->GetWebContents()->GetController().CanGoBack(); |
95 case CMD_FORWARD: | 97 case CMD_FORWARD: |
96 return web_view_->GetWebContents()->GetController().CanGoForward(); | 98 return web_view_->GetWebContents()->GetController().CanGoForward(); |
97 case CMD_CLOSE: | 99 case CMD_CLOSE: |
98 // TODO(oshima): check onbeforeunload handler. | 100 // TODO(oshima): check onbeforeunload handler. |
99 return true; | 101 return true; |
| 102 case CMD_STOP: |
| 103 return web_view_->GetWebContents()->IsLoading(); |
100 } | 104 } |
101 return false; | 105 return false; |
102 } | 106 } |
103 | 107 |
104 virtual bool OnAcceleratorFired(int command_id, | 108 virtual bool OnAcceleratorFired(int command_id, |
105 const ui::Accelerator& accelerator) OVERRIDE { | 109 const ui::Accelerator& accelerator) OVERRIDE { |
106 switch (command_id) { | 110 switch (command_id) { |
107 case CMD_RELOAD: | 111 case CMD_RELOAD: |
108 web_view_->GetWebContents()->GetController().Reload(false); | 112 web_view_->GetWebContents()->GetController().Reload(false); |
109 return true; | 113 return true; |
110 case CMD_RELOAD_IGNORE_CACHE: | 114 case CMD_RELOAD_IGNORE_CACHE: |
111 web_view_->GetWebContents()->GetController().ReloadIgnoringCache(false); | 115 web_view_->GetWebContents()->GetController().ReloadIgnoringCache(false); |
112 return true; | 116 return true; |
113 case CMD_BACK: | 117 case CMD_BACK: |
114 web_view_->GetWebContents()->GetController().GoBack(); | 118 web_view_->GetWebContents()->GetController().GoBack(); |
115 return true; | 119 return true; |
116 case CMD_FORWARD: | 120 case CMD_FORWARD: |
117 web_view_->GetWebContents()->GetController().GoForward(); | 121 web_view_->GetWebContents()->GetController().GoForward(); |
118 return true; | 122 return true; |
119 case CMD_CLOSE: | 123 case CMD_CLOSE: |
120 web_view_->GetWidget()->Close(); | 124 web_view_->GetWidget()->Close(); |
121 return true; | 125 return true; |
| 126 case CMD_STOP: |
| 127 web_view_->GetWebContents()->Stop(); |
| 128 return true; |
122 } | 129 } |
123 return false; | 130 return false; |
124 } | 131 } |
125 | 132 |
126 views::WebView* web_view_; | 133 views::WebView* web_view_; |
127 bool reserved_accelerator_enabled_; | 134 bool reserved_accelerator_enabled_; |
128 scoped_ptr<AcceleratorManager> accelerator_manager_; | 135 scoped_ptr<AcceleratorManager> accelerator_manager_; |
129 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_; | 136 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_; |
130 | 137 |
131 DISALLOW_COPY_AND_ASSIGN(WebActivityController); | 138 DISALLOW_COPY_AND_ASSIGN(WebActivityController); |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 void WebActivity::DidUpdateFaviconURL( | 419 void WebActivity::DidUpdateFaviconURL( |
413 const std::vector<content::FaviconURL>& candidates) { | 420 const std::vector<content::FaviconURL>& candidates) { |
414 ActivityManager::Get()->UpdateActivity(this); | 421 ActivityManager::Get()->UpdateActivity(this); |
415 } | 422 } |
416 | 423 |
417 void WebActivity::DidChangeThemeColor(SkColor theme_color) { | 424 void WebActivity::DidChangeThemeColor(SkColor theme_color) { |
418 title_color_ = theme_color; | 425 title_color_ = theme_color; |
419 } | 426 } |
420 | 427 |
421 } // namespace athena | 428 } // namespace athena |
OLD | NEW |