Chromium Code Reviews| 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) |
| 54 default_url_ = base::WideToUTF8(args[0]); | 54 default_url_ = base::WideToUTF8(args[0]); |
| 55 #else | 55 #else |
| 56 default_url_ = args[0]; | 56 default_url_ = args[0]; |
| 57 #endif | 57 #endif |
| 58 } | 58 } |
| 59 } | 59 } |
| 60 | 60 |
| 61 Browser::~Browser() { | 61 Browser::~Browser() { |
| 62 // Destruct ui_ manually while |this| is alive and reset the pointer first. | 62 // Destruct ui_ manually while |this| is alive and reset the pointer first. |
| 63 // This is to avoid a double delete when OnViewManagerDestroyed gets | 63 // This is to avoid a double delete when OnViewManagerDestroyed gets |
| 64 // called. | 64 // called. |
| 65 ui_.reset(); | 65 ui_.reset(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void Browser::ReplaceContentWithRequest(mojo::URLRequestPtr request) { | 68 void Browser::ReplaceContentWithRequest(mojo::URLRequestPtr request) { |
| 69 Embed(request.Pass()); | 69 Embed(request.Pass()); |
| 70 } | 70 } |
| 71 | 71 |
| 72 mojo::ApplicationConnection* Browser::GetViewManagerConnectionForTesting() { | |
|
sky
2015/06/30 16:41:46
Position should match that of header.
Fady Samuel
2015/06/30 17:31:19
Done.
| |
| 73 return view_manager_init_.connection(); | |
| 74 } | |
| 75 | |
| 72 void Browser::OnDevicePixelRatioAvailable() { | 76 void Browser::OnDevicePixelRatioAvailable() { |
| 73 content_ = root_->view_manager()->CreateView(); | 77 content_ = root_->view_manager()->CreateView(); |
| 74 ui_->Init(root_); | 78 ui_->Init(root_); |
| 75 | 79 |
| 76 view_manager_init_.view_manager_root()->SetViewportSize( | 80 view_manager_init_.view_manager_root()->SetViewportSize( |
| 77 mojo::Size::From(GetInitialViewportSize())); | 81 mojo::Size::From(GetInitialViewportSize())); |
| 78 | 82 |
| 79 root_->AddChild(content_); | 83 root_->AddChild(content_); |
| 80 content_->SetVisible(true); | 84 content_->SetVisible(true); |
| 81 | 85 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 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 |