web_dialog_web_contents_delegate.cc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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
  3. // found in the LICENSE file.
  4. #include "ui/web_dialogs/web_dialog_web_contents_delegate.h"
  5. #include <utility>
  6. #include "base/check.h"
  7. #include "content/public/browser/file_select_listener.h"
  8. #include "content/public/browser/web_contents.h"
  9. #include "third_party/blink/public/common/input/web_gesture_event.h"
  10. using content::BrowserContext;
  11. using content::OpenURLParams;
  12. using content::WebContents;
  13. namespace ui {
  14. // Incognito profiles are not long-lived, so we always want to store a
  15. // non-incognito profile.
  16. //
  17. // TODO(akalin): Should we make it so that we have a default incognito
  18. // profile that's long-lived? Of course, we'd still have to clear it out
  19. // when all incognito browsers close.
  20. WebDialogWebContentsDelegate::WebDialogWebContentsDelegate(
  21. content::BrowserContext* browser_context,
  22. std::unique_ptr<WebContentsHandler> handler)
  23. : browser_context_(browser_context), handler_(std::move(handler)) {
  24. DCHECK(handler_);
  25. }
  26. WebDialogWebContentsDelegate::~WebDialogWebContentsDelegate() {
  27. }
  28. void WebDialogWebContentsDelegate::Detach() {
  29. browser_context_ = nullptr;
  30. }
  31. WebContents* WebDialogWebContentsDelegate::OpenURLFromTab(
  32. WebContents* source, const OpenURLParams& params) {
  33. return handler_->OpenURLFromTab(browser_context_, source, params);
  34. }
  35. void WebDialogWebContentsDelegate::AddNewContents(
  36. WebContents* source,
  37. std::unique_ptr<WebContents> new_contents,
  38. const GURL& target_url,
  39. WindowOpenDisposition disposition,
  40. const gfx::Rect& initial_rect,
  41. bool user_gesture,
  42. bool* was_blocked) {
  43. // TODO(erikchen): Refactor AddNewContents to take strong ownership semantics.
  44. // https://crbug.com/832879.
  45. handler_->AddNewContents(browser_context_, source, std::move(new_contents),
  46. target_url, disposition, initial_rect, user_gesture);
  47. }
  48. bool WebDialogWebContentsDelegate::PreHandleGestureEvent(
  49. WebContents* source,
  50. const blink::WebGestureEvent& event) {
  51. // Disable pinch zooming.
  52. return blink::WebInputEvent::IsPinchGestureEventType(event.GetType());
  53. }
  54. void WebDialogWebContentsDelegate::RunFileChooser(
  55. content::RenderFrameHost* render_frame_host,
  56. scoped_refptr<content::FileSelectListener> listener,
  57. const blink::mojom::FileChooserParams& params) {
  58. handler_->RunFileChooser(render_frame_host, listener, params);
  59. }
  60. } // namespace ui