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

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

Issue 10214001: WebDialogs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 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) 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 "chrome/browser/ui/webui/constrained_html_ui.h" 5 #include "chrome/browser/ui/webui/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" 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/web_dialog_ui.h"
16 #include "chrome/common/chrome_notification_types.h" 16 #include "chrome/common/chrome_notification_types.h"
17 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
18 #include "content/public/browser/render_view_host.h" 18 #include "content/public/browser/render_view_host.h"
19 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
20 #include "content/public/browser/web_ui.h" 20 #include "content/public/browser/web_ui.h"
21 21
22 using content::RenderViewHost; 22 using content::RenderViewHost;
23 using content::WebContents; 23 using content::WebContents;
24 using content::WebUIMessageHandler; 24 using content::WebUIMessageHandler;
25 25
26 static base::LazyInstance<base::PropertyAccessor<ConstrainedHtmlUIDelegate*> > 26 static base::LazyInstance<base::PropertyAccessor<ConstrainedWebDialogDelegate*> >
27 g_constrained_html_ui_property_accessor = LAZY_INSTANCE_INITIALIZER; 27 g_constrained_web_dialog_ui_property_accessor = LAZY_INSTANCE_INITIALIZER;
28 28
29 ConstrainedHtmlUI::ConstrainedHtmlUI(content::WebUI* web_ui) 29 ConstrainedWebDialogUI::ConstrainedWebDialogUI(content::WebUI* web_ui)
30 : WebUIController(web_ui) { 30 : WebUIController(web_ui) {
31 } 31 }
32 32
33 ConstrainedHtmlUI::~ConstrainedHtmlUI() { 33 ConstrainedWebDialogUI::~ConstrainedWebDialogUI() {
34 } 34 }
35 35
36 void ConstrainedHtmlUI::RenderViewCreated(RenderViewHost* render_view_host) { 36 void ConstrainedWebDialogUI::RenderViewCreated(
37 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate(); 37 RenderViewHost* render_view_host) {
38 ConstrainedWebDialogDelegate* delegate = GetConstrainedDelegate();
38 if (!delegate) 39 if (!delegate)
39 return; 40 return;
40 41
41 HtmlDialogUIDelegate* dialog_delegate = delegate->GetHtmlDialogUIDelegate(); 42 WebDialogDelegate* dialog_delegate = delegate->GetWebDialogDelegate();
42 std::vector<WebUIMessageHandler*> handlers; 43 std::vector<WebUIMessageHandler*> handlers;
43 dialog_delegate->GetWebUIMessageHandlers(&handlers); 44 dialog_delegate->GetWebUIMessageHandlers(&handlers);
44 render_view_host->SetWebUIProperty("dialogArguments", 45 render_view_host->SetWebUIProperty("dialogArguments",
45 dialog_delegate->GetDialogArgs()); 46 dialog_delegate->GetDialogArgs());
46 for (std::vector<WebUIMessageHandler*>::iterator it = handlers.begin(); 47 for (std::vector<WebUIMessageHandler*>::iterator it = handlers.begin();
47 it != handlers.end(); ++it) { 48 it != handlers.end(); ++it) {
48 web_ui()->AddMessageHandler(*it); 49 web_ui()->AddMessageHandler(*it);
49 } 50 }
50 51
51 // Add a "DialogClose" callback which matches HTMLDialogUI behavior. 52 // Add a "DialogClose" callback which matches HTMLDialogUI behavior.
52 web_ui()->RegisterMessageCallback("DialogClose", 53 web_ui()->RegisterMessageCallback("DialogClose",
53 base::Bind(&ConstrainedHtmlUI::OnDialogCloseMessage, 54 base::Bind(&ConstrainedWebDialogUI::OnDialogCloseMessage,
54 base::Unretained(this))); 55 base::Unretained(this)));
55 56
56 content::NotificationService::current()->Notify( 57 content::NotificationService::current()->Notify(
57 chrome::NOTIFICATION_HTML_DIALOG_SHOWN, 58 chrome::NOTIFICATION_HTML_DIALOG_SHOWN,
58 content::Source<content::WebUI>(web_ui()), 59 content::Source<content::WebUI>(web_ui()),
59 content::Details<RenderViewHost>(render_view_host)); 60 content::Details<RenderViewHost>(render_view_host));
60 } 61 }
61 62
62 void ConstrainedHtmlUI::OnDialogCloseMessage(const ListValue* args) { 63 void ConstrainedWebDialogUI::OnDialogCloseMessage(const ListValue* args) {
63 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate(); 64 ConstrainedWebDialogDelegate* delegate = GetConstrainedDelegate();
64 if (!delegate) 65 if (!delegate)
65 return; 66 return;
66 67
67 std::string json_retval; 68 std::string json_retval;
68 if (!args->empty() && !args->GetString(0, &json_retval)) 69 if (!args->empty() && !args->GetString(0, &json_retval))
69 NOTREACHED() << "Could not read JSON argument"; 70 NOTREACHED() << "Could not read JSON argument";
70 delegate->GetHtmlDialogUIDelegate()->OnDialogClosed(json_retval); 71 delegate->GetWebDialogDelegate()->OnDialogClosed(json_retval);
71 delegate->OnDialogCloseFromWebUI(); 72 delegate->OnDialogCloseFromWebUI();
72 } 73 }
73 74
74 ConstrainedHtmlUIDelegate* ConstrainedHtmlUI::GetConstrainedDelegate() { 75 ConstrainedWebDialogDelegate* ConstrainedWebDialogUI::GetConstrainedDelegate() {
75 ConstrainedHtmlUIDelegate** property = GetPropertyAccessor().GetProperty( 76 ConstrainedWebDialogDelegate** property = GetPropertyAccessor().GetProperty(
76 web_ui()->GetWebContents()->GetPropertyBag()); 77 web_ui()->GetWebContents()->GetPropertyBag());
77 return property ? *property : NULL; 78 return property ? *property : NULL;
78 } 79 }
79 80
80 // static 81 // static
81 base::PropertyAccessor<ConstrainedHtmlUIDelegate*>& 82 base::PropertyAccessor<ConstrainedWebDialogDelegate*>&
82 ConstrainedHtmlUI::GetPropertyAccessor() { 83 ConstrainedWebDialogUI::GetPropertyAccessor() {
83 return g_constrained_html_ui_property_accessor.Get(); 84 return g_constrained_web_dialog_ui_property_accessor.Get();
84 } 85 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/constrained_web_dialog_ui.h ('k') | chrome/browser/ui/webui/constrained_web_dialog_ui_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698