OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef COMPONENTS_HTML_VIEWER_FRAME_H_ | |
6 #define COMPONENTS_HTML_VIEWER_FRAME_H_ | |
7 | |
8 #include <vector> | |
9 | |
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" | |
20 | |
21 namespace blink { | |
22 class WebFrame; | |
23 } | |
24 | |
25 namespace mojo { | |
26 class Rect; | |
27 class View; | |
28 } | |
29 | |
30 namespace html_viewer { | |
31 | |
32 class FrameTreeManager; | |
33 class GeolocationClientImpl; | |
34 class TouchHandler; | |
35 class WebLayerImpl; | |
36 class WebLayerTreeViewImpl; | |
37 | |
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() {} | |
51 | |
52 FrameTreeManager* manager; | |
53 Frame* parent; | |
54 uint32_t id; | |
55 }; | |
56 | |
57 explicit Frame(const CreateParams& params); | |
58 | |
59 void Init(mojo::View* local_view, | |
60 const blink::WebString& remote_frame_name, | |
61 const blink::WebString& remote_origin); | |
62 | |
63 // Closes and deletes this Frame. | |
64 void Close(); | |
65 | |
66 uint32_t id() const { return id_; } | |
67 | |
68 // Returns the Frame whose id is |id|. | |
69 Frame* FindFrame(uint32_t id) { | |
70 return const_cast<Frame*>(const_cast<const Frame*>(this)->FindFrame(id)); | |
71 } | |
72 const Frame* FindFrame(uint32_t id) const; | |
73 | |
74 Frame* parent() { return parent_; } | |
75 | |
76 const std::vector<Frame*>& children() { return children_; } | |
77 | |
78 // Returns the WebFrame for this Frame. This is either a WebLocalFrame or | |
79 // WebRemoteFrame. | |
80 blink::WebFrame* web_frame() { return web_frame_; } | |
81 | |
82 // Returns the WebView for this frame, or null if there isn't one. The root | |
83 // has a WebView, the children WebFrameWidgets. | |
84 blink::WebView* web_view(); | |
85 | |
86 // The mojo::View this frame renders to. This is non-null for the local frame | |
87 // the frame tree was created with as well as non-null for any frames created | |
88 // locally. | |
89 mojo::View* view() { return view_; } | |
90 | |
91 private: | |
92 friend class FrameTreeManager; | |
93 | |
94 virtual ~Frame(); | |
95 | |
96 // Sets the name of the remote frame. Does nothing if this is a local frame. | |
97 void SetRemoteFrameName(const mojo::String& name); | |
98 | |
99 // Returns true if the Frame is local, false if remote. | |
100 bool IsLocal() const; | |
101 | |
102 void SetView(mojo::View* view); | |
103 | |
104 // Creates the appropriate WebWidget implementation for the Frame. | |
105 void CreateWebWidget(); | |
106 | |
107 void UpdateFocus(); | |
108 | |
109 // Updates the size and scale factor of the webview and related classes from | |
110 // |root_|. | |
111 void UpdateWebViewSizeFromViewSize(); | |
112 | |
113 // Swaps this frame from a local frame to remote frame. |request| is the url | |
114 // to load in the frame. | |
115 void SwapToRemote(const blink::WebURLRequest& request); | |
116 | |
117 // See comment in SwapToRemote() for details on this. | |
118 void FinishSwapToRemote(); | |
119 | |
120 GlobalState* global_state() { return frame_tree_manager_->global_state(); } | |
121 | |
122 // Returns the Frame associated with the specified WebFrame. | |
123 Frame* FindFrameWithWebFrame(blink::WebFrame* web_frame); | |
124 | |
125 // The various frameDetached() implementations call into this. | |
126 void FrameDetachedImpl(blink::WebFrame* web_frame); | |
127 | |
128 // mojo::ViewObserver methods: | |
129 void OnViewBoundsChanged(mojo::View* view, | |
130 const mojo::Rect& old_bounds, | |
131 const mojo::Rect& new_bounds) override; | |
132 void OnViewDestroyed(mojo::View* view) override; | |
133 void OnViewInputEvent(mojo::View* view, const mojo::EventPtr& event) override; | |
134 void OnViewFocusChanged(mojo::View* gained_focus, | |
135 mojo::View* lost_focus) override; | |
136 | |
137 // WebViewClient methods: | |
138 virtual void initializeLayerTreeView() override; | |
139 virtual blink::WebLayerTreeView* layerTreeView() override; | |
140 virtual blink::WebStorageNamespace* createSessionStorageNamespace(); | |
141 | |
142 // WebFrameClient methods: | |
143 virtual blink::WebMediaPlayer* createMediaPlayer( | |
144 blink::WebLocalFrame* frame, | |
145 const blink::WebURL& url, | |
146 blink::WebMediaPlayerClient* client, | |
147 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, | |
148 blink::WebContentDecryptionModule* initial_cdm); | |
149 virtual blink::WebFrame* createChildFrame( | |
150 blink::WebLocalFrame* parent, | |
151 blink::WebTreeScopeType scope, | |
152 const blink::WebString& frame_ame, | |
153 blink::WebSandboxFlags sandbox_flags); | |
154 virtual void frameDetached(blink::WebFrame* frame, | |
155 blink::WebFrameClient::DetachType type); | |
156 virtual blink::WebCookieJar* cookieJar(blink::WebLocalFrame* frame); | |
157 virtual blink::WebNavigationPolicy decidePolicyForNavigation( | |
158 const NavigationPolicyInfo& info); | |
159 virtual void didAddMessageToConsole(const blink::WebConsoleMessage& message, | |
160 const blink::WebString& source_name, | |
161 unsigned source_line, | |
162 const blink::WebString& stack_trace); | |
163 virtual void didFinishLoad(blink::WebLocalFrame* frame); | |
164 virtual void didNavigateWithinPage(blink::WebLocalFrame* frame, | |
165 const blink::WebHistoryItem& history_item, | |
166 blink::WebHistoryCommitType commit_type); | |
167 virtual blink::WebGeolocationClient* geolocationClient(); | |
168 virtual blink::WebEncryptedMediaClient* encryptedMediaClient(); | |
169 virtual void didStartLoading(bool to_different_document); | |
170 virtual void didStopLoading(); | |
171 virtual void didChangeLoadProgress(double load_progress); | |
172 virtual void didChangeName(blink::WebLocalFrame* frame, | |
173 const blink::WebString& name); | |
174 | |
175 // blink::WebRemoteFrameClient: | |
176 virtual void frameDetached(blink::WebRemoteFrameClient::DetachType type); | |
177 virtual void postMessageEvent(blink::WebLocalFrame* source_frame, | |
178 blink::WebRemoteFrame* target_frame, | |
179 blink::WebSecurityOrigin target_origin, | |
180 blink::WebDOMMessageEvent event); | |
181 virtual void initializeChildFrame(const blink::WebRect& frame_rect, | |
182 float scale_factor); | |
183 virtual void navigate(const blink::WebURLRequest& request, | |
184 bool should_replace_current_entry); | |
185 virtual void reload(bool ignore_cache, bool is_client_redirect); | |
186 virtual void forwardInputEvent(const blink::WebInputEvent* event); | |
187 | |
188 FrameTreeManager* frame_tree_manager_; | |
189 Frame* parent_; | |
190 mojo::View* view_; | |
191 // The id for this frame. If there is a view, this is the same id as the | |
192 // view has. | |
193 const uint32_t id_; | |
194 std::vector<Frame*> children_; | |
195 blink::WebFrame* web_frame_; | |
196 blink::WebWidget* web_widget_; | |
197 scoped_ptr<GeolocationClientImpl> geolocation_client_impl_; | |
198 scoped_ptr<WebLayerTreeViewImpl> web_layer_tree_view_impl_; | |
199 scoped_ptr<TouchHandler> touch_handler_; | |
200 | |
201 // TODO(sky): better factor this, maybe push to View. | |
202 blink::WebTreeScopeType scope_; | |
203 | |
204 scoped_ptr<WebLayerImpl> web_layer_; | |
205 | |
206 base::WeakPtrFactory<Frame> weak_factory_; | |
207 | |
208 DISALLOW_COPY_AND_ASSIGN(Frame); | |
209 }; | |
210 | |
211 } // namespace html_viewer | |
212 | |
213 #endif // COMPONENTS_HTML_VIEWER_FRAME_H_ | |
OLD | NEW |