| 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 "ui/web_dialogs/constrained_web_dialog_ui.h" | 5 #include "ui/web_dialogs/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" | |
| 14 #include "base/values.h" | 13 #include "base/values.h" |
| 15 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
| 16 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
| 17 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 18 #include "content/public/browser/web_ui.h" | 17 #include "content/public/browser/web_ui.h" |
| 19 #include "ui/web_dialogs/web_dialog_delegate.h" | 18 #include "ui/web_dialogs/web_dialog_delegate.h" |
| 20 #include "ui/web_dialogs/web_dialog_ui.h" | 19 #include "ui/web_dialogs/web_dialog_ui.h" |
| 21 | 20 |
| 22 using content::RenderViewHost; | 21 using content::RenderViewHost; |
| 23 using content::WebContents; | 22 using content::WebContents; |
| 24 using content::WebUIMessageHandler; | 23 using content::WebUIMessageHandler; |
| 25 | 24 |
| 26 static base::LazyInstance< | 25 namespace ui { |
| 27 base::PropertyAccessor<ui::ConstrainedWebDialogDelegate*> > | |
| 28 g_constrained_web_dialog_ui_property_accessor = LAZY_INSTANCE_INITIALIZER; | |
| 29 | 26 |
| 30 namespace ui { | 27 namespace { |
| 28 |
| 29 const char kConstrainedWebDialogDelegateUserDataKey[] = |
| 30 "ConstrainedWebDialogDelegateUserData"; |
| 31 |
| 32 class ConstrainedWebDialogDelegateUserData |
| 33 : public base::SupportsUserData::Data { |
| 34 public: |
| 35 explicit ConstrainedWebDialogDelegateUserData( |
| 36 ConstrainedWebDialogDelegate* delegate) : delegate_(delegate) {} |
| 37 virtual ~ConstrainedWebDialogDelegateUserData() {} |
| 38 |
| 39 ConstrainedWebDialogDelegate* delegate() { return delegate_; } |
| 40 |
| 41 private: |
| 42 ConstrainedWebDialogDelegate* delegate_; // unowned |
| 43 |
| 44 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateUserData); |
| 45 }; |
| 46 |
| 47 } // namespace |
| 31 | 48 |
| 32 ConstrainedWebDialogUI::ConstrainedWebDialogUI(content::WebUI* web_ui) | 49 ConstrainedWebDialogUI::ConstrainedWebDialogUI(content::WebUI* web_ui) |
| 33 : WebUIController(web_ui) { | 50 : WebUIController(web_ui) { |
| 34 } | 51 } |
| 35 | 52 |
| 36 ConstrainedWebDialogUI::~ConstrainedWebDialogUI() { | 53 ConstrainedWebDialogUI::~ConstrainedWebDialogUI() { |
| 37 } | 54 } |
| 38 | 55 |
| 39 void ConstrainedWebDialogUI::RenderViewCreated( | 56 void ConstrainedWebDialogUI::RenderViewCreated( |
| 40 RenderViewHost* render_view_host) { | 57 RenderViewHost* render_view_host) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 65 if (!delegate) | 82 if (!delegate) |
| 66 return; | 83 return; |
| 67 | 84 |
| 68 std::string json_retval; | 85 std::string json_retval; |
| 69 if (!args->empty() && !args->GetString(0, &json_retval)) | 86 if (!args->empty() && !args->GetString(0, &json_retval)) |
| 70 NOTREACHED() << "Could not read JSON argument"; | 87 NOTREACHED() << "Could not read JSON argument"; |
| 71 delegate->GetWebDialogDelegate()->OnDialogClosed(json_retval); | 88 delegate->GetWebDialogDelegate()->OnDialogClosed(json_retval); |
| 72 delegate->OnDialogCloseFromWebUI(); | 89 delegate->OnDialogCloseFromWebUI(); |
| 73 } | 90 } |
| 74 | 91 |
| 75 ConstrainedWebDialogDelegate* ConstrainedWebDialogUI::GetConstrainedDelegate() { | 92 // static |
| 76 ConstrainedWebDialogDelegate** property = GetPropertyAccessor().GetProperty( | 93 void ConstrainedWebDialogUI::SetConstrainedDelegate( |
| 77 web_ui()->GetWebContents()->GetPropertyBag()); | 94 content::WebContents* web_contents, |
| 78 return property ? *property : NULL; | 95 ConstrainedWebDialogDelegate* delegate) { |
| 96 web_contents->SetUserData(&kConstrainedWebDialogDelegateUserDataKey, |
| 97 new ConstrainedWebDialogDelegateUserData(delegate)); |
| 79 } | 98 } |
| 80 | 99 |
| 81 // static | 100 ConstrainedWebDialogDelegate* ConstrainedWebDialogUI::GetConstrainedDelegate() { |
| 82 base::PropertyAccessor<ConstrainedWebDialogDelegate*>& | 101 ConstrainedWebDialogDelegateUserData* user_data = |
| 83 ConstrainedWebDialogUI::GetPropertyAccessor() { | 102 static_cast<ConstrainedWebDialogDelegateUserData*>( |
| 84 return g_constrained_web_dialog_ui_property_accessor.Get(); | 103 web_ui()->GetWebContents()-> |
| 104 GetUserData(&kConstrainedWebDialogDelegateUserDataKey)); |
| 105 |
| 106 return user_data ? user_data->delegate() : NULL; |
| 85 } | 107 } |
| 86 | 108 |
| 87 } // namespace ui | 109 } // namespace ui |
| OLD | NEW |