OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "components/html_viewer/html_document.h" | 5 #include "components/html_viewer/html_document.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "mojo/application/public/cpp/application_impl.h" | 24 #include "mojo/application/public/cpp/application_impl.h" |
25 #include "mojo/application/public/cpp/connect.h" | 25 #include "mojo/application/public/cpp/connect.h" |
26 #include "mojo/application/public/interfaces/shell.mojom.h" | 26 #include "mojo/application/public/interfaces/shell.mojom.h" |
27 #include "mojo/converters/geometry/geometry_type_converters.h" | 27 #include "mojo/converters/geometry/geometry_type_converters.h" |
28 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 28 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
29 #include "third_party/mojo/src/mojo/public/cpp/system/data_pipe.h" | 29 #include "third_party/mojo/src/mojo/public/cpp/system/data_pipe.h" |
30 #include "ui/gfx/geometry/dip_util.h" | 30 #include "ui/gfx/geometry/dip_util.h" |
31 #include "ui/gfx/geometry/size.h" | 31 #include "ui/gfx/geometry/size.h" |
32 | 32 |
33 using mojo::AxProvider; | 33 using mojo::AxProvider; |
34 using mojo::View; | 34 using mus::View; |
35 | 35 |
36 namespace html_viewer { | 36 namespace html_viewer { |
37 namespace { | 37 namespace { |
38 | 38 |
39 const char kEnableTestInterface[] = "enable-html-viewer-test-interface"; | 39 const char kEnableTestInterface[] = "enable-html-viewer-test-interface"; |
40 | 40 |
41 bool IsTestInterfaceEnabled() { | 41 bool IsTestInterfaceEnabled() { |
42 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 42 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
43 kEnableTestInterface); | 43 kEnableTestInterface); |
44 } | 44 } |
45 | 45 |
46 } // namespace | 46 } // namespace |
47 | 47 |
48 // A ViewTreeDelegate implementation that delegates to a (swappable) delegate. | 48 // A ViewTreeDelegate implementation that delegates to a (swappable) delegate. |
49 // This is used when one HTMLDocument takes over for another delegate | 49 // This is used when one HTMLDocument takes over for another delegate |
50 // (OnSwap()). | 50 // (OnSwap()). |
51 class ViewTreeDelegateImpl : public mojo::ViewTreeDelegate { | 51 class ViewTreeDelegateImpl : public mus::ViewTreeDelegate { |
52 public: | 52 public: |
53 explicit ViewTreeDelegateImpl(mojo::ViewTreeDelegate* delegate) | 53 explicit ViewTreeDelegateImpl(mus::ViewTreeDelegate* delegate) |
54 : delegate_(delegate) {} | 54 : delegate_(delegate) {} |
55 ~ViewTreeDelegateImpl() override {} | 55 ~ViewTreeDelegateImpl() override {} |
56 | 56 |
57 void set_delegate(mojo::ViewTreeDelegate* delegate) { delegate_ = delegate; } | 57 void set_delegate(mus::ViewTreeDelegate* delegate) { delegate_ = delegate; } |
58 | 58 |
59 private: | 59 private: |
60 // ViewTreeDelegate: | 60 // ViewTreeDelegate: |
61 void OnEmbed(mojo::View* root) override { delegate_->OnEmbed(root); } | 61 void OnEmbed(mus::View* root) override { delegate_->OnEmbed(root); } |
62 void OnUnembed() override { delegate_->OnUnembed(); } | 62 void OnUnembed() override { delegate_->OnUnembed(); } |
63 void OnConnectionLost(mojo::ViewTreeConnection* connection) override { | 63 void OnConnectionLost(mus::ViewTreeConnection* connection) override { |
64 delegate_->OnConnectionLost(connection); | 64 delegate_->OnConnectionLost(connection); |
65 } | 65 } |
66 | 66 |
67 mojo::ViewTreeDelegate* delegate_; | 67 mus::ViewTreeDelegate* delegate_; |
68 | 68 |
69 DISALLOW_COPY_AND_ASSIGN(ViewTreeDelegateImpl); | 69 DISALLOW_COPY_AND_ASSIGN(ViewTreeDelegateImpl); |
70 }; | 70 }; |
71 | 71 |
72 HTMLDocument::BeforeLoadCache::BeforeLoadCache() {} | 72 HTMLDocument::BeforeLoadCache::BeforeLoadCache() {} |
73 | 73 |
74 HTMLDocument::BeforeLoadCache::~BeforeLoadCache() { | 74 HTMLDocument::BeforeLoadCache::~BeforeLoadCache() { |
75 STLDeleteElements(&ax_provider_requests); | 75 STLDeleteElements(&ax_provider_requests); |
76 STLDeleteElements(&test_interface_requests); | 76 STLDeleteElements(&test_interface_requests); |
77 } | 77 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 connection->AddService<devtools_service::DevToolsAgent>(this); | 110 connection->AddService<devtools_service::DevToolsAgent>(this); |
111 if (IsTestInterfaceEnabled()) | 111 if (IsTestInterfaceEnabled()) |
112 connection->AddService<TestHTMLViewer>(this); | 112 connection->AddService<TestHTMLViewer>(this); |
113 | 113 |
114 resource_waiter_.reset( | 114 resource_waiter_.reset( |
115 new DocumentResourceWaiter(global_state_, response.Pass(), this)); | 115 new DocumentResourceWaiter(global_state_, response.Pass(), this)); |
116 } | 116 } |
117 | 117 |
118 void HTMLDocument::Destroy() { | 118 void HTMLDocument::Destroy() { |
119 if (resource_waiter_) { | 119 if (resource_waiter_) { |
120 mojo::View* root = resource_waiter_->root(); | 120 mus::View* root = resource_waiter_->root(); |
121 if (root) { | 121 if (root) { |
122 resource_waiter_.reset(); | 122 resource_waiter_.reset(); |
123 delete root->connection(); | 123 delete root->connection(); |
124 } else { | 124 } else { |
125 delete this; | 125 delete this; |
126 } | 126 } |
127 } else if (frame_) { | 127 } else if (frame_) { |
128 // Closing the frame ends up destroying the ViewManager, which triggers | 128 // Closing the frame ends up destroying the ViewManager, which triggers |
129 // deleting this (OnConnectionLost()). | 129 // deleting this (OnConnectionLost()). |
130 frame_->Close(); | 130 frame_->Close(); |
(...skipping 11 matching lines...) Expand all Loading... |
142 HTMLDocument::~HTMLDocument() { | 142 HTMLDocument::~HTMLDocument() { |
143 delete_callback_.Run(this); | 143 delete_callback_.Run(this); |
144 | 144 |
145 STLDeleteElements(&ax_providers_); | 145 STLDeleteElements(&ax_providers_); |
146 } | 146 } |
147 | 147 |
148 void HTMLDocument::Load() { | 148 void HTMLDocument::Load() { |
149 DCHECK(resource_waiter_ && resource_waiter_->is_ready()); | 149 DCHECK(resource_waiter_ && resource_waiter_->is_ready()); |
150 | 150 |
151 // Note: |view| is null if we're taking over for an existing frame. | 151 // Note: |view| is null if we're taking over for an existing frame. |
152 mojo::View* view = resource_waiter_->root(); | 152 mus::View* view = resource_waiter_->root(); |
153 if (view) { | 153 if (view) { |
154 global_state_->InitIfNecessary( | 154 global_state_->InitIfNecessary( |
155 view->viewport_metrics().size_in_pixels.To<gfx::Size>(), | 155 view->viewport_metrics().size_in_pixels.To<gfx::Size>(), |
156 view->viewport_metrics().device_pixel_ratio); | 156 view->viewport_metrics().device_pixel_ratio); |
157 } | 157 } |
158 | 158 |
159 scoped_ptr<WebURLRequestExtraData> extra_data(new WebURLRequestExtraData); | 159 scoped_ptr<WebURLRequestExtraData> extra_data(new WebURLRequestExtraData); |
160 extra_data->synthetic_response = | 160 extra_data->synthetic_response = |
161 resource_waiter_->ReleaseURLResponse().Pass(); | 161 resource_waiter_->ReleaseURLResponse().Pass(); |
162 | 162 |
(...skipping 30 matching lines...) Expand all Loading... |
193 if (!before_load_cache_.get()) | 193 if (!before_load_cache_.get()) |
194 before_load_cache_.reset(new BeforeLoadCache); | 194 before_load_cache_.reset(new BeforeLoadCache); |
195 return before_load_cache_.get(); | 195 return before_load_cache_.get(); |
196 } | 196 } |
197 | 197 |
198 void HTMLDocument::OnEmbed(View* root) { | 198 void HTMLDocument::OnEmbed(View* root) { |
199 transferable_state_.root = root; | 199 transferable_state_.root = root; |
200 resource_waiter_->SetRoot(root); | 200 resource_waiter_->SetRoot(root); |
201 } | 201 } |
202 | 202 |
203 void HTMLDocument::OnConnectionLost(mojo::ViewTreeConnection* connection) { | 203 void HTMLDocument::OnConnectionLost(mus::ViewTreeConnection* connection) { |
204 delete this; | 204 delete this; |
205 } | 205 } |
206 | 206 |
207 void HTMLDocument::OnFrameDidFinishLoad() { | 207 void HTMLDocument::OnFrameDidFinishLoad() { |
208 did_finish_local_frame_load_ = true; | 208 did_finish_local_frame_load_ = true; |
209 scoped_ptr<BeforeLoadCache> before_load_cache = before_load_cache_.Pass(); | 209 scoped_ptr<BeforeLoadCache> before_load_cache = before_load_cache_.Pass(); |
210 if (!before_load_cache) | 210 if (!before_load_cache) |
211 return; | 211 return; |
212 | 212 |
213 // Bind any pending AxProvider and TestHTMLViewer interface requests. | 213 // Bind any pending AxProvider and TestHTMLViewer interface requests. |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 } | 309 } |
310 } | 310 } |
311 | 311 |
312 void HTMLDocument::Create( | 312 void HTMLDocument::Create( |
313 mojo::ApplicationConnection* connection, | 313 mojo::ApplicationConnection* connection, |
314 mojo::InterfaceRequest<mojo::ViewTreeClient> request) { | 314 mojo::InterfaceRequest<mojo::ViewTreeClient> request) { |
315 DCHECK(!transferable_state_.view_tree_delegate_impl); | 315 DCHECK(!transferable_state_.view_tree_delegate_impl); |
316 transferable_state_.view_tree_delegate_impl.reset( | 316 transferable_state_.view_tree_delegate_impl.reset( |
317 new ViewTreeDelegateImpl(this)); | 317 new ViewTreeDelegateImpl(this)); |
318 transferable_state_.owns_view_tree_connection = true; | 318 transferable_state_.owns_view_tree_connection = true; |
319 mojo::ViewTreeConnection::Create( | 319 mus::ViewTreeConnection::Create( |
320 transferable_state_.view_tree_delegate_impl.get(), request.Pass()); | 320 transferable_state_.view_tree_delegate_impl.get(), request.Pass()); |
321 } | 321 } |
322 | 322 |
323 } // namespace html_viewer | 323 } // namespace html_viewer |
OLD | NEW |