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

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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 return false; 187 return false;
188 } 188 }
189 189
190 return true; 190 return true;
191 } 191 }
192 192
193 } // namespace 193 } // namespace
194 194
195 namespace ChoosePath = api::developer_private::ChoosePath; 195 namespace ChoosePath = api::developer_private::ChoosePath;
196 namespace GetItemsInfo = api::developer_private::GetItemsInfo; 196 namespace GetItemsInfo = api::developer_private::GetItemsInfo;
197 namespace Inspect = api::developer_private::Inspect;
198 namespace PackDirectory = api::developer_private::PackDirectory; 197 namespace PackDirectory = api::developer_private::PackDirectory;
199 namespace Reload = api::developer_private::Reload; 198 namespace Reload = api::developer_private::Reload;
200 199
201 static base::LazyInstance<BrowserContextKeyedAPIFactory<DeveloperPrivateAPI> > 200 static base::LazyInstance<BrowserContextKeyedAPIFactory<DeveloperPrivateAPI> >
202 g_factory = LAZY_INSTANCE_INITIALIZER; 201 g_factory = LAZY_INSTANCE_INITIALIZER;
203 202
204 // static 203 // static
205 BrowserContextKeyedAPIFactory<DeveloperPrivateAPI>* 204 BrowserContextKeyedAPIFactory<DeveloperPrivateAPI>*
206 DeveloperPrivateAPI::GetFactoryInstance() { 205 DeveloperPrivateAPI::GetFactoryInstance() {
207 return g_factory.Pointer(); 206 return g_factory.Pointer();
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 target_extension, 604 target_extension,
606 source_context_type() == Feature::WEBUI_CONTEXT, 605 source_context_type() == Feature::WEBUI_CONTEXT,
607 base::Bind(&DeveloperPrivateShowPermissionsDialogFunction::Finish, this)); 606 base::Bind(&DeveloperPrivateShowPermissionsDialogFunction::Finish, this));
608 return RespondLater(); 607 return RespondLater();
609 } 608 }
610 609
611 void DeveloperPrivateShowPermissionsDialogFunction::Finish() { 610 void DeveloperPrivateShowPermissionsDialogFunction::Finish() {
612 Respond(NoArguments()); 611 Respond(NoArguments());
613 } 612 }
614 613
615 ExtensionFunction::ResponseAction DeveloperPrivateInspectFunction::Run() {
616 scoped_ptr<developer::Inspect::Params> params(
617 developer::Inspect::Params::Create(*args_));
618 EXTENSION_FUNCTION_VALIDATE(params);
619 const developer::InspectOptions& options = params->options;
620
621 int render_process_id = 0;
622 if (options.render_process_id.as_string &&
623 !base::StringToInt(*options.render_process_id.as_string,
624 &render_process_id)) {
625 return RespondNow(Error(kNoSuchRendererError));
626 } else if (options.render_process_id.as_integer) {
627 render_process_id = *options.render_process_id.as_integer;
628 }
629
630 int render_view_id = 0;
631 if (options.render_view_id.as_string &&
632 !base::StringToInt(*options.render_view_id.as_string, &render_view_id)) {
633 return RespondNow(Error(kNoSuchRendererError));
634 } else if (options.render_view_id.as_integer) {
635 render_view_id = *options.render_view_id.as_integer;
636 }
637
638 if (render_process_id == -1) {
639 // This is a lazy background page.
640 const Extension* extension = ExtensionRegistry::Get(
641 browser_context())->enabled_extensions().GetByID(options.extension_id);
642 if (!extension)
643 return RespondNow(Error(kNoSuchExtensionError));
644
645 Profile* profile = Profile::FromBrowserContext(browser_context());
646 if (options.incognito)
647 profile = profile->GetOffTheRecordProfile();
648
649 // Wakes up the background page and opens the inspect window.
650 devtools_util::InspectBackgroundPage(extension, profile);
651 return RespondNow(NoArguments());
652 }
653
654 content::RenderViewHost* host = content::RenderViewHost::FromID(
655 render_process_id, render_view_id);
656
657 if (!host || !content::WebContents::FromRenderViewHost(host))
658 return RespondNow(Error(kNoSuchRendererError));
659
660 DevToolsWindow::OpenDevToolsWindow(
661 content::WebContents::FromRenderViewHost(host));
662 return RespondNow(NoArguments());
663 }
664
665 DeveloperPrivateInspectFunction::~DeveloperPrivateInspectFunction() {}
666
667 DeveloperPrivateLoadUnpackedFunction::DeveloperPrivateLoadUnpackedFunction() 614 DeveloperPrivateLoadUnpackedFunction::DeveloperPrivateLoadUnpackedFunction()
668 : fail_quietly_(false) { 615 : fail_quietly_(false) {
669 } 616 }
670 617
671 ExtensionFunction::ResponseAction DeveloperPrivateLoadUnpackedFunction::Run() { 618 ExtensionFunction::ResponseAction DeveloperPrivateLoadUnpackedFunction::Run() {
672 scoped_ptr<developer_private::LoadUnpacked::Params> params( 619 scoped_ptr<developer_private::LoadUnpacked::Params> params(
673 developer_private::LoadUnpacked::Params::Create(*args_)); 620 developer_private::LoadUnpacked::Params::Create(*args_));
674 EXTENSION_FUNCTION_VALIDATE(params); 621 EXTENSION_FUNCTION_VALIDATE(params);
675 622
676 if (!ShowPicker( 623 if (!ShowPicker(
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 DeveloperPrivateOpenDevToolsFunction::DeveloperPrivateOpenDevToolsFunction() {} 1142 DeveloperPrivateOpenDevToolsFunction::DeveloperPrivateOpenDevToolsFunction() {}
1196 DeveloperPrivateOpenDevToolsFunction::~DeveloperPrivateOpenDevToolsFunction() {} 1143 DeveloperPrivateOpenDevToolsFunction::~DeveloperPrivateOpenDevToolsFunction() {}
1197 1144
1198 ExtensionFunction::ResponseAction 1145 ExtensionFunction::ResponseAction
1199 DeveloperPrivateOpenDevToolsFunction::Run() { 1146 DeveloperPrivateOpenDevToolsFunction::Run() {
1200 scoped_ptr<developer::OpenDevTools::Params> params( 1147 scoped_ptr<developer::OpenDevTools::Params> params(
1201 developer::OpenDevTools::Params::Create(*args_)); 1148 developer::OpenDevTools::Params::Create(*args_));
1202 EXTENSION_FUNCTION_VALIDATE(params); 1149 EXTENSION_FUNCTION_VALIDATE(params);
1203 const developer::OpenDevToolsProperties& properties = params->properties; 1150 const developer::OpenDevToolsProperties& properties = params->properties;
1204 1151
1152 if (properties.render_process_id == -1) {
1153 // This is a lazy background page.
1154 const Extension* extension = properties.extension_id ?
1155 ExtensionRegistry::Get(browser_context())->enabled_extensions().GetByID(
1156 *properties.extension_id) : nullptr;
1157 if (!extension)
1158 return RespondNow(Error(kNoSuchExtensionError));
1159
1160 Profile* profile = Profile::FromBrowserContext(browser_context());
1161 if (properties.incognito && *properties.incognito)
1162 profile = profile->GetOffTheRecordProfile();
1163
1164 // Wakes up the background page and opens the inspect window.
1165 devtools_util::InspectBackgroundPage(extension, profile);
1166 return RespondNow(NoArguments());
1167 }
1168
1205 content::RenderViewHost* rvh = 1169 content::RenderViewHost* rvh =
1206 content::RenderViewHost::FromID(properties.render_process_id, 1170 content::RenderViewHost::FromID(properties.render_process_id,
1207 properties.render_view_id); 1171 properties.render_view_id);
1172
1208 content::WebContents* web_contents = 1173 content::WebContents* web_contents =
1209 rvh ? content::WebContents::FromRenderViewHost(rvh) : nullptr; 1174 rvh ? content::WebContents::FromRenderViewHost(rvh) : nullptr;
1210 // It's possible that the render view was closed since we last updated the 1175 // It's possible that the render view was closed since we last updated the
1211 // links. Handle this gracefully. 1176 // links. Handle this gracefully.
1212 if (!web_contents) 1177 if (!web_contents)
1213 return RespondNow(Error(kNoSuchRendererError)); 1178 return RespondNow(Error(kNoSuchRendererError));
1214 1179
1215 // If we include a url, we should inspect it specifically (and not just the 1180 // If we include a url, we should inspect it specifically (and not just the
1216 // render view). 1181 // render view).
1217 if (properties.url) { 1182 if (properties.url) {
(...skipping 21 matching lines...) Expand all
1239 1204
1240 TabStripModel* tab_strip = browser->tab_strip_model(); 1205 TabStripModel* tab_strip = browser->tab_strip_model();
1241 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(web_contents), 1206 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(web_contents),
1242 false); // Not through direct user gesture. 1207 false); // Not through direct user gesture.
1243 return RespondNow(NoArguments()); 1208 return RespondNow(NoArguments());
1244 } 1209 }
1245 1210
1246 } // namespace api 1211 } // namespace api
1247 1212
1248 } // namespace extensions 1213 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698