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

Side by Side Diff: chrome/browser/extensions/api/developer_private/developer_private_api.cc

Issue 989843002: [Extensions] Make chrome://extensions use developerPrivate for inspect (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/api/developer_private/developer_private_api. h" 5 #include "chrome/browser/extensions/api/developer_private/developer_private_api. h"
6 6
7 #include "apps/app_load_service.h" 7 #include "apps/app_load_service.h"
8 #include "apps/saved_files_service.h" 8 #include "apps/saved_files_service.h"
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 const char kSupervisedUserError[] = 96 const char kSupervisedUserError[] =
97 "Supervised users cannot modify extension settings."; 97 "Supervised users cannot modify extension settings.";
98 const char kCannotModifyPolicyExtensionError[] = 98 const char kCannotModifyPolicyExtensionError[] =
99 "Cannot modify the extension by policy."; 99 "Cannot modify the extension by policy.";
100 const char kRequiresUserGestureError[] = 100 const char kRequiresUserGestureError[] =
101 "This action requires a user gesture."; 101 "This action requires a user gesture.";
102 const char kCouldNotShowSelectFileDialogError[] = 102 const char kCouldNotShowSelectFileDialogError[] =
103 "Could not show a file chooser."; 103 "Could not show a file chooser.";
104 const char kFileSelectionCanceled[] = 104 const char kFileSelectionCanceled[] =
105 "File selection was canceled."; 105 "File selection was canceled.";
106 const char kNoSuchRendererError[] = "No such renderer.";
106 const char kInvalidPathError[] = "Invalid path."; 107 const char kInvalidPathError[] = "Invalid path.";
107 const char kManifestKeyIsRequiredError[] = 108 const char kManifestKeyIsRequiredError[] =
108 "The 'manifestKey' argument is required for manifest files."; 109 "The 'manifestKey' argument is required for manifest files.";
109 const char kNoSuchRendererError[] = "Could not find the renderer.";
110 110
111 const char kUnpackedAppsFolder[] = "apps_target"; 111 const char kUnpackedAppsFolder[] = "apps_target";
112 const char kManifestFile[] = "manifest.json"; 112 const char kManifestFile[] = "manifest.json";
113 113
114 ExtensionService* GetExtensionService(content::BrowserContext* context) { 114 ExtensionService* GetExtensionService(content::BrowserContext* context) {
115 return ExtensionSystem::Get(context)->extension_service(); 115 return ExtensionSystem::Get(context)->extension_service();
116 } 116 }
117 117
118 ExtensionUpdater* GetExtensionUpdater(Profile* profile) { 118 ExtensionUpdater* GetExtensionUpdater(Profile* profile) {
119 return GetExtensionService(profile)->updater(); 119 return GetExtensionService(profile)->updater();
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 SendResponse(true); 843 SendResponse(true);
844 Release(); 844 Release();
845 } 845 }
846 846
847 DeveloperPrivateShowPermissionsDialogFunction:: 847 DeveloperPrivateShowPermissionsDialogFunction::
848 DeveloperPrivateShowPermissionsDialogFunction() {} 848 DeveloperPrivateShowPermissionsDialogFunction() {}
849 849
850 DeveloperPrivateShowPermissionsDialogFunction:: 850 DeveloperPrivateShowPermissionsDialogFunction::
851 ~DeveloperPrivateShowPermissionsDialogFunction() {} 851 ~DeveloperPrivateShowPermissionsDialogFunction() {}
852 852
853 bool DeveloperPrivateInspectFunction::RunSync() { 853 ExtensionFunction::ResponseAction DeveloperPrivateInspectFunction::Run() {
854 scoped_ptr<developer::Inspect::Params> params( 854 scoped_ptr<developer::Inspect::Params> params(
855 developer::Inspect::Params::Create(*args_)); 855 developer::Inspect::Params::Create(*args_));
856 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); 856 EXTENSION_FUNCTION_VALIDATE(params);
857 const developer::InspectOptions& options = params->options; 857 const developer::InspectOptions& options = params->options;
858 858
859 int render_process_id; 859 int render_process_id = 0;
860 base::StringToInt(options.render_process_id, &render_process_id); 860 if (options.render_process_id.as_string &&
861 !base::StringToInt(*options.render_process_id.as_string,
862 &render_process_id)) {
863 return RespondNow(Error(kNoSuchRendererError));
864 } else {
865 render_process_id = *options.render_process_id.as_integer;
866 }
867
868 int render_view_id = 0;
869 if (options.render_view_id.as_string &&
870 !base::StringToInt(*options.render_view_id.as_string, &render_view_id)) {
871 return RespondNow(Error(kNoSuchRendererError));
872 } else {
873 render_view_id = *options.render_view_id.as_integer;
874 }
861 875
862 if (render_process_id == -1) { 876 if (render_process_id == -1) {
863 // This is a lazy background page. Identify if it is a normal 877 // This is a lazy background page.
864 // or incognito background page.
865 const Extension* extension = ExtensionRegistry::Get( 878 const Extension* extension = ExtensionRegistry::Get(
866 GetProfile())->enabled_extensions().GetByID(options.extension_id); 879 browser_context())->enabled_extensions().GetByID(options.extension_id);
867 DCHECK(extension); 880 if (!extension)
868 // Wakes up the background page and opens the inspect window. 881 return RespondNow(Error(kNoSuchExtensionError));
869 devtools_util::InspectBackgroundPage(extension, GetProfile()); 882
870 return false; 883 Profile* profile = Profile::FromBrowserContext(browser_context());
884 if (options.incognito)
885 profile = profile->GetOffTheRecordProfile();
886
887 // Wakes up the background page and opens the inspect window.
888 devtools_util::InspectBackgroundPage(extension, profile);
889 return RespondNow(NoArguments());
871 } 890 }
872 891
873 int render_view_id;
874 base::StringToInt(options.render_view_id, &render_view_id);
875 content::RenderViewHost* host = content::RenderViewHost::FromID( 892 content::RenderViewHost* host = content::RenderViewHost::FromID(
876 render_process_id, render_view_id); 893 render_process_id, render_view_id);
877 894
878 if (!host || !content::WebContents::FromRenderViewHost(host)) { 895 if (!host || !content::WebContents::FromRenderViewHost(host))
879 // This can happen if the host has gone away since the page was displayed. 896 return RespondNow(Error(kNoSuchRendererError));
880 return false;
881 }
882 897
883 DevToolsWindow::OpenDevToolsWindow( 898 DevToolsWindow::OpenDevToolsWindow(
884 content::WebContents::FromRenderViewHost(host)); 899 content::WebContents::FromRenderViewHost(host));
885 return true; 900 return RespondNow(NoArguments());
886 } 901 }
887 902
888 DeveloperPrivateInspectFunction::~DeveloperPrivateInspectFunction() {} 903 DeveloperPrivateInspectFunction::~DeveloperPrivateInspectFunction() {}
889 904
890 DeveloperPrivateLoadUnpackedFunction::DeveloperPrivateLoadUnpackedFunction() 905 DeveloperPrivateLoadUnpackedFunction::DeveloperPrivateLoadUnpackedFunction()
891 : fail_quietly_(false) { 906 : fail_quietly_(false) {
892 } 907 }
893 908
894 ExtensionFunction::ResponseAction DeveloperPrivateLoadUnpackedFunction::Run() { 909 ExtensionFunction::ResponseAction DeveloperPrivateLoadUnpackedFunction::Run() {
895 scoped_ptr<developer_private::LoadUnpacked::Params> params( 910 scoped_ptr<developer_private::LoadUnpacked::Params> params(
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 1477
1463 TabStripModel* tab_strip = browser->tab_strip_model(); 1478 TabStripModel* tab_strip = browser->tab_strip_model();
1464 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(web_contents), 1479 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(web_contents),
1465 false); // Not through direct user gesture. 1480 false); // Not through direct user gesture.
1466 return RespondNow(NoArguments()); 1481 return RespondNow(NoArguments());
1467 } 1482 }
1468 1483
1469 } // namespace api 1484 } // namespace api
1470 1485
1471 } // namespace extensions 1486 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698