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