| 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" |
| 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/web_dialog_ui.h" | 15 #include "ui/web_dialogs/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<ConstrainedWebDialogDelegate*>
> | 26 static base::LazyInstance<base::PropertyAccessor<ConstrainedWebDialogDelegate*>
> |
| 27 g_constrained_web_dialog_ui_property_accessor = LAZY_INSTANCE_INITIALIZER; | 27 g_constrained_web_dialog_ui_property_accessor = LAZY_INSTANCE_INITIALIZER; |
| 28 | 28 |
| 29 ConstrainedWebDialogUI::ConstrainedWebDialogUI(content::WebUI* web_ui) | 29 ConstrainedWebDialogUI::ConstrainedWebDialogUI(content::WebUI* web_ui) |
| 30 : WebUIController(web_ui) { | 30 : WebUIController(web_ui) { |
| 31 } | 31 } |
| 32 | 32 |
| 33 ConstrainedWebDialogUI::~ConstrainedWebDialogUI() { | 33 ConstrainedWebDialogUI::~ConstrainedWebDialogUI() { |
| 34 } | 34 } |
| 35 | 35 |
| 36 void ConstrainedWebDialogUI::RenderViewCreated( | 36 void ConstrainedWebDialogUI::RenderViewCreated( |
| 37 RenderViewHost* render_view_host) { | 37 RenderViewHost* render_view_host) { |
| 38 ConstrainedWebDialogDelegate* delegate = GetConstrainedDelegate(); | 38 ConstrainedWebDialogDelegate* delegate = GetConstrainedDelegate(); |
| 39 if (!delegate) | 39 if (!delegate) |
| 40 return; | 40 return; |
| 41 | 41 |
| 42 WebDialogDelegate* dialog_delegate = delegate->GetWebDialogDelegate(); | 42 views::WebDialogDelegate* dialog_delegate = delegate->GetWebDialogDelegate(); |
| 43 std::vector<WebUIMessageHandler*> handlers; | 43 std::vector<WebUIMessageHandler*> handlers; |
| 44 dialog_delegate->GetWebUIMessageHandlers(&handlers); | 44 dialog_delegate->GetWebUIMessageHandlers(&handlers); |
| 45 render_view_host->SetWebUIProperty("dialogArguments", | 45 render_view_host->SetWebUIProperty("dialogArguments", |
| 46 dialog_delegate->GetDialogArgs()); | 46 dialog_delegate->GetDialogArgs()); |
| 47 for (std::vector<WebUIMessageHandler*>::iterator it = handlers.begin(); | 47 for (std::vector<WebUIMessageHandler*>::iterator it = handlers.begin(); |
| 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. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 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 |