Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Side by Side Diff: chrome/browser/ui/webui/sync_internals_ui.cc

Issue 9188056: Start splitting out WebUI into an implementation class and an interface that each page implements... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 bool SyncInternalsUI::OverrideHandleWebUIMessage(const GURL& source_url,
98 const std::string& name, 98 const std::string& name,
99 const ListValue& content) { 99 const ListValue& content) {
100 scoped_ptr<ListValue> content_copy(content.DeepCopy()); 100 scoped_ptr<ListValue> content_copy(content.DeepCopy());
101 JsArgList args(content_copy.get()); 101 JsArgList args(content_copy.get());
102 VLOG(1) << "Received message: " << name << " with args " 102 VLOG(1) << "Received message: " << name << " with args "
103 << args.ToString(); 103 << args.ToString();
104 // We handle this case directly because it needs to work even if 104 // We handle this case directly because it needs to work even if
105 // the sync service doesn't exist. 105 // the sync service doesn't exist.
106 if (name == "getAboutInfo") { 106 if (name == "getAboutInfo") {
107 ListValue return_args; 107 ListValue return_args;
108 DictionaryValue* about_info = new DictionaryValue(); 108 DictionaryValue* about_info = new DictionaryValue();
109 return_args.Append(about_info); 109 return_args.Append(about_info);
110 Profile* profile = 110 Profile* profile =
111 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 111 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
112 ProfileSyncService* service = GetProfileSyncService(profile); 112 ProfileSyncService* service = GetProfileSyncService(profile);
113 sync_ui_util::ConstructAboutInformation(service, about_info); 113 sync_ui_util::ConstructAboutInformation(service, about_info);
114 HandleJsReply(name, JsArgList(&return_args)); 114 HandleJsReply(name, JsArgList(&return_args));
115 } else { 115 } else {
116 if (js_controller_.get()) { 116 if (js_controller_.get()) {
117 js_controller_->ProcessJsMessage( 117 js_controller_->ProcessJsMessage(
118 name, args, 118 name, args,
119 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr())); 119 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()));
120 } else { 120 } else {
121 LOG(WARNING) << "No sync service; dropping message " << name 121 LOG(WARNING) << "No sync service; dropping message " << name
122 << " with args " << args.ToString(); 122 << " with args " << args.ToString();
123 } 123 }
124 } 124 }
125 return true;
125 } 126 }
126 127
127 void SyncInternalsUI::HandleJsEvent( 128 void SyncInternalsUI::HandleJsEvent(
128 const std::string& name, const JsEventDetails& details) { 129 const std::string& name, const JsEventDetails& details) {
129 VLOG(1) << "Handling event: " << name << " with details " 130 VLOG(1) << "Handling event: " << name << " with details "
130 << details.ToString(); 131 << details.ToString();
131 const std::string& event_handler = "chrome.sync." + name + ".fire"; 132 const std::string& event_handler = "chrome.sync." + name + ".fire";
132 std::vector<const Value*> arg_list(1, &details.Get()); 133 std::vector<const Value*> arg_list(1, &details.Get());
133 CallJavascriptFunction(event_handler, arg_list); 134 CallJavascriptFunction(event_handler, arg_list);
134 } 135 }
135 136
136 void SyncInternalsUI::HandleJsReply( 137 void SyncInternalsUI::HandleJsReply(
137 const std::string& name, const JsArgList& args) { 138 const std::string& name, const JsArgList& args) {
138 VLOG(1) << "Handling reply for " << name << " message with args " 139 VLOG(1) << "Handling reply for " << name << " message with args "
139 << args.ToString(); 140 << args.ToString();
140 const std::string& reply_handler = "chrome.sync." + name + ".handleReply"; 141 const std::string& reply_handler = "chrome.sync." + name + ".handleReply";
141 std::vector<const Value*> arg_list(args.Get().begin(), args.Get().end()); 142 std::vector<const Value*> arg_list(args.Get().begin(), args.Get().end());
142 CallJavascriptFunction(reply_handler, arg_list); 143 CallJavascriptFunction(reply_handler, arg_list);
143 } 144 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/sync_internals_ui.h ('k') | chrome/browser/ui/webui/sync_internals_ui_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698