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/task.h" | 12 #include "base/task.h" |
13 #include "base/tracked_objects.h" | 13 #include "base/tracked_objects.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/sync/js/js_arg_list.h" | 16 #include "chrome/browser/sync/js/js_arg_list.h" |
17 #include "chrome/browser/sync/js/js_controller.h" | 17 #include "chrome/browser/sync/js/js_controller.h" |
18 #include "chrome/browser/sync/js/js_event_details.h" | 18 #include "chrome/browser/sync/js/js_event_details.h" |
19 #include "chrome/browser/sync/profile_sync_service.h" | 19 #include "chrome/browser/sync/profile_sync_service.h" |
20 #include "chrome/browser/sync/sync_ui_util.h" | 20 #include "chrome/browser/sync/sync_ui_util.h" |
21 #include "chrome/browser/sync/util/weak_handle.h" | 21 #include "chrome/browser/sync/util/weak_handle.h" |
22 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 22 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
23 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 23 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
24 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 24 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
25 #include "chrome/common/extensions/extension_messages.h" | 25 #include "chrome/common/extensions/extension_messages.h" |
26 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
27 #include "content/browser/tab_contents/tab_contents.h" | 27 #include "content/public/browser/web_contents.h" |
28 #include "grit/sync_internals_resources.h" | 28 #include "grit/sync_internals_resources.h" |
29 #include "ui/base/resource/resource_bundle.h" | 29 #include "ui/base/resource/resource_bundle.h" |
30 | 30 |
| 31 using browser_sync::JsArgList; |
| 32 using browser_sync::JsEventDetails; |
| 33 using browser_sync::JsReplyHandler; |
| 34 using browser_sync::WeakHandle; |
| 35 using content::WebContents; |
| 36 |
31 namespace { | 37 namespace { |
32 | 38 |
33 ChromeWebUIDataSource* CreateSyncInternalsHTMLSource() { | 39 ChromeWebUIDataSource* CreateSyncInternalsHTMLSource() { |
34 ChromeWebUIDataSource* source = | 40 ChromeWebUIDataSource* source = |
35 new ChromeWebUIDataSource(chrome::kChromeUISyncInternalsHost); | 41 new ChromeWebUIDataSource(chrome::kChromeUISyncInternalsHost); |
36 | 42 |
37 source->set_json_path("strings.js"); | 43 source->set_json_path("strings.js"); |
38 source->add_resource_path("sync_index.js", IDR_SYNC_INTERNALS_INDEX_JS); | 44 source->add_resource_path("sync_index.js", IDR_SYNC_INTERNALS_INDEX_JS); |
39 source->add_resource_path("chrome_sync.js", | 45 source->add_resource_path("chrome_sync.js", |
40 IDR_SYNC_INTERNALS_CHROME_SYNC_JS); | 46 IDR_SYNC_INTERNALS_CHROME_SYNC_JS); |
41 source->add_resource_path("sync_log.js", IDR_SYNC_INTERNALS_SYNC_LOG_JS); | 47 source->add_resource_path("sync_log.js", IDR_SYNC_INTERNALS_SYNC_LOG_JS); |
42 source->add_resource_path("sync_node_browser.js", | 48 source->add_resource_path("sync_node_browser.js", |
43 IDR_SYNC_INTERNALS_SYNC_NODE_BROWSER_JS); | 49 IDR_SYNC_INTERNALS_SYNC_NODE_BROWSER_JS); |
44 source->add_resource_path("sync_search.js", | 50 source->add_resource_path("sync_search.js", |
45 IDR_SYNC_INTERNALS_SYNC_SEARCH_JS); | 51 IDR_SYNC_INTERNALS_SYNC_SEARCH_JS); |
46 source->add_resource_path("about.js", IDR_SYNC_INTERNALS_ABOUT_JS); | 52 source->add_resource_path("about.js", IDR_SYNC_INTERNALS_ABOUT_JS); |
47 source->add_resource_path("data.js", IDR_SYNC_INTERNALS_DATA_JS); | 53 source->add_resource_path("data.js", IDR_SYNC_INTERNALS_DATA_JS); |
48 source->add_resource_path("events.js", IDR_SYNC_INTERNALS_EVENTS_JS); | 54 source->add_resource_path("events.js", IDR_SYNC_INTERNALS_EVENTS_JS); |
49 source->add_resource_path("notifications.js", | 55 source->add_resource_path("notifications.js", |
50 IDR_SYNC_INTERNALS_NOTIFICATIONS_JS); | 56 IDR_SYNC_INTERNALS_NOTIFICATIONS_JS); |
51 source->add_resource_path("search.js", IDR_SYNC_INTERNALS_SEARCH_JS); | 57 source->add_resource_path("search.js", IDR_SYNC_INTERNALS_SEARCH_JS); |
52 source->add_resource_path("node_browser.js", | 58 source->add_resource_path("node_browser.js", |
53 IDR_SYNC_INTERNALS_NODE_BROWSER_JS); | 59 IDR_SYNC_INTERNALS_NODE_BROWSER_JS); |
54 source->set_default_resource(IDR_SYNC_INTERNALS_INDEX_HTML); | 60 source->set_default_resource(IDR_SYNC_INTERNALS_INDEX_HTML); |
55 return source; | 61 return source; |
56 } | 62 } |
57 | 63 |
58 } // namespace | 64 } // namespace |
59 | 65 |
60 using browser_sync::JsArgList; | |
61 using browser_sync::JsEventDetails; | |
62 using browser_sync::JsReplyHandler; | |
63 using browser_sync::WeakHandle; | |
64 | |
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(TabContents* contents) | 76 SyncInternalsUI::SyncInternalsUI(WebContents* contents) |
76 : ChromeWebUI(contents), | 77 : ChromeWebUI(contents), |
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(contents->GetBrowserContext()); |
80 profile->GetChromeURLDataManager()->AddDataSource( | 81 profile->GetChromeURLDataManager()->AddDataSource( |
81 CreateSyncInternalsHTMLSource()); | 82 CreateSyncInternalsHTMLSource()); |
82 ProfileSyncService* sync_service = GetProfileSyncService(profile); | 83 ProfileSyncService* sync_service = GetProfileSyncService(profile); |
83 if (sync_service) { | 84 if (sync_service) { |
84 js_controller_ = sync_service->GetJsController(); | 85 js_controller_ = sync_service->GetJsController(); |
85 } | 86 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 } | 133 } |
133 | 134 |
134 void SyncInternalsUI::HandleJsReply( | 135 void SyncInternalsUI::HandleJsReply( |
135 const std::string& name, const JsArgList& args) { | 136 const std::string& name, const JsArgList& args) { |
136 VLOG(1) << "Handling reply for " << name << " message with args " | 137 VLOG(1) << "Handling reply for " << name << " message with args " |
137 << args.ToString(); | 138 << args.ToString(); |
138 const std::string& reply_handler = "chrome.sync." + name + ".handleReply"; | 139 const std::string& reply_handler = "chrome.sync." + name + ".handleReply"; |
139 std::vector<const Value*> arg_list(args.Get().begin(), args.Get().end()); | 140 std::vector<const Value*> arg_list(args.Get().begin(), args.Get().end()); |
140 CallJavascriptFunction(reply_handler, arg_list); | 141 CallJavascriptFunction(reply_handler, arg_list); |
141 } | 142 } |
OLD | NEW |