| OLD | NEW |
| 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 Loading... |
| 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 constrained_window::UpdateWebContentsModalDialogPosition( | 83 content::WebContents* top_level_web_contents = |
| 84 web_view_->GetWidget(), | 84 constrained_window::GetTopLevelWebContents( |
| 85 web_modal::WebContentsModalDialogManager::FromWebContents( | 85 initiator_observer_->web_contents()); |
| 86 initiator_observer_->web_contents())->delegate()-> | 86 if (top_level_web_contents) { |
| 87 GetWebContentsModalDialogHost()); | 87 constrained_window::UpdateWebContentsModalDialogPosition( |
| 88 web_view_->GetWidget(), |
| 89 web_modal::WebContentsModalDialogManager::FromWebContents( |
| 90 top_level_web_contents) |
| 91 ->delegate() |
| 92 ->GetWebContentsModalDialogHost()); |
| 93 } |
| 88 } | 94 } |
| 89 | 95 |
| 90 private: | 96 private: |
| 91 InitiatorWebContentsObserver* const initiator_observer_; | 97 InitiatorWebContentsObserver* const initiator_observer_; |
| 92 views::WebView* web_view_; | 98 views::WebView* web_view_; |
| 93 | 99 |
| 94 DISALLOW_COPY_AND_ASSIGN(WebDialogWebContentsDelegateViews); | 100 DISALLOW_COPY_AND_ASSIGN(WebDialogWebContentsDelegateViews); |
| 95 }; | 101 }; |
| 96 | 102 |
| 97 class ConstrainedWebDialogDelegateViews | 103 class ConstrainedWebDialogDelegateViews |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 if (!max_size_.IsEmpty()) | 237 if (!max_size_.IsEmpty()) |
| 232 EnableAutoResize(); | 238 EnableAutoResize(); |
| 233 } | 239 } |
| 234 void RenderViewHostChanged(content::RenderViewHost* old_host, | 240 void RenderViewHostChanged(content::RenderViewHost* old_host, |
| 235 content::RenderViewHost* new_host) override { | 241 content::RenderViewHost* new_host) override { |
| 236 if (!max_size_.IsEmpty()) | 242 if (!max_size_.IsEmpty()) |
| 237 EnableAutoResize(); | 243 EnableAutoResize(); |
| 238 } | 244 } |
| 239 void DocumentOnLoadCompletedInMainFrame() override { | 245 void DocumentOnLoadCompletedInMainFrame() override { |
| 240 if (!max_size_.IsEmpty() && initiator_observer_.web_contents()) { | 246 if (!max_size_.IsEmpty() && initiator_observer_.web_contents()) { |
| 241 constrained_window::ShowModalDialog(GetWidget()->GetNativeWindow(), | 247 content::WebContents* top_level_web_contents = |
| 242 initiator_observer_.web_contents()); | 248 constrained_window::GetTopLevelWebContents( |
| 249 initiator_observer_.web_contents()); |
| 250 if (top_level_web_contents) { |
| 251 constrained_window::ShowModalDialog(GetWidget()->GetNativeWindow(), |
| 252 top_level_web_contents); |
| 253 } |
| 243 } | 254 } |
| 244 } | 255 } |
| 245 | 256 |
| 246 private: | 257 private: |
| 247 void EnableAutoResize() { | 258 void EnableAutoResize() { |
| 248 content::RenderViewHost* render_view_host = | 259 content::RenderViewHost* render_view_host = |
| 249 GetWebContents()->GetRenderViewHost(); | 260 GetWebContents()->GetRenderViewHost(); |
| 250 render_view_host->EnableAutoResize(min_size_, max_size_); | 261 render_view_host->EnableAutoResize(min_size_, max_size_); |
| 251 } | 262 } |
| 252 | 263 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 280 ui::WebDialogDelegate* delegate, | 291 ui::WebDialogDelegate* delegate, |
| 281 content::WebContents* web_contents, | 292 content::WebContents* web_contents, |
| 282 const gfx::Size& min_size, | 293 const gfx::Size& min_size, |
| 283 const gfx::Size& max_size) { | 294 const gfx::Size& max_size) { |
| 284 DCHECK(!min_size.IsEmpty()); | 295 DCHECK(!min_size.IsEmpty()); |
| 285 DCHECK(!max_size.IsEmpty()); | 296 DCHECK(!max_size.IsEmpty()); |
| 286 ConstrainedWebDialogDelegateViewViews* dialog = | 297 ConstrainedWebDialogDelegateViewViews* dialog = |
| 287 new ConstrainedWebDialogDelegateViewViews( | 298 new ConstrainedWebDialogDelegateViewViews( |
| 288 browser_context, delegate, web_contents, | 299 browser_context, delegate, web_contents, |
| 289 min_size, max_size); | 300 min_size, max_size); |
| 290 constrained_window::CreateWebModalDialogViews(dialog, web_contents); | 301 |
| 302 // For embedded WebContents, use the embedder's WebContents for constrained |
| 303 // window. |
| 304 content::WebContents* top_level_web_contents = |
| 305 constrained_window::GetTopLevelWebContents(web_contents); |
| 306 DCHECK(top_level_web_contents); |
| 307 constrained_window::CreateWebModalDialogViews(dialog, top_level_web_contents); |
| 291 return dialog; | 308 return dialog; |
| 292 } | 309 } |
| OLD | NEW |