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/extensions/extensions_ui.h" | 5 #include "chrome/browser/extensions/extensions_ui.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "chrome/browser/extensions/extension_host.h" | 21 #include "chrome/browser/extensions/extension_host.h" |
22 #include "chrome/browser/extensions/extension_message_service.h" | 22 #include "chrome/browser/extensions/extension_message_service.h" |
23 #include "chrome/browser/extensions/extension_service.h" | 23 #include "chrome/browser/extensions/extension_service.h" |
24 #include "chrome/browser/extensions/extension_updater.h" | 24 #include "chrome/browser/extensions/extension_updater.h" |
25 #include "chrome/browser/google/google_util.h" | 25 #include "chrome/browser/google/google_util.h" |
26 #include "chrome/browser/prefs/pref_service.h" | 26 #include "chrome/browser/prefs/pref_service.h" |
27 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
28 #include "chrome/browser/tab_contents/background_contents.h" | 28 #include "chrome/browser/tab_contents/background_contents.h" |
29 #include "chrome/browser/ui/browser_list.h" | 29 #include "chrome/browser/ui/browser_list.h" |
30 #include "chrome/browser/ui/webui/extension_icon_source.h" | 30 #include "chrome/browser/ui/webui/extension_icon_source.h" |
| 31 #include "chrome/common/chrome_notification_types.h" |
31 #include "chrome/common/extensions/extension.h" | 32 #include "chrome/common/extensions/extension.h" |
32 #include "chrome/common/extensions/extension_icon_set.h" | 33 #include "chrome/common/extensions/extension_icon_set.h" |
33 #include "chrome/common/extensions/url_pattern.h" | 34 #include "chrome/common/extensions/url_pattern.h" |
34 #include "chrome/common/extensions/user_script.h" | 35 #include "chrome/common/extensions/user_script.h" |
35 #include "chrome/common/jstemplate_builder.h" | 36 #include "chrome/common/jstemplate_builder.h" |
36 #include "chrome/common/pref_names.h" | 37 #include "chrome/common/pref_names.h" |
37 #include "chrome/common/url_constants.h" | 38 #include "chrome/common/url_constants.h" |
38 #include "content/browser/debugger/devtools_window.h" | 39 #include "content/browser/debugger/devtools_window.h" |
39 #include "content/browser/renderer_host/render_process_host.h" | 40 #include "content/browser/renderer_host/render_process_host.h" |
40 #include "content/browser/renderer_host/render_view_host.h" | 41 #include "content/browser/renderer_host/render_view_host.h" |
41 #include "content/browser/renderer_host/render_widget_host.h" | 42 #include "content/browser/renderer_host/render_widget_host.h" |
42 #include "content/browser/tab_contents/tab_contents.h" | 43 #include "content/browser/tab_contents/tab_contents.h" |
43 #include "content/browser/tab_contents/tab_contents_view.h" | 44 #include "content/browser/tab_contents/tab_contents_view.h" |
| 45 #include "content/common/content_notification_types.h" |
44 #include "content/common/notification_service.h" | 46 #include "content/common/notification_service.h" |
45 #include "content/common/notification_type.h" | |
46 #include "googleurl/src/gurl.h" | 47 #include "googleurl/src/gurl.h" |
47 #include "grit/browser_resources.h" | 48 #include "grit/browser_resources.h" |
48 #include "grit/chromium_strings.h" | 49 #include "grit/chromium_strings.h" |
49 #include "grit/generated_resources.h" | 50 #include "grit/generated_resources.h" |
50 #include "grit/theme_resources.h" | 51 #include "grit/theme_resources.h" |
51 #include "net/base/net_util.h" | 52 #include "net/base/net_util.h" |
52 #include "ui/base/l10n/l10n_util.h" | 53 #include "ui/base/l10n/l10n_util.h" |
53 #include "ui/base/resource/resource_bundle.h" | 54 #include "ui/base/resource/resource_bundle.h" |
54 | 55 |
55 namespace { | 56 namespace { |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 | 284 |
284 bool developer_mode = web_ui_->GetProfile()->GetPrefs() | 285 bool developer_mode = web_ui_->GetProfile()->GetPrefs() |
285 ->GetBoolean(prefs::kExtensionsUIDeveloperMode); | 286 ->GetBoolean(prefs::kExtensionsUIDeveloperMode); |
286 results.SetBoolean("developerMode", developer_mode); | 287 results.SetBoolean("developerMode", developer_mode); |
287 | 288 |
288 web_ui_->CallJavascriptFunction("returnExtensionsData", results); | 289 web_ui_->CallJavascriptFunction("returnExtensionsData", results); |
289 } | 290 } |
290 | 291 |
291 void ExtensionsDOMHandler::RegisterForNotifications() { | 292 void ExtensionsDOMHandler::RegisterForNotifications() { |
292 // Register for notifications that we need to reload the page. | 293 // Register for notifications that we need to reload the page. |
293 registrar_.Add(this, NotificationType::EXTENSION_LOADED, | 294 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
294 NotificationService::AllSources()); | 295 NotificationService::AllSources()); |
295 registrar_.Add(this, NotificationType::EXTENSION_PROCESS_CREATED, | 296 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_CREATED, |
296 NotificationService::AllSources()); | 297 NotificationService::AllSources()); |
297 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, | 298 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
298 NotificationService::AllSources()); | 299 NotificationService::AllSources()); |
299 registrar_.Add(this, NotificationType::EXTENSION_UPDATE_DISABLED, | 300 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, |
300 NotificationService::AllSources()); | 301 NotificationService::AllSources()); |
301 registrar_.Add(this, | 302 registrar_.Add(this, |
302 NotificationType::NAV_ENTRY_COMMITTED, | 303 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
303 NotificationService::AllSources()); | 304 NotificationService::AllSources()); |
304 registrar_.Add(this, | 305 registrar_.Add(this, |
305 NotificationType::RENDER_VIEW_HOST_CREATED, | 306 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, |
306 NotificationService::AllSources()); | 307 NotificationService::AllSources()); |
307 registrar_.Add(this, | 308 registrar_.Add(this, |
308 NotificationType::RENDER_VIEW_HOST_DELETED, | 309 content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, |
309 NotificationService::AllSources()); | 310 NotificationService::AllSources()); |
310 registrar_.Add(this, | 311 registrar_.Add(this, |
311 NotificationType::BACKGROUND_CONTENTS_NAVIGATED, | 312 chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, |
312 NotificationService::AllSources()); | 313 NotificationService::AllSources()); |
313 registrar_.Add(this, | 314 registrar_.Add(this, |
314 NotificationType::BACKGROUND_CONTENTS_DELETED, | 315 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, |
315 NotificationService::AllSources()); | 316 NotificationService::AllSources()); |
316 registrar_.Add(this, | 317 registrar_.Add(this, |
317 NotificationType::EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, | 318 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, |
318 NotificationService::AllSources()); | 319 NotificationService::AllSources()); |
319 } | 320 } |
320 | 321 |
321 ExtensionUninstallDialog* ExtensionsDOMHandler::GetExtensionUninstallDialog() { | 322 ExtensionUninstallDialog* ExtensionsDOMHandler::GetExtensionUninstallDialog() { |
322 if (!extension_uninstall_dialog_.get()) { | 323 if (!extension_uninstall_dialog_.get()) { |
323 extension_uninstall_dialog_.reset( | 324 extension_uninstall_dialog_.reset( |
324 new ExtensionUninstallDialog(web_ui_->GetProfile())); | 325 new ExtensionUninstallDialog(web_ui_->GetProfile())); |
325 } | 326 } |
326 return extension_uninstall_dialog_.get(); | 327 return extension_uninstall_dialog_.get(); |
327 } | 328 } |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 ListValue results; | 611 ListValue results; |
611 results.Append(Value::CreateStringValue(path.value())); | 612 results.Append(Value::CreateStringValue(path.value())); |
612 web_ui_->CallJavascriptFunction("window.handleFilePathSelected", results); | 613 web_ui_->CallJavascriptFunction("window.handleFilePathSelected", results); |
613 } | 614 } |
614 | 615 |
615 void ExtensionsDOMHandler::MultiFilesSelected( | 616 void ExtensionsDOMHandler::MultiFilesSelected( |
616 const std::vector<FilePath>& files, void* params) { | 617 const std::vector<FilePath>& files, void* params) { |
617 NOTREACHED(); | 618 NOTREACHED(); |
618 } | 619 } |
619 | 620 |
620 void ExtensionsDOMHandler::Observe(NotificationType type, | 621 void ExtensionsDOMHandler::Observe(int type, |
621 const NotificationSource& source, | 622 const NotificationSource& source, |
622 const NotificationDetails& details) { | 623 const NotificationDetails& details) { |
623 switch (type.value) { | 624 switch (type) { |
624 // We listen for notifications that will result in the page being | 625 // We listen for notifications that will result in the page being |
625 // repopulated with data twice for the same event in certain cases. | 626 // repopulated with data twice for the same event in certain cases. |
626 // For instance, EXTENSION_LOADED & EXTENSION_PROCESS_CREATED because | 627 // For instance, EXTENSION_LOADED & EXTENSION_PROCESS_CREATED because |
627 // we don't know about the views for an extension at EXTENSION_LOADED, but | 628 // we don't know about the views for an extension at EXTENSION_LOADED, but |
628 // if we only listen to EXTENSION_PROCESS_CREATED, we'll miss extensions | 629 // if we only listen to EXTENSION_PROCESS_CREATED, we'll miss extensions |
629 // that don't have a process at startup. Similarly, NAV_ENTRY_COMMITTED & | 630 // that don't have a process at startup. Similarly, NAV_ENTRY_COMMITTED & |
630 // RENDER_VIEW_HOST_CREATED because we want to handle both | 631 // RENDER_VIEW_HOST_CREATED because we want to handle both |
631 // the case of navigating from a non-extension page to an extension page in | 632 // the case of navigating from a non-extension page to an extension page in |
632 // a TabContents (which will generate NAV_ENTRY_COMMITTED) as well as | 633 // a TabContents (which will generate NAV_ENTRY_COMMITTED) as well as |
633 // extension content being shown in popups and balloons (which will generate | 634 // extension content being shown in popups and balloons (which will generate |
634 // RENDER_VIEW_HOST_CREATED but no NAV_ENTRY_COMMITTED). | 635 // RENDER_VIEW_HOST_CREATED but no NAV_ENTRY_COMMITTED). |
635 // | 636 // |
636 // Doing it this way gets everything but causes the page to be rendered | 637 // Doing it this way gets everything but causes the page to be rendered |
637 // more than we need. It doesn't seem to result in any noticeable flicker. | 638 // more than we need. It doesn't seem to result in any noticeable flicker. |
638 case NotificationType::RENDER_VIEW_HOST_DELETED: | 639 case content::NOTIFICATION_RENDER_VIEW_HOST_DELETED: |
639 deleting_rvh_ = Source<RenderViewHost>(source).ptr(); | 640 deleting_rvh_ = Source<RenderViewHost>(source).ptr(); |
640 MaybeUpdateAfterNotification(); | 641 MaybeUpdateAfterNotification(); |
641 break; | 642 break; |
642 case NotificationType::BACKGROUND_CONTENTS_DELETED: | 643 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED: |
643 deleting_rvh_ = Details<BackgroundContents>(details)->render_view_host(); | 644 deleting_rvh_ = Details<BackgroundContents>(details)->render_view_host(); |
644 MaybeUpdateAfterNotification(); | 645 MaybeUpdateAfterNotification(); |
645 break; | 646 break; |
646 case NotificationType::EXTENSION_LOADED: | 647 case chrome::NOTIFICATION_EXTENSION_LOADED: |
647 case NotificationType::EXTENSION_PROCESS_CREATED: | 648 case chrome::NOTIFICATION_EXTENSION_PROCESS_CREATED: |
648 case NotificationType::EXTENSION_UNLOADED: | 649 case chrome::NOTIFICATION_EXTENSION_UNLOADED: |
649 case NotificationType::EXTENSION_UPDATE_DISABLED: | 650 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: |
650 case NotificationType::RENDER_VIEW_HOST_CREATED: | 651 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED: |
651 case NotificationType::NAV_ENTRY_COMMITTED: | 652 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: |
652 case NotificationType::BACKGROUND_CONTENTS_NAVIGATED: | 653 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED: |
653 case NotificationType::EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: | 654 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: |
654 MaybeUpdateAfterNotification(); | 655 MaybeUpdateAfterNotification(); |
655 break; | 656 break; |
656 default: | 657 default: |
657 NOTREACHED(); | 658 NOTREACHED(); |
658 } | 659 } |
659 } | 660 } |
660 | 661 |
661 const Extension* ExtensionsDOMHandler::GetExtension(const ListValue* args) { | 662 const Extension* ExtensionsDOMHandler::GetExtension(const ListValue* args) { |
662 std::string extension_id = UTF16ToASCII(ExtractStringValue(args)); | 663 std::string extension_id = UTF16ToASCII(ExtractStringValue(args)); |
663 CHECK(!extension_id.empty()); | 664 CHECK(!extension_id.empty()); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 return ResourceBundle::GetSharedInstance(). | 835 return ResourceBundle::GetSharedInstance(). |
835 LoadDataResourceBytes(IDR_PLUGIN); | 836 LoadDataResourceBytes(IDR_PLUGIN); |
836 } | 837 } |
837 | 838 |
838 // static | 839 // static |
839 void ExtensionsUI::RegisterUserPrefs(PrefService* prefs) { | 840 void ExtensionsUI::RegisterUserPrefs(PrefService* prefs) { |
840 prefs->RegisterBooleanPref(prefs::kExtensionsUIDeveloperMode, | 841 prefs->RegisterBooleanPref(prefs::kExtensionsUIDeveloperMode, |
841 false, | 842 false, |
842 PrefService::SYNCABLE_PREF); | 843 PrefService::SYNCABLE_PREF); |
843 } | 844 } |
OLD | NEW |