| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_HTML_VIEWER_FRAME_H_ | 5 #ifndef COMPONENTS_HTML_VIEWER_HTML_FRAME_H_ |
| 6 #define COMPONENTS_HTML_VIEWER_FRAME_H_ | 6 #define COMPONENTS_HTML_VIEWER_HTML_FRAME_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "components/html_viewer/frame_tree_manager.h" | 12 #include "components/html_viewer/html_frame_tree_manager.h" |
| 13 #include "components/view_manager/public/cpp/view_observer.h" | 13 #include "components/view_manager/public/cpp/view_observer.h" |
| 14 #include "mandoline/tab/public/interfaces/frame_tree.mojom.h" | 14 #include "mandoline/tab/public/interfaces/frame_tree.mojom.h" |
| 15 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 15 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 16 #include "third_party/WebKit/public/web/WebFrameClient.h" | 16 #include "third_party/WebKit/public/web/WebFrameClient.h" |
| 17 #include "third_party/WebKit/public/web/WebRemoteFrameClient.h" | 17 #include "third_party/WebKit/public/web/WebRemoteFrameClient.h" |
| 18 #include "third_party/WebKit/public/web/WebSandboxFlags.h" | 18 #include "third_party/WebKit/public/web/WebSandboxFlags.h" |
| 19 #include "third_party/WebKit/public/web/WebViewClient.h" | 19 #include "third_party/WebKit/public/web/WebViewClient.h" |
| 20 | 20 |
| 21 namespace blink { | 21 namespace blink { |
| 22 class WebFrame; | 22 class WebFrame; |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace mojo { | 25 namespace mojo { |
| 26 class Rect; | 26 class Rect; |
| 27 class View; | 27 class View; |
| 28 } | 28 } |
| 29 | 29 |
| 30 namespace html_viewer { | 30 namespace html_viewer { |
| 31 | 31 |
| 32 class FrameTreeManager; | |
| 33 class GeolocationClientImpl; | 32 class GeolocationClientImpl; |
| 33 class HTMLFrameTreeManager; |
| 34 class TouchHandler; | 34 class TouchHandler; |
| 35 class WebLayerImpl; | 35 class WebLayerImpl; |
| 36 class WebLayerTreeViewImpl; | 36 class WebLayerTreeViewImpl; |
| 37 | 37 |
| 38 // Frame is used to represent a single frame in the frame tree of a page. The | 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 | 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 | 40 // HTMLFrameTreeManager and can not be moved to another HTMLFrameTreeManager. |
| 41 // Local |
| 41 // frames have a mojo::View, remote frames do not. | 42 // frames have a mojo::View, remote frames do not. |
| 42 class Frame : public blink::WebFrameClient, | 43 class HTMLFrame : public blink::WebFrameClient, |
| 43 public blink::WebViewClient, | 44 public blink::WebViewClient, |
| 44 public blink::WebRemoteFrameClient, | 45 public blink::WebRemoteFrameClient, |
| 45 public mojo::ViewObserver { | 46 public mojo::ViewObserver { |
| 46 public: | 47 public: |
| 47 struct CreateParams { | 48 struct CreateParams { |
| 48 CreateParams(FrameTreeManager* manager, Frame* parent, uint32_t id) | 49 CreateParams(HTMLFrameTreeManager* manager, HTMLFrame* parent, uint32_t id) |
| 49 : manager(manager), parent(parent), id(id) {} | 50 : manager(manager), parent(parent), id(id) {} |
| 50 ~CreateParams() {} | 51 ~CreateParams() {} |
| 51 | 52 |
| 52 FrameTreeManager* manager; | 53 HTMLFrameTreeManager* manager; |
| 53 Frame* parent; | 54 HTMLFrame* parent; |
| 54 uint32_t id; | 55 uint32_t id; |
| 55 }; | 56 }; |
| 56 | 57 |
| 57 explicit Frame(const CreateParams& params); | 58 explicit HTMLFrame(const CreateParams& params); |
| 58 | 59 |
| 59 void Init(mojo::View* local_view, | 60 void Init(mojo::View* local_view, |
| 60 const blink::WebString& remote_frame_name, | 61 const blink::WebString& remote_frame_name, |
| 61 const blink::WebString& remote_origin); | 62 const blink::WebString& remote_origin); |
| 62 | 63 |
| 63 // Closes and deletes this Frame. | 64 // Closes and deletes this Frame. |
| 64 void Close(); | 65 void Close(); |
| 65 | 66 |
| 66 uint32_t id() const { return id_; } | 67 uint32_t id() const { return id_; } |
| 67 | 68 |
| 68 // Returns the Frame whose id is |id|. | 69 // Returns the Frame whose id is |id|. |
| 69 Frame* FindFrame(uint32_t id) { | 70 HTMLFrame* FindFrame(uint32_t id) { |
| 70 return const_cast<Frame*>(const_cast<const Frame*>(this)->FindFrame(id)); | 71 return const_cast<HTMLFrame*>( |
| 72 const_cast<const HTMLFrame*>(this)->FindFrame(id)); |
| 71 } | 73 } |
| 72 const Frame* FindFrame(uint32_t id) const; | 74 const HTMLFrame* FindFrame(uint32_t id) const; |
| 73 | 75 |
| 74 Frame* parent() { return parent_; } | 76 HTMLFrame* parent() { return parent_; } |
| 75 | 77 |
| 76 const std::vector<Frame*>& children() { return children_; } | 78 const std::vector<HTMLFrame*>& children() { return children_; } |
| 77 | 79 |
| 78 // Returns the WebFrame for this Frame. This is either a WebLocalFrame or | 80 // Returns the WebFrame for this Frame. This is either a WebLocalFrame or |
| 79 // WebRemoteFrame. | 81 // WebRemoteFrame. |
| 80 blink::WebFrame* web_frame() { return web_frame_; } | 82 blink::WebFrame* web_frame() { return web_frame_; } |
| 81 | 83 |
| 82 // Returns the WebView for this frame, or null if there isn't one. The root | 84 // Returns the WebView for this frame, or null if there isn't one. The root |
| 83 // has a WebView, the children WebFrameWidgets. | 85 // has a WebView, the children WebFrameWidgets. |
| 84 blink::WebView* web_view(); | 86 blink::WebView* web_view(); |
| 85 | 87 |
| 86 // The mojo::View this frame renders to. This is non-null for the local frame | 88 // 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 | 89 // the frame tree was created with as well as non-null for any frames created |
| 88 // locally. | 90 // locally. |
| 89 mojo::View* view() { return view_; } | 91 mojo::View* view() { return view_; } |
| 90 | 92 |
| 91 private: | 93 private: |
| 92 friend class FrameTreeManager; | 94 friend class HTMLFrameTreeManager; |
| 93 | 95 |
| 94 virtual ~Frame(); | 96 virtual ~HTMLFrame(); |
| 95 | 97 |
| 96 // Sets the name of the remote frame. Does nothing if this is a local frame. | 98 // Sets the name of the remote frame. Does nothing if this is a local frame. |
| 97 void SetRemoteFrameName(const mojo::String& name); | 99 void SetRemoteFrameName(const mojo::String& name); |
| 98 | 100 |
| 99 // Returns true if the Frame is local, false if remote. | 101 // Returns true if the Frame is local, false if remote. |
| 100 bool IsLocal() const; | 102 bool IsLocal() const; |
| 101 | 103 |
| 102 void SetView(mojo::View* view); | 104 void SetView(mojo::View* view); |
| 103 | 105 |
| 104 // Creates the appropriate WebWidget implementation for the Frame. | 106 // Creates the appropriate WebWidget implementation for the Frame. |
| 105 void CreateWebWidget(); | 107 void CreateWebWidget(); |
| 106 | 108 |
| 107 void UpdateFocus(); | 109 void UpdateFocus(); |
| 108 | 110 |
| 109 // Updates the size and scale factor of the webview and related classes from | 111 // Updates the size and scale factor of the webview and related classes from |
| 110 // |root_|. | 112 // |root_|. |
| 111 void UpdateWebViewSizeFromViewSize(); | 113 void UpdateWebViewSizeFromViewSize(); |
| 112 | 114 |
| 113 // Swaps this frame from a local frame to remote frame. |request| is the url | 115 // Swaps this frame from a local frame to remote frame. |request| is the url |
| 114 // to load in the frame. | 116 // to load in the frame. |
| 115 void SwapToRemote(const blink::WebURLRequest& request); | 117 void SwapToRemote(const blink::WebURLRequest& request); |
| 116 | 118 |
| 117 // See comment in SwapToRemote() for details on this. | 119 // See comment in SwapToRemote() for details on this. |
| 118 void FinishSwapToRemote(); | 120 void FinishSwapToRemote(); |
| 119 | 121 |
| 120 GlobalState* global_state() { return frame_tree_manager_->global_state(); } | 122 GlobalState* global_state() { return frame_tree_manager_->global_state(); } |
| 121 | 123 |
| 122 // Returns the Frame associated with the specified WebFrame. | 124 // Returns the Frame associated with the specified WebFrame. |
| 123 Frame* FindFrameWithWebFrame(blink::WebFrame* web_frame); | 125 HTMLFrame* FindFrameWithWebFrame(blink::WebFrame* web_frame); |
| 124 | 126 |
| 125 // The various frameDetached() implementations call into this. | 127 // The various frameDetached() implementations call into this. |
| 126 void FrameDetachedImpl(blink::WebFrame* web_frame); | 128 void FrameDetachedImpl(blink::WebFrame* web_frame); |
| 127 | 129 |
| 128 // mojo::ViewObserver methods: | 130 // mojo::ViewObserver methods: |
| 129 void OnViewBoundsChanged(mojo::View* view, | 131 void OnViewBoundsChanged(mojo::View* view, |
| 130 const mojo::Rect& old_bounds, | 132 const mojo::Rect& old_bounds, |
| 131 const mojo::Rect& new_bounds) override; | 133 const mojo::Rect& new_bounds) override; |
| 132 void OnViewDestroyed(mojo::View* view) override; | 134 void OnViewDestroyed(mojo::View* view) override; |
| 133 void OnViewInputEvent(mojo::View* view, const mojo::EventPtr& event) override; | 135 void OnViewInputEvent(mojo::View* view, const mojo::EventPtr& event) override; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 blink::WebRemoteFrame* target_frame, | 180 blink::WebRemoteFrame* target_frame, |
| 179 blink::WebSecurityOrigin target_origin, | 181 blink::WebSecurityOrigin target_origin, |
| 180 blink::WebDOMMessageEvent event); | 182 blink::WebDOMMessageEvent event); |
| 181 virtual void initializeChildFrame(const blink::WebRect& frame_rect, | 183 virtual void initializeChildFrame(const blink::WebRect& frame_rect, |
| 182 float scale_factor); | 184 float scale_factor); |
| 183 virtual void navigate(const blink::WebURLRequest& request, | 185 virtual void navigate(const blink::WebURLRequest& request, |
| 184 bool should_replace_current_entry); | 186 bool should_replace_current_entry); |
| 185 virtual void reload(bool ignore_cache, bool is_client_redirect); | 187 virtual void reload(bool ignore_cache, bool is_client_redirect); |
| 186 virtual void forwardInputEvent(const blink::WebInputEvent* event); | 188 virtual void forwardInputEvent(const blink::WebInputEvent* event); |
| 187 | 189 |
| 188 FrameTreeManager* frame_tree_manager_; | 190 HTMLFrameTreeManager* frame_tree_manager_; |
| 189 Frame* parent_; | 191 HTMLFrame* parent_; |
| 190 mojo::View* view_; | 192 mojo::View* view_; |
| 191 // The id for this frame. If there is a view, this is the same id as the | 193 // The id for this frame. If there is a view, this is the same id as the |
| 192 // view has. | 194 // view has. |
| 193 const uint32_t id_; | 195 const uint32_t id_; |
| 194 std::vector<Frame*> children_; | 196 std::vector<HTMLFrame*> children_; |
| 195 blink::WebFrame* web_frame_; | 197 blink::WebFrame* web_frame_; |
| 196 blink::WebWidget* web_widget_; | 198 blink::WebWidget* web_widget_; |
| 197 scoped_ptr<GeolocationClientImpl> geolocation_client_impl_; | 199 scoped_ptr<GeolocationClientImpl> geolocation_client_impl_; |
| 198 scoped_ptr<WebLayerTreeViewImpl> web_layer_tree_view_impl_; | 200 scoped_ptr<WebLayerTreeViewImpl> web_layer_tree_view_impl_; |
| 199 scoped_ptr<TouchHandler> touch_handler_; | 201 scoped_ptr<TouchHandler> touch_handler_; |
| 200 | 202 |
| 201 // TODO(sky): better factor this, maybe push to View. | 203 // TODO(sky): better factor this, maybe push to View. |
| 202 blink::WebTreeScopeType scope_; | 204 blink::WebTreeScopeType scope_; |
| 203 | 205 |
| 204 scoped_ptr<WebLayerImpl> web_layer_; | 206 scoped_ptr<WebLayerImpl> web_layer_; |
| 205 | 207 |
| 206 base::WeakPtrFactory<Frame> weak_factory_; | 208 base::WeakPtrFactory<HTMLFrame> weak_factory_; |
| 207 | 209 |
| 208 DISALLOW_COPY_AND_ASSIGN(Frame); | 210 DISALLOW_COPY_AND_ASSIGN(HTMLFrame); |
| 209 }; | 211 }; |
| 210 | 212 |
| 211 } // namespace html_viewer | 213 } // namespace html_viewer |
| 212 | 214 |
| 213 #endif // COMPONENTS_HTML_VIEWER_FRAME_H_ | 215 #endif // COMPONENTS_HTML_VIEWER_HTML_FRAME_H_ |
| OLD | NEW |