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

Side by Side Diff: ui/web_dialogs/constrained_web_dialog_ui.cc

Issue 10831407: Kill PropertyBag, switch WebContents to SupportsUserData. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: works Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « ui/web_dialogs/constrained_web_dialog_ui.h ('k') | ui/web_dialogs/web_dialog_ui.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ui/web_dialogs/constrained_web_dialog_ui.h" 5 #include "ui/web_dialogs/constrained_web_dialog_ui.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/property_bag.h"
14 #include "base/values.h" 13 #include "base/values.h"
15 #include "content/public/browser/notification_service.h" 14 #include "content/public/browser/notification_service.h"
16 #include "content/public/browser/render_view_host.h" 15 #include "content/public/browser/render_view_host.h"
17 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
18 #include "content/public/browser/web_ui.h" 17 #include "content/public/browser/web_ui.h"
19 #include "ui/web_dialogs/web_dialog_delegate.h" 18 #include "ui/web_dialogs/web_dialog_delegate.h"
20 #include "ui/web_dialogs/web_dialog_ui.h" 19 #include "ui/web_dialogs/web_dialog_ui.h"
21 20
22 using content::RenderViewHost; 21 using content::RenderViewHost;
23 using content::WebContents; 22 using content::WebContents;
24 using content::WebUIMessageHandler; 23 using content::WebUIMessageHandler;
25 24
26 static base::LazyInstance< 25 namespace ui {
27 base::PropertyAccessor<ui::ConstrainedWebDialogDelegate*> >
28 g_constrained_web_dialog_ui_property_accessor = LAZY_INSTANCE_INITIALIZER;
29 26
30 namespace ui { 27 namespace {
28
29 const char kConstrainedWebDialogDelegateUserDataKey[] =
30 "ConstrainedWebDialogDelegateUserData";
31
32 class ConstrainedWebDialogDelegateUserData
33 : public base::SupportsUserData::Data {
34 public:
35 explicit ConstrainedWebDialogDelegateUserData(
36 ConstrainedWebDialogDelegate* delegate) : delegate_(delegate) {}
37 virtual ~ConstrainedWebDialogDelegateUserData() {}
38 ConstrainedWebDialogDelegate* delegate() { return delegate_; }
Ben Goodger (Google) 2012/08/22 19:43:29 nit: nl above
39
40 private:
41 ConstrainedWebDialogDelegate* delegate_; // unowned
42 };
Ben Goodger (Google) 2012/08/22 19:43:29 DISALLOW_COPY_AND..
43
44 } // namespace
31 45
32 ConstrainedWebDialogUI::ConstrainedWebDialogUI(content::WebUI* web_ui) 46 ConstrainedWebDialogUI::ConstrainedWebDialogUI(content::WebUI* web_ui)
33 : WebUIController(web_ui) { 47 : WebUIController(web_ui) {
34 } 48 }
35 49
36 ConstrainedWebDialogUI::~ConstrainedWebDialogUI() { 50 ConstrainedWebDialogUI::~ConstrainedWebDialogUI() {
37 } 51 }
38 52
39 void ConstrainedWebDialogUI::RenderViewCreated( 53 void ConstrainedWebDialogUI::RenderViewCreated(
40 RenderViewHost* render_view_host) { 54 RenderViewHost* render_view_host) {
(...skipping 24 matching lines...) Expand all
65 if (!delegate) 79 if (!delegate)
66 return; 80 return;
67 81
68 std::string json_retval; 82 std::string json_retval;
69 if (!args->empty() && !args->GetString(0, &json_retval)) 83 if (!args->empty() && !args->GetString(0, &json_retval))
70 NOTREACHED() << "Could not read JSON argument"; 84 NOTREACHED() << "Could not read JSON argument";
71 delegate->GetWebDialogDelegate()->OnDialogClosed(json_retval); 85 delegate->GetWebDialogDelegate()->OnDialogClosed(json_retval);
72 delegate->OnDialogCloseFromWebUI(); 86 delegate->OnDialogCloseFromWebUI();
73 } 87 }
74 88
75 ConstrainedWebDialogDelegate* ConstrainedWebDialogUI::GetConstrainedDelegate() { 89 // static
76 ConstrainedWebDialogDelegate** property = GetPropertyAccessor().GetProperty( 90 void ConstrainedWebDialogUI::SetConstrainedDelegate(
77 web_ui()->GetWebContents()->GetPropertyBag()); 91 content::WebContents* web_contents,
78 return property ? *property : NULL; 92 ConstrainedWebDialogDelegate* delegate) {
93 web_contents->SetUserData(&kConstrainedWebDialogDelegateUserDataKey,
94 new ConstrainedWebDialogDelegateUserData(delegate));
79 } 95 }
80 96
81 // static 97 ConstrainedWebDialogDelegate* ConstrainedWebDialogUI::GetConstrainedDelegate() {
82 base::PropertyAccessor<ConstrainedWebDialogDelegate*>& 98 ConstrainedWebDialogDelegateUserData* user_data =
83 ConstrainedWebDialogUI::GetPropertyAccessor() { 99 static_cast<ConstrainedWebDialogDelegateUserData*>(
84 return g_constrained_web_dialog_ui_property_accessor.Get(); 100 web_ui()->GetWebContents()->
101 GetUserData(&kConstrainedWebDialogDelegateUserDataKey));
102
103 return user_data ? user_data->delegate() : NULL;
85 } 104 }
86 105
87 } // namespace ui 106 } // namespace ui
OLDNEW
« no previous file with comments | « ui/web_dialogs/constrained_web_dialog_ui.h ('k') | ui/web_dialogs/web_dialog_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698