Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: mash/browser_driver/browser_driver_application_delegate.cc

Issue 1725353003: Eliminate mojo::Shell client lib class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@15connector
Patch Set: . Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/connection.h" 11 #include "mojo/shell/public/cpp/connection.h"
12 #include "mojo/shell/public/cpp/shell.h" 12 #include "mojo/shell/public/cpp/connector.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
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 : shell_(nullptr), 48 : connector_(nullptr),
49 binding_(this) {} 49 binding_(this) {}
50 50
51 BrowserDriverApplicationDelegate::~BrowserDriverApplicationDelegate() {} 51 BrowserDriverApplicationDelegate::~BrowserDriverApplicationDelegate() {}
52 52
53 void BrowserDriverApplicationDelegate::Initialize(mojo::Shell* shell, 53 void BrowserDriverApplicationDelegate::Initialize(mojo::Connector* connector,
54 const std::string& url, 54 const std::string& url,
55 uint32_t id, 55 uint32_t id,
56 uint32_t user_id) { 56 uint32_t user_id) {
57 shell_ = shell; 57 connector_ = connector;
58 AddAccelerators(); 58 AddAccelerators();
59 } 59 }
60 60
61 bool BrowserDriverApplicationDelegate::AcceptConnection( 61 bool BrowserDriverApplicationDelegate::AcceptConnection(
62 mojo::Connection* connection) { 62 mojo::Connection* connection) {
63 return true; 63 return true;
64 } 64 }
65 65
66 void BrowserDriverApplicationDelegate::OnAccelerator( 66 void BrowserDriverApplicationDelegate::OnAccelerator(
67 uint32_t id, mus::mojom::EventPtr event) { 67 uint32_t id, mus::mojom::EventPtr event) {
68 switch (static_cast<Accelerator>(id)) { 68 switch (static_cast<Accelerator>(id)) {
69 case Accelerator::NewWindow: 69 case Accelerator::NewWindow:
70 case Accelerator::NewTab: 70 case Accelerator::NewTab:
71 case Accelerator::NewIncognitoWindow: 71 case Accelerator::NewIncognitoWindow:
72 shell_->Connect("exe:chrome"); 72 connector_->Connect("exe:chrome");
73 // TODO(beng): have Chrome export a service that allows it to be driven by 73 // TODO(beng): have Chrome export a service that allows it to be driven by
74 // this driver, e.g. to open new tabs, incognito windows, etc. 74 // this driver, e.g. to open new tabs, incognito windows, etc.
75 break; 75 break;
76 default: 76 default:
77 NOTREACHED(); 77 NOTREACHED();
78 break; 78 break;
79 } 79 }
80 } 80 }
81 81
82 void BrowserDriverApplicationDelegate::AddAccelerators() { 82 void BrowserDriverApplicationDelegate::AddAccelerators() {
83 // TODO(beng): find some other way to get the window manager. I don't like 83 // TODO(beng): find some other way to get the window manager. I don't like
84 // having to specify it by URL because it may differ per display. 84 // having to specify it by URL because it may differ per display.
85 mus::mojom::AcceleratorRegistrarPtr registrar; 85 mus::mojom::AcceleratorRegistrarPtr registrar;
86 shell_->ConnectToInterface("mojo:desktop_wm", &registrar); 86 connector_->ConnectToInterface("mojo:desktop_wm", &registrar);
87 87
88 if (binding_.is_bound()) 88 if (binding_.is_bound())
89 binding_.Unbind(); 89 binding_.Unbind();
90 registrar->SetHandler(binding_.CreateInterfacePtrAndBind()); 90 registrar->SetHandler(binding_.CreateInterfacePtrAndBind());
91 // If the window manager restarts, the handler pipe will close and we'll need 91 // If the window manager restarts, the handler pipe will close and we'll need
92 // to re-add our accelerators when the window manager comes back up. 92 // to re-add our accelerators when the window manager comes back up.
93 binding_.set_connection_error_handler( 93 binding_.set_connection_error_handler(
94 base::Bind(&BrowserDriverApplicationDelegate::AddAccelerators, 94 base::Bind(&BrowserDriverApplicationDelegate::AddAccelerators,
95 base::Unretained(this))); 95 base::Unretained(this)));
96 96
97 for (const AcceleratorSpec& spec : g_spec) { 97 for (const AcceleratorSpec& spec : g_spec) {
98 registrar->AddAccelerator( 98 registrar->AddAccelerator(
99 static_cast<uint32_t>(spec.id), 99 static_cast<uint32_t>(spec.id),
100 mus::CreateKeyMatcher(spec.keyboard_code, spec.event_flags), 100 mus::CreateKeyMatcher(spec.keyboard_code, spec.event_flags),
101 base::Bind(&AssertTrue)); 101 base::Bind(&AssertTrue));
102 } 102 }
103 } 103 }
104 104
105 } // namespace browser_driver 105 } // namespace browser_driver
106 } // namespace main 106 } // namespace main
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698