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_
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"
30 namespace html_viewer
{
32 class FrameTreeManager
;
33 class GeolocationClientImpl
;
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
{
48 CreateParams(FrameTreeManager
* manager
, Frame
* parent
, uint32_t id
)
49 : manager(manager
), parent(parent
), id(id
) {}
52 FrameTreeManager
* manager
;
57 explicit Frame(const CreateParams
& params
);
59 void Init(mojo::View
* local_view
);
61 // Closes and deletes this Frame.
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
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
87 mojo::View
* view() { return view_
; }
90 friend class FrameTreeManager
;
94 // Returns true if the Frame is local, false if remote.
97 void SetView(mojo::View
* view
);
99 // Creates the appropriate WebWidget implementation for the Frame.
100 void CreateWebWidget();
104 // Updates the size and scale factor of the webview and related classes from
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
,
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_
;
184 // The id for this frame. If there is a view, this is the same id as the
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_