| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "mash/browser_driver/browser_driver_application_delegate.h" | 5 #include "mash/browser_driver/browser_driver_application_delegate.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "components/mus/public/cpp/event_matcher.h" | 10 #include "components/mus/public/cpp/event_matcher.h" |
| 11 #include "mojo/shell/public/cpp/application_connection.h" | 11 #include "mojo/shell/public/cpp/application_connection.h" |
| 12 #include "mojo/shell/public/cpp/application_impl.h" | 12 #include "mojo/shell/public/cpp/shell.h" |
| 13 | 13 |
| 14 namespace mash { | 14 namespace mash { |
| 15 namespace browser_driver { | 15 namespace browser_driver { |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 enum class Accelerator : uint32_t { | 18 enum class Accelerator : uint32_t { |
| 19 NewWindow, | 19 NewWindow, |
| 20 NewTab, | 20 NewTab, |
| 21 NewIncognitoWindow, | 21 NewIncognitoWindow, |
| 22 }; | 22 }; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 38 mus::mojom::kEventFlagControlDown | mus::mojom::kEventFlagShiftDown}, | 38 mus::mojom::kEventFlagControlDown | mus::mojom::kEventFlagShiftDown}, |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 void AssertTrue(bool success) { | 41 void AssertTrue(bool success) { |
| 42 DCHECK(success); | 42 DCHECK(success); |
| 43 } | 43 } |
| 44 | 44 |
| 45 } // namespace | 45 } // namespace |
| 46 | 46 |
| 47 BrowserDriverApplicationDelegate::BrowserDriverApplicationDelegate() | 47 BrowserDriverApplicationDelegate::BrowserDriverApplicationDelegate() |
| 48 : app_(nullptr), | 48 : shell_(nullptr), |
| 49 binding_(this) {} | 49 binding_(this) {} |
| 50 | 50 |
| 51 BrowserDriverApplicationDelegate::~BrowserDriverApplicationDelegate() {} | 51 BrowserDriverApplicationDelegate::~BrowserDriverApplicationDelegate() {} |
| 52 | 52 |
| 53 void BrowserDriverApplicationDelegate::Initialize(mojo::ApplicationImpl* app) { | 53 void BrowserDriverApplicationDelegate::Initialize(mojo::Shell* shell, |
| 54 app_ = app; | 54 const std::string& url, |
| 55 uint32_t id) { |
| 56 shell_ = shell; |
| 55 AddAccelerators(); | 57 AddAccelerators(); |
| 56 } | 58 } |
| 57 | 59 |
| 58 bool BrowserDriverApplicationDelegate::AcceptConnection( | 60 bool BrowserDriverApplicationDelegate::AcceptConnection( |
| 59 mojo::ApplicationConnection* connection) { | 61 mojo::ApplicationConnection* connection) { |
| 60 return true; | 62 return true; |
| 61 } | 63 } |
| 62 | 64 |
| 63 void BrowserDriverApplicationDelegate::OnAccelerator( | 65 void BrowserDriverApplicationDelegate::OnAccelerator( |
| 64 uint32_t id, mus::mojom::EventPtr event) { | 66 uint32_t id, mus::mojom::EventPtr event) { |
| 65 switch (static_cast<Accelerator>(id)) { | 67 switch (static_cast<Accelerator>(id)) { |
| 66 case Accelerator::NewWindow: | 68 case Accelerator::NewWindow: |
| 67 case Accelerator::NewTab: | 69 case Accelerator::NewTab: |
| 68 case Accelerator::NewIncognitoWindow: | 70 case Accelerator::NewIncognitoWindow: |
| 69 app_->ConnectToApplication("exe:chrome"); | 71 shell_->ConnectToApplication("exe:chrome"); |
| 70 // TODO(beng): have Chrome export a service that allows it to be driven by | 72 // TODO(beng): have Chrome export a service that allows it to be driven by |
| 71 // this driver, e.g. to open new tabs, incognito windows, etc. | 73 // this driver, e.g. to open new tabs, incognito windows, etc. |
| 72 break; | 74 break; |
| 73 default: | 75 default: |
| 74 NOTREACHED(); | 76 NOTREACHED(); |
| 75 break; | 77 break; |
| 76 } | 78 } |
| 77 } | 79 } |
| 78 | 80 |
| 79 void BrowserDriverApplicationDelegate::AddAccelerators() { | 81 void BrowserDriverApplicationDelegate::AddAccelerators() { |
| 80 // TODO(beng): find some other way to get the window manager. I don't like | 82 // TODO(beng): find some other way to get the window manager. I don't like |
| 81 // having to specify it by URL because it may differ per display. | 83 // having to specify it by URL because it may differ per display. |
| 82 mus::mojom::AcceleratorRegistrarPtr registrar; | 84 mus::mojom::AcceleratorRegistrarPtr registrar; |
| 83 app_->ConnectToService("mojo:desktop_wm", ®istrar); | 85 shell_->ConnectToService("mojo:desktop_wm", ®istrar); |
| 84 | 86 |
| 85 if (binding_.is_bound()) | 87 if (binding_.is_bound()) |
| 86 binding_.Unbind(); | 88 binding_.Unbind(); |
| 87 registrar->SetHandler(binding_.CreateInterfacePtrAndBind()); | 89 registrar->SetHandler(binding_.CreateInterfacePtrAndBind()); |
| 88 // If the window manager restarts, the handler pipe will close and we'll need | 90 // If the window manager restarts, the handler pipe will close and we'll need |
| 89 // to re-add our accelerators when the window manager comes back up. | 91 // to re-add our accelerators when the window manager comes back up. |
| 90 binding_.set_connection_error_handler( | 92 binding_.set_connection_error_handler( |
| 91 base::Bind(&BrowserDriverApplicationDelegate::AddAccelerators, | 93 base::Bind(&BrowserDriverApplicationDelegate::AddAccelerators, |
| 92 base::Unretained(this))); | 94 base::Unretained(this))); |
| 93 | 95 |
| 94 for (const AcceleratorSpec& spec : g_spec) { | 96 for (const AcceleratorSpec& spec : g_spec) { |
| 95 registrar->AddAccelerator( | 97 registrar->AddAccelerator( |
| 96 static_cast<uint32_t>(spec.id), | 98 static_cast<uint32_t>(spec.id), |
| 97 mus::CreateKeyMatcher(spec.keyboard_code, spec.event_flags), | 99 mus::CreateKeyMatcher(spec.keyboard_code, spec.event_flags), |
| 98 base::Bind(&AssertTrue)); | 100 base::Bind(&AssertTrue)); |
| 99 } | 101 } |
| 100 } | 102 } |
| 101 | 103 |
| 102 } // namespace browser_driver | 104 } // namespace browser_driver |
| 103 } // namespace main | 105 } // namespace main |
| OLD | NEW |