Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(888)

Side by Side Diff: chrome/browser/guest_view/guest_view_base.cc

Issue 427883002: <webview>: Move autosize from content to chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_frame_url
Patch Set: Code cleanup Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 &= !!max_auto_size_.width() && !!max_auto_size_.height();
156 if (!enabled && !auto_size_enabled_)
157 return;
158
159 auto_size_enabled_ = enabled;
160
161 if (!attached())
162 return;
163
164 content::RenderViewHost* rvh = guest_web_contents()->GetRenderViewHost();
165 if (auto_size_enabled_) {
166 rvh->EnableAutoResize(min_auto_size_, max_auto_size_);
167 } else {
168 rvh->DisableAutoResize(element_size_);
169 guest_size_ = element_size_;
170 GuestSizeChangedDueToAutoSize(guest_size_, element_size_);
171 }
172 }
173
146 // static 174 // static
147 void GuestViewBase::RegisterGuestViewType( 175 void GuestViewBase::RegisterGuestViewType(
148 const std::string& view_type, 176 const std::string& view_type,
149 const GuestCreationCallback& callback) { 177 const GuestCreationCallback& callback) {
150 GuestViewCreationMap::iterator it = 178 GuestViewCreationMap::iterator it =
151 guest_view_registry.Get().find(view_type); 179 guest_view_registry.Get().find(view_type);
152 DCHECK(it == guest_view_registry.Get().end()); 180 DCHECK(it == guest_view_registry.Get().end());
153 guest_view_registry.Get()[view_type] = callback; 181 guest_view_registry.Get()[view_type] = callback;
154 } 182 }
155 183
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 delete guest_web_contents(); 289 delete guest_web_contents();
262 } 290 }
263 291
264 void GuestViewBase::DidAttach() { 292 void GuestViewBase::DidAttach() {
265 // Give the derived class an opportunity to perform some actions. 293 // Give the derived class an opportunity to perform some actions.
266 DidAttachToEmbedder(); 294 DidAttachToEmbedder();
267 295
268 SendQueuedEvents(); 296 SendQueuedEvents();
269 } 297 }
270 298
299 void GuestViewBase::ElementSizeChanged(const gfx::Size& old_size,
300 const gfx::Size& new_size) {
301 element_size_ = new_size;
302 }
303
271 int GuestViewBase::GetGuestInstanceID() const { 304 int GuestViewBase::GetGuestInstanceID() const {
272 return guest_instance_id_; 305 return guest_instance_id_;
273 } 306 }
274 307
308 void GuestViewBase::GuestSizeChanged(const gfx::Size& old_size,
309 const gfx::Size& new_size) {
ericzeng 2014/08/01 18:55:09 indentation
Fady Samuel 2014/08/01 20:06:13 Done.
310 if (!auto_size_enabled_)
311 return;
312 guest_size_ = new_size;
313 GuestSizeChangedDueToAutoSize(old_size, new_size);
314 }
315
275 void GuestViewBase::SetOpener(GuestViewBase* guest) { 316 void GuestViewBase::SetOpener(GuestViewBase* guest) {
276 if (guest && guest->IsViewType(GetViewType())) { 317 if (guest && guest->IsViewType(GetViewType())) {
277 opener_ = guest->AsWeakPtr(); 318 opener_ = guest->AsWeakPtr();
278 return; 319 return;
279 } 320 }
280 opener_ = base::WeakPtr<GuestViewBase>(); 321 opener_ = base::WeakPtr<GuestViewBase>();
281 } 322 }
282 323
283 void GuestViewBase::RegisterDestructionCallback( 324 void GuestViewBase::RegisterDestructionCallback(
284 const DestructionCallback& callback) { 325 const DestructionCallback& callback) {
(...skipping 19 matching lines...) Expand all
304 if (!IsDragAndDropEnabled()) { 345 if (!IsDragAndDropEnabled()) {
305 const char script[] = "window.addEventListener('dragstart', function() { " 346 const char script[] = "window.addEventListener('dragstart', function() { "
306 " window.event.preventDefault(); " 347 " window.event.preventDefault(); "
307 "});"; 348 "});";
308 render_view_host->GetMainFrame()->ExecuteJavaScript( 349 render_view_host->GetMainFrame()->ExecuteJavaScript(
309 base::ASCIIToUTF16(script)); 350 base::ASCIIToUTF16(script));
310 } 351 }
311 DidStopLoading(); 352 DidStopLoading();
312 } 353 }
313 354
355 void GuestViewBase::RenderViewReady() {
356 GuestReady();
357 content::RenderViewHost* rvh = guest_web_contents()->GetRenderViewHost();
358 if (auto_size_enabled_) {
359 rvh->EnableAutoResize(min_auto_size_, max_auto_size_);
360 } else {
361 rvh->DisableAutoResize(element_size_);
362 }
363 }
364
314 void GuestViewBase::WebContentsDestroyed() { 365 void GuestViewBase::WebContentsDestroyed() {
315 GuestDestroyed(); 366 GuestDestroyed();
316 delete this; 367 delete this;
317 } 368 }
318 369
319 bool GuestViewBase::ShouldFocusPageAfterCrash() { 370 bool GuestViewBase::ShouldFocusPageAfterCrash() {
320 // Focus is managed elsewhere. 371 // Focus is managed elsewhere.
321 return false; 372 return false;
322 } 373 }
323 374
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 guest_web_contents); 435 guest_web_contents);
385 callback.Run(guest_web_contents); 436 callback.Run(guest_web_contents);
386 } 437 }
387 438
388 // static 439 // static
389 void GuestViewBase::RegisterGuestViewTypes() { 440 void GuestViewBase::RegisterGuestViewTypes() {
390 AppViewGuest::Register(); 441 AppViewGuest::Register();
391 ExtensionOptionsGuest::Register(); 442 ExtensionOptionsGuest::Register();
392 WebViewGuest::Register(); 443 WebViewGuest::Register();
393 } 444 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698