Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / mandoline / ui / browser / browser.h
blobcca1cb9fcccea39d8d16f567e19364f7d8983f00
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
3 // found in the LICENSE file.
5 #ifndef MANDOLINE_UI_BROWSER_BROWSER_H_
6 #define MANDOLINE_UI_BROWSER_BROWSER_H_
8 #include "base/gtest_prod_util.h"
9 #include "components/view_manager/public/cpp/view_manager.h"
10 #include "components/view_manager/public/cpp/view_manager_delegate.h"
11 #include "components/view_manager/public/cpp/view_manager_init.h"
12 #include "components/view_manager/public/interfaces/view_manager_root.mojom.h"
13 #include "mandoline/services/navigation/public/interfaces/navigation.mojom.h"
14 #include "mandoline/tab/frame_tree_delegate.h"
15 #include "mandoline/ui/browser/navigator_host_impl.h"
16 #include "mandoline/ui/browser/public/interfaces/omnibox.mojom.h"
17 #include "mandoline/ui/browser/public/interfaces/view_embedder.mojom.h"
18 #include "mojo/application/public/cpp/application_delegate.h"
19 #include "mojo/application/public/cpp/application_impl.h"
20 #include "mojo/application/public/cpp/connect.h"
21 #include "mojo/common/weak_binding_set.h"
22 #include "ui/mojo/events/input_events.mojom.h"
23 #include "url/gurl.h"
25 namespace mojo {
26 class ViewManagerInit;
29 namespace mandoline {
31 FORWARD_DECLARE_TEST(BrowserTest, ClosingBrowserClosesAppConnection);
33 class BrowserDelegate;
34 class BrowserUI;
35 class FrameTree;
37 class Browser : public mojo::ViewManagerDelegate,
38 public mojo::ViewManagerRootClient,
39 public OmniboxClient,
40 public ViewEmbedder,
41 public FrameTreeDelegate,
42 public mojo::InterfaceFactory<mojo::NavigatorHost>,
43 public mojo::InterfaceFactory<ViewEmbedder> {
44 public:
45 Browser(mojo::ApplicationImpl* app,
46 BrowserDelegate* delegate,
47 const GURL& default_url);
48 ~Browser() override;
50 void ReplaceContentWithRequest(mojo::URLRequestPtr request);
52 mojo::View* content() { return content_; }
53 mojo::View* omnibox() { return omnibox_; }
55 const GURL& current_url() const { return current_url_; }
57 private:
58 FRIEND_TEST_ALL_PREFIXES(BrowserTest, ClosingBrowserClosesAppConnection);
59 FRIEND_TEST_ALL_PREFIXES(BrowserTest, TwoBrowsers);
61 friend class TestBrowser;
63 mojo::ApplicationConnection* GetViewManagerConnectionForTesting();
65 // Overridden from mojo::ViewManagerDelegate:
66 void OnEmbed(mojo::View* root) override;
67 void OnEmbedForDescendant(mojo::View* view,
68 mojo::URLRequestPtr request,
69 mojo::ViewManagerClientPtr* client) override;
70 void OnViewManagerDestroyed(mojo::ViewManager* view_manager) override;
72 // Overridden from ViewManagerRootClient:
73 void OnAccelerator(mojo::EventPtr event) override;
75 // Overridden from OmniboxClient:
76 void OpenURL(const mojo::String& url) override;
78 // Overridden from ViewEmbedder:
79 void Embed(mojo::URLRequestPtr request) override;
81 // Overridden from FrameTreeDelegate:
82 bool CanPostMessageEventToFrame(const Frame* source,
83 const Frame* target,
84 MessageEvent* event) override;
85 void LoadingStateChanged(bool loading) override;
86 void ProgressChanged(double progress) override;
87 void RequestNavigate(Frame* source,
88 NavigationTarget target,
89 mojo::URLRequestPtr request) override;
91 // Overridden from mojo::InterfaceFactory<mojo::NavigatorHost>:
92 void Create(mojo::ApplicationConnection* connection,
93 mojo::InterfaceRequest<mojo::NavigatorHost> request) override;
95 // Overridden from mojo::InterfaceFactory<ViewEmbedder>:
96 void Create(mojo::ApplicationConnection* connection,
97 mojo::InterfaceRequest<ViewEmbedder> request) override;
99 void ShowOmnibox(mojo::URLRequestPtr request);
101 mojo::ViewManagerInit view_manager_init_;
103 // Only support being embedded once, so both application-level
104 // and embedding-level state are shared on the same object.
105 mojo::View* root_;
106 mojo::View* content_;
107 mojo::View* omnibox_;
108 GURL default_url_;
109 mojo::URLRequestPtr pending_request_;
111 mojo::WeakBindingSet<ViewEmbedder> view_embedder_bindings_;
113 NavigatorHostImpl navigator_host_;
115 GURL current_url_;
117 scoped_ptr<BrowserUI> ui_;
118 mojo::ApplicationImpl* app_;
119 BrowserDelegate* delegate_;
121 scoped_ptr<FrameTree> frame_tree_;
123 DISALLOW_COPY_AND_ASSIGN(Browser);
126 } // namespace mandoline
128 #endif // MANDOLINE_UI_BROWSER_BROWSER_H_