| 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/options/extension_settings_handler.h" | 5 #include "chrome/browser/ui/webui/options/extension_settings_handler.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/base64.h" | 8 #include "base/base64.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 26 #include "chrome/browser/tab_contents/background_contents.h" | 26 #include "chrome/browser/tab_contents/background_contents.h" |
| 27 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 27 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
| 28 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
| 29 #include "chrome/common/chrome_view_type.h" | 29 #include "chrome/common/chrome_view_type.h" |
| 30 #include "chrome/common/extensions/extension.h" | 30 #include "chrome/common/extensions/extension.h" |
| 31 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 32 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
| 33 #include "content/browser/browsing_instance.h" | 33 #include "content/browser/browsing_instance.h" |
| 34 #include "content/browser/renderer_host/render_view_host.h" | 34 #include "content/browser/renderer_host/render_view_host.h" |
| 35 #include "content/browser/tab_contents/tab_contents.h" | 35 #include "content/browser/site_instance.h" |
| 36 #include "content/browser/tab_contents/tab_contents_view.h" | 36 #include "content/browser/tab_contents/tab_contents_view.h" |
| 37 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
| 38 #include "content/public/browser/notification_types.h" | 38 #include "content/public/browser/notification_types.h" |
| 39 #include "content/public/browser/web_contents.h" |
| 39 #include "grit/browser_resources.h" | 40 #include "grit/browser_resources.h" |
| 40 #include "grit/chromium_strings.h" | 41 #include "grit/chromium_strings.h" |
| 41 #include "grit/generated_resources.h" | 42 #include "grit/generated_resources.h" |
| 42 #include "grit/theme_resources.h" | 43 #include "grit/theme_resources.h" |
| 43 #include "ui/base/l10n/l10n_util.h" | 44 #include "ui/base/l10n/l10n_util.h" |
| 44 #include "ui/base/resource/resource_bundle.h" | 45 #include "ui/base/resource/resource_bundle.h" |
| 45 | 46 |
| 47 using content::WebContents; |
| 48 |
| 46 namespace { | 49 namespace { |
| 47 | 50 |
| 48 bool ShouldShowExtension(const Extension* extension) { | 51 bool ShouldShowExtension(const Extension* extension) { |
| 49 // Don't show themes since this page's UI isn't really useful for themes. | 52 // Don't show themes since this page's UI isn't really useful for themes. |
| 50 if (extension->is_theme()) | 53 if (extension->is_theme()) |
| 51 return false; | 54 return false; |
| 52 | 55 |
| 53 // Don't show component extensions because they are only extensions as an | 56 // Don't show component extensions because they are only extensions as an |
| 54 // implementation detail of Chrome. | 57 // implementation detail of Chrome. |
| 55 if (extension->location() == Extension::COMPONENT && | 58 if (extension->location() == Extension::COMPONENT && |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 IDS_EXTENSION_PACK_DIALOG_KEY_FILE_TYPE_DESCRIPTION)); | 480 IDS_EXTENSION_PACK_DIALOG_KEY_FILE_TYPE_DESCRIPTION)); |
| 478 info.include_all_files = true; | 481 info.include_all_files = true; |
| 479 file_type_index = 1; | 482 file_type_index = 1; |
| 480 } else { | 483 } else { |
| 481 NOTREACHED(); | 484 NOTREACHED(); |
| 482 return; | 485 return; |
| 483 } | 486 } |
| 484 | 487 |
| 485 load_extension_dialog_ = SelectFileDialog::Create(this); | 488 load_extension_dialog_ = SelectFileDialog::Create(this); |
| 486 load_extension_dialog_->SelectFile(type, select_title, FilePath(), &info, | 489 load_extension_dialog_->SelectFile(type, select_title, FilePath(), &info, |
| 487 file_type_index, FILE_PATH_LITERAL(""), web_ui()->tab_contents(), | 490 file_type_index, FILE_PATH_LITERAL(""), web_ui()->web_contents(), |
| 488 web_ui()->tab_contents()->GetView()->GetTopLevelNativeWindow(), NULL); | 491 web_ui()->web_contents()->GetView()->GetTopLevelNativeWindow(), NULL); |
| 489 } | 492 } |
| 490 | 493 |
| 491 | 494 |
| 492 void ExtensionSettingsHandler::FileSelected(const FilePath& path, int index, | 495 void ExtensionSettingsHandler::FileSelected(const FilePath& path, int index, |
| 493 void* params) { | 496 void* params) { |
| 494 // Add the extensions to the results structure. | 497 // Add the extensions to the results structure. |
| 495 ListValue results; | 498 ListValue results; |
| 496 results.Append(Value::CreateStringValue(path.value())); | 499 results.Append(Value::CreateStringValue(path.value())); |
| 497 web_ui()->CallJavascriptFunction("window.handleFilePathSelected", results); | 500 web_ui()->CallJavascriptFunction("window.handleFilePathSelected", results); |
| 498 } | 501 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED: | 603 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED: |
| 601 source_profile = Profile::FromBrowserContext( | 604 source_profile = Profile::FromBrowserContext( |
| 602 content::Source<RenderViewHost>(source)->site_instance()-> | 605 content::Source<RenderViewHost>(source)->site_instance()-> |
| 603 browsing_instance()->browser_context()); | 606 browsing_instance()->browser_context()); |
| 604 if (!profile->IsSameProfile(source_profile)) | 607 if (!profile->IsSameProfile(source_profile)) |
| 605 return; | 608 return; |
| 606 MaybeUpdateAfterNotification(); | 609 MaybeUpdateAfterNotification(); |
| 607 break; | 610 break; |
| 608 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED: | 611 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED: |
| 609 deleting_rvh_ = content::Details<BackgroundContents>(details)-> | 612 deleting_rvh_ = content::Details<BackgroundContents>(details)-> |
| 610 tab_contents()->GetRenderViewHost(); | 613 web_contents()->GetRenderViewHost(); |
| 611 // Fall through. | 614 // Fall through. |
| 612 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED: | 615 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED: |
| 613 case chrome::NOTIFICATION_EXTENSION_HOST_CREATED: | 616 case chrome::NOTIFICATION_EXTENSION_HOST_CREATED: |
| 614 source_profile = content::Source<Profile>(source).ptr(); | 617 source_profile = content::Source<Profile>(source).ptr(); |
| 615 if (!profile->IsSameProfile(source_profile)) | 618 if (!profile->IsSameProfile(source_profile)) |
| 616 return; | 619 return; |
| 617 MaybeUpdateAfterNotification(); | 620 MaybeUpdateAfterNotification(); |
| 618 break; | 621 break; |
| 619 case chrome::NOTIFICATION_EXTENSION_LOADED: | 622 case chrome::NOTIFICATION_EXTENSION_LOADED: |
| 620 case chrome::NOTIFICATION_EXTENSION_UNLOADED: | 623 case chrome::NOTIFICATION_EXTENSION_UNLOADED: |
| 621 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: | 624 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: |
| 622 case chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED: | 625 case chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED: |
| 623 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: | 626 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: |
| 624 MaybeUpdateAfterNotification(); | 627 MaybeUpdateAfterNotification(); |
| 625 break; | 628 break; |
| 626 default: | 629 default: |
| 627 NOTREACHED(); | 630 NOTREACHED(); |
| 628 } | 631 } |
| 629 } | 632 } |
| 630 | 633 |
| 631 const Extension* ExtensionSettingsHandler::GetExtension(const ListValue* args) { | 634 const Extension* ExtensionSettingsHandler::GetExtension(const ListValue* args) { |
| 632 std::string extension_id = UTF16ToUTF8(ExtractStringValue(args)); | 635 std::string extension_id = UTF16ToUTF8(ExtractStringValue(args)); |
| 633 CHECK(!extension_id.empty()); | 636 CHECK(!extension_id.empty()); |
| 634 return extension_service_->GetExtensionById(extension_id, true); | 637 return extension_service_->GetExtensionById(extension_id, true); |
| 635 } | 638 } |
| 636 | 639 |
| 637 void ExtensionSettingsHandler::MaybeUpdateAfterNotification() { | 640 void ExtensionSettingsHandler::MaybeUpdateAfterNotification() { |
| 638 TabContents* contents = web_ui()->tab_contents(); | 641 WebContents* contents = web_ui()->web_contents(); |
| 639 if (!ignore_notifications_ && contents && contents->GetRenderViewHost()) | 642 if (!ignore_notifications_ && contents && contents->GetRenderViewHost()) |
| 640 HandleRequestExtensionsData(NULL); | 643 HandleRequestExtensionsData(NULL); |
| 641 deleting_rvh_ = NULL; | 644 deleting_rvh_ = NULL; |
| 642 } | 645 } |
| 643 | 646 |
| 644 // Static | 647 // Static |
| 645 DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue( | 648 DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue( |
| 646 ExtensionService* service, const Extension* extension, | 649 ExtensionService* service, const Extension* extension, |
| 647 const std::vector<ExtensionPage>& pages, | 650 const std::vector<ExtensionPage>& pages, |
| 648 const ExtensionWarningSet* warnings_set, | 651 const ExtensionWarningSet* warnings_set, |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 chrome::VIEW_TYPE_EXTENSION_DIALOG == host_type) | 769 chrome::VIEW_TYPE_EXTENSION_DIALOG == host_type) |
| 767 continue; | 770 continue; |
| 768 | 771 |
| 769 GURL url = host->delegate()->GetURL(); | 772 GURL url = host->delegate()->GetURL(); |
| 770 content::RenderProcessHost* process = host->process(); | 773 content::RenderProcessHost* process = host->process(); |
| 771 result->push_back( | 774 result->push_back( |
| 772 ExtensionPage(url, process->GetID(), host->routing_id(), | 775 ExtensionPage(url, process->GetID(), host->routing_id(), |
| 773 process->GetBrowserContext()->IsOffTheRecord())); | 776 process->GetBrowserContext()->IsOffTheRecord())); |
| 774 } | 777 } |
| 775 } | 778 } |
| OLD | NEW |