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_HTML_VIEWER_HTML_FRAME_TREE_MANAGER_H_
6 #define COMPONENTS_HTML_VIEWER_HTML_FRAME_TREE_MANAGER_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "mandoline/services/navigation/public/interfaces/navigation.mojom.h"
11 #include "mandoline/tab/public/interfaces/frame_tree.mojom.h"
12 #include "mojo/application/public/cpp/lazy_interface_ptr.h"
13 #include "third_party/WebKit/public/web/WebFrameClient.h"
14 #include "third_party/WebKit/public/web/WebNavigationPolicy.h"
20 class WebRemoteFrameClient
;
30 class ApplicationConnection
;
31 class ApplicationImpl
;
35 namespace html_viewer
{
38 class HTMLFrameTreeManagerDelegate
;
41 // HTMLFrameTreeManager is responsible for managing the frames that comprise a
42 // document. Some of the frames may be remote. HTMLFrameTreeManager updates its
43 // state in response to changes from the FrameTreeServer, as well as changes
44 // from the underlying frames. The frame tree has at least one local frame
45 // that is backed by a mojo::View.
46 class HTMLFrameTreeManager
: public mandoline::FrameTreeClient
{
48 HTMLFrameTreeManager(GlobalState
* global_state
,
49 mojo::ApplicationImpl
* app
,
50 mojo::ApplicationConnection
* app_connection
,
51 uint32_t local_frame_id
,
52 mandoline::FrameTreeServerPtr server
);
53 ~HTMLFrameTreeManager() override
;
55 void Init(mojo::View
* local_view
,
56 mojo::Array
<mandoline::FrameDataPtr
> frame_data
);
58 void set_delegate(HTMLFrameTreeManagerDelegate
* delegate
) {
62 GlobalState
* global_state() { return global_state_
; }
63 mojo::ApplicationImpl
* app() { return app_
; }
65 // Returns the Frame/WebFrame that is rendering to the supplied view.
66 // TODO(sky): we need to support more than one local frame.
67 HTMLFrame
* GetLocalFrame();
68 blink::WebLocalFrame
* GetLocalWebFrame();
70 blink::WebView
* GetWebView();
72 void LoadingStarted(HTMLFrame
* frame
);
73 void LoadingStopped(HTMLFrame
* frame
);
74 void ProgressChanged(HTMLFrame
* frame
, double progress
);
77 friend class HTMLFrame
;
79 // Returns the navigation policy for the specified frame.
80 blink::WebNavigationPolicy
DecidePolicyForNavigation(
82 const blink::WebFrameClient::NavigationPolicyInfo
& info
);
84 // Invoked when a Frame finishes loading.
85 void OnFrameDidFinishLoad(HTMLFrame
* frame
);
87 // Invoked when a Frame navigates.
88 void OnFrameDidNavigateLocally(HTMLFrame
* frame
, const std::string
& url
);
90 // Invoked when a Frame is destroye.
91 void OnFrameDestroyed(HTMLFrame
* frame
);
93 // Invoked when the name of a frame changes.
94 void OnFrameDidChangeName(HTMLFrame
* frame
, const blink::WebString
& name
);
96 // mandoline::FrameTreeClient:
97 void OnConnect(mandoline::FrameTreeServerPtr server
,
98 mojo::Array
<mandoline::FrameDataPtr
> frame_data
) override
;
99 void OnFrameAdded(mandoline::FrameDataPtr frame_data
) override
;
100 void OnFrameRemoved(uint32_t frame_id
) override
;
101 void OnFrameNameChanged(uint32_t frame_id
, const mojo::String
& name
) override
;
103 GlobalState
* global_state_
;
105 mojo::ApplicationImpl
* app_
;
107 HTMLFrameTreeManagerDelegate
* delegate_
;
109 // Frame id of the frame we're rendering to.
110 const uint32_t local_frame_id_
;
112 mandoline::FrameTreeServerPtr server_
;
114 mojo::LazyInterfacePtr
<mojo::NavigatorHost
> navigator_host_
;
118 DISALLOW_COPY_AND_ASSIGN(HTMLFrameTreeManager
);
121 } // namespace html_viewer
123 #endif // COMPONENTS_HTML_VIEWER_HTML_FRAME_TREE_MANAGER_H_