 Chromium Code Reviews
 Chromium Code Reviews Issue 989813002:
  [Extensions] Make a chrome.developerPrivate.getExtensionsInfo function  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 989813002:
  [Extensions] Make a chrome.developerPrivate.getExtensionsInfo function  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| OLD | NEW | 
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/extensions/api/developer_private/inspectable_views_find er.h" | |
| 6 | |
| 7 #include "chrome/browser/profiles/profile.h" | |
| 8 #include "chrome/common/extensions/api/developer_private.h" | |
| 9 #include "content/public/browser/render_process_host.h" | |
| 10 #include "content/public/browser/render_view_host.h" | |
| 11 #include "content/public/browser/web_contents.h" | |
| 12 #include "extensions/browser/app_window/app_window.h" | |
| 13 #include "extensions/browser/app_window/app_window_registry.h" | |
| 14 #include "extensions/browser/process_manager.h" | |
| 15 #include "extensions/browser/view_type_utils.h" | |
| 16 #include "extensions/common/constants.h" | |
| 17 #include "extensions/common/extension.h" | |
| 18 #include "extensions/common/manifest_handlers/background_info.h" | |
| 19 #include "url/gurl.h" | |
| 20 | |
| 21 namespace extensions { | |
| 22 | |
| 23 InspectableViewsFinder::InspectableViewsFinder( | |
| 24 Profile* profile, | |
| 25 content::RenderViewHost* deleting_rvh) | |
| 26 : profile_(profile), | |
| 27 deleting_rvh_(deleting_rvh) { | |
| 28 } | |
| 29 | |
| 30 InspectableViewsFinder::~InspectableViewsFinder() { | |
| 31 } | |
| 32 | |
| 33 // static | |
| 34 InspectableViewsFinder::View InspectableViewsFinder::ConstructView( | |
| 35 const GURL& url, | |
| 36 int render_process_id, | |
| 37 int render_view_id, | |
| 38 bool incognito, | |
| 39 bool generated_background_page) { | |
| 40 linked_ptr<api::developer_private::ExtensionView> view( | |
| 41 new api::developer_private::ExtensionView()); | |
| 42 if (url.scheme() == kExtensionScheme) { | |
| 43 // No leading slash. | |
| 44 view->path = url.path().substr(1); | |
| 45 } else { | |
| 46 // 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.
 | |
| 47 view->path = url.spec(); | |
| 48 } | |
| 49 view->render_process_id = render_process_id; | |
| 50 view->render_view_id = render_view_id; | |
| 51 view->incognito = incognito; | |
| 52 view->generated_background_page = generated_background_page; | |
| 53 return view; | |
| 54 } | |
| 55 | |
| 56 InspectableViewsFinder::ViewList InspectableViewsFinder::GetViewsForExtension( | |
| 57 const Extension& extension, | |
| 58 bool is_enabled) { | |
| 59 ViewList result; | |
| 60 GetViewsForExtensionForProfile( | |
| 61 extension, profile_, is_enabled, false, &result); | |
| 62 if (profile_->HasOffTheRecordProfile()) { | |
| 63 GetViewsForExtensionForProfile( | |
| 64 extension, | |
| 65 profile_->GetOffTheRecordProfile(), | |
| 66 is_enabled, | |
| 67 true, | |
| 68 &result); | |
| 69 } | |
| 70 | |
| 71 return result; | |
| 72 } | |
| 73 | |
| 74 void InspectableViewsFinder::GetViewsForExtensionForProfile( | |
| 75 const Extension& extension, | |
| 76 Profile* profile, | |
| 77 bool is_enabled, | |
| 78 bool is_incognito, | |
| 79 ViewList* result) { | |
| 80 ProcessManager* process_manager = ProcessManager::Get(profile); | |
| 81 // Get the extension process's active views. | |
| 82 GetViewsForExtensionProcess( | |
| 83 extension, | |
| 84 process_manager->GetRenderViewHostsForExtension(extension.id()), | |
| 85 is_incognito, | |
| 86 result); | |
| 87 // Get app window views, if not incognito. | |
| 88 if (!is_incognito) | |
| 89 GetAppWindowViewsForExtension(extension, result); | |
| 90 // Include a link to start the lazy background page, if applicable. | |
| 91 if (BackgroundInfo::HasLazyBackgroundPage(&extension) && | |
| 92 is_enabled && | |
| 93 !process_manager->GetBackgroundHostForExtension(extension.id())) { | |
| 94 result->push_back(ConstructView( | |
| 95 BackgroundInfo::GetBackgroundURL(&extension), | |
| 96 -1, | |
| 97 -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
 | |
| 98 is_incognito, | |
| 99 BackgroundInfo::HasGeneratedBackgroundPage(&extension))); | |
| 100 } | |
| 101 } | |
| 102 | |
| 103 void InspectableViewsFinder::GetViewsForExtensionProcess( | |
| 104 const Extension& extension, | |
| 105 const std::set<content::RenderViewHost*>& views, | |
| 106 bool is_incognito, | |
| 107 ViewList* result) { | |
| 108 bool has_generated_background_page = | |
| 109 BackgroundInfo::HasGeneratedBackgroundPage(&extension); | |
| 110 for (const content::RenderViewHost* host : views) { | |
| 111 content::WebContents* web_contents = | |
| 112 content::WebContents::FromRenderViewHost(host); | |
| 113 ViewType host_type = GetViewType(web_contents); | |
| 114 if (host == deleting_rvh_ || | |
| 115 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
 | |
| 116 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.
 | |
| 117 continue; | |
| 118 | |
| 119 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.
 | |
| 120 content::RenderProcessHost* process = host->GetProcess(); | |
| 121 bool is_background_page = | |
| 122 (url == BackgroundInfo::GetBackgroundURL(&extension)); | |
| 123 result->push_back(ConstructView( | |
| 124 url, | |
| 125 process->GetID(), | |
| 126 host->GetRoutingID(), | |
| 127 is_incognito, | |
| 128 is_background_page && has_generated_background_page)); | |
| 129 } | |
| 130 } | |
| 131 | |
| 132 void InspectableViewsFinder::GetAppWindowViewsForExtension( | |
| 133 const Extension& extension, | |
| 134 ViewList* result) { | |
| 135 AppWindowRegistry* registry = AppWindowRegistry::Get(profile_); | |
| 136 if (!registry) | |
| 137 return; | |
| 138 | |
| 139 AppWindowRegistry::AppWindowList windows = | |
| 140 registry->GetAppWindowsForApp(extension.id()); | |
| 141 | |
| 142 bool has_generated_background_page = | |
| 143 BackgroundInfo::HasGeneratedBackgroundPage(&extension); | |
| 144 for (const AppWindow* window : windows) { | |
| 145 content::WebContents* web_contents = window->web_contents(); | |
| 146 content::RenderViewHost* host = web_contents->GetRenderViewHost(); | |
| 147 content::RenderProcessHost* process = host->GetProcess(); | |
| 148 | |
| 149 bool is_background_page = | |
| 150 (web_contents->GetURL() == | |
| 151 BackgroundInfo::GetBackgroundURL(&extension)); | |
| 152 result->push_back(ConstructView( | |
| 153 web_contents->GetURL(), | |
| 154 process->GetID(), | |
| 155 host->GetRoutingID(), | |
| 156 false, | |
| 157 is_background_page && has_generated_background_page)); | |
| 158 } | |
| 159 } | |
| 160 | |
| 161 } // namespace extensions | |
| OLD | NEW |