OLD | NEW |
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_web_dialog_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" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 it != handlers.end(); ++it) { | 48 it != handlers.end(); ++it) { |
49 web_ui()->AddMessageHandler(*it); | 49 web_ui()->AddMessageHandler(*it); |
50 } | 50 } |
51 | 51 |
52 // Add a "DialogClose" callback which matches HTMLDialogUI behavior. | 52 // Add a "DialogClose" callback which matches HTMLDialogUI behavior. |
53 web_ui()->RegisterMessageCallback("DialogClose", | 53 web_ui()->RegisterMessageCallback("DialogClose", |
54 base::Bind(&ConstrainedWebDialogUI::OnDialogCloseMessage, | 54 base::Bind(&ConstrainedWebDialogUI::OnDialogCloseMessage, |
55 base::Unretained(this))); | 55 base::Unretained(this))); |
56 | 56 |
57 content::NotificationService::current()->Notify( | 57 content::NotificationService::current()->Notify( |
58 chrome::NOTIFICATION_HTML_DIALOG_SHOWN, | 58 chrome::NOTIFICATION_WEB_DIALOG_SHOWN, |
59 content::Source<content::WebUI>(web_ui()), | 59 content::Source<content::WebUI>(web_ui()), |
60 content::Details<RenderViewHost>(render_view_host)); | 60 content::Details<RenderViewHost>(render_view_host)); |
61 } | 61 } |
62 | 62 |
63 void ConstrainedWebDialogUI::OnDialogCloseMessage(const ListValue* args) { | 63 void ConstrainedWebDialogUI::OnDialogCloseMessage(const ListValue* args) { |
64 ConstrainedWebDialogDelegate* delegate = GetConstrainedDelegate(); | 64 ConstrainedWebDialogDelegate* delegate = GetConstrainedDelegate(); |
65 if (!delegate) | 65 if (!delegate) |
66 return; | 66 return; |
67 | 67 |
68 std::string json_retval; | 68 std::string json_retval; |
69 if (!args->empty() && !args->GetString(0, &json_retval)) | 69 if (!args->empty() && !args->GetString(0, &json_retval)) |
70 NOTREACHED() << "Could not read JSON argument"; | 70 NOTREACHED() << "Could not read JSON argument"; |
71 delegate->GetWebDialogDelegate()->OnDialogClosed(json_retval); | 71 delegate->GetWebDialogDelegate()->OnDialogClosed(json_retval); |
72 delegate->OnDialogCloseFromWebUI(); | 72 delegate->OnDialogCloseFromWebUI(); |
73 } | 73 } |
74 | 74 |
75 ConstrainedWebDialogDelegate* ConstrainedWebDialogUI::GetConstrainedDelegate() { | 75 ConstrainedWebDialogDelegate* ConstrainedWebDialogUI::GetConstrainedDelegate() { |
76 ConstrainedWebDialogDelegate** property = GetPropertyAccessor().GetProperty( | 76 ConstrainedWebDialogDelegate** property = GetPropertyAccessor().GetProperty( |
77 web_ui()->GetWebContents()->GetPropertyBag()); | 77 web_ui()->GetWebContents()->GetPropertyBag()); |
78 return property ? *property : NULL; | 78 return property ? *property : NULL; |
79 } | 79 } |
80 | 80 |
81 // static | 81 // static |
82 base::PropertyAccessor<ConstrainedWebDialogDelegate*>& | 82 base::PropertyAccessor<ConstrainedWebDialogDelegate*>& |
83 ConstrainedWebDialogUI::GetPropertyAccessor() { | 83 ConstrainedWebDialogUI::GetPropertyAccessor() { |
84 return g_constrained_web_dialog_ui_property_accessor.Get(); | 84 return g_constrained_web_dialog_ui_property_accessor.Get(); |
85 } | 85 } |
OLD | NEW |