Allow only one bookmark to be added for multiple fast starring
[chromium-blink-merge.git] / components / html_viewer / document_resource_waiter.h
blobd979abe5e3c770473fc31a1f8f437a1ad17e0007
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 "mandoline/tab/public/interfaces/frame_tree.mojom.h"
10 #include "mojo/services/network/public/interfaces/url_loader.mojom.h"
12 namespace mojo {
13 class View;
16 namespace html_viewer {
18 class HTMLDocumentOOPIF;
19 class GlobalState;
21 // DocumentResourceWaiter waits for the necessary resources needed to load an
22 // HTMLDocument. Use IsReady() to determine when everything is available. Once
23 // ready it is assumed HTMLDocument will call back for the FrameTreeClient and
24 // FrameData.
25 class DocumentResourceWaiter : public mandoline::FrameTreeClient {
26 public:
27 DocumentResourceWaiter(GlobalState* global_state,
28 mojo::URLResponsePtr response,
29 HTMLDocumentOOPIF* document);
30 ~DocumentResourceWaiter() override;
32 // Releases all the resources that have been accumulated.
33 void Release(mojo::InterfaceRequest<mandoline::FrameTreeClient>*
34 frame_tree_client_request,
35 mandoline::FrameTreeServerPtr* frame_tree_server,
36 mojo::Array<mandoline::FrameDataPtr>* frame_data);
38 mojo::URLResponsePtr ReleaseURLResponse();
40 // See class description.
41 bool IsReady() const;
43 void set_root(mojo::View* root) { root_ = root; }
44 mojo::View* root() { return root_; }
46 void Bind(mojo::InterfaceRequest<mandoline::FrameTreeClient> request);
48 private:
49 // mandoline::FrameTreeClient:
50 void OnConnect(mandoline::FrameTreeServerPtr server,
51 mojo::Array<mandoline::FrameDataPtr> frame_data) override;
52 void OnFrameAdded(mandoline::FrameDataPtr frame_data) override;
53 void OnFrameRemoved(uint32_t frame_id) override;
54 void OnFrameClientPropertyChanged(uint32_t frame_id,
55 const mojo::String& name,
56 mojo::Array<uint8_t> new_value) override;
58 GlobalState* global_state_;
59 HTMLDocumentOOPIF* document_;
60 mojo::URLResponsePtr response_;
61 mojo::View* root_;
62 mandoline::FrameTreeServerPtr server_;
63 mojo::Array<mandoline::FrameDataPtr> frame_data_;
65 // Once we get OnConnect() we unbind |frame_tree_client_binding_| and put it
66 // here.
67 mojo::InterfaceRequest<mandoline::FrameTreeClient> frame_tree_client_request_;
68 mojo::Binding<mandoline::FrameTreeClient> frame_tree_client_binding_;
70 DISALLOW_COPY_AND_ASSIGN(DocumentResourceWaiter);
73 } // namespace html_viewer
75 #endif // COMPONENTS_HTML_VIEWER_DOCUMENT_RESOURCE_WAITER_H_