| OLD | NEW |
| 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" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 g_constrained_html_ui_property_accessor = LAZY_INSTANCE_INITIALIZER; | 22 g_constrained_html_ui_property_accessor = LAZY_INSTANCE_INITIALIZER; |
| 23 | 23 |
| 24 ConstrainedHtmlUI::ConstrainedHtmlUI(TabContents* contents) | 24 ConstrainedHtmlUI::ConstrainedHtmlUI(TabContents* contents) |
| 25 : ChromeWebUI(contents) { | 25 : ChromeWebUI(contents) { |
| 26 } | 26 } |
| 27 | 27 |
| 28 ConstrainedHtmlUI::~ConstrainedHtmlUI() { | 28 ConstrainedHtmlUI::~ConstrainedHtmlUI() { |
| 29 } | 29 } |
| 30 | 30 |
| 31 void ConstrainedHtmlUI::RenderViewCreated(RenderViewHost* render_view_host) { | 31 void ConstrainedHtmlUI::RenderViewCreated(RenderViewHost* render_view_host) { |
| 32 ChromeWebUI::RenderViewCreated(render_view_host); |
| 33 |
| 32 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate(); | 34 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate(); |
| 33 if (!delegate) | 35 if (!delegate) |
| 34 return; | 36 return; |
| 35 | 37 |
| 36 HtmlDialogUIDelegate* dialog_delegate = delegate->GetHtmlDialogUIDelegate(); | 38 HtmlDialogUIDelegate* dialog_delegate = delegate->GetHtmlDialogUIDelegate(); |
| 37 std::vector<WebUIMessageHandler*> handlers; | 39 std::vector<WebUIMessageHandler*> handlers; |
| 38 dialog_delegate->GetWebUIMessageHandlers(&handlers); | 40 dialog_delegate->GetWebUIMessageHandlers(&handlers); |
| 39 render_view_host->SetWebUIProperty("dialogArguments", | 41 render_view_host->SetWebUIProperty("dialogArguments", |
| 40 dialog_delegate->GetDialogArgs()); | 42 dialog_delegate->GetDialogArgs()); |
| 41 for (std::vector<WebUIMessageHandler*>::iterator it = handlers.begin(); | 43 for (std::vector<WebUIMessageHandler*>::iterator it = handlers.begin(); |
| 42 it != handlers.end(); ++it) { | 44 it != handlers.end(); ++it) { |
| 43 (*it)->Attach(this); | 45 (*it)->Attach(this); |
| 44 AddMessageHandler(*it); | 46 AddMessageHandler(*it); |
| 45 } | 47 } |
| 46 | 48 |
| 47 // Add a "DialogClose" callback which matches HTMLDialogUI behavior. | 49 // Add a "DialogClose" callback which matches HTMLDialogUI behavior. |
| 48 RegisterMessageCallback("DialogClose", | 50 RegisterMessageCallback("DialogClose", |
| 49 base::Bind(&ConstrainedHtmlUI::OnDialogCloseMessage, | 51 base::Bind(&ConstrainedHtmlUI::OnDialogCloseMessage, |
| 50 base::Unretained(this))); | 52 base::Unretained(this))); |
| 51 | 53 |
| 52 content::NotificationService::current()->Notify( | 54 content::NotificationService::current()->Notify( |
| 53 chrome::NOTIFICATION_HTML_DIALOG_SHOWN, | 55 chrome::NOTIFICATION_HTML_DIALOG_SHOWN, |
| 54 content::Source<WebUI>(this), | 56 content::Source<WebUI>(this), |
| 55 content::Details<RenderViewHost>(render_view_host)); | 57 content::Details<RenderViewHost>(render_view_host)); |
| 56 | |
| 57 ChromeWebUI::RenderViewCreated(render_view_host); | |
| 58 } | 58 } |
| 59 | 59 |
| 60 void ConstrainedHtmlUI::OnDialogCloseMessage(const ListValue* args) { | 60 void ConstrainedHtmlUI::OnDialogCloseMessage(const ListValue* args) { |
| 61 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate(); | 61 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate(); |
| 62 if (!delegate) | 62 if (!delegate) |
| 63 return; | 63 return; |
| 64 | 64 |
| 65 std::string json_retval; | 65 std::string json_retval; |
| 66 if (!args->empty() && !args->GetString(0, &json_retval)) | 66 if (!args->empty() && !args->GetString(0, &json_retval)) |
| 67 NOTREACHED() << "Could not read JSON argument"; | 67 NOTREACHED() << "Could not read JSON argument"; |
| 68 delegate->GetHtmlDialogUIDelegate()->OnDialogClosed(json_retval); | 68 delegate->GetHtmlDialogUIDelegate()->OnDialogClosed(json_retval); |
| 69 delegate->OnDialogCloseFromWebUI(); | 69 delegate->OnDialogCloseFromWebUI(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 ConstrainedHtmlUIDelegate* ConstrainedHtmlUI::GetConstrainedDelegate() { | 72 ConstrainedHtmlUIDelegate* ConstrainedHtmlUI::GetConstrainedDelegate() { |
| 73 ConstrainedHtmlUIDelegate** property = | 73 ConstrainedHtmlUIDelegate** property = |
| 74 GetPropertyAccessor().GetProperty(tab_contents()->property_bag()); | 74 GetPropertyAccessor().GetProperty(tab_contents()->property_bag()); |
| 75 return property ? *property : NULL; | 75 return property ? *property : NULL; |
| 76 } | 76 } |
| 77 | 77 |
| 78 // static | 78 // static |
| 79 base::PropertyAccessor<ConstrainedHtmlUIDelegate*>& | 79 base::PropertyAccessor<ConstrainedHtmlUIDelegate*>& |
| 80 ConstrainedHtmlUI::GetPropertyAccessor() { | 80 ConstrainedHtmlUI::GetPropertyAccessor() { |
| 81 return g_constrained_html_ui_property_accessor.Get(); | 81 return g_constrained_html_ui_property_accessor.Get(); |
| 82 } | 82 } |
| OLD | NEW |