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 "base/macros.h" | 5 #include "base/macros.h" |
6 #include "base/strings/string_util.h" | 6 #include "base/strings/string_util.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "examples/browser/browser_host.mojom.h" | 8 #include "examples/browser/browser_host.mojom.h" |
9 #include "examples/window_manager/window_manager.mojom.h" | 9 #include "examples/window_manager/window_manager.mojom.h" |
10 #include "mojo/application/application_runner_chromium.h" | 10 #include "mojo/application/application_runner_chromium.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 namespace examples { | 29 namespace examples { |
30 | 30 |
31 // This is the basics of creating a views widget with a textfield. | 31 // This is the basics of creating a views widget with a textfield. |
32 // TODO: cleanup! | 32 // TODO: cleanup! |
33 class Browser : public ApplicationDelegate, | 33 class Browser : public ApplicationDelegate, |
34 public ViewManagerDelegate, | 34 public ViewManagerDelegate, |
35 public ViewObserver, | 35 public ViewObserver, |
36 public examples::BrowserHost, | 36 public examples::BrowserHost, |
37 public mojo::InterfaceFactory<examples::BrowserHost> { | 37 public mojo::InterfaceFactory<examples::BrowserHost> { |
38 public: | 38 public: |
39 Browser() : shell_(nullptr), root_(NULL), binding_(this) {} | 39 Browser() : shell_(nullptr), root_(NULL), binding_(this) { |
| 40 browser_host_services_impl_.AddService(this); |
| 41 } |
40 | 42 |
41 virtual ~Browser() { | 43 virtual ~Browser() { |
42 if (root_) | 44 if (root_) |
43 root_->RemoveObserver(this); | 45 root_->RemoveObserver(this); |
44 } | 46 } |
45 | 47 |
46 private: | 48 private: |
47 // Overridden from ApplicationDelegate: | 49 // Overridden from ApplicationDelegate: |
48 void Initialize(ApplicationImpl* app) override { | 50 void Initialize(ApplicationImpl* app) override { |
49 shell_ = app->shell(); | 51 shell_ = app->shell(); |
50 view_manager_client_factory_.reset( | 52 view_manager_client_factory_.reset( |
51 new ViewManagerClientFactory(shell_, this)); | 53 new ViewManagerClientFactory(shell_, this)); |
52 app->ConnectToService("mojo:window_manager", &window_manager_); | 54 app->ConnectToService("mojo:window_manager", &window_manager_); |
53 | 55 |
54 // FIXME: Mojo applications don't know their URLs yet: | 56 // FIXME: Mojo applications don't know their URLs yet: |
55 // https://docs.google.com/a/chromium.org/document/d/1AQ2y6ekzvbdaMF5WrUQmne
yXJnke-MnYYL4Gz1AKDos | 57 // https://docs.google.com/a/chromium.org/document/d/1AQ2y6ekzvbdaMF5WrUQmne
yXJnke-MnYYL4Gz1AKDos |
56 url_ = GURL(app->args()[1]); | 58 url_ = GURL(app->args()[1]); |
57 } | 59 } |
58 | 60 |
59 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { | 61 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { |
60 connection->AddService(view_manager_client_factory_.get()); | 62 connection->AddService(view_manager_client_factory_.get()); |
61 return true; | 63 return true; |
62 } | 64 } |
63 | 65 |
64 // ViewManagerDelegate: | 66 // ViewManagerDelegate: |
65 void OnEmbed(View* root, | 67 void OnEmbed(View* root, |
66 ServiceProviderImpl* exported_services, | 68 InterfaceRequest<ServiceProvider> services, |
67 scoped_ptr<ServiceProvider> imported_services) override { | 69 ServiceProviderPtr exposed_services) override { |
68 // TODO: deal with OnEmbed() being invoked multiple times. | 70 // TODO: deal with OnEmbed() being invoked multiple times. |
69 ConnectToService(imported_services.get(), &navigator_host_); | 71 ConnectToService(exposed_services.get(), &navigator_host_); |
70 root_ = root; | 72 root_ = root; |
71 root_->AddObserver(this); | 73 root_->AddObserver(this); |
72 root_->SetFocus(); | 74 root_->SetFocus(); |
73 | 75 |
74 // Create a child view for our sky document. | 76 // Create a child view for our sky document. |
75 View* view = root->view_manager()->CreateView(); | 77 View* view = root->view_manager()->CreateView(); |
76 root->AddChild(view); | 78 root->AddChild(view); |
77 Rect bounds; | 79 Rect bounds; |
78 bounds.x = 0; | 80 bounds.x = 0; |
79 bounds.y = 0; | 81 bounds.y = 0; |
80 bounds.width = root->bounds().width; | 82 bounds.width = root->bounds().width; |
81 bounds.height = root->bounds().height; | 83 bounds.height = root->bounds().height; |
82 view->SetBounds(bounds); | 84 view->SetBounds(bounds); |
83 view->SetVisible(true); | 85 view->SetVisible(true); |
84 root->SetVisible(true); | 86 root->SetVisible(true); |
85 | 87 |
86 scoped_ptr<mojo::ServiceProviderImpl> browser_host_services( | 88 ServiceProviderPtr browser_host_services; |
87 new mojo::ServiceProviderImpl()); | 89 browser_host_services_impl_.Bind(GetProxy(&browser_host_services)); |
88 browser_host_services->AddService(this); | |
89 | 90 |
90 GURL frame_url = url_.Resolve("/examples/browser/browser.sky"); | 91 GURL frame_url = url_.Resolve("/examples/browser/browser.sky"); |
91 browser_input_ = | 92 view->Embed(frame_url.spec(), nullptr, browser_host_services.Pass()); |
92 view->Embed(frame_url.spec(), browser_host_services.Pass()); | |
93 } | 93 } |
94 | 94 |
95 void OnViewManagerDisconnected(ViewManager* view_manager) override { | 95 void OnViewManagerDisconnected(ViewManager* view_manager) override { |
96 base::MessageLoop::current()->Quit(); | 96 base::MessageLoop::current()->Quit(); |
97 } | 97 } |
98 | 98 |
99 // ViewObserver: | 99 // ViewObserver: |
100 void OnViewDestroyed(View* view) override { | 100 void OnViewDestroyed(View* view) override { |
101 DCHECK_EQ(root_, view); | 101 DCHECK_EQ(root_, view); |
102 view->RemoveObserver(this); | 102 view->RemoveObserver(this); |
103 root_ = NULL; | 103 root_ = NULL; |
104 } | 104 } |
105 | 105 |
106 // examples::BrowserHost: | 106 // examples::BrowserHost: |
107 void NavigateTo(const mojo::String& url) override { | 107 void NavigateTo(const mojo::String& url) override { |
108 URLRequestPtr request(URLRequest::New()); | 108 URLRequestPtr request(URLRequest::New()); |
109 request->url = url; | 109 request->url = url; |
110 navigator_host_->RequestNavigate(TARGET_NEW_NODE, request.Pass()); | 110 navigator_host_->RequestNavigate(TARGET_NEW_NODE, request.Pass()); |
111 } | 111 } |
112 | 112 |
113 // mojo::InterfaceFactory<examples::BrowserHost> implementation. | 113 // mojo::InterfaceFactory<examples::BrowserHost> implementation. |
114 void Create(mojo::ApplicationConnection* connection, | 114 void Create(mojo::ApplicationConnection* connection, |
115 mojo::InterfaceRequest<examples::BrowserHost> request) override { | 115 mojo::InterfaceRequest<examples::BrowserHost> request) override { |
116 binding_.Bind(request.Pass()); | 116 binding_.Bind(request.Pass()); |
117 } | 117 } |
118 | 118 |
119 Shell* shell_; | 119 Shell* shell_; |
120 | 120 |
121 scoped_ptr<mojo::ServiceProvider> browser_input_; | |
122 | |
123 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; | 121 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; |
124 View* root_; | 122 View* root_; |
125 NavigatorHostPtr navigator_host_; | 123 NavigatorHostPtr navigator_host_; |
126 IWindowManagerPtr window_manager_; | 124 IWindowManagerPtr window_manager_; |
| 125 ServiceProviderImpl browser_host_services_impl_; |
127 | 126 |
128 GURL url_; | 127 GURL url_; |
129 | 128 |
130 mojo::Binding<examples::BrowserHost> binding_; | 129 mojo::Binding<examples::BrowserHost> binding_; |
131 | 130 |
132 DISALLOW_COPY_AND_ASSIGN(Browser); | 131 DISALLOW_COPY_AND_ASSIGN(Browser); |
133 }; | 132 }; |
134 | 133 |
135 } // namespace examples | 134 } // namespace examples |
136 } // namespace mojo | 135 } // namespace mojo |
137 | 136 |
138 MojoResult MojoMain(MojoHandle shell_handle) { | 137 MojoResult MojoMain(MojoHandle shell_handle) { |
139 mojo::ApplicationRunnerChromium runner(new mojo::examples::Browser); | 138 mojo::ApplicationRunnerChromium runner(new mojo::examples::Browser); |
140 return runner.Run(shell_handle); | 139 return runner.Run(shell_handle); |
141 } | 140 } |
OLD | NEW |