diff options
author | mazda@chromium.org <mazda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-20 06:20:08 +0000 |
---|---|---|
committer | mazda@chromium.org <mazda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-20 06:20:08 +0000 |
commit | 41c5a18eaf43bfb282dacc9c3a7a5d0ffa258982 (patch) | |
tree | b3c7d3e1c2f06932537e4e98c95d46786490fbef /ui/web_dialogs | |
parent | ff6256104abc7e766684f28ef4c42b945fd3225e (diff) | |
download | chromium_src-41c5a18eaf43bfb282dacc9c3a7a5d0ffa258982.zip chromium_src-41c5a18eaf43bfb282dacc9c3a7a5d0ffa258982.tar.gz chromium_src-41c5a18eaf43bfb282dacc9c3a7a5d0ffa258982.tar.bz2 |
Move WebDialogWebContentsDelegate to ui/web_dialogs.
Also move WebDialogWebContentsDelegate into ui namespace.
BUG=124222,125841
TEST=None
Review URL: https://chromiumcodereview.appspot.com/10796049
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147620 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/web_dialogs')
-rw-r--r-- | ui/web_dialogs/constrained_web_dialog_ui.h | 2 | ||||
-rw-r--r-- | ui/web_dialogs/web_dialog_web_contents_delegate.cc | 63 | ||||
-rw-r--r-- | ui/web_dialogs/web_dialog_web_contents_delegate.h | 82 | ||||
-rw-r--r-- | ui/web_dialogs/web_dialogs.gyp | 2 |
4 files changed, 148 insertions, 1 deletions
diff --git a/ui/web_dialogs/constrained_web_dialog_ui.h b/ui/web_dialogs/constrained_web_dialog_ui.h index 45da6ef..4837c5f 100644 --- a/ui/web_dialogs/constrained_web_dialog_ui.h +++ b/ui/web_dialogs/constrained_web_dialog_ui.h @@ -12,7 +12,6 @@ class ConstrainedWindow; class Profile; class TabContents; -class WebDialogWebContentsDelegate; namespace base { template<class T> class PropertyAccessor; @@ -24,6 +23,7 @@ class RenderViewHost; namespace ui { class WebDialogDelegate; +class WebDialogWebContentsDelegate; class WEB_DIALOGS_EXPORT ConstrainedWebDialogDelegate { public: diff --git a/ui/web_dialogs/web_dialog_web_contents_delegate.cc b/ui/web_dialogs/web_dialog_web_contents_delegate.cc new file mode 100644 index 0000000..19d97a5 --- /dev/null +++ b/ui/web_dialogs/web_dialog_web_contents_delegate.cc @@ -0,0 +1,63 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/web_dialogs/web_dialog_web_contents_delegate.h" + +#include "base/logging.h" +#include "content/public/browser/web_contents.h" + +using content::BrowserContext; +using content::OpenURLParams; +using content::WebContents; + +namespace ui { + +// Incognito profiles are not long-lived, so we always want to store a +// non-incognito profile. +// +// TODO(akalin): Should we make it so that we have a default incognito +// profile that's long-lived? Of course, we'd still have to clear it out +// when all incognito browsers close. +WebDialogWebContentsDelegate::WebDialogWebContentsDelegate( + content::BrowserContext* browser_context, + WebContentsHandler* handler) + : browser_context_(browser_context), + handler_(handler) { + CHECK(handler_.get()); +} + +WebDialogWebContentsDelegate::~WebDialogWebContentsDelegate() { +} + +void WebDialogWebContentsDelegate::Detach() { + browser_context_ = NULL; +} + +WebContents* WebDialogWebContentsDelegate::OpenURLFromTab( + WebContents* source, const OpenURLParams& params) { + return handler_->OpenURLFromTab(browser_context_, source, params); +} + +void WebDialogWebContentsDelegate::AddNewContents( + WebContents* source, WebContents* new_contents, + WindowOpenDisposition disposition, const gfx::Rect& initial_pos, + bool user_gesture) { + handler_->AddNewContents(browser_context_, source, new_contents, disposition, + initial_pos, user_gesture); +} + +bool WebDialogWebContentsDelegate::IsPopupOrPanel( + const WebContents* source) const { + // This needs to return true so that we are allowed to be resized by our + // contents. + return true; +} + +bool WebDialogWebContentsDelegate::ShouldAddNavigationToHistory( + const history::HistoryAddPageArgs& add_page_args, + content::NavigationType navigation_type) { + return false; +} + +} // namespace ui diff --git a/ui/web_dialogs/web_dialog_web_contents_delegate.h b/ui/web_dialogs/web_dialog_web_contents_delegate.h new file mode 100644 index 0000000..e7965c9 --- /dev/null +++ b/ui/web_dialogs/web_dialog_web_contents_delegate.h @@ -0,0 +1,82 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_WEB_DIALOGS_WEB_DIALOG_WEB_CONTENTS_DELEGATE_H_ +#define UI_WEB_DIALOGS_WEB_DIALOG_WEB_CONTENTS_DELEGATE_H_ + +#include "base/compiler_specific.h" +#include "content/public/browser/web_contents_delegate.h" +#include "ui/web_dialogs/web_dialogs_export.h" + +namespace ui { + +// This class implements (and mostly ignores) most of +// content::WebContentsDelegate for use in a Web dialog. Subclasses need only +// override a few methods instead of the everything from +// content::WebContentsDelegate; this way, implementations on all platforms +// behave consistently. +class WEB_DIALOGS_EXPORT WebDialogWebContentsDelegate + : public content::WebContentsDelegate { + public: + // Handles OpenURLFromTab and AddNewContents for WebDialogWebContentsDelegate. + class WebContentsHandler { + public: + virtual ~WebContentsHandler() {} + virtual content::WebContents* OpenURLFromTab( + content::BrowserContext* context, + content::WebContents* source, + const content::OpenURLParams& params) = 0; + virtual void AddNewContents(content::BrowserContext* context, + content::WebContents* source, + content::WebContents* new_contents, + WindowOpenDisposition disposition, + const gfx::Rect& initial_pos, + bool user_gesture) = 0; + }; + + // context and handler must be non-NULL. + // Takes the ownership of handler. + WebDialogWebContentsDelegate(content::BrowserContext* context, + WebContentsHandler* handler); + + virtual ~WebDialogWebContentsDelegate(); + + // The returned browser context is guaranteed to be original if non-NULL. + content::BrowserContext* browser_context() const { + return browser_context_; + } + + // Calling this causes all following events sent from the + // WebContents object to be ignored. It also makes all following + // calls to browser_context() return NULL. + void Detach(); + + // content::WebContentsDelegate declarations. + virtual content::WebContents* OpenURLFromTab( + content::WebContents* source, + const content::OpenURLParams& params) OVERRIDE; + + virtual void AddNewContents(content::WebContents* source, + content::WebContents* new_contents, + WindowOpenDisposition disposition, + const gfx::Rect& initial_pos, + bool user_gesture) OVERRIDE; + virtual bool IsPopupOrPanel( + const content::WebContents* source) const OVERRIDE; + virtual bool ShouldAddNavigationToHistory( + const history::HistoryAddPageArgs& add_page_args, + content::NavigationType navigation_type) OVERRIDE; + + private: + // Weak pointer. Always an original profile. + content::BrowserContext* browser_context_; + + scoped_ptr<WebContentsHandler> handler_; + + DISALLOW_COPY_AND_ASSIGN(WebDialogWebContentsDelegate); +}; + +} // namespace ui + +#endif // UI_WEB_DIALOGS_WEB_DIALOG_WEB_CONTENTS_DELEGATE_H_ diff --git a/ui/web_dialogs/web_dialogs.gyp b/ui/web_dialogs/web_dialogs.gyp index fc32c9a..12be315 100644 --- a/ui/web_dialogs/web_dialogs.gyp +++ b/ui/web_dialogs/web_dialogs.gyp @@ -28,6 +28,8 @@ 'web_dialog_observer.h', 'web_dialog_ui.cc', 'web_dialog_ui.h', + 'web_dialog_web_contents_delegate.cc', + 'web_dialog_web_contents_delegate.h', 'web_dialogs_export.h', ], }, |