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 "mandoline/ui/browser/browser.h" | 5 #include "mandoline/ui/browser/browser.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "mandoline/ui/browser/browser_ui.h" | 9 #include "mandoline/ui/browser/browser_ui.h" |
10 #include "mandoline/ui/browser/merged_service_provider.h" | 10 #include "mandoline/ui/browser/merged_service_provider.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 exposed_services_impl_.AddService(this); | 24 exposed_services_impl_.AddService(this); |
25 } | 25 } |
26 | 26 |
27 Browser::~Browser() { | 27 Browser::~Browser() { |
28 } | 28 } |
29 | 29 |
30 base::WeakPtr<Browser> Browser::GetWeakPtr() { | 30 base::WeakPtr<Browser> Browser::GetWeakPtr() { |
31 return weak_factory_.GetWeakPtr(); | 31 return weak_factory_.GetWeakPtr(); |
32 } | 32 } |
33 | 33 |
| 34 // Convenience method: |
| 35 void Browser::ReplaceContentWithURL(const mojo::String& url) { |
| 36 Embed(url, nullptr, nullptr); |
| 37 } |
| 38 |
34 void Browser::Initialize(mojo::ApplicationImpl* app) { | 39 void Browser::Initialize(mojo::ApplicationImpl* app) { |
35 window_manager_app_->Initialize(app); | 40 window_manager_app_->Initialize(app); |
36 ui_.reset(BrowserUI::Create(this, app->shell())); | 41 ui_.reset(BrowserUI::Create(this, app->shell())); |
37 | 42 |
38 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 43 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
39 base::CommandLine::StringVector args = command_line->GetArgs(); | 44 base::CommandLine::StringVector args = command_line->GetArgs(); |
40 if (args.empty()) { | 45 if (args.empty()) { |
41 default_url_ = "http://www.google.com/"; | 46 default_url_ = "http://www.google.com/"; |
42 } else { | 47 } else { |
43 #if defined(OS_WIN) | 48 #if defined(OS_WIN) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 window_manager_app_->AddAccelerator(mojo::KEYBOARD_CODE_BROWSER_BACK, | 92 window_manager_app_->AddAccelerator(mojo::KEYBOARD_CODE_BROWSER_BACK, |
88 mojo::EVENT_FLAGS_NONE); | 93 mojo::EVENT_FLAGS_NONE); |
89 | 94 |
90 // Now that we're ready, either load a pending url or the default url. | 95 // Now that we're ready, either load a pending url or the default url. |
91 if (!pending_url_.empty()) | 96 if (!pending_url_.empty()) |
92 Embed(pending_url_, services.Pass(), exposed_services.Pass()); | 97 Embed(pending_url_, services.Pass(), exposed_services.Pass()); |
93 else if (!default_url_.empty()) | 98 else if (!default_url_.empty()) |
94 Embed(default_url_, services.Pass(), exposed_services.Pass()); | 99 Embed(default_url_, services.Pass(), exposed_services.Pass()); |
95 } | 100 } |
96 | 101 |
| 102 void Browser::OnViewManagerDisconnected( |
| 103 mojo::ViewManager* view_manager) { |
| 104 ui_.reset(); |
| 105 root_ = nullptr; |
| 106 } |
| 107 |
97 void Browser::Embed(const mojo::String& url, | 108 void Browser::Embed(const mojo::String& url, |
98 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 109 mojo::InterfaceRequest<mojo::ServiceProvider> services, |
99 mojo::ServiceProviderPtr exposed_services) { | 110 mojo::ServiceProviderPtr exposed_services) { |
100 // We can get Embed calls before we've actually been | 111 // We can get Embed calls before we've actually been |
101 // embedded into the root view and content_ is created. | 112 // embedded into the root view and content_ is created. |
102 // Just save the last url, we'll embed it when we're ready. | 113 // Just save the last url, we'll embed it when we're ready. |
103 if (!content_) { | 114 if (!content_) { |
104 pending_url_ = url; | 115 pending_url_ = url; |
105 return; | 116 return; |
106 } | 117 } |
(...skipping 11 matching lines...) Expand all Loading... |
118 mojo::EventFlags flags) { | 129 mojo::EventFlags flags) { |
119 DCHECK_EQ(mojo::KEYBOARD_CODE_BROWSER_BACK, keyboard_code); | 130 DCHECK_EQ(mojo::KEYBOARD_CODE_BROWSER_BACK, keyboard_code); |
120 navigator_host_.RequestNavigateHistory(-1); | 131 navigator_host_.RequestNavigateHistory(-1); |
121 } | 132 } |
122 | 133 |
123 void Browser::Create(mojo::ApplicationConnection* connection, | 134 void Browser::Create(mojo::ApplicationConnection* connection, |
124 mojo::InterfaceRequest<mojo::NavigatorHost> request) { | 135 mojo::InterfaceRequest<mojo::NavigatorHost> request) { |
125 navigator_host_.Bind(request.Pass()); | 136 navigator_host_.Bind(request.Pass()); |
126 } | 137 } |
127 | 138 |
128 void Browser::OnViewManagerDisconnected( | |
129 mojo::ViewManager* view_manager) { | |
130 root_ = nullptr; | |
131 } | |
132 | |
133 // Convenience method: | |
134 void Browser::ReplaceContentWithURL(const mojo::String& url) { | |
135 Embed(url, nullptr, nullptr); | |
136 } | |
137 | |
138 } // namespace mandoline | 139 } // namespace mandoline |
OLD | NEW |