Remove 'blink::WebSerializedOrigin' (7/7)
[chromium-blink-merge.git] / components / html_viewer / frame.h
blob68dedfc3f580ff7a33351bd1ad5a6a54cd026b8f
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_FRAME_H_
6 #define COMPONENTS_HTML_VIEWER_FRAME_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "components/html_viewer/frame_tree_manager.h"
13 #include "components/view_manager/public/cpp/view_observer.h"
14 #include "mandoline/tab/public/interfaces/frame_tree.mojom.h"
15 #include "third_party/WebKit/public/platform/WebURLRequest.h"
16 #include "third_party/WebKit/public/web/WebFrameClient.h"
17 #include "third_party/WebKit/public/web/WebRemoteFrameClient.h"
18 #include "third_party/WebKit/public/web/WebSandboxFlags.h"
19 #include "third_party/WebKit/public/web/WebViewClient.h"
21 namespace blink {
22 class WebFrame;
25 namespace mojo {
26 class Rect;
27 class View;
30 namespace html_viewer {
32 class FrameTreeManager;
33 class GeolocationClientImpl;
34 class TouchHandler;
35 class WebLayerImpl;
36 class WebLayerTreeViewImpl;
38 // Frame is used to represent a single frame in the frame tree of a page. The
39 // frame is either local or remote. Each Frame is associated with a single
40 // FrameTreeManager and can not be moved to another FrameTreeManager. Local
41 // frames have a mojo::View, remote frames do not.
42 class Frame : public blink::WebFrameClient,
43 public blink::WebViewClient,
44 public blink::WebRemoteFrameClient,
45 public mojo::ViewObserver {
46 public:
47 struct CreateParams {
48 CreateParams(FrameTreeManager* manager, Frame* parent, uint32_t id)
49 : manager(manager), parent(parent), id(id) {}
50 ~CreateParams() {}
52 FrameTreeManager* manager;
53 Frame* parent;
54 uint32_t id;
57 explicit Frame(const CreateParams& params);
59 void Init(mojo::View* local_view);
61 // Closes and deletes this Frame.
62 void Close();
64 uint32_t id() const { return id_; }
66 // Returns the Frame whose id is |id|.
67 Frame* FindFrame(uint32_t id) {
68 return const_cast<Frame*>(const_cast<const Frame*>(this)->FindFrame(id));
70 const Frame* FindFrame(uint32_t id) const;
72 Frame* parent() { return parent_; }
74 const std::vector<Frame*>& children() { return children_; }
76 // Returns the WebFrame for this Frame. This is either a WebLocalFrame or
77 // WebRemoteFrame.
78 blink::WebFrame* web_frame() { return web_frame_; }
80 // Returns the WebView for this frame, or null if there isn't one. The root
81 // has a WebView, the children WebFrameWidgets.
82 blink::WebView* web_view();
84 // The mojo::View this frame renders to. This is non-null for the local frame
85 // the frame tree was created with as well as non-null for any frames created
86 // locally.
87 mojo::View* view() { return view_; }
89 private:
90 friend class FrameTreeManager;
92 virtual ~Frame();
94 // Returns true if the Frame is local, false if remote.
95 bool IsLocal() const;
97 void SetView(mojo::View* view);
99 // Creates the appropriate WebWidget implementation for the Frame.
100 void CreateWebWidget();
102 void UpdateFocus();
104 // Updates the size and scale factor of the webview and related classes from
105 // |root_|.
106 void UpdateWebViewSizeFromViewSize();
108 // Swaps this frame from a local frame to remote frame. |request| is the url
109 // to load in the frame.
110 void SwapToRemote(const blink::WebURLRequest& request);
112 // See comment in SwapToRemote() for details on this.
113 void FinishSwapToRemote();
115 GlobalState* global_state() { return frame_tree_manager_->global_state(); }
117 // Returns the Frame associated with the specified WebFrame.
118 Frame* FindFrameWithWebFrame(blink::WebFrame* web_frame);
120 // The various frameDetached() implementations call into this.
121 void FrameDetachedImpl(blink::WebFrame* web_frame);
123 // mojo::ViewObserver methods:
124 void OnViewBoundsChanged(mojo::View* view,
125 const mojo::Rect& old_bounds,
126 const mojo::Rect& new_bounds) override;
127 void OnViewDestroyed(mojo::View* view) override;
128 void OnViewInputEvent(mojo::View* view, const mojo::EventPtr& event) override;
129 void OnViewFocusChanged(mojo::View* gained_focus,
130 mojo::View* lost_focus) override;
132 // WebViewClient methods:
133 virtual void initializeLayerTreeView() override;
134 virtual blink::WebLayerTreeView* layerTreeView() override;
135 virtual blink::WebStorageNamespace* createSessionStorageNamespace();
137 // WebFrameClient methods:
138 virtual blink::WebMediaPlayer* createMediaPlayer(
139 blink::WebLocalFrame* frame,
140 const blink::WebURL& url,
141 blink::WebMediaPlayerClient* client,
142 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client,
143 blink::WebContentDecryptionModule* initial_cdm);
144 virtual blink::WebFrame* createChildFrame(
145 blink::WebLocalFrame* parent,
146 blink::WebTreeScopeType scope,
147 const blink::WebString& frame_ame,
148 blink::WebSandboxFlags sandbox_flags);
149 virtual void frameDetached(blink::WebFrame* frame,
150 blink::WebFrameClient::DetachType type);
151 virtual blink::WebCookieJar* cookieJar(blink::WebLocalFrame* frame);
152 virtual blink::WebNavigationPolicy decidePolicyForNavigation(
153 const NavigationPolicyInfo& info);
154 virtual void didAddMessageToConsole(const blink::WebConsoleMessage& message,
155 const blink::WebString& source_name,
156 unsigned source_line,
157 const blink::WebString& stack_trace);
158 virtual void didFinishLoad(blink::WebLocalFrame* frame);
159 virtual void didNavigateWithinPage(blink::WebLocalFrame* frame,
160 const blink::WebHistoryItem& history_item,
161 blink::WebHistoryCommitType commit_type);
162 virtual blink::WebGeolocationClient* geolocationClient();
163 virtual blink::WebEncryptedMediaClient* encryptedMediaClient();
164 virtual void didStartLoading(bool to_different_document);
165 virtual void didStopLoading();
166 virtual void didChangeLoadProgress(double load_progress);
168 // blink::WebRemoteFrameClient:
169 virtual void frameDetached(blink::WebRemoteFrameClient::DetachType type);
170 virtual void postMessageEvent(blink::WebLocalFrame* source_frame,
171 blink::WebRemoteFrame* target_frame,
172 blink::WebSecurityOrigin target_origin,
173 blink::WebDOMMessageEvent event);
174 virtual void initializeChildFrame(const blink::WebRect& frame_rect,
175 float scale_factor);
176 virtual void navigate(const blink::WebURLRequest& request,
177 bool should_replace_current_entry);
178 virtual void reload(bool ignore_cache, bool is_client_redirect);
179 virtual void forwardInputEvent(const blink::WebInputEvent* event);
181 FrameTreeManager* frame_tree_manager_;
182 Frame* parent_;
183 mojo::View* view_;
184 // The id for this frame. If there is a view, this is the same id as the
185 // view has.
186 const uint32_t id_;
187 std::vector<Frame*> children_;
188 blink::WebFrame* web_frame_;
189 blink::WebWidget* web_widget_;
190 scoped_ptr<GeolocationClientImpl> geolocation_client_impl_;
191 scoped_ptr<WebLayerTreeViewImpl> web_layer_tree_view_impl_;
192 scoped_ptr<TouchHandler> touch_handler_;
194 // TODO(sky): better factor this, maybe push to View.
195 blink::WebTreeScopeType scope_;
197 scoped_ptr<WebLayerImpl> web_layer_;
199 base::WeakPtrFactory<Frame> weak_factory_;
201 DISALLOW_COPY_AND_ASSIGN(Frame);
204 } // namespace html_viewer
206 #endif // COMPONENTS_HTML_VIEWER_FRAME_H_