| 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 "extensions/browser/guest_view/guest_view_base.h" | 5 #include "extensions/browser/guest_view/guest_view_base.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "content/public/browser/render_frame_host.h" | 9 #include "content/public/browser/render_frame_host.h" |
| 10 #include "content/public/browser/render_process_host.h" | 10 #include "content/public/browser/render_process_host.h" |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 enabled &= !min_auto_size_.IsEmpty() && !max_auto_size_.IsEmpty() && | 186 enabled &= !min_auto_size_.IsEmpty() && !max_auto_size_.IsEmpty() && |
| 187 IsAutoSizeSupported(); | 187 IsAutoSizeSupported(); |
| 188 if (!enabled && !auto_size_enabled_) | 188 if (!enabled && !auto_size_enabled_) |
| 189 return; | 189 return; |
| 190 | 190 |
| 191 auto_size_enabled_ = enabled; | 191 auto_size_enabled_ = enabled; |
| 192 | 192 |
| 193 if (!attached()) | 193 if (!attached()) |
| 194 return; | 194 return; |
| 195 | 195 |
| 196 content::RenderViewHost* rvh = guest_web_contents()->GetRenderViewHost(); | 196 content::RenderViewHost* rvh = web_contents()->GetRenderViewHost(); |
| 197 if (auto_size_enabled_) { | 197 if (auto_size_enabled_) { |
| 198 rvh->EnableAutoResize(min_auto_size_, max_auto_size_); | 198 rvh->EnableAutoResize(min_auto_size_, max_auto_size_); |
| 199 } else { | 199 } else { |
| 200 rvh->DisableAutoResize(element_size_); | 200 rvh->DisableAutoResize(element_size_); |
| 201 guest_size_ = element_size_; | 201 guest_size_ = element_size_; |
| 202 GuestSizeChangedDueToAutoSize(guest_size_, element_size_); | 202 GuestSizeChangedDueToAutoSize(guest_size_, element_size_); |
| 203 } | 203 } |
| 204 } | 204 } |
| 205 | 205 |
| 206 // static | 206 // static |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 CHECK(!attached()); | 282 CHECK(!attached()); |
| 283 CHECK_EQ(host->GetID(), embedder_render_process_id()); | 283 CHECK_EQ(host->GetID(), embedder_render_process_id()); |
| 284 | 284 |
| 285 // This code path may be reached if the embedder WebContents is killed for | 285 // This code path may be reached if the embedder WebContents is killed for |
| 286 // whatever reason immediately after a called to GuestViewInternal.createGuest | 286 // whatever reason immediately after a called to GuestViewInternal.createGuest |
| 287 // and before attaching the new guest to a frame. | 287 // and before attaching the new guest to a frame. |
| 288 Destroy(); | 288 Destroy(); |
| 289 } | 289 } |
| 290 | 290 |
| 291 void GuestViewBase::Destroy() { | 291 void GuestViewBase::Destroy() { |
| 292 DCHECK(guest_web_contents()); | 292 DCHECK(web_contents()); |
| 293 content::RenderProcessHost* host = | 293 content::RenderProcessHost* host = |
| 294 content::RenderProcessHost::FromID(embedder_render_process_id()); | 294 content::RenderProcessHost::FromID(embedder_render_process_id()); |
| 295 if (host) | 295 if (host) |
| 296 host->RemoveObserver(this); | 296 host->RemoveObserver(this); |
| 297 WillDestroy(); | 297 WillDestroy(); |
| 298 if (!destruction_callback_.is_null()) | 298 if (!destruction_callback_.is_null()) |
| 299 destruction_callback_.Run(); | 299 destruction_callback_.Run(); |
| 300 | 300 |
| 301 webcontents_guestview_map.Get().erase(guest_web_contents()); | 301 webcontents_guestview_map.Get().erase(web_contents()); |
| 302 GuestViewManager::FromBrowserContext(browser_context_)-> | 302 GuestViewManager::FromBrowserContext(browser_context_)-> |
| 303 RemoveGuest(guest_instance_id_); | 303 RemoveGuest(guest_instance_id_); |
| 304 pending_events_.clear(); | 304 pending_events_.clear(); |
| 305 | 305 |
| 306 delete guest_web_contents(); | 306 delete web_contents(); |
| 307 } | 307 } |
| 308 | 308 |
| 309 void GuestViewBase::DidAttach() { | 309 void GuestViewBase::DidAttach() { |
| 310 // Give the derived class an opportunity to perform some actions. | 310 // Give the derived class an opportunity to perform some actions. |
| 311 DidAttachToEmbedder(); | 311 DidAttachToEmbedder(); |
| 312 | 312 |
| 313 SendQueuedEvents(); | 313 SendQueuedEvents(); |
| 314 } | 314 } |
| 315 | 315 |
| 316 void GuestViewBase::ElementSizeChanged(const gfx::Size& old_size, | 316 void GuestViewBase::ElementSizeChanged(const gfx::Size& old_size, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 " window.event.preventDefault(); " | 363 " window.event.preventDefault(); " |
| 364 "});"; | 364 "});"; |
| 365 render_view_host->GetMainFrame()->ExecuteJavaScript( | 365 render_view_host->GetMainFrame()->ExecuteJavaScript( |
| 366 base::ASCIIToUTF16(script)); | 366 base::ASCIIToUTF16(script)); |
| 367 } | 367 } |
| 368 DidStopLoading(); | 368 DidStopLoading(); |
| 369 } | 369 } |
| 370 | 370 |
| 371 void GuestViewBase::RenderViewReady() { | 371 void GuestViewBase::RenderViewReady() { |
| 372 GuestReady(); | 372 GuestReady(); |
| 373 content::RenderViewHost* rvh = guest_web_contents()->GetRenderViewHost(); | 373 content::RenderViewHost* rvh = web_contents()->GetRenderViewHost(); |
| 374 if (auto_size_enabled_) { | 374 if (auto_size_enabled_) { |
| 375 rvh->EnableAutoResize(min_auto_size_, max_auto_size_); | 375 rvh->EnableAutoResize(min_auto_size_, max_auto_size_); |
| 376 } else { | 376 } else { |
| 377 rvh->DisableAutoResize(element_size_); | 377 rvh->DisableAutoResize(element_size_); |
| 378 } | 378 } |
| 379 } | 379 } |
| 380 | 380 |
| 381 void GuestViewBase::WebContentsDestroyed() { | 381 void GuestViewBase::WebContentsDestroyed() { |
| 382 GuestDestroyed(); | 382 GuestDestroyed(); |
| 383 delete this; | 383 delete this; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 } | 449 } |
| 450 | 450 |
| 451 // static | 451 // static |
| 452 void GuestViewBase::RegisterGuestViewTypes() { | 452 void GuestViewBase::RegisterGuestViewTypes() { |
| 453 AppViewGuest::Register(); | 453 AppViewGuest::Register(); |
| 454 WebViewGuest::Register(); | 454 WebViewGuest::Register(); |
| 455 ExtensionsAPIClient::Get()->RegisterGuestViewTypes(); | 455 ExtensionsAPIClient::Get()->RegisterGuestViewTypes(); |
| 456 } | 456 } |
| 457 | 457 |
| 458 } // namespace extensions | 458 } // namespace extensions |
| OLD | NEW |