| 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 "components/view_manager/public/cpp/view.h" | 9 #include "components/view_manager/public/cpp/view.h" |
| 10 #include "components/view_manager/public/cpp/view_manager_init.h" | 10 #include "components/view_manager/public/cpp/view_manager_init.h" |
| 11 #include "mandoline/tab/frame.h" | 11 #include "mandoline/tab/frame.h" |
| 12 #include "mandoline/tab/frame_connection.h" | 12 #include "mandoline/tab/frame_connection.h" |
| 13 #include "mandoline/tab/frame_tree.h" | 13 #include "mandoline/tab/frame_tree.h" |
| 14 #include "mandoline/ui/browser/browser_manager.h" | 14 #include "mandoline/ui/browser/browser_delegate.h" |
| 15 #include "mandoline/ui/browser/browser_ui.h" | 15 #include "mandoline/ui/browser/browser_ui.h" |
| 16 #include "mojo/application/public/cpp/application_runner.h" | 16 #include "mojo/application/public/cpp/application_runner.h" |
| 17 #include "mojo/common/common_type_converters.h" | 17 #include "mojo/common/common_type_converters.h" |
| 18 #include "mojo/converters/geometry/geometry_type_converters.h" | 18 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 19 #include "third_party/mojo/src/mojo/public/c/system/main.h" | 19 #include "third_party/mojo/src/mojo/public/c/system/main.h" |
| 20 #include "ui/gfx/geometry/size.h" | 20 #include "ui/gfx/geometry/size.h" |
| 21 | 21 |
| 22 namespace mandoline { | 22 namespace mandoline { |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 gfx::Size GetInitialViewportSize() { | 25 gfx::Size GetInitialViewportSize() { |
| 26 #if defined(OS_ANDROID) | 26 #if defined(OS_ANDROID) |
| 27 // Resize to match the Nexus 5 aspect ratio: | 27 // Resize to match the Nexus 5 aspect ratio: |
| 28 return gfx::Size(320, 640); | 28 return gfx::Size(320, 640); |
| 29 #else | 29 #else |
| 30 return gfx::Size(1280, 800); | 30 return gfx::Size(1280, 800); |
| 31 #endif | 31 #endif |
| 32 } | 32 } |
| 33 | 33 |
| 34 } // namespace | 34 } // namespace |
| 35 | 35 |
| 36 Browser::Browser(mojo::ApplicationImpl* app, BrowserManager* browser_manager) | 36 Browser::Browser(mojo::ApplicationImpl* app, BrowserDelegate* delegate) |
| 37 : view_manager_init_(app, this, this), | 37 : view_manager_init_(app, this, this), |
| 38 root_(nullptr), | 38 root_(nullptr), |
| 39 content_(nullptr), | 39 content_(nullptr), |
| 40 omnibox_(nullptr), | 40 omnibox_(nullptr), |
| 41 navigator_host_(this), | 41 navigator_host_(this), |
| 42 app_(app), | 42 app_(app), |
| 43 browser_manager_(browser_manager) { | 43 delegate_(delegate) { |
| 44 view_manager_init_.connection()->AddService<ViewEmbedder>(this); | 44 view_manager_init_.connection()->AddService<ViewEmbedder>(this); |
| 45 | 45 |
| 46 ui_.reset(BrowserUI::Create(this, app)); | 46 ui_.reset(BrowserUI::Create(this, app)); |
| 47 | 47 |
| 48 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 48 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 49 base::CommandLine::StringVector args = command_line->GetArgs(); | 49 base::CommandLine::StringVector args = command_line->GetArgs(); |
| 50 if (args.empty()) { | 50 if (args.empty()) { |
| 51 default_url_ = "http://www.google.com/"; | 51 default_url_ = "http://www.google.com/"; |
| 52 } else { | 52 } else { |
| 53 #if defined(OS_WIN) | 53 #if defined(OS_WIN) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 // Now that we're ready, either load a pending url or the default url. | 85 // Now that we're ready, either load a pending url or the default url. |
| 86 if (pending_request_) { | 86 if (pending_request_) { |
| 87 Embed(pending_request_.Pass()); | 87 Embed(pending_request_.Pass()); |
| 88 } else if (!default_url_.empty()) { | 88 } else if (!default_url_.empty()) { |
| 89 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 89 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
| 90 request->url = mojo::String::From(default_url_); | 90 request->url = mojo::String::From(default_url_); |
| 91 Embed(request.Pass()); | 91 Embed(request.Pass()); |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 mojo::ApplicationConnection* Browser::GetViewManagerConnectionForTesting() { |
| 96 return view_manager_init_.connection(); |
| 97 } |
| 98 |
| 95 void Browser::OnEmbed(mojo::View* root) { | 99 void Browser::OnEmbed(mojo::View* root) { |
| 96 // Browser does not support being embedded more than once. | 100 // Browser does not support being embedded more than once. |
| 97 CHECK(!root_); | 101 CHECK(!root_); |
| 98 | 102 |
| 99 // Make it so we get OnWillEmbed() for any Embed()s done by other apps we | 103 // Make it so we get OnWillEmbed() for any Embed()s done by other apps we |
| 100 // Embed(). | 104 // Embed(). |
| 101 root->view_manager()->SetEmbedRoot(); | 105 root->view_manager()->SetEmbedRoot(); |
| 102 | 106 |
| 103 // TODO(beng): still unhappy with the fact that both this class & the UI class | 107 // TODO(beng): still unhappy with the fact that both this class & the UI class |
| 104 // know so much about these views. Figure out how to shift more to | 108 // know so much about these views. Figure out how to shift more to |
| 105 // the UI class. | 109 // the UI class. |
| 106 root_ = root; | 110 root_ = root; |
| 107 | 111 |
| 108 if (!browser_manager_->InitUIIfNecessary(this, root_)) | 112 if (!delegate_->InitUIIfNecessary(this, root_)) |
| 109 return; // We'll be called back from OnDevicePixelRatioAvailable(). | 113 return; // We'll be called back from OnDevicePixelRatioAvailable(). |
| 110 OnDevicePixelRatioAvailable(); | 114 OnDevicePixelRatioAvailable(); |
| 111 } | 115 } |
| 112 | 116 |
| 113 void Browser::OnEmbedForDescendant(mojo::View* view, | 117 void Browser::OnEmbedForDescendant(mojo::View* view, |
| 114 mojo::URLRequestPtr request, | 118 mojo::URLRequestPtr request, |
| 115 mojo::ViewManagerClientPtr* client) { | 119 mojo::ViewManagerClientPtr* client) { |
| 116 // TODO(sky): move this to Frame/FrameTree. | 120 // TODO(sky): move this to Frame/FrameTree. |
| 117 Frame* frame = Frame::FindFirstFrameAncestor(view); | 121 Frame* frame = Frame::FindFirstFrameAncestor(view); |
| 118 if (!frame || !frame->HasAncestor(frame_tree_->root()) || | 122 if (!frame || !frame->HasAncestor(frame_tree_->root()) || |
| 119 frame == frame_tree_->root()) { | 123 frame == frame_tree_->root()) { |
| 120 // TODO(sky): add requestor url so that we can return false if it's not | 124 // TODO(sky): add requestor url so that we can return false if it's not |
| 121 // an app we expect. | 125 // an app we expect. |
| 122 mojo::ApplicationConnection* connection = | 126 mojo::ApplicationConnection* connection = |
| 123 app_->ConnectToApplication(request.Pass()); | 127 app_->ConnectToApplication(request.Pass()); |
| 124 connection->ConnectToService(client); | 128 connection->ConnectToService(client); |
| 125 return; | 129 return; |
| 126 } | 130 } |
| 127 | 131 |
| 128 scoped_ptr<FrameConnection> frame_connection(new FrameConnection); | 132 scoped_ptr<FrameConnection> frame_connection(new FrameConnection); |
| 129 frame_connection->Init(app_, request.Pass(), client); | 133 frame_connection->Init(app_, request.Pass(), client); |
| 130 FrameTreeClient* frame_tree_client = frame_connection->frame_tree_client(); | 134 FrameTreeClient* frame_tree_client = frame_connection->frame_tree_client(); |
| 131 frame_tree_->CreateOrReplaceFrame(frame, view, frame_tree_client, | 135 frame_tree_->CreateOrReplaceFrame(frame, view, frame_tree_client, |
| 132 frame_connection.Pass()); | 136 frame_connection.Pass()); |
| 133 } | 137 } |
| 134 | 138 |
| 135 void Browser::OnViewManagerDestroyed(mojo::ViewManager* view_manager) { | 139 void Browser::OnViewManagerDestroyed(mojo::ViewManager* view_manager) { |
| 136 ui_.reset(); | 140 ui_.reset(); |
| 137 root_ = nullptr; | 141 root_ = nullptr; |
| 138 browser_manager_->BrowserClosed(this); | 142 delegate_->BrowserClosed(this); |
| 139 } | 143 } |
| 140 | 144 |
| 141 void Browser::OnAccelerator(mojo::EventPtr event) { | 145 void Browser::OnAccelerator(mojo::EventPtr event) { |
| 142 DCHECK_EQ(mojo::KEYBOARD_CODE_BROWSER_BACK, | 146 DCHECK_EQ(mojo::KEYBOARD_CODE_BROWSER_BACK, |
| 143 event->key_data->windows_key_code); | 147 event->key_data->windows_key_code); |
| 144 navigator_host_.RequestNavigateHistory(-1); | 148 navigator_host_.RequestNavigateHistory(-1); |
| 145 } | 149 } |
| 146 | 150 |
| 147 void Browser::OpenURL(const mojo::String& url) { | 151 void Browser::OpenURL(const mojo::String& url) { |
| 148 omnibox_->SetVisible(false); | 152 omnibox_->SetVisible(false); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 omnibox_->SetBounds(root_->bounds()); | 207 omnibox_->SetBounds(root_->bounds()); |
| 204 } | 208 } |
| 205 mojo::ViewManagerClientPtr view_manager_client; | 209 mojo::ViewManagerClientPtr view_manager_client; |
| 206 mojo::ApplicationConnection* connection = | 210 mojo::ApplicationConnection* connection = |
| 207 app_->ConnectToApplication(request.Pass()); | 211 app_->ConnectToApplication(request.Pass()); |
| 208 connection->ConnectToService(&view_manager_client); | 212 connection->ConnectToService(&view_manager_client); |
| 209 omnibox_->Embed(view_manager_client.Pass()); | 213 omnibox_->Embed(view_manager_client.Pass()); |
| 210 } | 214 } |
| 211 | 215 |
| 212 } // namespace mandoline | 216 } // namespace mandoline |
| OLD | NEW |