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

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

Issue 1018493002: [Extensions] Combine developerPrivate.inspect and developerPrivate.openDevTools (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 "base/base64.h" 7 #include "base/base64.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 ignore_result(base::ReadFileToString(path, &data)); 164 ignore_result(base::ReadFileToString(path, &data));
165 return data; 165 return data;
166 } 166 }
167 167
168 } // namespace 168 } // namespace
169 169
170 namespace AllowFileAccess = api::developer_private::AllowFileAccess; 170 namespace AllowFileAccess = api::developer_private::AllowFileAccess;
171 namespace AllowIncognito = api::developer_private::AllowIncognito; 171 namespace AllowIncognito = api::developer_private::AllowIncognito;
172 namespace ChoosePath = api::developer_private::ChoosePath; 172 namespace ChoosePath = api::developer_private::ChoosePath;
173 namespace GetItemsInfo = api::developer_private::GetItemsInfo; 173 namespace GetItemsInfo = api::developer_private::GetItemsInfo;
174 namespace Inspect = api::developer_private::Inspect;
175 namespace PackDirectory = api::developer_private::PackDirectory; 174 namespace PackDirectory = api::developer_private::PackDirectory;
176 namespace Reload = api::developer_private::Reload; 175 namespace Reload = api::developer_private::Reload;
177 176
178 static base::LazyInstance<BrowserContextKeyedAPIFactory<DeveloperPrivateAPI> > 177 static base::LazyInstance<BrowserContextKeyedAPIFactory<DeveloperPrivateAPI> >
179 g_factory = LAZY_INSTANCE_INITIALIZER; 178 g_factory = LAZY_INSTANCE_INITIALIZER;
180 179
181 // static 180 // static
182 BrowserContextKeyedAPIFactory<DeveloperPrivateAPI>* 181 BrowserContextKeyedAPIFactory<DeveloperPrivateAPI>*
183 DeveloperPrivateAPI::GetFactoryInstance() { 182 DeveloperPrivateAPI::GetFactoryInstance() {
184 return g_factory.Pointer(); 183 return g_factory.Pointer();
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 target_extension, 590 target_extension,
592 source_context_type() == Feature::WEBUI_CONTEXT, 591 source_context_type() == Feature::WEBUI_CONTEXT,
593 base::Bind(&DeveloperPrivateShowPermissionsDialogFunction::Finish, this)); 592 base::Bind(&DeveloperPrivateShowPermissionsDialogFunction::Finish, this));
594 return RespondLater(); 593 return RespondLater();
595 } 594 }
596 595
597 void DeveloperPrivateShowPermissionsDialogFunction::Finish() { 596 void DeveloperPrivateShowPermissionsDialogFunction::Finish() {
598 Respond(NoArguments()); 597 Respond(NoArguments());
599 } 598 }
600 599
601 ExtensionFunction::ResponseAction DeveloperPrivateInspectFunction::Run() {
602 scoped_ptr<developer::Inspect::Params> params(
603 developer::Inspect::Params::Create(*args_));
604 EXTENSION_FUNCTION_VALIDATE(params);
605 const developer::InspectOptions& options = params->options;
606
607 int render_process_id = 0;
608 if (options.render_process_id.as_string &&
609 !base::StringToInt(*options.render_process_id.as_string,
610 &render_process_id)) {
611 return RespondNow(Error(kNoSuchRendererError));
612 } else if (options.render_process_id.as_integer) {
613 render_process_id = *options.render_process_id.as_integer;
614 }
615
616 int render_view_id = 0;
617 if (options.render_view_id.as_string &&
618 !base::StringToInt(*options.render_view_id.as_string, &render_view_id)) {
619 return RespondNow(Error(kNoSuchRendererError));
620 } else if (options.render_view_id.as_integer) {
621 render_view_id = *options.render_view_id.as_integer;
622 }
623
624 if (render_process_id == -1) {
625 // This is a lazy background page.
626 const Extension* extension = ExtensionRegistry::Get(
627 browser_context())->enabled_extensions().GetByID(options.extension_id);
628 if (!extension)
629 return RespondNow(Error(kNoSuchExtensionError));
630
631 Profile* profile = Profile::FromBrowserContext(browser_context());
632 if (options.incognito)
633 profile = profile->GetOffTheRecordProfile();
634
635 // Wakes up the background page and opens the inspect window.
636 devtools_util::InspectBackgroundPage(extension, profile);
637 return RespondNow(NoArguments());
638 }
639
640 content::RenderViewHost* host = content::RenderViewHost::FromID(
641 render_process_id, render_view_id);
642
643 if (!host || !content::WebContents::FromRenderViewHost(host))
644 return RespondNow(Error(kNoSuchRendererError));
645
646 DevToolsWindow::OpenDevToolsWindow(
647 content::WebContents::FromRenderViewHost(host));
648 return RespondNow(NoArguments());
649 }
650
651 DeveloperPrivateInspectFunction::~DeveloperPrivateInspectFunction() {}
652
653 DeveloperPrivateLoadUnpackedFunction::DeveloperPrivateLoadUnpackedFunction() 600 DeveloperPrivateLoadUnpackedFunction::DeveloperPrivateLoadUnpackedFunction()
654 : fail_quietly_(false) { 601 : fail_quietly_(false) {
655 } 602 }
656 603
657 ExtensionFunction::ResponseAction DeveloperPrivateLoadUnpackedFunction::Run() { 604 ExtensionFunction::ResponseAction DeveloperPrivateLoadUnpackedFunction::Run() {
658 scoped_ptr<developer_private::LoadUnpacked::Params> params( 605 scoped_ptr<developer_private::LoadUnpacked::Params> params(
659 developer_private::LoadUnpacked::Params::Create(*args_)); 606 developer_private::LoadUnpacked::Params::Create(*args_));
660 EXTENSION_FUNCTION_VALIDATE(params); 607 EXTENSION_FUNCTION_VALIDATE(params);
661 608
662 if (!ShowPicker( 609 if (!ShowPicker(
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 DeveloperPrivateOpenDevToolsFunction::DeveloperPrivateOpenDevToolsFunction() {} 1128 DeveloperPrivateOpenDevToolsFunction::DeveloperPrivateOpenDevToolsFunction() {}
1182 DeveloperPrivateOpenDevToolsFunction::~DeveloperPrivateOpenDevToolsFunction() {} 1129 DeveloperPrivateOpenDevToolsFunction::~DeveloperPrivateOpenDevToolsFunction() {}
1183 1130
1184 ExtensionFunction::ResponseAction 1131 ExtensionFunction::ResponseAction
1185 DeveloperPrivateOpenDevToolsFunction::Run() { 1132 DeveloperPrivateOpenDevToolsFunction::Run() {
1186 scoped_ptr<developer::OpenDevTools::Params> params( 1133 scoped_ptr<developer::OpenDevTools::Params> params(
1187 developer::OpenDevTools::Params::Create(*args_)); 1134 developer::OpenDevTools::Params::Create(*args_));
1188 EXTENSION_FUNCTION_VALIDATE(params); 1135 EXTENSION_FUNCTION_VALIDATE(params);
1189 const developer::OpenDevToolsProperties& properties = params->properties; 1136 const developer::OpenDevToolsProperties& properties = params->properties;
1190 1137
1138 if (properties.render_process_id == -1) {
1139 // This is a lazy background page.
1140 const Extension* extension = properties.extension_id ?
1141 ExtensionRegistry::Get(browser_context())->enabled_extensions().GetByID(
1142 *properties.extension_id) : nullptr;
1143 if (!extension)
1144 return RespondNow(Error(kNoSuchExtensionError));
1145
1146 Profile* profile = Profile::FromBrowserContext(browser_context());
1147 if (properties.incognito && *properties.incognito)
1148 profile = profile->GetOffTheRecordProfile();
1149
1150 // Wakes up the background page and opens the inspect window.
1151 devtools_util::InspectBackgroundPage(extension, profile);
1152 return RespondNow(NoArguments());
1153 }
1154
1191 content::RenderViewHost* rvh = 1155 content::RenderViewHost* rvh =
1192 content::RenderViewHost::FromID(properties.render_process_id, 1156 content::RenderViewHost::FromID(properties.render_process_id,
1193 properties.render_view_id); 1157 properties.render_view_id);
1158
1194 content::WebContents* web_contents = 1159 content::WebContents* web_contents =
1195 rvh ? content::WebContents::FromRenderViewHost(rvh) : nullptr; 1160 rvh ? content::WebContents::FromRenderViewHost(rvh) : nullptr;
1196 // It's possible that the render view was closed since we last updated the 1161 // It's possible that the render view was closed since we last updated the
1197 // links. Handle this gracefully. 1162 // links. Handle this gracefully.
1198 if (!web_contents) 1163 if (!web_contents)
1199 return RespondNow(Error(kNoSuchRendererError)); 1164 return RespondNow(Error(kNoSuchRendererError));
1200 1165
1201 // If we include a url, we should inspect it specifically (and not just the 1166 // If we include a url, we should inspect it specifically (and not just the
1202 // render view). 1167 // render view).
1203 if (properties.url) { 1168 if (properties.url) {
(...skipping 21 matching lines...) Expand all
1225 1190
1226 TabStripModel* tab_strip = browser->tab_strip_model(); 1191 TabStripModel* tab_strip = browser->tab_strip_model();
1227 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(web_contents), 1192 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(web_contents),
1228 false); // Not through direct user gesture. 1193 false); // Not through direct user gesture.
1229 return RespondNow(NoArguments()); 1194 return RespondNow(NoArguments());
1230 } 1195 }
1231 1196
1232 } // namespace api 1197 } // namespace api
1233 1198
1234 } // namespace extensions 1199 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698