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

Side by Side Diff: mandoline/ui/browser/browser.cc

Issue 1195003002: Mandoline: Introduce ApplicationConnection::CloseConnection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added test Created 5 years, 5 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 "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() {
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
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) { 122 if (!frame) {
(...skipping 16 matching lines...) Expand all
135 scoped_ptr<FrameConnection> frame_connection(new FrameConnection); 139 scoped_ptr<FrameConnection> frame_connection(new FrameConnection);
136 frame_connection->Init(app_, request.Pass(), client); 140 frame_connection->Init(app_, request.Pass(), client);
137 FrameTreeClient* frame_tree_client = frame_connection->frame_tree_client(); 141 FrameTreeClient* frame_tree_client = frame_connection->frame_tree_client();
138 frame_tree_->CreateAndAddFrame(view, parent, frame_tree_client, 142 frame_tree_->CreateAndAddFrame(view, parent, frame_tree_client,
139 frame_connection.Pass()); 143 frame_connection.Pass());
140 } 144 }
141 145
142 void Browser::OnViewManagerDestroyed(mojo::ViewManager* view_manager) { 146 void Browser::OnViewManagerDestroyed(mojo::ViewManager* view_manager) {
143 ui_.reset(); 147 ui_.reset();
144 root_ = nullptr; 148 root_ = nullptr;
145 browser_manager_->BrowserClosed(this); 149 delegate_->BrowserClosed(this);
146 } 150 }
147 151
148 void Browser::OnAccelerator(mojo::EventPtr event) { 152 void Browser::OnAccelerator(mojo::EventPtr event) {
149 DCHECK_EQ(mojo::KEYBOARD_CODE_BROWSER_BACK, 153 DCHECK_EQ(mojo::KEYBOARD_CODE_BROWSER_BACK,
150 event->key_data->windows_key_code); 154 event->key_data->windows_key_code);
151 navigator_host_.RequestNavigateHistory(-1); 155 navigator_host_.RequestNavigateHistory(-1);
152 } 156 }
153 157
154 void Browser::OpenURL(const mojo::String& url) { 158 void Browser::OpenURL(const mojo::String& url) {
155 omnibox_->SetVisible(false); 159 omnibox_->SetVisible(false);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 omnibox_->SetBounds(root_->bounds()); 214 omnibox_->SetBounds(root_->bounds());
211 } 215 }
212 mojo::ViewManagerClientPtr view_manager_client; 216 mojo::ViewManagerClientPtr view_manager_client;
213 mojo::ApplicationConnection* connection = 217 mojo::ApplicationConnection* connection =
214 app_->ConnectToApplication(request.Pass()); 218 app_->ConnectToApplication(request.Pass());
215 connection->ConnectToService(&view_manager_client); 219 connection->ConnectToService(&view_manager_client);
216 omnibox_->Embed(view_manager_client.Pass()); 220 omnibox_->Embed(view_manager_client.Pass());
217 } 221 }
218 222
219 } // namespace mandoline 223 } // namespace mandoline
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698