| 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 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/callback.h" | 6 #include "base/callback.h" |
| 7 #include "base/containers/hash_tables.h" | 7 #include "base/containers/hash_tables.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "components/mus/public/cpp/types.h" | 9 #include "components/mus/public/cpp/types.h" |
| 10 #include "components/mus/public/cpp/window.h" | 10 #include "components/mus/public/cpp/window.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 namespace pdf_viewer { | 49 namespace pdf_viewer { |
| 50 namespace { | 50 namespace { |
| 51 | 51 |
| 52 void LostContext(void*) { | 52 void LostContext(void*) { |
| 53 DCHECK(false); | 53 DCHECK(false); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void OnGotContentHandlerID(uint32_t content_handler_id) {} | 56 void OnGotContentHandlerID(uint32_t content_handler_id) {} |
| 57 | 57 |
| 58 // BitmapUploader is useful if you want to draw a bitmap or color in a View. | 58 // BitmapUploader is useful if you want to draw a bitmap or color in a View. |
| 59 class BitmapUploader : public mojo::SurfaceClient { | 59 class BitmapUploader : public mus::mojom::SurfaceClient { |
| 60 public: | 60 public: |
| 61 explicit BitmapUploader(mus::Window* view) | 61 explicit BitmapUploader(mus::Window* view) |
| 62 : view_(view), | 62 : view_(view), |
| 63 color_(g_transparent_color), | 63 color_(g_transparent_color), |
| 64 width_(0), | 64 width_(0), |
| 65 height_(0), | 65 height_(0), |
| 66 format_(BGRA), | 66 format_(BGRA), |
| 67 next_resource_id_(1u), | 67 next_resource_id_(1u), |
| 68 id_namespace_(0u), | 68 id_namespace_(0u), |
| 69 local_id_(0u), | 69 local_id_(0u), |
| 70 returner_binding_(this) {} | 70 returner_binding_(this) {} |
| 71 ~BitmapUploader() override { | 71 ~BitmapUploader() override { |
| 72 MojoGLES2DestroyContext(gles2_context_); | 72 MojoGLES2DestroyContext(gles2_context_); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void Init(mojo::Shell* shell) { | 75 void Init(mojo::Shell* shell) { |
| 76 surface_ = view_->RequestSurface(); | 76 surface_ = view_->RequestSurface(); |
| 77 surface_->BindToThread(); | 77 surface_->BindToThread(); |
| 78 | 78 |
| 79 mojo::ServiceProviderPtr gpu_service_provider; | 79 mojo::ServiceProviderPtr gpu_service_provider; |
| 80 mojo::URLRequestPtr request2(mojo::URLRequest::New()); | 80 mojo::URLRequestPtr request2(mojo::URLRequest::New()); |
| 81 request2->url = mojo::String::From("mojo:mus"); | 81 request2->url = mojo::String::From("mojo:mus"); |
| 82 shell->ConnectToApplication(request2.Pass(), | 82 shell->ConnectToApplication(request2.Pass(), |
| 83 mojo::GetProxy(&gpu_service_provider), nullptr, | 83 mojo::GetProxy(&gpu_service_provider), nullptr, |
| 84 nullptr, base::Bind(&OnGotContentHandlerID)); | 84 nullptr, base::Bind(&OnGotContentHandlerID)); |
| 85 ConnectToService(gpu_service_provider.get(), &gpu_service_); | 85 ConnectToService(gpu_service_provider.get(), &gpu_service_); |
| 86 | 86 |
| 87 mojo::CommandBufferPtr gles2_client; | 87 mus::mojom::CommandBufferPtr gles2_client; |
| 88 gpu_service_->CreateOffscreenGLES2Context(GetProxy(&gles2_client)); | 88 gpu_service_->CreateOffscreenGLES2Context(GetProxy(&gles2_client)); |
| 89 gles2_context_ = MojoGLES2CreateContext( | 89 gles2_context_ = MojoGLES2CreateContext( |
| 90 gles2_client.PassInterface().PassHandle().release().value(), | 90 gles2_client.PassInterface().PassHandle().release().value(), |
| 91 nullptr, | 91 nullptr, |
| 92 &LostContext, NULL, mojo::Environment::GetDefaultAsyncWaiter()); | 92 &LostContext, NULL, mojo::Environment::GetDefaultAsyncWaiter()); |
| 93 MojoGLES2MakeCurrent(gles2_context_); | 93 MojoGLES2MakeCurrent(gles2_context_); |
| 94 } | 94 } |
| 95 | 95 |
| 96 // Sets the color which is RGBA. | 96 // Sets the color which is RGBA. |
| 97 void SetColor(uint32_t color) { | 97 void SetColor(uint32_t color) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 116 height_ = height; | 116 height_ = height; |
| 117 bitmap_ = data.Pass(); | 117 bitmap_ = data.Pass(); |
| 118 format_ = format; | 118 format_ = format; |
| 119 if (surface_) | 119 if (surface_) |
| 120 Upload(); | 120 Upload(); |
| 121 } | 121 } |
| 122 | 122 |
| 123 private: | 123 private: |
| 124 void Upload() { | 124 void Upload() { |
| 125 gfx::Rect bounds(view_->bounds().To<gfx::Rect>()); | 125 gfx::Rect bounds(view_->bounds().To<gfx::Rect>()); |
| 126 mojo::PassPtr pass = mojo::CreateDefaultPass(1, bounds); | 126 mus::mojom::PassPtr pass = mojo::CreateDefaultPass(1, bounds); |
| 127 mojo::CompositorFramePtr frame = mojo::CompositorFrame::New(); | 127 mus::mojom::CompositorFramePtr frame = mus::mojom::CompositorFrame::New(); |
| 128 | 128 |
| 129 // TODO(rjkroege): Support device scale factor in PDF viewer | 129 // TODO(rjkroege): Support device scale factor in PDF viewer |
| 130 mojo::CompositorFrameMetadataPtr meta = | 130 mus::mojom::CompositorFrameMetadataPtr meta = |
| 131 mojo::CompositorFrameMetadata::New(); | 131 mus::mojom::CompositorFrameMetadata::New(); |
| 132 meta->device_scale_factor = 1.0f; | 132 meta->device_scale_factor = 1.0f; |
| 133 frame->metadata = meta.Pass(); | 133 frame->metadata = meta.Pass(); |
| 134 | 134 |
| 135 frame->resources.resize(0u); | 135 frame->resources.resize(0u); |
| 136 | 136 |
| 137 pass->quads.resize(0u); | 137 pass->quads.resize(0u); |
| 138 pass->shared_quad_states.push_back( | 138 pass->shared_quad_states.push_back( |
| 139 mojo::CreateDefaultSQS(bounds.size())); | 139 mojo::CreateDefaultSQS(bounds.size())); |
| 140 | 140 |
| 141 MojoGLES2MakeCurrent(gles2_context_); | 141 MojoGLES2MakeCurrent(gles2_context_); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 152 bitmap_size.height, | 152 bitmap_size.height, |
| 153 TextureFormat(), | 153 TextureFormat(), |
| 154 GL_UNSIGNED_BYTE, | 154 GL_UNSIGNED_BYTE, |
| 155 &((*bitmap_)[0])); | 155 &((*bitmap_)[0])); |
| 156 | 156 |
| 157 GLbyte mailbox[GL_MAILBOX_SIZE_CHROMIUM]; | 157 GLbyte mailbox[GL_MAILBOX_SIZE_CHROMIUM]; |
| 158 glGenMailboxCHROMIUM(mailbox); | 158 glGenMailboxCHROMIUM(mailbox); |
| 159 glProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox); | 159 glProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox); |
| 160 GLuint sync_point = glInsertSyncPointCHROMIUM(); | 160 GLuint sync_point = glInsertSyncPointCHROMIUM(); |
| 161 | 161 |
| 162 mojo::TransferableResourcePtr resource = | 162 mus::mojom::TransferableResourcePtr resource = |
| 163 mojo::TransferableResource::New(); | 163 mus::mojom::TransferableResource::New(); |
| 164 resource->id = next_resource_id_++; | 164 resource->id = next_resource_id_++; |
| 165 resource_to_texture_id_map_[resource->id] = texture_id; | 165 resource_to_texture_id_map_[resource->id] = texture_id; |
| 166 resource->format = mojo::RESOURCE_FORMAT_RGBA_8888; | 166 resource->format = mus::mojom::RESOURCE_FORMAT_RGBA_8888; |
| 167 resource->filter = GL_LINEAR; | 167 resource->filter = GL_LINEAR; |
| 168 resource->size = bitmap_size.Clone(); | 168 resource->size = bitmap_size.Clone(); |
| 169 mojo::MailboxHolderPtr mailbox_holder = mojo::MailboxHolder::New(); | 169 mus::mojom::MailboxHolderPtr mailbox_holder = |
| 170 mailbox_holder->mailbox = mojo::Mailbox::New(); | 170 mus::mojom::MailboxHolder::New(); |
| 171 mailbox_holder->mailbox = mus::mojom::Mailbox::New(); |
| 171 for (int i = 0; i < GL_MAILBOX_SIZE_CHROMIUM; ++i) | 172 for (int i = 0; i < GL_MAILBOX_SIZE_CHROMIUM; ++i) |
| 172 mailbox_holder->mailbox->name.push_back(mailbox[i]); | 173 mailbox_holder->mailbox->name.push_back(mailbox[i]); |
| 173 mailbox_holder->texture_target = GL_TEXTURE_2D; | 174 mailbox_holder->texture_target = GL_TEXTURE_2D; |
| 174 mailbox_holder->sync_point = sync_point; | 175 mailbox_holder->sync_point = sync_point; |
| 175 resource->mailbox_holder = mailbox_holder.Pass(); | 176 resource->mailbox_holder = mailbox_holder.Pass(); |
| 176 resource->is_repeated = false; | 177 resource->is_repeated = false; |
| 177 resource->is_software = false; | 178 resource->is_software = false; |
| 178 | 179 |
| 179 mojo::QuadPtr quad = mojo::Quad::New(); | 180 mus::mojom::QuadPtr quad = mus::mojom::Quad::New(); |
| 180 quad->material = mojo::MATERIAL_TEXTURE_CONTENT; | 181 quad->material = mus::mojom::MATERIAL_TEXTURE_CONTENT; |
| 181 | 182 |
| 182 mojo::RectPtr rect = mojo::Rect::New(); | 183 mojo::RectPtr rect = mojo::Rect::New(); |
| 183 if (width_ <= bounds.width() && height_ <= bounds.height()) { | 184 if (width_ <= bounds.width() && height_ <= bounds.height()) { |
| 184 rect->width = width_; | 185 rect->width = width_; |
| 185 rect->height = height_; | 186 rect->height = height_; |
| 186 } else { | 187 } else { |
| 187 // The source bitmap is larger than the viewport. Resize it while | 188 // The source bitmap is larger than the viewport. Resize it while |
| 188 // maintaining the aspect ratio. | 189 // maintaining the aspect ratio. |
| 189 float width_ratio = static_cast<float>(width_) / bounds.width(); | 190 float width_ratio = static_cast<float>(width_) / bounds.width(); |
| 190 float height_ratio = static_cast<float>(height_) / bounds.height(); | 191 float height_ratio = static_cast<float>(height_) / bounds.height(); |
| 191 if (width_ratio > height_ratio) { | 192 if (width_ratio > height_ratio) { |
| 192 rect->width = bounds.width(); | 193 rect->width = bounds.width(); |
| 193 rect->height = height_ / width_ratio; | 194 rect->height = height_ / width_ratio; |
| 194 } else { | 195 } else { |
| 195 rect->height = bounds.height(); | 196 rect->height = bounds.height(); |
| 196 rect->width = width_ / height_ratio; | 197 rect->width = width_ / height_ratio; |
| 197 } | 198 } |
| 198 } | 199 } |
| 199 quad->rect = rect.Clone(); | 200 quad->rect = rect.Clone(); |
| 200 quad->opaque_rect = rect.Clone(); | 201 quad->opaque_rect = rect.Clone(); |
| 201 quad->visible_rect = rect.Clone(); | 202 quad->visible_rect = rect.Clone(); |
| 202 quad->needs_blending = true; | 203 quad->needs_blending = true; |
| 203 quad->shared_quad_state_index = 0u; | 204 quad->shared_quad_state_index = 0u; |
| 204 | 205 |
| 205 mojo::TextureQuadStatePtr texture_state = mojo::TextureQuadState::New(); | 206 mus::mojom::TextureQuadStatePtr texture_state = |
| 207 mus::mojom::TextureQuadState::New(); |
| 206 texture_state->resource_id = resource->id; | 208 texture_state->resource_id = resource->id; |
| 207 texture_state->premultiplied_alpha = true; | 209 texture_state->premultiplied_alpha = true; |
| 208 texture_state->uv_top_left = mojo::PointF::New(); | 210 texture_state->uv_top_left = mojo::PointF::New(); |
| 209 texture_state->uv_bottom_right = mojo::PointF::New(); | 211 texture_state->uv_bottom_right = mojo::PointF::New(); |
| 210 texture_state->uv_bottom_right->x = 1.f; | 212 texture_state->uv_bottom_right->x = 1.f; |
| 211 texture_state->uv_bottom_right->y = 1.f; | 213 texture_state->uv_bottom_right->y = 1.f; |
| 212 texture_state->background_color = mojo::Color::New(); | 214 texture_state->background_color = mus::mojom::Color::New(); |
| 213 texture_state->background_color->rgba = g_transparent_color; | 215 texture_state->background_color->rgba = g_transparent_color; |
| 214 for (int i = 0; i < 4; ++i) | 216 for (int i = 0; i < 4; ++i) |
| 215 texture_state->vertex_opacity.push_back(1.f); | 217 texture_state->vertex_opacity.push_back(1.f); |
| 216 texture_state->y_flipped = false; | 218 texture_state->y_flipped = false; |
| 217 | 219 |
| 218 frame->resources.push_back(resource.Pass()); | 220 frame->resources.push_back(resource.Pass()); |
| 219 quad->texture_quad_state = texture_state.Pass(); | 221 quad->texture_quad_state = texture_state.Pass(); |
| 220 pass->quads.push_back(quad.Pass()); | 222 pass->quads.push_back(quad.Pass()); |
| 221 } | 223 } |
| 222 | 224 |
| 223 if (color_ != g_transparent_color) { | 225 if (color_ != g_transparent_color) { |
| 224 mojo::QuadPtr quad = mojo::Quad::New(); | 226 mus::mojom::QuadPtr quad = mus::mojom::Quad::New(); |
| 225 quad->material = mojo::MATERIAL_SOLID_COLOR; | 227 quad->material = mus::mojom::MATERIAL_SOLID_COLOR; |
| 226 quad->rect = mojo::Rect::From(bounds); | 228 quad->rect = mojo::Rect::From(bounds); |
| 227 quad->opaque_rect = mojo::Rect::New(); | 229 quad->opaque_rect = mojo::Rect::New(); |
| 228 quad->visible_rect = mojo::Rect::From(bounds); | 230 quad->visible_rect = mojo::Rect::From(bounds); |
| 229 quad->needs_blending = true; | 231 quad->needs_blending = true; |
| 230 quad->shared_quad_state_index = 0u; | 232 quad->shared_quad_state_index = 0u; |
| 231 | 233 |
| 232 mojo::SolidColorQuadStatePtr color_state = | 234 mus::mojom::SolidColorQuadStatePtr color_state = |
| 233 mojo::SolidColorQuadState::New(); | 235 mus::mojom::SolidColorQuadState::New(); |
| 234 color_state->color = mojo::Color::New(); | 236 color_state->color = mus::mojom::Color::New(); |
| 235 color_state->color->rgba = color_; | 237 color_state->color->rgba = color_; |
| 236 color_state->force_anti_aliasing_off = false; | 238 color_state->force_anti_aliasing_off = false; |
| 237 | 239 |
| 238 quad->solid_color_quad_state = color_state.Pass(); | 240 quad->solid_color_quad_state = color_state.Pass(); |
| 239 pass->quads.push_back(quad.Pass()); | 241 pass->quads.push_back(quad.Pass()); |
| 240 } | 242 } |
| 241 | 243 |
| 242 frame->passes.push_back(pass.Pass()); | 244 frame->passes.push_back(pass.Pass()); |
| 243 | 245 |
| 244 // TODO(rjkroege, fsamuel): We should throttle frames. | 246 // TODO(rjkroege, fsamuel): We should throttle frames. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 268 } | 270 } |
| 269 | 271 |
| 270 void SetIdNamespace(uint32_t id_namespace) { | 272 void SetIdNamespace(uint32_t id_namespace) { |
| 271 id_namespace_ = id_namespace; | 273 id_namespace_ = id_namespace; |
| 272 if (color_ != g_transparent_color || bitmap_.get()) | 274 if (color_ != g_transparent_color || bitmap_.get()) |
| 273 Upload(); | 275 Upload(); |
| 274 } | 276 } |
| 275 | 277 |
| 276 // SurfaceClient implementation. | 278 // SurfaceClient implementation. |
| 277 void ReturnResources( | 279 void ReturnResources( |
| 278 mojo::Array<mojo::ReturnedResourcePtr> resources) override { | 280 mojo::Array<mus::mojom::ReturnedResourcePtr> resources) override { |
| 279 MojoGLES2MakeCurrent(gles2_context_); | 281 MojoGLES2MakeCurrent(gles2_context_); |
| 280 // TODO(jamesr): Recycle. | 282 // TODO(jamesr): Recycle. |
| 281 for (size_t i = 0; i < resources.size(); ++i) { | 283 for (size_t i = 0; i < resources.size(); ++i) { |
| 282 mojo::ReturnedResourcePtr resource = resources[i].Pass(); | 284 mus::mojom::ReturnedResourcePtr resource = resources[i].Pass(); |
| 283 DCHECK_EQ(1, resource->count); | 285 DCHECK_EQ(1, resource->count); |
| 284 glWaitSyncPointCHROMIUM(resource->sync_point); | 286 glWaitSyncPointCHROMIUM(resource->sync_point); |
| 285 uint32_t texture_id = resource_to_texture_id_map_[resource->id]; | 287 uint32_t texture_id = resource_to_texture_id_map_[resource->id]; |
| 286 DCHECK_NE(0u, texture_id); | 288 DCHECK_NE(0u, texture_id); |
| 287 resource_to_texture_id_map_.erase(resource->id); | 289 resource_to_texture_id_map_.erase(resource->id); |
| 288 glDeleteTextures(1, &texture_id); | 290 glDeleteTextures(1, &texture_id); |
| 289 } | 291 } |
| 290 } | 292 } |
| 291 | 293 |
| 292 mus::Window* view_; | 294 mus::Window* view_; |
| 293 mojo::GpuPtr gpu_service_; | 295 mus::mojom::GpuPtr gpu_service_; |
| 294 scoped_ptr<mus::WindowSurface> surface_; | 296 scoped_ptr<mus::WindowSurface> surface_; |
| 295 MojoGLES2Context gles2_context_; | 297 MojoGLES2Context gles2_context_; |
| 296 | 298 |
| 297 mojo::Size size_; | 299 mojo::Size size_; |
| 298 uint32_t color_; | 300 uint32_t color_; |
| 299 int width_; | 301 int width_; |
| 300 int height_; | 302 int height_; |
| 301 Format format_; | 303 Format format_; |
| 302 scoped_ptr<std::vector<unsigned char>> bitmap_; | 304 scoped_ptr<std::vector<unsigned char>> bitmap_; |
| 303 uint32_t next_resource_id_; | 305 uint32_t next_resource_id_; |
| 304 uint32_t id_namespace_; | 306 uint32_t id_namespace_; |
| 305 uint32_t local_id_; | 307 uint32_t local_id_; |
| 306 base::hash_map<uint32_t, uint32_t> resource_to_texture_id_map_; | 308 base::hash_map<uint32_t, uint32_t> resource_to_texture_id_map_; |
| 307 mojo::Binding<mojo::SurfaceClient> returner_binding_; | 309 mojo::Binding<mus::mojom::SurfaceClient> returner_binding_; |
| 308 | 310 |
| 309 DISALLOW_COPY_AND_ASSIGN(BitmapUploader); | 311 DISALLOW_COPY_AND_ASSIGN(BitmapUploader); |
| 310 }; | 312 }; |
| 311 | 313 |
| 312 class EmbedderData { | 314 class EmbedderData { |
| 313 public: | 315 public: |
| 314 EmbedderData(mojo::Shell* shell, mus::Window* root) : bitmap_uploader_(root) { | 316 EmbedderData(mojo::Shell* shell, mus::Window* root) : bitmap_uploader_(root) { |
| 315 bitmap_uploader_.Init(shell); | 317 bitmap_uploader_.Init(shell); |
| 316 bitmap_uploader_.SetColor(g_background_color); | 318 bitmap_uploader_.SetColor(g_background_color); |
| 317 } | 319 } |
| 318 | 320 |
| 319 BitmapUploader& bitmap_uploader() { return bitmap_uploader_; } | 321 BitmapUploader& bitmap_uploader() { return bitmap_uploader_; } |
| 320 | 322 |
| 321 private: | 323 private: |
| 322 BitmapUploader bitmap_uploader_; | 324 BitmapUploader bitmap_uploader_; |
| 323 | 325 |
| 324 DISALLOW_COPY_AND_ASSIGN(EmbedderData); | 326 DISALLOW_COPY_AND_ASSIGN(EmbedderData); |
| 325 }; | 327 }; |
| 326 | 328 |
| 327 class PDFView : public mojo::ApplicationDelegate, | 329 class PDFView : public mojo::ApplicationDelegate, |
| 328 public mus::WindowTreeDelegate, | 330 public mus::WindowTreeDelegate, |
| 329 public mus::WindowObserver, | 331 public mus::WindowObserver, |
| 330 public mojo::InterfaceFactory<mojo::ViewTreeClient> { | 332 public mojo::InterfaceFactory<mus::mojom::WindowTreeClient> { |
| 331 public: | 333 public: |
| 332 PDFView(mojo::InterfaceRequest<mojo::Application> request, | 334 PDFView(mojo::InterfaceRequest<mojo::Application> request, |
| 333 mojo::URLResponsePtr response) | 335 mojo::URLResponsePtr response) |
| 334 : app_(this, request.Pass(), base::Bind(&PDFView::OnTerminate, | 336 : app_(this, request.Pass(), base::Bind(&PDFView::OnTerminate, |
| 335 base::Unretained(this))), | 337 base::Unretained(this))), |
| 336 current_page_(0), page_count_(0), doc_(nullptr) { | 338 current_page_(0), page_count_(0), doc_(nullptr) { |
| 337 FetchPDF(response.Pass()); | 339 FetchPDF(response.Pass()); |
| 338 } | 340 } |
| 339 | 341 |
| 340 ~PDFView() override { | 342 ~PDFView() override { |
| 341 if (doc_) | 343 if (doc_) |
| 342 FPDF_CloseDocument(doc_); | 344 FPDF_CloseDocument(doc_); |
| 343 for (auto& roots : embedder_for_roots_) { | 345 for (auto& roots : embedder_for_roots_) { |
| 344 roots.first->RemoveObserver(this); | 346 roots.first->RemoveObserver(this); |
| 345 delete roots.second; | 347 delete roots.second; |
| 346 } | 348 } |
| 347 } | 349 } |
| 348 | 350 |
| 349 private: | 351 private: |
| 350 // Overridden from ApplicationDelegate: | 352 // Overridden from ApplicationDelegate: |
| 351 bool ConfigureIncomingConnection( | 353 bool ConfigureIncomingConnection( |
| 352 mojo::ApplicationConnection* connection) override { | 354 mojo::ApplicationConnection* connection) override { |
| 353 connection->AddService<mojo::ViewTreeClient>(this); | 355 connection->AddService<mus::mojom::WindowTreeClient>(this); |
| 354 return true; | 356 return true; |
| 355 } | 357 } |
| 356 | 358 |
| 357 // Overridden from WindowTreeDelegate: | 359 // Overridden from WindowTreeDelegate: |
| 358 void OnEmbed(mus::Window* root) override { | 360 void OnEmbed(mus::Window* root) override { |
| 359 DCHECK(embedder_for_roots_.find(root) == embedder_for_roots_.end()); | 361 DCHECK(embedder_for_roots_.find(root) == embedder_for_roots_.end()); |
| 360 root->AddObserver(this); | 362 root->AddObserver(this); |
| 361 EmbedderData* embedder_data = new EmbedderData(app_.shell(), root); | 363 EmbedderData* embedder_data = new EmbedderData(app_.shell(), root); |
| 362 embedder_for_roots_[root] = embedder_data; | 364 embedder_for_roots_[root] = embedder_data; |
| 363 DrawBitmap(embedder_data); | 365 DrawBitmap(embedder_data); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 void OnWindowDestroyed(mus::Window* view) override { | 406 void OnWindowDestroyed(mus::Window* view) override { |
| 405 DCHECK(embedder_for_roots_.find(view) != embedder_for_roots_.end()); | 407 DCHECK(embedder_for_roots_.find(view) != embedder_for_roots_.end()); |
| 406 const auto& it = embedder_for_roots_.find(view); | 408 const auto& it = embedder_for_roots_.find(view); |
| 407 DCHECK(it != embedder_for_roots_.end()); | 409 DCHECK(it != embedder_for_roots_.end()); |
| 408 delete it->second; | 410 delete it->second; |
| 409 embedder_for_roots_.erase(it); | 411 embedder_for_roots_.erase(it); |
| 410 if (embedder_for_roots_.size() == 0) | 412 if (embedder_for_roots_.size() == 0) |
| 411 app_.Quit(); | 413 app_.Quit(); |
| 412 } | 414 } |
| 413 | 415 |
| 414 // Overridden from mojo::InterfaceFactory<mojo::ViewTreeClient>: | 416 // Overridden from mojo::InterfaceFactory<mus::mojom::WindowTreeClient>: |
| 415 void Create( | 417 void Create( |
| 416 mojo::ApplicationConnection* connection, | 418 mojo::ApplicationConnection* connection, |
| 417 mojo::InterfaceRequest<mojo::ViewTreeClient> request) override { | 419 mojo::InterfaceRequest<mus::mojom::WindowTreeClient> request) override { |
| 418 mus::WindowTreeConnection::Create( | 420 mus::WindowTreeConnection::Create( |
| 419 this, request.Pass(), | 421 this, request.Pass(), |
| 420 mus::WindowTreeConnection::CreateType::DONT_WAIT_FOR_EMBED); | 422 mus::WindowTreeConnection::CreateType::DONT_WAIT_FOR_EMBED); |
| 421 } | 423 } |
| 422 | 424 |
| 423 void DrawBitmap(EmbedderData* embedder_data) { | 425 void DrawBitmap(EmbedderData* embedder_data) { |
| 424 if (!doc_) | 426 if (!doc_) |
| 425 return; | 427 return; |
| 426 | 428 |
| 427 FPDF_PAGE page = FPDF_LoadPage(doc_, current_page_); | 429 FPDF_PAGE page = FPDF_LoadPage(doc_, current_page_); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 DISALLOW_COPY_AND_ASSIGN(PDFViewer); | 520 DISALLOW_COPY_AND_ASSIGN(PDFViewer); |
| 519 }; | 521 }; |
| 520 | 522 |
| 521 } // namespace | 523 } // namespace |
| 522 } // namespace pdf_viewer | 524 } // namespace pdf_viewer |
| 523 | 525 |
| 524 MojoResult MojoMain(MojoHandle application_request) { | 526 MojoResult MojoMain(MojoHandle application_request) { |
| 525 mojo::ApplicationRunner runner(new pdf_viewer::PDFViewer()); | 527 mojo::ApplicationRunner runner(new pdf_viewer::PDFViewer()); |
| 526 return runner.Run(application_request); | 528 return runner.Run(application_request); |
| 527 } | 529 } |
| OLD | NEW |