Add Smart Lock warm welcome on Windows.
[chromium-blink-merge.git] / components / html_viewer / document_resource_waiter.h
blobd6a5c25c50d778a3c09d7f031adb2c0fb0bcea7a
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_DOCUMENT_RESOURCE_WAITER_H_
6 #define COMPONENTS_HTML_VIEWER_DOCUMENT_RESOURCE_WAITER_H_
8 #include "base/basictypes.h"
9 #include "components/html_viewer/html_frame_tree_manager_observer.h"
10 #include "components/view_manager/public/cpp/view_observer.h"
11 #include "components/web_view/public/interfaces/frame_tree.mojom.h"
12 #include "mojo/services/network/public/interfaces/url_loader.mojom.h"
13 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"
15 namespace mojo {
16 class View;
19 namespace html_viewer {
21 class HTMLDocumentOOPIF;
22 class HTMLFrameTreeManager;
23 class GlobalState;
25 // DocumentResourceWaiter waits for the necessary resources needed to load an
26 // HTMLDocument. Once ready it calls to HTMLDocumentOOPIF::Load(). Once
27 // ready it is assumed HTMLDocument will call back for the FrameTreeClient and
28 // FrameData.
29 class DocumentResourceWaiter : public web_view::FrameTreeClient,
30 public HTMLFrameTreeManagerObserver,
31 public mojo::ViewObserver {
32 public:
33 DocumentResourceWaiter(GlobalState* global_state,
34 mojo::URLResponsePtr response,
35 HTMLDocumentOOPIF* document);
36 ~DocumentResourceWaiter() override;
38 // Releases all the resources that have been accumulated.
39 void Release(mojo::InterfaceRequest<web_view::FrameTreeClient>*
40 frame_tree_client_request,
41 web_view::FrameTreeServerPtr* frame_tree_server,
42 mojo::Array<web_view::FrameDataPtr>* frame_data,
43 uint32_t* view_id,
44 uint32_t* change_id,
45 web_view::ViewConnectType* view_connect_type,
46 OnConnectCallback* on_connect_callback);
48 uint32_t change_id() const { return change_id_; }
50 mojo::URLResponsePtr ReleaseURLResponse();
52 // See class description.
53 bool is_ready() const { return is_ready_; }
55 void SetRoot(mojo::View* root);
56 mojo::View* root() { return root_; }
58 void Bind(mojo::InterfaceRequest<web_view::FrameTreeClient> request);
60 private:
61 // Updates |is_ready_|, and if ready starts the Load() in the document.
62 void UpdateIsReady();
64 // web_view::FrameTreeClient:
65 void OnConnect(web_view::FrameTreeServerPtr server,
66 uint32_t change_id,
67 uint32_t view_id,
68 web_view::ViewConnectType view_connect_type,
69 mojo::Array<web_view::FrameDataPtr> frame_data,
70 const OnConnectCallback& callback) override;
71 void OnFrameAdded(uint32_t change_id,
72 web_view::FrameDataPtr frame_data) override;
73 void OnFrameRemoved(uint32_t change_id, uint32_t frame_id) override;
74 void OnFrameClientPropertyChanged(uint32_t frame_id,
75 const mojo::String& name,
76 mojo::Array<uint8_t> new_value) override;
77 void OnPostMessageEvent(uint32_t source_frame_id,
78 uint32_t target_frame_id,
79 web_view::HTMLMessageEventPtr event) override;
80 void OnWillNavigate(uint32_t target_frame_id) override;
82 // ViewObserver:
83 void OnViewViewportMetricsChanged(
84 mojo::View* view,
85 const mojo::ViewportMetrics& old_metrics,
86 const mojo::ViewportMetrics& new_metrics) override;
87 void OnViewDestroyed(mojo::View* view) override;
89 // HTMLFrameTreeManagerObserver:
90 void OnHTMLFrameTreeManagerChangeIdAdvanced() override;
91 void OnHTMLFrameTreeManagerDestroyed() override;
93 GlobalState* global_state_;
94 HTMLDocumentOOPIF* document_;
95 mojo::URLResponsePtr response_;
96 mojo::View* root_;
97 web_view::FrameTreeServerPtr server_;
98 mojo::Array<web_view::FrameDataPtr> frame_data_;
99 uint32_t change_id_;
100 uint32_t view_id_;
101 web_view::ViewConnectType view_connect_type_;
102 OnConnectCallback on_connect_callback_;
104 // Once we get OnConnect() we unbind |frame_tree_client_binding_| and put it
105 // here.
106 mojo::InterfaceRequest<web_view::FrameTreeClient> frame_tree_client_request_;
107 mojo::Binding<web_view::FrameTreeClient> frame_tree_client_binding_;
109 bool is_ready_;
111 // See comments in UpdateIsReady() for details of this.
113 // While |waiting_for_change_id_| is true DocumentResourceWaiter is an
114 // HTMLFrameTreeManagerObserver on |target_frame_tree_|.
115 bool waiting_for_change_id_;
117 HTMLFrameTreeManager* target_frame_tree_;
119 DISALLOW_COPY_AND_ASSIGN(DocumentResourceWaiter);
122 } // namespace html_viewer
124 #endif // COMPONENTS_HTML_VIEWER_DOCUMENT_RESOURCE_WAITER_H_