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 COMPONENTS_WEB_VIEW_WEB_VIEW_IMPL_H_
6 #define COMPONENTS_WEB_VIEW_WEB_VIEW_IMPL_H_
8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "components/mus/public/cpp/view_observer.h"
11 #include "components/mus/public/cpp/view_tree_delegate.h"
12 #include "components/web_view/frame_devtools_agent_delegate.h"
13 #include "components/web_view/frame_tree_delegate.h"
14 #include "components/web_view/navigation_controller.h"
15 #include "components/web_view/navigation_controller_delegate.h"
16 #include "components/web_view/public/interfaces/web_view.mojom.h"
17 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h"
20 class ApplicationImpl
;
26 class FrameDevToolsAgent
;
28 class PendingWebViewLoad
;
29 class URLRequestCloneable
;
32 class HTMLMessageEvent
;
35 class WebViewImpl
: public mojom::WebView
,
36 public mus::ViewTreeDelegate
,
37 public mus::ViewObserver
,
38 public FrameTreeDelegate
,
39 public FrameDevToolsAgentDelegate
,
40 public NavigationControllerDelegate
{
42 WebViewImpl(mojo::ApplicationImpl
* app
,
43 mojom::WebViewClientPtr client
,
44 mojo::InterfaceRequest
<WebView
> request
);
45 ~WebViewImpl() override
;
48 friend class PendingWebViewLoad
;
50 // See description above |pending_load_| for details.
53 // Overridden from WebView:
54 void LoadRequest(mojo::URLRequestPtr request
) override
;
55 void GetViewTreeClient(
56 mojo::InterfaceRequest
<mojo::ViewTreeClient
> view_tree_client
)
58 void GoBack() override
;
59 void GoForward() override
;
61 // Overridden from mus::ViewTreeDelegate:
62 void OnEmbed(mus::View
* root
) override
;
63 void OnConnectionLost(mus::ViewTreeConnection
* connection
) override
;
65 // Overridden from mus::ViewObserver:
66 void OnViewBoundsChanged(mus::View
* view
,
67 const mojo::Rect
& old_bounds
,
68 const mojo::Rect
& new_bounds
) override
;
69 void OnViewDestroyed(mus::View
* view
) override
;
71 // Overridden from FrameTreeDelegate:
72 scoped_ptr
<FrameUserData
> CreateUserDataForNewFrame(
73 mojom::FrameClientPtr frame_client
) override
;
74 bool CanPostMessageEventToFrame(const Frame
* source
,
76 mojom::HTMLMessageEvent
* event
) override
;
77 void LoadingStateChanged(bool loading
, double progress
) override
;
78 void TitleChanged(const mojo::String
& title
) override
;
79 void NavigateTopLevel(Frame
* source
, mojo::URLRequestPtr request
) override
;
80 void CanNavigateFrame(Frame
* target
,
81 mojo::URLRequestPtr request
,
82 const CanNavigateFrameCallback
& callback
) override
;
83 void DidStartNavigation(Frame
* frame
) override
;
84 void DidCommitProvisionalLoad(Frame
* frame
) override
;
86 // Overridden from FrameDevToolsAgent::Delegate:
87 void HandlePageNavigateRequest(const GURL
& url
) override
;
89 // Overridden from NavigationControllerDelegate:
90 void OnNavigate(mojo::URLRequestPtr request
) override
;
91 void OnDidNavigate() override
;
93 mojo::ApplicationImpl
* app_
;
94 mojom::WebViewClientPtr client_
;
95 mojo::StrongBinding
<WebView
> binding_
;
98 scoped_ptr
<FrameTree
> frame_tree_
;
100 // When LoadRequest() is called a PendingWebViewLoad is created to wait for
101 // state needed to process the request. When the state is obtained OnLoad()
103 scoped_ptr
<PendingWebViewLoad
> pending_load_
;
105 scoped_ptr
<FrameDevToolsAgent
> devtools_agent_
;
107 NavigationController navigation_controller_
;
109 DISALLOW_COPY_AND_ASSIGN(WebViewImpl
);
112 } // namespace web_view
114 #endif // COMPONENTS_WEB_VIEW_WEB_VIEW_IMPL_H_