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/sync_internals_ui.h" | 5 #include "chrome/browser/ui/webui/sync_internals_ui.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/tracked_objects.h" | 12 #include "base/tracked_objects.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/sync/js/js_arg_list.h" | 15 #include "chrome/browser/sync/js/js_arg_list.h" |
16 #include "chrome/browser/sync/js/js_controller.h" | 16 #include "chrome/browser/sync/js/js_controller.h" |
17 #include "chrome/browser/sync/js/js_event_details.h" | 17 #include "chrome/browser/sync/js/js_event_details.h" |
18 #include "chrome/browser/sync/profile_sync_service.h" | 18 #include "chrome/browser/sync/profile_sync_service.h" |
19 #include "chrome/browser/sync/sync_ui_util.h" | 19 #include "chrome/browser/sync/sync_ui_util.h" |
20 #include "chrome/browser/sync/util/weak_handle.h" | 20 #include "chrome/browser/sync/util/weak_handle.h" |
21 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 21 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
22 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 22 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
23 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 23 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
24 #include "chrome/common/extensions/extension_messages.h" | 24 #include "chrome/common/extensions/extension_messages.h" |
25 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
| 26 #include "content/browser/webui/web_ui.h" |
26 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
27 #include "grit/sync_internals_resources.h" | 28 #include "grit/sync_internals_resources.h" |
28 #include "ui/base/resource/resource_bundle.h" | 29 #include "ui/base/resource/resource_bundle.h" |
29 | 30 |
30 using browser_sync::JsArgList; | 31 using browser_sync::JsArgList; |
31 using browser_sync::JsEventDetails; | 32 using browser_sync::JsEventDetails; |
32 using browser_sync::JsReplyHandler; | 33 using browser_sync::JsReplyHandler; |
33 using browser_sync::WeakHandle; | 34 using browser_sync::WeakHandle; |
34 using content::WebContents; | 35 using content::WebContents; |
35 | 36 |
(...skipping 29 matching lines...) Expand all Loading... |
65 namespace { | 66 namespace { |
66 | 67 |
67 // Gets the ProfileSyncService of the underlying original profile. | 68 // Gets the ProfileSyncService of the underlying original profile. |
68 // May return NULL (e.g., if sync is disabled on the command line). | 69 // May return NULL (e.g., if sync is disabled on the command line). |
69 ProfileSyncService* GetProfileSyncService(Profile* profile) { | 70 ProfileSyncService* GetProfileSyncService(Profile* profile) { |
70 return profile->GetOriginalProfile()->GetProfileSyncService(); | 71 return profile->GetOriginalProfile()->GetProfileSyncService(); |
71 } | 72 } |
72 | 73 |
73 } // namespace | 74 } // namespace |
74 | 75 |
75 SyncInternalsUI::SyncInternalsUI(WebContents* contents) | 76 SyncInternalsUI::SyncInternalsUI(WebUI* web_ui) |
76 : WebUI(contents, this), | 77 : WebUIController(web_ui), |
77 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 78 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
78 // TODO(akalin): Fix. | 79 // TODO(akalin): Fix. |
79 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 80 Profile* profile = Profile::FromBrowserContext( |
| 81 web_ui->web_contents()->GetBrowserContext()); |
80 profile->GetChromeURLDataManager()->AddDataSource( | 82 profile->GetChromeURLDataManager()->AddDataSource( |
81 CreateSyncInternalsHTMLSource()); | 83 CreateSyncInternalsHTMLSource()); |
82 ProfileSyncService* sync_service = GetProfileSyncService(profile); | 84 ProfileSyncService* sync_service = GetProfileSyncService(profile); |
83 if (sync_service) { | 85 if (sync_service) { |
84 js_controller_ = sync_service->GetJsController(); | 86 js_controller_ = sync_service->GetJsController(); |
85 } | 87 } |
86 if (js_controller_.get()) { | 88 if (js_controller_.get()) { |
87 js_controller_->AddJsEventHandler(this); | 89 js_controller_->AddJsEventHandler(this); |
88 } | 90 } |
89 } | 91 } |
(...skipping 10 matching lines...) Expand all Loading... |
100 scoped_ptr<ListValue> content_copy(content.DeepCopy()); | 102 scoped_ptr<ListValue> content_copy(content.DeepCopy()); |
101 JsArgList args(content_copy.get()); | 103 JsArgList args(content_copy.get()); |
102 VLOG(1) << "Received message: " << name << " with args " | 104 VLOG(1) << "Received message: " << name << " with args " |
103 << args.ToString(); | 105 << args.ToString(); |
104 // We handle this case directly because it needs to work even if | 106 // We handle this case directly because it needs to work even if |
105 // the sync service doesn't exist. | 107 // the sync service doesn't exist. |
106 if (name == "getAboutInfo") { | 108 if (name == "getAboutInfo") { |
107 ListValue return_args; | 109 ListValue return_args; |
108 DictionaryValue* about_info = new DictionaryValue(); | 110 DictionaryValue* about_info = new DictionaryValue(); |
109 return_args.Append(about_info); | 111 return_args.Append(about_info); |
110 Profile* profile = | 112 Profile* profile = Profile::FromBrowserContext( |
111 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 113 web_ui()->web_contents()->GetBrowserContext()); |
112 ProfileSyncService* service = GetProfileSyncService(profile); | 114 ProfileSyncService* service = GetProfileSyncService(profile); |
113 sync_ui_util::ConstructAboutInformation(service, about_info); | 115 sync_ui_util::ConstructAboutInformation(service, about_info); |
114 HandleJsReply(name, JsArgList(&return_args)); | 116 HandleJsReply(name, JsArgList(&return_args)); |
115 } else { | 117 } else { |
116 if (js_controller_.get()) { | 118 if (js_controller_.get()) { |
117 js_controller_->ProcessJsMessage( | 119 js_controller_->ProcessJsMessage( |
118 name, args, | 120 name, args, |
119 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr())); | 121 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr())); |
120 } else { | 122 } else { |
121 LOG(WARNING) << "No sync service; dropping message " << name | 123 LOG(WARNING) << "No sync service; dropping message " << name |
122 << " with args " << args.ToString(); | 124 << " with args " << args.ToString(); |
123 } | 125 } |
124 } | 126 } |
125 return true; | 127 return true; |
126 } | 128 } |
127 | 129 |
128 void SyncInternalsUI::HandleJsEvent( | 130 void SyncInternalsUI::HandleJsEvent( |
129 const std::string& name, const JsEventDetails& details) { | 131 const std::string& name, const JsEventDetails& details) { |
130 VLOG(1) << "Handling event: " << name << " with details " | 132 VLOG(1) << "Handling event: " << name << " with details " |
131 << details.ToString(); | 133 << details.ToString(); |
132 const std::string& event_handler = "chrome.sync." + name + ".fire"; | 134 const std::string& event_handler = "chrome.sync." + name + ".fire"; |
133 std::vector<const Value*> arg_list(1, &details.Get()); | 135 std::vector<const Value*> arg_list(1, &details.Get()); |
134 CallJavascriptFunction(event_handler, arg_list); | 136 web_ui()->CallJavascriptFunction(event_handler, arg_list); |
135 } | 137 } |
136 | 138 |
137 void SyncInternalsUI::HandleJsReply( | 139 void SyncInternalsUI::HandleJsReply( |
138 const std::string& name, const JsArgList& args) { | 140 const std::string& name, const JsArgList& args) { |
139 VLOG(1) << "Handling reply for " << name << " message with args " | 141 VLOG(1) << "Handling reply for " << name << " message with args " |
140 << args.ToString(); | 142 << args.ToString(); |
141 const std::string& reply_handler = "chrome.sync." + name + ".handleReply"; | 143 const std::string& reply_handler = "chrome.sync." + name + ".handleReply"; |
142 std::vector<const Value*> arg_list(args.Get().begin(), args.Get().end()); | 144 std::vector<const Value*> arg_list(args.Get().begin(), args.Get().end()); |
143 CallJavascriptFunction(reply_handler, arg_list); | 145 web_ui()->CallJavascriptFunction(reply_handler, arg_list); |
144 } | 146 } |
OLD | NEW |