Don't preload rarely seen large images
[chromium-blink-merge.git] / components / html_viewer / frame.h
blob34fc046a21f1ca667f547d4938f5be649c0c6da2
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 TouchHandler;
34 class WebLayerTreeViewImpl;
36 // Frame is used to represent a single frame in the frame tree of a page. The
37 // frame is either local or remote. Each Frame is associated with a single
38 // FrameTreeManager and can not be moved to another FrameTreeManager. Local
39 // frames have a mojo::View, remote frames do not.
40 class Frame : public blink::WebFrameClient,
41 public blink::WebViewClient,
42 public blink::WebRemoteFrameClient,
43 public mojo::ViewObserver {
44 public:
45 struct CreateParams {
46 CreateParams(FrameTreeManager* manager, Frame* parent, uint32_t id)
47 : manager(manager), parent(parent), id(id) {}
48 ~CreateParams() {}
50 FrameTreeManager* manager;
51 Frame* parent;
52 uint32_t id;
55 explicit Frame(const CreateParams& params);
57 void Init(mojo::View* local_view);
59 // Closes and deletes this Frame.
60 void Close();
62 uint32_t id() const { return id_; }
64 // Returns the Frame whose id is |id|.
65 Frame* FindFrame(uint32_t id) {
66 return const_cast<Frame*>(const_cast<const Frame*>(this)->FindFrame(id));
68 const Frame* FindFrame(uint32_t id) const;
70 Frame* parent() { return parent_; }
72 const std::vector<Frame*>& children() { return children_; }
74 // Returns the WebFrame for this Frame. This is either a WebLocalFrame or
75 // WebRemoteFrame.
76 blink::WebFrame* web_frame() { return web_frame_; }
78 // Returns the WebView for this frame, or null if there isn't one. The root
79 // has a WebView, the children WebFrameWidgets.
80 blink::WebView* web_view();
82 // The mojo::View this frame renders to. This is non-null for the local frame
83 // the frame tree was created with as well as non-null for any frames created
84 // locally.
85 mojo::View* view() { return view_; }
87 private:
88 friend class FrameTreeManager;
90 virtual ~Frame();
92 // Returns true if the Frame is local, false if remote.
93 bool IsLocal() const;
95 void SetView(mojo::View* view);
97 // Creates the appropriate WebWidget implementation for the Frame.
98 void CreateWebWidget();
100 void UpdateFocus();
102 // Updates the size and scale factor of the webview and related classes from
103 // |root_|.
104 void UpdateWebViewSizeFromViewSize();
106 // Swaps this frame from a local frame to remote frame. |request| is the url
107 // to load in the frame.
108 void SwapToRemote(const blink::WebURLRequest& request);
110 // See comment in SwapToRemote() for details on this.
111 void FinishSwapToRemote();
113 GlobalState* global_state() { return frame_tree_manager_->global_state(); }
115 // Returns the Frame associated with the specified WebFrame.
116 Frame* FindFrameWithWebFrame(blink::WebFrame* web_frame);
118 // The various frameDetached() implementations call into this.
119 void FrameDetachedImpl(blink::WebFrame* web_frame);
121 // mojo::ViewObserver methods:
122 void OnViewBoundsChanged(mojo::View* view,
123 const mojo::Rect& old_bounds,
124 const mojo::Rect& new_bounds) override;
125 void OnViewDestroyed(mojo::View* view) override;
126 void OnViewInputEvent(mojo::View* view, const mojo::EventPtr& event) override;
127 void OnViewFocusChanged(mojo::View* gained_focus,
128 mojo::View* lost_focus) override;
130 // WebViewClient methods:
131 virtual void initializeLayerTreeView() override;
132 virtual blink::WebLayerTreeView* layerTreeView() override;
133 virtual blink::WebStorageNamespace* createSessionStorageNamespace();
135 // WebFrameClient methods:
136 virtual blink::WebMediaPlayer* createMediaPlayer(
137 blink::WebLocalFrame* frame,
138 const blink::WebURL& url,
139 blink::WebMediaPlayerClient* client,
140 blink::WebContentDecryptionModule* initial_cdm);
141 virtual blink::WebFrame* createChildFrame(
142 blink::WebLocalFrame* parent,
143 blink::WebTreeScopeType scope,
144 const blink::WebString& frame_ame,
145 blink::WebSandboxFlags sandbox_flags);
146 virtual void frameDetached(blink::WebFrame* frame);
147 virtual void frameDetached(blink::WebFrame* frame,
148 blink::WebFrameClient::DetachType type);
149 virtual blink::WebCookieJar* cookieJar(blink::WebLocalFrame* frame);
150 virtual blink::WebNavigationPolicy decidePolicyForNavigation(
151 const NavigationPolicyInfo& info);
152 virtual void didAddMessageToConsole(const blink::WebConsoleMessage& message,
153 const blink::WebString& source_name,
154 unsigned source_line,
155 const blink::WebString& stack_trace);
156 virtual void didFinishLoad(blink::WebLocalFrame* frame);
157 virtual void didNavigateWithinPage(blink::WebLocalFrame* frame,
158 const blink::WebHistoryItem& history_item,
159 blink::WebHistoryCommitType commit_type);
160 virtual blink::WebEncryptedMediaClient* encryptedMediaClient();
162 // blink::WebRemoteFrameClient:
163 virtual void frameDetached(blink::WebRemoteFrameClient::DetachType type);
164 virtual void postMessageEvent(blink::WebLocalFrame* source_frame,
165 blink::WebRemoteFrame* target_frame,
166 blink::WebSecurityOrigin target_origin,
167 blink::WebDOMMessageEvent event);
168 virtual void initializeChildFrame(const blink::WebRect& frame_rect,
169 float scale_factor);
170 virtual void navigate(const blink::WebURLRequest& request,
171 bool should_replace_current_entry);
172 virtual void reload(bool ignore_cache, bool is_client_redirect);
173 virtual void forwardInputEvent(const blink::WebInputEvent* event);
175 FrameTreeManager* frame_tree_manager_;
176 Frame* parent_;
177 mojo::View* view_;
178 // The id for this frame. If there is a view, this is the same id as the
179 // view has.
180 const uint32_t id_;
181 std::vector<Frame*> children_;
182 blink::WebFrame* web_frame_;
183 blink::WebWidget* web_widget_;
184 scoped_ptr<WebLayerTreeViewImpl> web_layer_tree_view_impl_;
185 scoped_ptr<TouchHandler> touch_handler_;
187 // TODO(sky): better factor this, maybe push to View.
188 blink::WebTreeScopeType scope_;
190 base::WeakPtrFactory<Frame> weak_factory_;
192 DISALLOW_COPY_AND_ASSIGN(Frame);
195 } // namespace html_viewer
197 #endif // COMPONENTS_HTML_VIEWER_FRAME_H_