Chromium Code Reviews| Index: chrome/browser/extensions/api/developer_private/inspectable_views_finder.cc |
| diff --git a/chrome/browser/extensions/api/developer_private/inspectable_views_finder.cc b/chrome/browser/extensions/api/developer_private/inspectable_views_finder.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2c4e50c586613035f5f0ab26e1178cf33a2e9fe0 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/api/developer_private/inspectable_views_finder.cc |
| @@ -0,0 +1,161 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/extensions/api/developer_private/inspectable_views_finder.h" |
| + |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/common/extensions/api/developer_private.h" |
| +#include "content/public/browser/render_process_host.h" |
| +#include "content/public/browser/render_view_host.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "extensions/browser/app_window/app_window.h" |
| +#include "extensions/browser/app_window/app_window_registry.h" |
| +#include "extensions/browser/process_manager.h" |
| +#include "extensions/browser/view_type_utils.h" |
| +#include "extensions/common/constants.h" |
| +#include "extensions/common/extension.h" |
| +#include "extensions/common/manifest_handlers/background_info.h" |
| +#include "url/gurl.h" |
| + |
| +namespace extensions { |
| + |
| +InspectableViewsFinder::InspectableViewsFinder( |
| + Profile* profile, |
| + content::RenderViewHost* deleting_rvh) |
| + : profile_(profile), |
| + deleting_rvh_(deleting_rvh) { |
| +} |
| + |
| +InspectableViewsFinder::~InspectableViewsFinder() { |
| +} |
| + |
| +// static |
| +InspectableViewsFinder::View InspectableViewsFinder::ConstructView( |
| + const GURL& url, |
| + int render_process_id, |
| + int render_view_id, |
| + bool incognito, |
| + bool generated_background_page) { |
| + linked_ptr<api::developer_private::ExtensionView> view( |
| + new api::developer_private::ExtensionView()); |
| + if (url.scheme() == kExtensionScheme) { |
| + // No leading slash. |
| + view->path = url.path().substr(1); |
| + } else { |
| + // For live pages, use the full URL. |
|
not at google - send to devlin
2015/03/11 17:43:05
Why? Is this part of the API? Seems like the sort
Devlin
2015/03/11 21:45:53
I'd be inclined to agree, but kinda wanna leave it
not at google - send to devlin
2015/03/11 21:50:24
Backwards compatibility with a bad API? I think we
Devlin
2015/03/11 23:34:07
Done.
|
| + view->path = url.spec(); |
| + } |
| + view->render_process_id = render_process_id; |
| + view->render_view_id = render_view_id; |
| + view->incognito = incognito; |
| + view->generated_background_page = generated_background_page; |
| + return view; |
| +} |
| + |
| +InspectableViewsFinder::ViewList InspectableViewsFinder::GetViewsForExtension( |
| + const Extension& extension, |
| + bool is_enabled) { |
| + ViewList result; |
| + GetViewsForExtensionForProfile( |
| + extension, profile_, is_enabled, false, &result); |
| + if (profile_->HasOffTheRecordProfile()) { |
| + GetViewsForExtensionForProfile( |
| + extension, |
| + profile_->GetOffTheRecordProfile(), |
| + is_enabled, |
| + true, |
| + &result); |
| + } |
| + |
| + return result; |
| +} |
| + |
| +void InspectableViewsFinder::GetViewsForExtensionForProfile( |
| + const Extension& extension, |
| + Profile* profile, |
| + bool is_enabled, |
| + bool is_incognito, |
| + ViewList* result) { |
| + ProcessManager* process_manager = ProcessManager::Get(profile); |
| + // Get the extension process's active views. |
| + GetViewsForExtensionProcess( |
| + extension, |
| + process_manager->GetRenderViewHostsForExtension(extension.id()), |
| + is_incognito, |
| + result); |
| + // Get app window views, if not incognito. |
| + if (!is_incognito) |
| + GetAppWindowViewsForExtension(extension, result); |
| + // Include a link to start the lazy background page, if applicable. |
| + if (BackgroundInfo::HasLazyBackgroundPage(&extension) && |
| + is_enabled && |
| + !process_manager->GetBackgroundHostForExtension(extension.id())) { |
| + result->push_back(ConstructView( |
| + BackgroundInfo::GetBackgroundURL(&extension), |
| + -1, |
| + -1, |
|
not at google - send to devlin
2015/03/11 17:43:05
Why are these -1?
Devlin
2015/03/11 21:45:54
For some very strange reason, background pages hav
|
| + is_incognito, |
| + BackgroundInfo::HasGeneratedBackgroundPage(&extension))); |
| + } |
| +} |
| + |
| +void InspectableViewsFinder::GetViewsForExtensionProcess( |
| + const Extension& extension, |
| + const std::set<content::RenderViewHost*>& views, |
| + bool is_incognito, |
| + ViewList* result) { |
| + bool has_generated_background_page = |
| + BackgroundInfo::HasGeneratedBackgroundPage(&extension); |
| + for (const content::RenderViewHost* host : views) { |
| + content::WebContents* web_contents = |
| + content::WebContents::FromRenderViewHost(host); |
| + ViewType host_type = GetViewType(web_contents); |
| + if (host == deleting_rvh_ || |
| + VIEW_TYPE_EXTENSION_POPUP == host_type || |
|
not at google - send to devlin
2015/03/11 17:43:05
No yoda expressions; use host_type == VIEW_TYPE_EX
Devlin
2015/03/11 21:45:53
Like them either, I did not. Trying to make a sim
|
| + VIEW_TYPE_EXTENSION_DIALOG == host_type) |
|
not at google - send to devlin
2015/03/11 17:43:05
Why are popups and dialogs filtered out anyway? Th
Devlin
2015/03/11 21:45:53
My guess is because they are inspected separately
not at google - send to devlin
2015/03/11 21:50:24
Alright, well something needs to change, because t
Devlin
2015/03/11 23:34:07
Done.
|
| + continue; |
| + |
| + GURL url = web_contents->GetURL(); |
|
not at google - send to devlin
2015/03/11 17:43:05
const GURL&
Devlin
2015/03/11 21:45:53
Done.
|
| + content::RenderProcessHost* process = host->GetProcess(); |
| + bool is_background_page = |
| + (url == BackgroundInfo::GetBackgroundURL(&extension)); |
| + result->push_back(ConstructView( |
| + url, |
| + process->GetID(), |
| + host->GetRoutingID(), |
| + is_incognito, |
| + is_background_page && has_generated_background_page)); |
| + } |
| +} |
| + |
| +void InspectableViewsFinder::GetAppWindowViewsForExtension( |
| + const Extension& extension, |
| + ViewList* result) { |
| + AppWindowRegistry* registry = AppWindowRegistry::Get(profile_); |
| + if (!registry) |
| + return; |
| + |
| + AppWindowRegistry::AppWindowList windows = |
| + registry->GetAppWindowsForApp(extension.id()); |
| + |
| + bool has_generated_background_page = |
| + BackgroundInfo::HasGeneratedBackgroundPage(&extension); |
| + for (const AppWindow* window : windows) { |
| + content::WebContents* web_contents = window->web_contents(); |
| + content::RenderViewHost* host = web_contents->GetRenderViewHost(); |
| + content::RenderProcessHost* process = host->GetProcess(); |
| + |
| + bool is_background_page = |
| + (web_contents->GetURL() == |
| + BackgroundInfo::GetBackgroundURL(&extension)); |
| + result->push_back(ConstructView( |
| + web_contents->GetURL(), |
| + process->GetID(), |
| + host->GetRoutingID(), |
| + false, |
| + is_background_page && has_generated_background_page)); |
| + } |
| +} |
| + |
| +} // namespace extensions |