| 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/app_driver/app_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 "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "components/mus/common/event_matcher_util.h" | 11 #include "components/mus/common/event_matcher_util.h" |
| 12 #include "mash/public/interfaces/launchable.mojom.h" | 12 #include "mash/public/interfaces/launchable.mojom.h" |
| 13 #include "services/shell/public/cpp/connection.h" | 13 #include "services/shell/public/cpp/connection.h" |
| 14 #include "services/shell/public/cpp/connector.h" | 14 #include "services/shell/public/cpp/connector.h" |
| 15 | 15 |
| 16 using mash::mojom::LaunchablePtr; | 16 using mash::mojom::LaunchablePtr; |
| 17 using mash::mojom::LaunchMode; | 17 using mash::mojom::LaunchMode; |
| 18 | 18 |
| 19 namespace mash { | 19 namespace mash { |
| 20 namespace browser_driver { | 20 namespace app_driver { |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 enum class Accelerator : uint32_t { | 23 enum class Accelerator : uint32_t { |
| 24 NewWindow, | 24 NewWindow, |
| 25 NewTab, | 25 NewTab, |
| 26 NewIncognitoWindow, | 26 NewIncognitoWindow, |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 struct AcceleratorSpec { | 29 struct AcceleratorSpec { |
| 30 Accelerator id; | 30 Accelerator id; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 void AssertTrue(bool success) { | 46 void AssertTrue(bool success) { |
| 47 DCHECK(success); | 47 DCHECK(success); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void DoNothing() {} | 50 void DoNothing() {} |
| 51 | 51 |
| 52 } // namespace | 52 } // namespace |
| 53 | 53 |
| 54 BrowserDriverApplicationDelegate::BrowserDriverApplicationDelegate() | 54 AppDriverApplicationDelegate::AppDriverApplicationDelegate() |
| 55 : connector_(nullptr), | 55 : connector_(nullptr), binding_(this), weak_factory_(this) {} |
| 56 binding_(this), | |
| 57 weak_factory_(this) {} | |
| 58 | 56 |
| 59 BrowserDriverApplicationDelegate::~BrowserDriverApplicationDelegate() {} | 57 AppDriverApplicationDelegate::~AppDriverApplicationDelegate() {} |
| 60 | 58 |
| 61 void BrowserDriverApplicationDelegate::OnAvailableCatalogEntries( | 59 void AppDriverApplicationDelegate::OnAvailableCatalogEntries( |
| 62 const mojo::Array<catalog::mojom::EntryPtr>& entries) { | 60 const mojo::Array<catalog::mojom::EntryPtr>& entries) { |
| 63 if (entries.empty()) { | 61 if (entries.empty()) { |
| 64 LOG(ERROR) << "Unable to install accelerators for launching chrome."; | 62 LOG(ERROR) << "Unable to install accelerators for launching chrome."; |
| 65 return; | 63 return; |
| 66 } | 64 } |
| 67 | 65 |
| 68 mus::mojom::AcceleratorRegistrarPtr registrar; | 66 mus::mojom::AcceleratorRegistrarPtr registrar; |
| 69 connector_->ConnectToInterface(entries[0]->name, ®istrar); | 67 connector_->ConnectToInterface(entries[0]->name, ®istrar); |
| 70 | 68 |
| 71 if (binding_.is_bound()) | 69 if (binding_.is_bound()) |
| 72 binding_.Unbind(); | 70 binding_.Unbind(); |
| 73 registrar->SetHandler(binding_.CreateInterfacePtrAndBind()); | 71 registrar->SetHandler(binding_.CreateInterfacePtrAndBind()); |
| 74 // If the window manager restarts, the handler pipe will close and we'll need | 72 // If the window manager restarts, the handler pipe will close and we'll need |
| 75 // to re-add our accelerators when the window manager comes back up. | 73 // to re-add our accelerators when the window manager comes back up. |
| 76 binding_.set_connection_error_handler( | 74 binding_.set_connection_error_handler( |
| 77 base::Bind(&BrowserDriverApplicationDelegate::AddAccelerators, | 75 base::Bind(&AppDriverApplicationDelegate::AddAccelerators, |
| 78 weak_factory_.GetWeakPtr())); | 76 weak_factory_.GetWeakPtr())); |
| 79 | 77 |
| 80 for (const AcceleratorSpec& spec : g_spec) { | 78 for (const AcceleratorSpec& spec : g_spec) { |
| 81 registrar->AddAccelerator( | 79 registrar->AddAccelerator( |
| 82 static_cast<uint32_t>(spec.id), | 80 static_cast<uint32_t>(spec.id), |
| 83 mus::CreateKeyMatcher(spec.keyboard_code, spec.event_flags), | 81 mus::CreateKeyMatcher(spec.keyboard_code, spec.event_flags), |
| 84 base::Bind(&AssertTrue)); | 82 base::Bind(&AssertTrue)); |
| 85 } | 83 } |
| 86 } | 84 } |
| 87 | 85 |
| 88 void BrowserDriverApplicationDelegate::Initialize( | 86 void AppDriverApplicationDelegate::Initialize(shell::Connector* connector, |
| 89 shell::Connector* connector, | 87 const shell::Identity& identity, |
| 90 const shell::Identity& identity, | 88 uint32_t id) { |
| 91 uint32_t id) { | |
| 92 connector_ = connector; | 89 connector_ = connector; |
| 93 AddAccelerators(); | 90 AddAccelerators(); |
| 94 } | 91 } |
| 95 | 92 |
| 96 bool BrowserDriverApplicationDelegate::AcceptConnection( | 93 bool AppDriverApplicationDelegate::AcceptConnection( |
| 97 shell::Connection* connection) { | 94 shell::Connection* connection) { |
| 98 return true; | 95 return true; |
| 99 } | 96 } |
| 100 | 97 |
| 101 bool BrowserDriverApplicationDelegate::ShellConnectionLost() { | 98 bool AppDriverApplicationDelegate::ShellConnectionLost() { |
| 102 // Prevent the code in AddAccelerators() from keeping this app alive. | 99 // Prevent the code in AddAccelerators() from keeping this app alive. |
| 103 binding_.set_connection_error_handler(base::Bind(&DoNothing)); | 100 binding_.set_connection_error_handler(base::Bind(&DoNothing)); |
| 104 return true; | 101 return true; |
| 105 } | 102 } |
| 106 | 103 |
| 107 void BrowserDriverApplicationDelegate::OnAccelerator( | 104 void AppDriverApplicationDelegate::OnAccelerator(uint32_t id, |
| 108 uint32_t id, mus::mojom::EventPtr event) { | 105 mus::mojom::EventPtr event) { |
| 109 uint32_t option = mojom::kWindow; | 106 uint32_t option = mojom::kWindow; |
| 110 switch (static_cast<Accelerator>(id)) { | 107 switch (static_cast<Accelerator>(id)) { |
| 111 case Accelerator::NewWindow: | 108 case Accelerator::NewWindow: |
| 112 option = mojom::kWindow; | 109 option = mojom::kWindow; |
| 113 break; | 110 break; |
| 114 case Accelerator::NewTab: | 111 case Accelerator::NewTab: |
| 115 option = mojom::kDocument; | 112 option = mojom::kDocument; |
| 116 break; | 113 break; |
| 117 case Accelerator::NewIncognitoWindow: | 114 case Accelerator::NewIncognitoWindow: |
| 118 option = mojom::kIncognitoWindow; | 115 option = mojom::kIncognitoWindow; |
| 119 break; | 116 break; |
| 120 default: | 117 default: |
| 121 NOTREACHED(); | 118 NOTREACHED(); |
| 122 break; | 119 break; |
| 123 } | 120 } |
| 124 LaunchablePtr launchable; | 121 LaunchablePtr launchable; |
| 125 connector_->ConnectToInterface("exe:chrome", &launchable); | 122 connector_->ConnectToInterface("exe:chrome", &launchable); |
| 126 launchable->Launch(option, LaunchMode::MAKE_NEW); | 123 launchable->Launch(option, LaunchMode::MAKE_NEW); |
| 127 } | 124 } |
| 128 | 125 |
| 129 void BrowserDriverApplicationDelegate::AddAccelerators() { | 126 void AppDriverApplicationDelegate::AddAccelerators() { |
| 130 connector_->ConnectToInterface("mojo:catalog", &catalog_); | 127 connector_->ConnectToInterface("mojo:catalog", &catalog_); |
| 131 catalog_->GetEntriesProvidingClass( | 128 catalog_->GetEntriesProvidingClass( |
| 132 "mus:window_manager", | 129 "mus:window_manager", |
| 133 base::Bind(&BrowserDriverApplicationDelegate::OnAvailableCatalogEntries, | 130 base::Bind(&AppDriverApplicationDelegate::OnAvailableCatalogEntries, |
| 134 weak_factory_.GetWeakPtr())); | 131 weak_factory_.GetWeakPtr())); |
| 135 } | 132 } |
| 136 | 133 |
| 137 } // namespace browser_driver | 134 } // namespace app_driver |
| 138 } // namespace mash | 135 } // namespace mash |
| OLD | NEW |