| 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     ViewType type) { | 
|  | 40   linked_ptr<api::developer_private::ExtensionView> view( | 
|  | 41       new api::developer_private::ExtensionView()); | 
|  | 42   view->url = url.spec(); | 
|  | 43   view->render_process_id = render_process_id; | 
|  | 44   view->render_view_id = render_view_id; | 
|  | 45   view->incognito = incognito; | 
|  | 46   switch (type) { | 
|  | 47     case VIEW_TYPE_APP_WINDOW: | 
|  | 48       view->type = api::developer_private::VIEW_TYPE_APP_WINDOW; | 
|  | 49       break; | 
|  | 50     case VIEW_TYPE_BACKGROUND_CONTENTS: | 
|  | 51       view->type = api::developer_private::VIEW_TYPE_BACKGROUND_CONTENTS; | 
|  | 52       break; | 
|  | 53     case VIEW_TYPE_EXTENSION_BACKGROUND_PAGE: | 
|  | 54       view->type = api::developer_private::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE; | 
|  | 55       break; | 
|  | 56     case VIEW_TYPE_EXTENSION_DIALOG: | 
|  | 57       view->type = api::developer_private::VIEW_TYPE_EXTENSION_DIALOG; | 
|  | 58       break; | 
|  | 59     case VIEW_TYPE_EXTENSION_POPUP: | 
|  | 60       view->type = api::developer_private::VIEW_TYPE_EXTENSION_POPUP; | 
|  | 61       break; | 
|  | 62     case VIEW_TYPE_LAUNCHER_PAGE: | 
|  | 63       view->type = api::developer_private::VIEW_TYPE_LAUNCHER_PAGE; | 
|  | 64       break; | 
|  | 65     case VIEW_TYPE_PANEL: | 
|  | 66       view->type = api::developer_private::VIEW_TYPE_PANEL; | 
|  | 67       break; | 
|  | 68     case VIEW_TYPE_TAB_CONTENTS: | 
|  | 69       view->type = api::developer_private::VIEW_TYPE_TAB_CONTENTS; | 
|  | 70       break; | 
|  | 71     case VIEW_TYPE_VIRTUAL_KEYBOARD: | 
|  | 72       view->type = api::developer_private::VIEW_TYPE_VIRTUAL_KEYBOARD; | 
|  | 73       break; | 
|  | 74     default: | 
|  | 75       NOTREACHED(); | 
|  | 76   } | 
|  | 77   return view; | 
|  | 78 } | 
|  | 79 | 
|  | 80 InspectableViewsFinder::ViewList InspectableViewsFinder::GetViewsForExtension( | 
|  | 81     const Extension& extension, | 
|  | 82     bool is_enabled) { | 
|  | 83   ViewList result; | 
|  | 84   GetViewsForExtensionForProfile( | 
|  | 85       extension, profile_, is_enabled, false, &result); | 
|  | 86   if (profile_->HasOffTheRecordProfile()) { | 
|  | 87     GetViewsForExtensionForProfile( | 
|  | 88         extension, | 
|  | 89         profile_->GetOffTheRecordProfile(), | 
|  | 90         is_enabled, | 
|  | 91         true, | 
|  | 92         &result); | 
|  | 93   } | 
|  | 94 | 
|  | 95   return result; | 
|  | 96 } | 
|  | 97 | 
|  | 98 void InspectableViewsFinder::GetViewsForExtensionForProfile( | 
|  | 99     const Extension& extension, | 
|  | 100     Profile* profile, | 
|  | 101     bool is_enabled, | 
|  | 102     bool is_incognito, | 
|  | 103     ViewList* result) { | 
|  | 104   ProcessManager* process_manager = ProcessManager::Get(profile); | 
|  | 105   // Get the extension process's active views. | 
|  | 106   GetViewsForExtensionProcess( | 
|  | 107       extension, | 
|  | 108       process_manager->GetRenderViewHostsForExtension(extension.id()), | 
|  | 109       is_incognito, | 
|  | 110       result); | 
|  | 111   // Get app window views, if not incognito. | 
|  | 112   if (!is_incognito) | 
|  | 113     GetAppWindowViewsForExtension(extension, result); | 
|  | 114   // Include a link to start the lazy background page, if applicable. | 
|  | 115   if (BackgroundInfo::HasLazyBackgroundPage(&extension) && | 
|  | 116       is_enabled && | 
|  | 117       !process_manager->GetBackgroundHostForExtension(extension.id())) { | 
|  | 118     result->push_back(ConstructView( | 
|  | 119         BackgroundInfo::GetBackgroundURL(&extension), | 
|  | 120         -1, | 
|  | 121         -1, | 
|  | 122         is_incognito, | 
|  | 123         VIEW_TYPE_EXTENSION_BACKGROUND_PAGE)); | 
|  | 124   } | 
|  | 125 } | 
|  | 126 | 
|  | 127 void InspectableViewsFinder::GetViewsForExtensionProcess( | 
|  | 128     const Extension& extension, | 
|  | 129     const std::set<content::RenderViewHost*>& views, | 
|  | 130     bool is_incognito, | 
|  | 131     ViewList* result) { | 
|  | 132   for (const content::RenderViewHost* host : views) { | 
|  | 133     content::WebContents* web_contents = | 
|  | 134         content::WebContents::FromRenderViewHost(host); | 
|  | 135     ViewType host_type = GetViewType(web_contents); | 
|  | 136     if (host == deleting_rvh_ || | 
|  | 137         host_type == VIEW_TYPE_EXTENSION_POPUP || | 
|  | 138         host_type == VIEW_TYPE_EXTENSION_DIALOG) { | 
|  | 139       continue; | 
|  | 140     } | 
|  | 141 | 
|  | 142     const GURL& url = web_contents->GetURL(); | 
|  | 143     content::RenderProcessHost* process = host->GetProcess(); | 
|  | 144     result->push_back(ConstructView( | 
|  | 145         url, | 
|  | 146         process->GetID(), | 
|  | 147         host->GetRoutingID(), | 
|  | 148         is_incognito, | 
|  | 149         host_type)); | 
|  | 150   } | 
|  | 151 } | 
|  | 152 | 
|  | 153 void InspectableViewsFinder::GetAppWindowViewsForExtension( | 
|  | 154     const Extension& extension, | 
|  | 155     ViewList* result) { | 
|  | 156   AppWindowRegistry* registry = AppWindowRegistry::Get(profile_); | 
|  | 157   if (!registry) | 
|  | 158     return; | 
|  | 159 | 
|  | 160   AppWindowRegistry::AppWindowList windows = | 
|  | 161       registry->GetAppWindowsForApp(extension.id()); | 
|  | 162 | 
|  | 163   for (const AppWindow* window : windows) { | 
|  | 164     content::WebContents* web_contents = window->web_contents(); | 
|  | 165     content::RenderViewHost* host = web_contents->GetRenderViewHost(); | 
|  | 166     content::RenderProcessHost* process = host->GetProcess(); | 
|  | 167 | 
|  | 168     result->push_back(ConstructView( | 
|  | 169         web_contents->GetURL(), | 
|  | 170         process->GetID(), | 
|  | 171         host->GetRoutingID(), | 
|  | 172         false, | 
|  | 173         GetViewType(web_contents))); | 
|  | 174   } | 
|  | 175 } | 
|  | 176 | 
|  | 177 }  // namespace extensions | 
| OLD | NEW | 
|---|