| 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 "chrome/browser/guest_view/guest_view_base.h" | 5 #include "chrome/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 "chrome/browser/guest_view/app_view/app_view_guest.h" | 9 #include "chrome/browser/guest_view/app_view/app_view_guest.h" |
| 10 #include "chrome/browser/guest_view/extension_options/extension_options_guest.h" | 10 #include "chrome/browser/guest_view/extension_options/extension_options_guest.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 GuestViewBase::GuestViewBase(content::BrowserContext* browser_context, | 88 GuestViewBase::GuestViewBase(content::BrowserContext* browser_context, |
| 89 int guest_instance_id) | 89 int guest_instance_id) |
| 90 : embedder_web_contents_(NULL), | 90 : embedder_web_contents_(NULL), |
| 91 embedder_render_process_id_(0), | 91 embedder_render_process_id_(0), |
| 92 browser_context_(browser_context), | 92 browser_context_(browser_context), |
| 93 guest_instance_id_(guest_instance_id), | 93 guest_instance_id_(guest_instance_id), |
| 94 view_instance_id_(guestview::kInstanceIDNone), | 94 view_instance_id_(guestview::kInstanceIDNone), |
| 95 initialized_(false), | 95 initialized_(false), |
| 96 auto_size_enabled_(false), | |
| 97 weak_ptr_factory_(this) { | 96 weak_ptr_factory_(this) { |
| 98 } | 97 } |
| 99 | 98 |
| 100 void GuestViewBase::Init( | 99 void GuestViewBase::Init( |
| 101 const std::string& embedder_extension_id, | 100 const std::string& embedder_extension_id, |
| 102 int embedder_render_process_id, | 101 int embedder_render_process_id, |
| 103 const base::DictionaryValue& create_params, | 102 const base::DictionaryValue& create_params, |
| 104 const WebContentsCreatedCallback& callback) { | 103 const WebContentsCreatedCallback& callback) { |
| 105 if (initialized_) | 104 if (initialized_) |
| 106 return; | 105 return; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 137 guest_web_contents->SetDelegate(this); | 136 guest_web_contents->SetDelegate(this); |
| 138 webcontents_guestview_map.Get().insert( | 137 webcontents_guestview_map.Get().insert( |
| 139 std::make_pair(guest_web_contents, this)); | 138 std::make_pair(guest_web_contents, this)); |
| 140 GuestViewManager::FromBrowserContext(browser_context_)-> | 139 GuestViewManager::FromBrowserContext(browser_context_)-> |
| 141 AddGuest(guest_instance_id_, guest_web_contents); | 140 AddGuest(guest_instance_id_, guest_web_contents); |
| 142 | 141 |
| 143 // Give the derived class an opportunity to perform additional initialization. | 142 // Give the derived class an opportunity to perform additional initialization. |
| 144 DidInitialize(); | 143 DidInitialize(); |
| 145 } | 144 } |
| 146 | 145 |
| 147 void GuestViewBase::SetAutoSize(bool enabled, | |
| 148 const gfx::Size& min_size, | |
| 149 const gfx::Size& max_size) { | |
| 150 min_auto_size_ = min_size; | |
| 151 min_auto_size_.SetToMin(max_size); | |
| 152 max_auto_size_ = max_size; | |
| 153 max_auto_size_.SetToMax(min_size); | |
| 154 | |
| 155 enabled &= !!max_auto_size_.width() && !!max_auto_size_.height() && | |
| 156 IsAutoSizeSupported(); | |
| 157 if (!enabled && !auto_size_enabled_) | |
| 158 return; | |
| 159 | |
| 160 auto_size_enabled_ = enabled; | |
| 161 | |
| 162 if (!attached()) | |
| 163 return; | |
| 164 | |
| 165 content::RenderViewHost* rvh = guest_web_contents()->GetRenderViewHost(); | |
| 166 if (auto_size_enabled_) { | |
| 167 rvh->EnableAutoResize(min_auto_size_, max_auto_size_); | |
| 168 } else { | |
| 169 rvh->DisableAutoResize(element_size_); | |
| 170 guest_size_ = element_size_; | |
| 171 GuestSizeChangedDueToAutoSize(guest_size_, element_size_); | |
| 172 } | |
| 173 } | |
| 174 | |
| 175 // static | 146 // static |
| 176 void GuestViewBase::RegisterGuestViewType( | 147 void GuestViewBase::RegisterGuestViewType( |
| 177 const std::string& view_type, | 148 const std::string& view_type, |
| 178 const GuestCreationCallback& callback) { | 149 const GuestCreationCallback& callback) { |
| 179 GuestViewCreationMap::iterator it = | 150 GuestViewCreationMap::iterator it = |
| 180 guest_view_registry.Get().find(view_type); | 151 guest_view_registry.Get().find(view_type); |
| 181 DCHECK(it == guest_view_registry.Get().end()); | 152 DCHECK(it == guest_view_registry.Get().end()); |
| 182 guest_view_registry.Get()[view_type] = callback; | 153 guest_view_registry.Get()[view_type] = callback; |
| 183 } | 154 } |
| 184 | 155 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 ContentSettingsPattern::Wildcard(), | 215 ContentSettingsPattern::Wildcard(), |
| 245 CONTENT_SETTING_ALLOW, | 216 CONTENT_SETTING_ALLOW, |
| 246 std::string(), | 217 std::string(), |
| 247 incognito)); | 218 incognito)); |
| 248 } | 219 } |
| 249 | 220 |
| 250 base::WeakPtr<GuestViewBase> GuestViewBase::AsWeakPtr() { | 221 base::WeakPtr<GuestViewBase> GuestViewBase::AsWeakPtr() { |
| 251 return weak_ptr_factory_.GetWeakPtr(); | 222 return weak_ptr_factory_.GetWeakPtr(); |
| 252 } | 223 } |
| 253 | 224 |
| 254 bool GuestViewBase::IsAutoSizeSupported() const { | |
| 255 return false; | |
| 256 } | |
| 257 | |
| 258 bool GuestViewBase::IsDragAndDropEnabled() const { | 225 bool GuestViewBase::IsDragAndDropEnabled() const { |
| 259 return false; | 226 return false; |
| 260 } | 227 } |
| 261 | 228 |
| 262 void GuestViewBase::RenderProcessExited(content::RenderProcessHost* host, | 229 void GuestViewBase::RenderProcessExited(content::RenderProcessHost* host, |
| 263 base::ProcessHandle handle, | 230 base::ProcessHandle handle, |
| 264 base::TerminationStatus status, | 231 base::TerminationStatus status, |
| 265 int exit_code) { | 232 int exit_code) { |
| 266 // GuestViewBase tracks the lifetime of its embedder render process until it | 233 // GuestViewBase tracks the lifetime of its embedder render process until it |
| 267 // is attached to a particular embedder WebContents. At that point, its | 234 // is attached to a particular embedder WebContents. At that point, its |
| (...skipping 26 matching lines...) Expand all Loading... |
| 294 delete guest_web_contents(); | 261 delete guest_web_contents(); |
| 295 } | 262 } |
| 296 | 263 |
| 297 void GuestViewBase::DidAttach() { | 264 void GuestViewBase::DidAttach() { |
| 298 // Give the derived class an opportunity to perform some actions. | 265 // Give the derived class an opportunity to perform some actions. |
| 299 DidAttachToEmbedder(); | 266 DidAttachToEmbedder(); |
| 300 | 267 |
| 301 SendQueuedEvents(); | 268 SendQueuedEvents(); |
| 302 } | 269 } |
| 303 | 270 |
| 304 void GuestViewBase::ElementSizeChanged(const gfx::Size& old_size, | |
| 305 const gfx::Size& new_size) { | |
| 306 element_size_ = new_size; | |
| 307 } | |
| 308 | |
| 309 int GuestViewBase::GetGuestInstanceID() const { | 271 int GuestViewBase::GetGuestInstanceID() const { |
| 310 return guest_instance_id_; | 272 return guest_instance_id_; |
| 311 } | 273 } |
| 312 | 274 |
| 313 void GuestViewBase::GuestSizeChanged(const gfx::Size& old_size, | |
| 314 const gfx::Size& new_size) { | |
| 315 if (!auto_size_enabled_) | |
| 316 return; | |
| 317 guest_size_ = new_size; | |
| 318 GuestSizeChangedDueToAutoSize(old_size, new_size); | |
| 319 } | |
| 320 | |
| 321 void GuestViewBase::SetOpener(GuestViewBase* guest) { | 275 void GuestViewBase::SetOpener(GuestViewBase* guest) { |
| 322 if (guest && guest->IsViewType(GetViewType())) { | 276 if (guest && guest->IsViewType(GetViewType())) { |
| 323 opener_ = guest->AsWeakPtr(); | 277 opener_ = guest->AsWeakPtr(); |
| 324 return; | 278 return; |
| 325 } | 279 } |
| 326 opener_ = base::WeakPtr<GuestViewBase>(); | 280 opener_ = base::WeakPtr<GuestViewBase>(); |
| 327 } | 281 } |
| 328 | 282 |
| 329 void GuestViewBase::RegisterDestructionCallback( | 283 void GuestViewBase::RegisterDestructionCallback( |
| 330 const DestructionCallback& callback) { | 284 const DestructionCallback& callback) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 350 if (!IsDragAndDropEnabled()) { | 304 if (!IsDragAndDropEnabled()) { |
| 351 const char script[] = "window.addEventListener('dragstart', function() { " | 305 const char script[] = "window.addEventListener('dragstart', function() { " |
| 352 " window.event.preventDefault(); " | 306 " window.event.preventDefault(); " |
| 353 "});"; | 307 "});"; |
| 354 render_view_host->GetMainFrame()->ExecuteJavaScript( | 308 render_view_host->GetMainFrame()->ExecuteJavaScript( |
| 355 base::ASCIIToUTF16(script)); | 309 base::ASCIIToUTF16(script)); |
| 356 } | 310 } |
| 357 DidStopLoading(); | 311 DidStopLoading(); |
| 358 } | 312 } |
| 359 | 313 |
| 360 void GuestViewBase::RenderViewReady() { | |
| 361 GuestReady(); | |
| 362 content::RenderViewHost* rvh = guest_web_contents()->GetRenderViewHost(); | |
| 363 if (auto_size_enabled_) { | |
| 364 rvh->EnableAutoResize(min_auto_size_, max_auto_size_); | |
| 365 } else { | |
| 366 rvh->DisableAutoResize(element_size_); | |
| 367 } | |
| 368 } | |
| 369 | |
| 370 void GuestViewBase::WebContentsDestroyed() { | 314 void GuestViewBase::WebContentsDestroyed() { |
| 371 GuestDestroyed(); | 315 GuestDestroyed(); |
| 372 delete this; | 316 delete this; |
| 373 } | 317 } |
| 374 | 318 |
| 375 bool GuestViewBase::ShouldFocusPageAfterCrash() { | 319 bool GuestViewBase::ShouldFocusPageAfterCrash() { |
| 376 // Focus is managed elsewhere. | 320 // Focus is managed elsewhere. |
| 377 return false; | 321 return false; |
| 378 } | 322 } |
| 379 | 323 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 guest_web_contents); | 384 guest_web_contents); |
| 441 callback.Run(guest_web_contents); | 385 callback.Run(guest_web_contents); |
| 442 } | 386 } |
| 443 | 387 |
| 444 // static | 388 // static |
| 445 void GuestViewBase::RegisterGuestViewTypes() { | 389 void GuestViewBase::RegisterGuestViewTypes() { |
| 446 AppViewGuest::Register(); | 390 AppViewGuest::Register(); |
| 447 ExtensionOptionsGuest::Register(); | 391 ExtensionOptionsGuest::Register(); |
| 448 WebViewGuest::Register(); | 392 WebViewGuest::Register(); |
| 449 } | 393 } |
| OLD | NEW |