| 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" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 | 66 |
| 67 // Gets the ProfileSyncService of the underlying original profile. | 67 // Gets the ProfileSyncService of the underlying original profile. |
| 68 // May return NULL (e.g., if sync is disabled on the command line). | 68 // May return NULL (e.g., if sync is disabled on the command line). |
| 69 ProfileSyncService* GetProfileSyncService(Profile* profile) { | 69 ProfileSyncService* GetProfileSyncService(Profile* profile) { |
| 70 return profile->GetOriginalProfile()->GetProfileSyncService(); | 70 return profile->GetOriginalProfile()->GetProfileSyncService(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 } // namespace | 73 } // namespace |
| 74 | 74 |
| 75 SyncInternalsUI::SyncInternalsUI(WebContents* contents) | 75 SyncInternalsUI::SyncInternalsUI(WebContents* contents) |
| 76 : WebUI(contents), | 76 : WebUI(contents, this), |
| 77 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 77 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 78 // TODO(akalin): Fix. | 78 // TODO(akalin): Fix. |
| 79 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 79 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
| 80 profile->GetChromeURLDataManager()->AddDataSource( | 80 profile->GetChromeURLDataManager()->AddDataSource( |
| 81 CreateSyncInternalsHTMLSource()); | 81 CreateSyncInternalsHTMLSource()); |
| 82 ProfileSyncService* sync_service = GetProfileSyncService(profile); | 82 ProfileSyncService* sync_service = GetProfileSyncService(profile); |
| 83 if (sync_service) { | 83 if (sync_service) { |
| 84 js_controller_ = sync_service->GetJsController(); | 84 js_controller_ = sync_service->GetJsController(); |
| 85 } | 85 } |
| 86 if (js_controller_.get()) { | 86 if (js_controller_.get()) { |
| 87 js_controller_->AddJsEventHandler(this); | 87 js_controller_->AddJsEventHandler(this); |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 | 90 |
| 91 SyncInternalsUI::~SyncInternalsUI() { | 91 SyncInternalsUI::~SyncInternalsUI() { |
| 92 if (js_controller_.get()) { | 92 if (js_controller_.get()) { |
| 93 js_controller_->RemoveJsEventHandler(this); | 93 js_controller_->RemoveJsEventHandler(this); |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 void SyncInternalsUI::OnWebUISend(const GURL& source_url, | 97 void SyncInternalsUI::HandleWebUIMessage(const GURL& source_url, |
| 98 const std::string& name, | 98 const std::string& name, |
| 99 const ListValue& content) { | 99 const ListValue& content, |
| 100 bool* overridden) { |
| 101 *overridden = true; |
| 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); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 134 } | 136 } |
| 135 | 137 |
| 136 void SyncInternalsUI::HandleJsReply( | 138 void SyncInternalsUI::HandleJsReply( |
| 137 const std::string& name, const JsArgList& args) { | 139 const std::string& name, const JsArgList& args) { |
| 138 VLOG(1) << "Handling reply for " << name << " message with args " | 140 VLOG(1) << "Handling reply for " << name << " message with args " |
| 139 << args.ToString(); | 141 << args.ToString(); |
| 140 const std::string& reply_handler = "chrome.sync." + name + ".handleReply"; | 142 const std::string& reply_handler = "chrome.sync." + name + ".handleReply"; |
| 141 std::vector<const Value*> arg_list(args.Get().begin(), args.Get().end()); | 143 std::vector<const Value*> arg_list(args.Get().begin(), args.Get().end()); |
| 142 CallJavascriptFunction(reply_handler, arg_list); | 144 CallJavascriptFunction(reply_handler, arg_list); |
| 143 } | 145 } |
| OLD | NEW |