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

Side by Side Diff: chrome/browser/ui/webui/constrained_html_ui.cc

Issue 9224002: Make WebUI objects not derive from WebUI. WebUI objects own the controller. This is the ownership... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync to head to clear linux_chromeos browsertest failures Created 8 years, 11 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_html_ui.h" 5 #include "chrome/browser/ui/webui/constrained_html_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" 13 #include "base/property_bag.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/ui/webui/html_dialog_ui.h" 15 #include "chrome/browser/ui/webui/html_dialog_ui.h"
16 #include "chrome/common/chrome_notification_types.h" 16 #include "chrome/common/chrome_notification_types.h"
17 #include "content/browser/renderer_host/render_view_host.h" 17 #include "content/browser/renderer_host/render_view_host.h"
18 #include "content/browser/webui/web_ui.h"
18 #include "content/public/browser/notification_service.h" 19 #include "content/public/browser/notification_service.h"
19 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
20 21
21 using content::WebContents; 22 using content::WebContents;
22 using content::WebUIMessageHandler; 23 using content::WebUIMessageHandler;
23 24
24 static base::LazyInstance<base::PropertyAccessor<ConstrainedHtmlUIDelegate*> > 25 static base::LazyInstance<base::PropertyAccessor<ConstrainedHtmlUIDelegate*> >
25 g_constrained_html_ui_property_accessor = LAZY_INSTANCE_INITIALIZER; 26 g_constrained_html_ui_property_accessor = LAZY_INSTANCE_INITIALIZER;
26 27
27 ConstrainedHtmlUI::ConstrainedHtmlUI(WebContents* contents) 28 ConstrainedHtmlUI::ConstrainedHtmlUI(WebUI* web_ui)
28 : WebUI(contents, this) { 29 : WebUIController(web_ui) {
29 } 30 }
30 31
31 ConstrainedHtmlUI::~ConstrainedHtmlUI() { 32 ConstrainedHtmlUI::~ConstrainedHtmlUI() {
32 } 33 }
33 34
34 void ConstrainedHtmlUI::RenderViewCreated(RenderViewHost* render_view_host) { 35 void ConstrainedHtmlUI::RenderViewCreated(RenderViewHost* render_view_host) {
35 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate(); 36 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate();
36 if (!delegate) 37 if (!delegate)
37 return; 38 return;
38 39
39 HtmlDialogUIDelegate* dialog_delegate = delegate->GetHtmlDialogUIDelegate(); 40 HtmlDialogUIDelegate* dialog_delegate = delegate->GetHtmlDialogUIDelegate();
40 std::vector<WebUIMessageHandler*> handlers; 41 std::vector<WebUIMessageHandler*> handlers;
41 dialog_delegate->GetWebUIMessageHandlers(&handlers); 42 dialog_delegate->GetWebUIMessageHandlers(&handlers);
42 render_view_host->SetWebUIProperty("dialogArguments", 43 render_view_host->SetWebUIProperty("dialogArguments",
43 dialog_delegate->GetDialogArgs()); 44 dialog_delegate->GetDialogArgs());
44 for (std::vector<WebUIMessageHandler*>::iterator it = handlers.begin(); 45 for (std::vector<WebUIMessageHandler*>::iterator it = handlers.begin();
45 it != handlers.end(); ++it) { 46 it != handlers.end(); ++it) {
46 AddMessageHandler(*it); 47 web_ui()->AddMessageHandler(*it);
47 } 48 }
48 49
49 // Add a "DialogClose" callback which matches HTMLDialogUI behavior. 50 // Add a "DialogClose" callback which matches HTMLDialogUI behavior.
50 RegisterMessageCallback("DialogClose", 51 web_ui()->RegisterMessageCallback("DialogClose",
51 base::Bind(&ConstrainedHtmlUI::OnDialogCloseMessage, 52 base::Bind(&ConstrainedHtmlUI::OnDialogCloseMessage,
52 base::Unretained(this))); 53 base::Unretained(this)));
53 54
54 content::NotificationService::current()->Notify( 55 content::NotificationService::current()->Notify(
55 chrome::NOTIFICATION_HTML_DIALOG_SHOWN, 56 chrome::NOTIFICATION_HTML_DIALOG_SHOWN,
56 content::Source<WebUI>(this), 57 content::Source<WebUI>(web_ui()),
57 content::Details<RenderViewHost>(render_view_host)); 58 content::Details<RenderViewHost>(render_view_host));
58 } 59 }
59 60
60 void ConstrainedHtmlUI::OnDialogCloseMessage(const ListValue* args) { 61 void ConstrainedHtmlUI::OnDialogCloseMessage(const ListValue* args) {
61 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate(); 62 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate();
62 if (!delegate) 63 if (!delegate)
63 return; 64 return;
64 65
65 std::string json_retval; 66 std::string json_retval;
66 if (!args->empty() && !args->GetString(0, &json_retval)) 67 if (!args->empty() && !args->GetString(0, &json_retval))
67 NOTREACHED() << "Could not read JSON argument"; 68 NOTREACHED() << "Could not read JSON argument";
68 delegate->GetHtmlDialogUIDelegate()->OnDialogClosed(json_retval); 69 delegate->GetHtmlDialogUIDelegate()->OnDialogClosed(json_retval);
69 delegate->OnDialogCloseFromWebUI(); 70 delegate->OnDialogCloseFromWebUI();
70 } 71 }
71 72
72 ConstrainedHtmlUIDelegate* ConstrainedHtmlUI::GetConstrainedDelegate() { 73 ConstrainedHtmlUIDelegate* ConstrainedHtmlUI::GetConstrainedDelegate() {
73 ConstrainedHtmlUIDelegate** property = 74 ConstrainedHtmlUIDelegate** property = GetPropertyAccessor().GetProperty(
74 GetPropertyAccessor().GetProperty(web_contents()->GetPropertyBag()); 75 web_ui()->web_contents()->GetPropertyBag());
75 return property ? *property : NULL; 76 return property ? *property : NULL;
76 } 77 }
77 78
78 // static 79 // static
79 base::PropertyAccessor<ConstrainedHtmlUIDelegate*>& 80 base::PropertyAccessor<ConstrainedHtmlUIDelegate*>&
80 ConstrainedHtmlUI::GetPropertyAccessor() { 81 ConstrainedHtmlUI::GetPropertyAccessor() {
81 return g_constrained_html_ui_property_accessor.Get(); 82 return g_constrained_html_ui_property_accessor.Get();
82 } 83 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698