summaryrefslogtreecommitdiffstats
path: root/ui/web_dialogs
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-23 00:03:11 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-23 00:03:11 +0000
commit36a22c4003317b933133d474f49cb5f97ed37e90 (patch)
treecd4ef16c2bbf798a73b1dda6058dde7c10d02415 /ui/web_dialogs
parent7cee190f9eaf5b9715057b2c66d8804fa34ed442 (diff)
downloadchromium_src-36a22c4003317b933133d474f49cb5f97ed37e90.zip
chromium_src-36a22c4003317b933133d474f49cb5f97ed37e90.tar.gz
chromium_src-36a22c4003317b933133d474f49cb5f97ed37e90.tar.bz2
Kill PropertyBag, switch WebContents to SupportsUserData.
BUG=141177 TEST=no visible change Review URL: https://chromiumcodereview.appspot.com/10831407 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152882 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/web_dialogs')
-rw-r--r--ui/web_dialogs/constrained_web_dialog_ui.cc48
-rw-r--r--ui/web_dialogs/constrained_web_dialog_ui.h16
-rw-r--r--ui/web_dialogs/web_dialog_ui.cc55
-rw-r--r--ui/web_dialogs/web_dialog_ui.h27
4 files changed, 93 insertions, 53 deletions
diff --git a/ui/web_dialogs/constrained_web_dialog_ui.cc b/ui/web_dialogs/constrained_web_dialog_ui.cc
index 13a40ab..b14b5ca 100644
--- a/ui/web_dialogs/constrained_web_dialog_ui.cc
+++ b/ui/web_dialogs/constrained_web_dialog_ui.cc
@@ -10,7 +10,6 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/lazy_instance.h"
-#include "base/property_bag.h"
#include "base/values.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_view_host.h"
@@ -23,12 +22,30 @@ using content::RenderViewHost;
using content::WebContents;
using content::WebUIMessageHandler;
-static base::LazyInstance<
- base::PropertyAccessor<ui::ConstrainedWebDialogDelegate*> >
- g_constrained_web_dialog_ui_property_accessor = LAZY_INSTANCE_INITIALIZER;
-
namespace ui {
+namespace {
+
+const char kConstrainedWebDialogDelegateUserDataKey[] =
+ "ConstrainedWebDialogDelegateUserData";
+
+class ConstrainedWebDialogDelegateUserData
+ : public base::SupportsUserData::Data {
+ public:
+ explicit ConstrainedWebDialogDelegateUserData(
+ ConstrainedWebDialogDelegate* delegate) : delegate_(delegate) {}
+ virtual ~ConstrainedWebDialogDelegateUserData() {}
+
+ ConstrainedWebDialogDelegate* delegate() { return delegate_; }
+
+ private:
+ ConstrainedWebDialogDelegate* delegate_; // unowned
+
+ DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateUserData);
+};
+
+} // namespace
+
ConstrainedWebDialogUI::ConstrainedWebDialogUI(content::WebUI* web_ui)
: WebUIController(web_ui) {
}
@@ -72,16 +89,21 @@ void ConstrainedWebDialogUI::OnDialogCloseMessage(const ListValue* args) {
delegate->OnDialogCloseFromWebUI();
}
-ConstrainedWebDialogDelegate* ConstrainedWebDialogUI::GetConstrainedDelegate() {
- ConstrainedWebDialogDelegate** property = GetPropertyAccessor().GetProperty(
- web_ui()->GetWebContents()->GetPropertyBag());
- return property ? *property : NULL;
+// static
+void ConstrainedWebDialogUI::SetConstrainedDelegate(
+ content::WebContents* web_contents,
+ ConstrainedWebDialogDelegate* delegate) {
+ web_contents->SetUserData(&kConstrainedWebDialogDelegateUserDataKey,
+ new ConstrainedWebDialogDelegateUserData(delegate));
}
-// static
-base::PropertyAccessor<ConstrainedWebDialogDelegate*>&
- ConstrainedWebDialogUI::GetPropertyAccessor() {
- return g_constrained_web_dialog_ui_property_accessor.Get();
+ConstrainedWebDialogDelegate* ConstrainedWebDialogUI::GetConstrainedDelegate() {
+ ConstrainedWebDialogDelegateUserData* user_data =
+ static_cast<ConstrainedWebDialogDelegateUserData*>(
+ web_ui()->GetWebContents()->
+ GetUserData(&kConstrainedWebDialogDelegateUserDataKey));
+
+ return user_data ? user_data->delegate() : NULL;
}
} // namespace ui
diff --git a/ui/web_dialogs/constrained_web_dialog_ui.h b/ui/web_dialogs/constrained_web_dialog_ui.h
index 4837c5f..04e9084 100644
--- a/ui/web_dialogs/constrained_web_dialog_ui.h
+++ b/ui/web_dialogs/constrained_web_dialog_ui.h
@@ -13,12 +13,9 @@ class ConstrainedWindow;
class Profile;
class TabContents;
-namespace base {
-template<class T> class PropertyAccessor;
-}
-
namespace content {
class RenderViewHost;
+class WebContents;
}
namespace ui {
@@ -69,14 +66,13 @@ class WEB_DIALOGS_EXPORT ConstrainedWebDialogUI
virtual void RenderViewCreated(
content::RenderViewHost* render_view_host) OVERRIDE;
- // Returns a property accessor that can be used to set the
- // ConstrainedWebDialogDelegate property on a WebContents.
- static base::PropertyAccessor<ConstrainedWebDialogDelegate*>&
- GetPropertyAccessor();
+ // Sets the delegate on the WebContents.
+ static void SetConstrainedDelegate(content::WebContents* web_contents,
+ ConstrainedWebDialogDelegate* delegate);
protected:
- // Returns the WebContents' PropertyBag's ConstrainedWebDialogDelegate.
- // Returns NULL if that property is not set.
+ // Returns the ConstrainedWebDialogDelegate saved with the WebContents.
+ // Returns NULL if no such delegate is set.
ConstrainedWebDialogDelegate* GetConstrainedDelegate();
private:
diff --git a/ui/web_dialogs/web_dialog_ui.cc b/ui/web_dialogs/web_dialog_ui.cc
index 2ef0f91..5f87096 100644
--- a/ui/web_dialogs/web_dialog_ui.cc
+++ b/ui/web_dialogs/web_dialog_ui.cc
@@ -7,7 +7,6 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/lazy_instance.h"
-#include "base/property_bag.h"
#include "base/values.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_view_host.h"
@@ -20,22 +19,36 @@
using content::RenderViewHost;
using content::WebUIMessageHandler;
-static base::LazyInstance<base::PropertyAccessor<ui::WebDialogDelegate*> >
- g_web_dialog_ui_property_accessor = LAZY_INSTANCE_INITIALIZER;
-
namespace ui {
+namespace {
+
+const char kWebDialogDelegateUserDataKey[] = "WebDialogDelegateUserData";
+
+class WebDialogDelegateUserData : public base::SupportsUserData::Data {
+ public:
+ explicit WebDialogDelegateUserData(WebDialogDelegate* delegate)
+ : delegate_(delegate) {}
+ virtual ~WebDialogDelegateUserData() {}
+ WebDialogDelegate* delegate() { return delegate_; }
+
+ private:
+ WebDialogDelegate* delegate_; // unowned
+};
+
+} // namespace
+
WebDialogUI::WebDialogUI(content::WebUI* web_ui)
: WebUIController(web_ui) {
}
WebDialogUI::~WebDialogUI() {
- // Don't unregister our property. During the teardown of the WebContents,
+ // Don't unregister our user data. During the teardown of the WebContents,
// this will be deleted, but the WebContents will already be destroyed.
//
// This object is owned indirectly by the WebContents. WebUIs can change, so
// it's scary if this WebUI is changed out and replaced with something else,
- // since the property will still point to the old delegate. But the delegate
+ // since the user data will still point to the old delegate. But the delegate
// is itself the owner of the WebContents for a dialog so will be in scope,
// and the HTML dialogs won't swap WebUIs anyway since they don't navigate.
}
@@ -45,13 +58,25 @@ void WebDialogUI::CloseDialog(const base::ListValue* args) {
}
// static
-base::PropertyAccessor<WebDialogDelegate*>& WebDialogUI::GetPropertyAccessor() {
- return g_web_dialog_ui_property_accessor.Get();
+void WebDialogUI::SetDelegate(content::WebContents* web_contents,
+ WebDialogDelegate* delegate) {
+ web_contents->SetUserData(&kWebDialogDelegateUserDataKey,
+ new WebDialogDelegateUserData(delegate));
}
////////////////////////////////////////////////////////////////////////////////
// Private:
+WebDialogDelegate* WebDialogUI::GetDelegate(
+ content::WebContents* web_contents) {
+ WebDialogDelegateUserData* user_data =
+ static_cast<WebDialogDelegateUserData*>(
+ web_contents->GetUserData(&kWebDialogDelegateUserDataKey));
+
+ return user_data ? user_data->delegate() : NULL;
+}
+
+
void WebDialogUI::RenderViewCreated(RenderViewHost* render_view_host) {
// Hook up the javascript function calls, also known as chrome.send("foo")
// calls in the HTML, to the actual C++ functions.
@@ -61,11 +86,10 @@ void WebDialogUI::RenderViewCreated(RenderViewHost* render_view_host) {
// Pass the arguments to the renderer supplied by the delegate.
std::string dialog_args;
std::vector<WebUIMessageHandler*> handlers;
- WebDialogDelegate** delegate = GetPropertyAccessor().GetProperty(
- web_ui()->GetWebContents()->GetPropertyBag());
+ WebDialogDelegate* delegate = GetDelegate(web_ui()->GetWebContents());
if (delegate) {
- dialog_args = (*delegate)->GetDialogArgs();
- (*delegate)->GetWebUIMessageHandlers(&handlers);
+ dialog_args = delegate->GetDialogArgs();
+ delegate->GetWebUIMessageHandlers(&handlers);
}
if (0 != (web_ui()->GetBindings() & content::BINDINGS_POLICY_WEB_UI))
@@ -76,18 +100,17 @@ void WebDialogUI::RenderViewCreated(RenderViewHost* render_view_host) {
}
if (delegate)
- (*delegate)->OnDialogShown(web_ui(), render_view_host);
+ delegate->OnDialogShown(web_ui(), render_view_host);
}
void WebDialogUI::OnDialogClosed(const ListValue* args) {
- WebDialogDelegate** delegate = GetPropertyAccessor().GetProperty(
- web_ui()->GetWebContents()->GetPropertyBag());
+ WebDialogDelegate* delegate = GetDelegate(web_ui()->GetWebContents());
if (delegate) {
std::string json_retval;
if (args && !args->empty() && !args->GetString(0, &json_retval))
NOTREACHED() << "Could not read JSON argument";
- (*delegate)->OnDialogClosed(json_retval);
+ delegate->OnDialogClosed(json_retval);
}
}
diff --git a/ui/web_dialogs/web_dialog_ui.h b/ui/web_dialogs/web_dialog_ui.h
index 562cbb4..e6e29f4 100644
--- a/ui/web_dialogs/web_dialog_ui.h
+++ b/ui/web_dialogs/web_dialog_ui.h
@@ -16,12 +16,6 @@
#include "ui/base/ui_base_types.h"
#include "ui/web_dialogs/web_dialogs_export.h"
-
-namespace base {
-class ListValue;
-template<class T> class PropertyAccessor;
-}
-
namespace content {
class WebContents;
class WebUIMessageHandler;
@@ -42,10 +36,11 @@ class WebDialogDelegate;
// just embed a RenderView in a dialog and be done with it.
//
// Before loading a URL corresponding to this WebUI, the caller should set its
-// delegate as a property on the WebContents. This WebUI will pick it up from
-// there and call it back. This is a bit of a hack to allow the dialog to pass
-// its delegate to the Web UI without having nasty accessors on the WebContents.
-// The correct design using RVH directly would avoid all of this.
+// delegate as user data on the WebContents by calling SetDelegate(). This WebUI
+// will pick it up from there and call it back. This is a bit of a hack to allow
+// the dialog to pass its delegate to the Web UI without having nasty accessors
+// on the WebContents. The correct design using RVH directly would avoid all of
+// this.
class WEB_DIALOGS_EXPORT WebDialogUI : public content::WebUIController {
public:
struct WebDialogParams {
@@ -59,22 +54,26 @@ class WEB_DIALOGS_EXPORT WebDialogUI : public content::WebUIController {
std::string json_input;
};
- // When created, the property should already be set on the WebContents.
+ // When created, the delegate should already be set as user data on the
+ // WebContents.
explicit WebDialogUI(content::WebUI* web_ui);
virtual ~WebDialogUI();
// Close the dialog, passing the specified arguments to the close handler.
void CloseDialog(const base::ListValue* args);
- // Returns the PropertyBag accessor object used to write the delegate pointer
- // into the WebContents (see class-level comment above).
- static base::PropertyAccessor<WebDialogDelegate*>& GetPropertyAccessor();
+ // Sets the delegate on the WebContents.
+ static void SetDelegate(content::WebContents* web_contents,
+ WebDialogDelegate* delegate);
private:
// WebUIController
virtual void RenderViewCreated(
content::RenderViewHost* render_view_host) OVERRIDE;
+ // Gets the delegate for the WebContent set with SetDelegate.
+ static WebDialogDelegate* GetDelegate(content::WebContents* web_contents);
+
// JS message handler.
void OnDialogClosed(const base::ListValue* args);