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

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

Issue 1136593004: Add a simple browser UI (with url bar) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 7 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 "mandoline/ui/browser/browser_ui.h"
9 #include "mandoline/ui/browser/merged_service_provider.h" 10 #include "mandoline/ui/browser/merged_service_provider.h"
10 #include "mojo/application/application_runner_chromium.h" 11 #include "mojo/application/application_runner_chromium.h"
12 #include "mojo/converters/geometry/geometry_type_converters.h"
11 #include "third_party/mojo/src/mojo/public/c/system/main.h" 13 #include "third_party/mojo/src/mojo/public/c/system/main.h"
14 #include "ui/gfx/geometry/rect.h"
12 #include "ui/gfx/geometry/size.h" 15 #include "ui/gfx/geometry/size.h"
13 16
14 namespace mandoline { 17 namespace mandoline {
15 18
16 Browser::Browser() 19 Browser::Browser()
17 : window_manager_app_(new window_manager::WindowManagerApp(this, this)), 20 : window_manager_app_(new window_manager::WindowManagerApp(this, this)),
18 root_(nullptr), 21 root_(nullptr),
19 content_(nullptr), 22 content_(nullptr),
20 navigator_host_(this), 23 navigator_host_(this),
24 ui_(nullptr),
21 weak_factory_(this) { 25 weak_factory_(this) {
22 exposed_services_impl_.AddService(this); 26 exposed_services_impl_.AddService(this);
23 } 27 }
24 28
25 Browser::~Browser() { 29 Browser::~Browser() {
26 } 30 }
27 31
28 base::WeakPtr<Browser> Browser::GetWeakPtr() { 32 base::WeakPtr<Browser> Browser::GetWeakPtr() {
29 return weak_factory_.GetWeakPtr(); 33 return weak_factory_.GetWeakPtr();
30 } 34 }
31 35
32 void Browser::Initialize(mojo::ApplicationImpl* app) { 36 void Browser::Initialize(mojo::ApplicationImpl* app) {
33 window_manager_app_->Initialize(app); 37 window_manager_app_->Initialize(app);
38 ui_.reset(BrowserUI::Create(this, app->shell()));
34 39
35 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 40 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
36 base::CommandLine::StringVector args = command_line->GetArgs(); 41 base::CommandLine::StringVector args = command_line->GetArgs();
37 if (args.empty()) { 42 if (args.empty()) {
38 default_url_ = "http://www.google.com/"; 43 default_url_ = "http://www.google.com/";
39 } else { 44 } else {
40 #if defined(OS_WIN) 45 #if defined(OS_WIN)
41 default_url_ = base::WideToUTF8(args[0]); 46 default_url_ = base::WideToUTF8(args[0]);
42 #else 47 #else
43 default_url_ = args[0]; 48 default_url_ = args[0];
(...skipping 13 matching lines...) Expand all
57 return true; 62 return true;
58 } 63 }
59 64
60 void Browser::OnEmbed( 65 void Browser::OnEmbed(
61 mojo::View* root, 66 mojo::View* root,
62 mojo::InterfaceRequest<mojo::ServiceProvider> services, 67 mojo::InterfaceRequest<mojo::ServiceProvider> services,
63 mojo::ServiceProviderPtr exposed_services) { 68 mojo::ServiceProviderPtr exposed_services) {
64 // Browser does not support being embedded more than once. 69 // Browser does not support being embedded more than once.
65 CHECK(!root_); 70 CHECK(!root_);
66 71
72 // TODO(beng): still unhappy with the fact that both this class & the UI class
73 // know so much about these views. Figure out how to shift more to
74 // the UI class.
67 root_ = root; 75 root_ = root;
68 root_->AddObserver(this); 76 content_ = root->view_manager()->CreateView();
77 ui_->Init(root_, content_);
69 78
70 #if defined(OS_ANDROID) 79 #if defined(OS_ANDROID)
71 // Resize to match the Nexus 5 aspect ratio: 80 // Resize to match the Nexus 5 aspect ratio:
72 window_manager_app_->SetViewportSize(gfx::Size(320, 640)); 81 window_manager_app_->SetViewportSize(gfx::Size(320, 640));
73 #else 82 #else
74 window_manager_app_->SetViewportSize(gfx::Size(1280, 800)); 83 window_manager_app_->SetViewportSize(gfx::Size(1280, 800));
75 #endif 84 #endif
76 85
77 content_ = root->view_manager()->CreateView();
78 content_->SetBounds(root_->bounds());
79 root_->AddChild(content_); 86 root_->AddChild(content_);
80 content_->SetVisible(true); 87 content_->SetVisible(true);
81 88
82 window_manager_app_->AddAccelerator(mojo::KEYBOARD_CODE_BROWSER_BACK, 89 window_manager_app_->AddAccelerator(mojo::KEYBOARD_CODE_BROWSER_BACK,
83 mojo::EVENT_FLAGS_NONE); 90 mojo::EVENT_FLAGS_NONE);
84 91
85 // Now that we're ready, either load a pending url or the default url. 92 // Now that we're ready, either load a pending url or the default url.
86 if (!pending_url_.empty()) 93 if (!pending_url_.empty())
87 Embed(pending_url_, services.Pass(), exposed_services.Pass()); 94 Embed(pending_url_, services.Pass(), exposed_services.Pass());
88 else if (!default_url_.empty()) 95 else if (!default_url_.empty())
(...skipping 29 matching lines...) Expand all
118 void Browser::Create(mojo::ApplicationConnection* connection, 125 void Browser::Create(mojo::ApplicationConnection* connection,
119 mojo::InterfaceRequest<mojo::NavigatorHost> request) { 126 mojo::InterfaceRequest<mojo::NavigatorHost> request) {
120 navigator_host_.Bind(request.Pass()); 127 navigator_host_.Bind(request.Pass());
121 } 128 }
122 129
123 void Browser::OnViewManagerDisconnected( 130 void Browser::OnViewManagerDisconnected(
124 mojo::ViewManager* view_manager) { 131 mojo::ViewManager* view_manager) {
125 root_ = nullptr; 132 root_ = nullptr;
126 } 133 }
127 134
128 void Browser::OnViewDestroyed(mojo::View* view) {
129 view->RemoveObserver(this);
130 }
131
132 void Browser::OnViewBoundsChanged(mojo::View* view,
133 const mojo::Rect& old_bounds,
134 const mojo::Rect& new_bounds) {
135 content_->SetBounds(new_bounds);
136 }
137
138 // Convenience method: 135 // Convenience method:
139 void Browser::ReplaceContentWithURL(const mojo::String& url) { 136 void Browser::ReplaceContentWithURL(const mojo::String& url) {
140 Embed(url, nullptr, nullptr); 137 Embed(url, nullptr, nullptr);
141 } 138 }
142 139
143 } // namespace mandoline 140 } // namespace mandoline
144 141
145 MojoResult MojoMain(MojoHandle shell_handle) { 142 MojoResult MojoMain(MojoHandle shell_handle) {
146 mojo::ApplicationRunnerChromium runner(new mandoline::Browser); 143 mojo::ApplicationRunnerChromium runner(new mandoline::Browser);
147 return runner.Run(shell_handle); 144 return runner.Run(shell_handle);
148 } 145 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698