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

Side by Side Diff: chrome/browser/ui/views/constrained_web_dialog_delegate_views.cc

Issue 2357243003: [UI] Make auto-resizable constrained web dialog work even when initiated (Closed)
Patch Set: Created 4 years, 3 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/webui/constrained_web_dialog_delegate_base.h" 5 #include "chrome/browser/ui/webui/constrained_web_dialog_delegate_base.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "chrome/browser/ui/browser_finder.h" 10 #include "chrome/browser/ui/browser_finder.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 const gfx::Size& preferred_size) override { 73 const gfx::Size& preferred_size) override {
74 if (source != web_view_->GetWebContents()) 74 if (source != web_view_->GetWebContents())
75 return; 75 return;
76 76
77 if (!initiator_observer_->web_contents()) 77 if (!initiator_observer_->web_contents())
78 return; 78 return;
79 79
80 // Sets WebView's preferred size based on auto-resized contents. 80 // Sets WebView's preferred size based on auto-resized contents.
81 web_view_->SetPreferredSize(preferred_size); 81 web_view_->SetPreferredSize(preferred_size);
82 82
83 content::WebContents* top_level_web_contents =
msw 2016/09/22 03:27:35 It seems odd to present a dialog from an embedded
imcheng 2016/09/22 04:32:23 Indeed, we currently allow embedded <webview> to c
msw 2016/09/22 13:36:19 Thanks for the info, this probably doesn't need se
imcheng 2016/09/22 17:20:58 Acknowledged.
84 constrained_window::GetTopLevelWebContents(
85 initiator_observer_->web_contents());
83 constrained_window::UpdateWebContentsModalDialogPosition( 86 constrained_window::UpdateWebContentsModalDialogPosition(
84 web_view_->GetWidget(), 87 web_view_->GetWidget(),
85 web_modal::WebContentsModalDialogManager::FromWebContents( 88 web_modal::WebContentsModalDialogManager::FromWebContents(
86 initiator_observer_->web_contents())->delegate()-> 89 top_level_web_contents)
msw 2016/09/22 13:36:19 Check for null before using |top_level_web_content
wjmaclean 2016/09/22 15:36:48 Definitely check for null ... there's no guarantee
imcheng 2016/09/22 17:20:57 Done. Although I did notice that constrained_windo
87 GetWebContentsModalDialogHost()); 90 ->delegate()
91 ->GetWebContentsModalDialogHost());
88 } 92 }
89 93
90 private: 94 private:
91 InitiatorWebContentsObserver* const initiator_observer_; 95 InitiatorWebContentsObserver* const initiator_observer_;
92 views::WebView* web_view_; 96 views::WebView* web_view_;
93 97
94 DISALLOW_COPY_AND_ASSIGN(WebDialogWebContentsDelegateViews); 98 DISALLOW_COPY_AND_ASSIGN(WebDialogWebContentsDelegateViews);
95 }; 99 };
96 100
97 class ConstrainedWebDialogDelegateViews 101 class ConstrainedWebDialogDelegateViews
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 if (!max_size_.IsEmpty()) 235 if (!max_size_.IsEmpty())
232 EnableAutoResize(); 236 EnableAutoResize();
233 } 237 }
234 void RenderViewHostChanged(content::RenderViewHost* old_host, 238 void RenderViewHostChanged(content::RenderViewHost* old_host,
235 content::RenderViewHost* new_host) override { 239 content::RenderViewHost* new_host) override {
236 if (!max_size_.IsEmpty()) 240 if (!max_size_.IsEmpty())
237 EnableAutoResize(); 241 EnableAutoResize();
238 } 242 }
239 void DocumentOnLoadCompletedInMainFrame() override { 243 void DocumentOnLoadCompletedInMainFrame() override {
240 if (!max_size_.IsEmpty() && initiator_observer_.web_contents()) { 244 if (!max_size_.IsEmpty() && initiator_observer_.web_contents()) {
241 constrained_window::ShowModalDialog(GetWidget()->GetNativeWindow(), 245 constrained_window::ShowModalDialog(
242 initiator_observer_.web_contents()); 246 GetWidget()->GetNativeWindow(),
247 constrained_window::GetTopLevelWebContents(
msw 2016/09/22 13:36:19 Ditto, check for null first?
imcheng 2016/09/22 17:20:57 Done.
248 initiator_observer_.web_contents()));
243 } 249 }
244 } 250 }
245 251
246 private: 252 private:
247 void EnableAutoResize() { 253 void EnableAutoResize() {
248 content::RenderViewHost* render_view_host = 254 content::RenderViewHost* render_view_host =
249 GetWebContents()->GetRenderViewHost(); 255 GetWebContents()->GetRenderViewHost();
250 render_view_host->EnableAutoResize(min_size_, max_size_); 256 render_view_host->EnableAutoResize(min_size_, max_size_);
251 } 257 }
252 258
(...skipping 27 matching lines...) Expand all
280 ui::WebDialogDelegate* delegate, 286 ui::WebDialogDelegate* delegate,
281 content::WebContents* web_contents, 287 content::WebContents* web_contents,
282 const gfx::Size& min_size, 288 const gfx::Size& min_size,
283 const gfx::Size& max_size) { 289 const gfx::Size& max_size) {
284 DCHECK(!min_size.IsEmpty()); 290 DCHECK(!min_size.IsEmpty());
285 DCHECK(!max_size.IsEmpty()); 291 DCHECK(!max_size.IsEmpty());
286 ConstrainedWebDialogDelegateViewViews* dialog = 292 ConstrainedWebDialogDelegateViewViews* dialog =
287 new ConstrainedWebDialogDelegateViewViews( 293 new ConstrainedWebDialogDelegateViewViews(
288 browser_context, delegate, web_contents, 294 browser_context, delegate, web_contents,
289 min_size, max_size); 295 min_size, max_size);
290 constrained_window::CreateWebModalDialogViews(dialog, web_contents); 296 // For embedded WebContents, use the embedder's WebContents for constrained
297 // window.
298 content::WebContents* top_level_web_contents =
299 constrained_window::GetTopLevelWebContents(web_contents);
300 constrained_window::CreateWebModalDialogViews(dialog, top_level_web_contents);
msw 2016/09/22 13:36:19 nit: maybe DCHECK that |top_level_web_contents| is
imcheng 2016/09/22 17:20:57 Done.
291 return dialog; 301 return dialog;
292 } 302 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698