| OLD | NEW |
| 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 "apps/app_load_service.h" | 7 #include "apps/app_load_service.h" |
| 8 #include "apps/saved_files_service.h" | 8 #include "apps/saved_files_service.h" |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/files/file_enumerator.h" | |
| 13 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 14 #include "base/i18n/file_util_icu.h" | |
| 15 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 16 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/values.h" | 17 #include "base/values.h" |
| 20 #include "chrome/browser/devtools/devtools_window.h" | 18 #include "chrome/browser/devtools/devtools_window.h" |
| 19 #include "chrome/browser/extensions/api/developer_private/developer_private_mang
le.h" |
| 21 #include "chrome/browser/extensions/api/developer_private/entry_picker.h" | 20 #include "chrome/browser/extensions/api/developer_private/entry_picker.h" |
| 21 #include "chrome/browser/extensions/api/developer_private/inspectable_views_find
er.h" |
| 22 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 22 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
| 23 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" | 23 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" |
| 24 #include "chrome/browser/extensions/chrome_requirements_checker.h" | 24 #include "chrome/browser/extensions/chrome_requirements_checker.h" |
| 25 #include "chrome/browser/extensions/devtools_util.h" | 25 #include "chrome/browser/extensions/devtools_util.h" |
| 26 #include "chrome/browser/extensions/extension_disabled_ui.h" | |
| 27 #include "chrome/browser/extensions/extension_error_reporter.h" | |
| 28 #include "chrome/browser/extensions/extension_service.h" | 26 #include "chrome/browser/extensions/extension_service.h" |
| 29 #include "chrome/browser/extensions/extension_ui_util.h" | 27 #include "chrome/browser/extensions/extension_ui_util.h" |
| 30 #include "chrome/browser/extensions/extension_util.h" | 28 #include "chrome/browser/extensions/extension_util.h" |
| 29 #include "chrome/browser/extensions/path_util.h" |
| 30 #include "chrome/browser/extensions/shared_module_service.h" |
| 31 #include "chrome/browser/extensions/unpacked_installer.h" | 31 #include "chrome/browser/extensions/unpacked_installer.h" |
| 32 #include "chrome/browser/extensions/updater/extension_updater.h" | 32 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 33 #include "chrome/browser/platform_util.h" | 33 #include "chrome/browser/platform_util.h" |
| 34 #include "chrome/browser/profiles/profile.h" | 34 #include "chrome/browser/profiles/profile.h" |
| 35 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" | |
| 36 #include "chrome/browser/ui/browser_finder.h" | 35 #include "chrome/browser/ui/browser_finder.h" |
| 37 #include "chrome/browser/ui/chrome_select_file_policy.h" | |
| 38 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 36 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 39 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 37 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
| 40 #include "chrome/common/extensions/api/developer_private.h" | 38 #include "chrome/common/extensions/api/developer_private.h" |
| 41 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 39 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
| 42 #include "chrome/common/url_constants.h" | 40 #include "chrome/common/url_constants.h" |
| 43 #include "chrome/grit/generated_resources.h" | 41 #include "chrome/grit/generated_resources.h" |
| 44 #include "content/public/browser/browser_thread.h" | 42 #include "content/public/browser/browser_thread.h" |
| 45 #include "content/public/browser/notification_service.h" | 43 #include "content/public/browser/notification_service.h" |
| 46 #include "content/public/browser/render_process_host.h" | 44 #include "content/public/browser/render_process_host.h" |
| 47 #include "content/public/browser/render_view_host.h" | 45 #include "content/public/browser/render_view_host.h" |
| 48 #include "content/public/browser/site_instance.h" | 46 #include "content/public/browser/site_instance.h" |
| 49 #include "content/public/browser/storage_partition.h" | 47 #include "content/public/browser/storage_partition.h" |
| 50 #include "content/public/browser/web_contents.h" | 48 #include "content/public/browser/web_contents.h" |
| 51 #include "extensions/browser/api/device_permissions_manager.h" | 49 #include "extensions/browser/api/device_permissions_manager.h" |
| 52 #include "extensions/browser/app_window/app_window.h" | 50 #include "extensions/browser/app_window/app_window.h" |
| 53 #include "extensions/browser/app_window/app_window_registry.h" | 51 #include "extensions/browser/app_window/app_window_registry.h" |
| 54 #include "extensions/browser/extension_error.h" | 52 #include "extensions/browser/extension_error.h" |
| 55 #include "extensions/browser/extension_prefs.h" | 53 #include "extensions/browser/extension_prefs.h" |
| 56 #include "extensions/browser/extension_registry.h" | 54 #include "extensions/browser/extension_registry.h" |
| 57 #include "extensions/browser/extension_system.h" | 55 #include "extensions/browser/extension_system.h" |
| 58 #include "extensions/browser/file_highlighter.h" | 56 #include "extensions/browser/file_highlighter.h" |
| 59 #include "extensions/browser/management_policy.h" | 57 #include "extensions/browser/management_policy.h" |
| 60 #include "extensions/browser/notification_types.h" | 58 #include "extensions/browser/notification_types.h" |
| 61 #include "extensions/browser/view_type_utils.h" | 59 #include "extensions/browser/warning_service.h" |
| 62 #include "extensions/common/constants.h" | 60 #include "extensions/common/constants.h" |
| 63 #include "extensions/common/extension_resource.h" | 61 #include "extensions/common/extension_resource.h" |
| 64 #include "extensions/common/extension_set.h" | 62 #include "extensions/common/extension_set.h" |
| 63 #include "extensions/common/feature_switch.h" |
| 65 #include "extensions/common/install_warning.h" | 64 #include "extensions/common/install_warning.h" |
| 66 #include "extensions/common/manifest.h" | 65 #include "extensions/common/manifest.h" |
| 67 #include "extensions/common/manifest_handlers/background_info.h" | 66 #include "extensions/common/manifest_handlers/background_info.h" |
| 68 #include "extensions/common/manifest_handlers/icons_handler.h" | 67 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 69 #include "extensions/common/manifest_handlers/incognito_info.h" | 68 #include "extensions/common/manifest_handlers/incognito_info.h" |
| 70 #include "extensions/common/manifest_handlers/offline_enabled_info.h" | 69 #include "extensions/common/manifest_handlers/offline_enabled_info.h" |
| 71 #include "extensions/common/manifest_handlers/options_page_info.h" | 70 #include "extensions/common/manifest_handlers/options_page_info.h" |
| 72 #include "extensions/common/manifest_url_handlers.h" | 71 #include "extensions/common/manifest_url_handlers.h" |
| 73 #include "extensions/common/permissions/permissions_data.h" | 72 #include "extensions/common/permissions/permissions_data.h" |
| 74 #include "extensions/common/switches.h" | 73 #include "extensions/common/switches.h" |
| 75 #include "extensions/grit/extensions_browser_resources.h" | 74 #include "extensions/grit/extensions_browser_resources.h" |
| 76 #include "net/base/net_util.h" | 75 #include "net/base/net_util.h" |
| 77 #include "storage/browser/blob/shareable_file_reference.h" | |
| 78 #include "storage/browser/fileapi/external_mount_points.h" | 76 #include "storage/browser/fileapi/external_mount_points.h" |
| 79 #include "storage/browser/fileapi/file_system_context.h" | 77 #include "storage/browser/fileapi/file_system_context.h" |
| 80 #include "storage/browser/fileapi/file_system_operation.h" | 78 #include "storage/browser/fileapi/file_system_operation.h" |
| 81 #include "storage/browser/fileapi/file_system_operation_runner.h" | 79 #include "storage/browser/fileapi/file_system_operation_runner.h" |
| 82 #include "storage/browser/fileapi/isolated_context.h" | 80 #include "storage/browser/fileapi/isolated_context.h" |
| 83 #include "ui/base/l10n/l10n_util.h" | 81 #include "ui/base/l10n/l10n_util.h" |
| 84 #include "ui/base/resource/resource_bundle.h" | 82 #include "ui/base/resource/resource_bundle.h" |
| 85 #include "ui/base/webui/web_ui_util.h" | 83 #include "ui/base/webui/web_ui_util.h" |
| 86 | 84 |
| 87 using content::RenderViewHost; | |
| 88 | |
| 89 namespace extensions { | 85 namespace extensions { |
| 90 | 86 |
| 91 namespace developer_private = api::developer_private; | 87 namespace developer_private = api::developer_private; |
| 92 | 88 |
| 93 namespace { | 89 namespace { |
| 94 | 90 |
| 95 const char kNoSuchExtensionError[] = "No such extension."; | 91 const char kNoSuchExtensionError[] = "No such extension."; |
| 96 const char kSupervisedUserError[] = | 92 const char kSupervisedUserError[] = |
| 97 "Supervised users cannot modify extension settings."; | 93 "Supervised users cannot modify extension settings."; |
| 98 const char kCannotModifyPolicyExtensionError[] = | 94 const char kCannotModifyPolicyExtensionError[] = |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 // extensions::ImageLoader. Also a resize should be performed to avoid | 146 // extensions::ImageLoader. Also a resize should be performed to avoid |
| 151 // potential huge URLs: crbug/297298. | 147 // potential huge URLs: crbug/297298. |
| 152 GURL ToDataURL(const base::FilePath& path, developer_private::ItemType type) { | 148 GURL ToDataURL(const base::FilePath& path, developer_private::ItemType type) { |
| 153 std::string contents; | 149 std::string contents; |
| 154 if (path.empty() || !base::ReadFileToString(path, &contents)) | 150 if (path.empty() || !base::ReadFileToString(path, &contents)) |
| 155 return GetDefaultImageURL(type); | 151 return GetDefaultImageURL(type); |
| 156 | 152 |
| 157 return GetImageURLFromData(contents); | 153 return GetImageURLFromData(contents); |
| 158 } | 154 } |
| 159 | 155 |
| 160 std::string GetExtensionID(const RenderViewHost* render_view_host) { | 156 std::string GetExtensionID(const content::RenderViewHost* render_view_host) { |
| 161 if (!render_view_host->GetSiteInstance()) | 157 if (!render_view_host->GetSiteInstance()) |
| 162 return std::string(); | 158 return std::string(); |
| 163 | 159 |
| 164 return render_view_host->GetSiteInstance()->GetSiteURL().host(); | 160 return render_view_host->GetSiteInstance()->GetSiteURL().host(); |
| 165 } | 161 } |
| 166 | 162 |
| 167 void BroadcastItemStateChanged(content::BrowserContext* browser_context, | 163 void BroadcastItemStateChanged(content::BrowserContext* browser_context, |
| 168 developer::EventType event_type, | 164 developer::EventType event_type, |
| 169 const std::string& item_id) { | 165 const std::string& item_id) { |
| 170 developer::EventData event_data; | 166 developer::EventData event_data; |
| 171 event_data.event_type = event_type; | 167 event_data.event_type = event_type; |
| 172 event_data.item_id = item_id; | 168 event_data.item_id = item_id; |
| 173 | 169 |
| 174 scoped_ptr<base::ListValue> args(new base::ListValue()); | 170 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 175 args->Append(event_data.ToValue().release()); | 171 args->Append(event_data.ToValue().release()); |
| 176 scoped_ptr<Event> event(new Event( | 172 scoped_ptr<Event> event(new Event( |
| 177 developer_private::OnItemStateChanged::kEventName, args.Pass())); | 173 developer_private::OnItemStateChanged::kEventName, args.Pass())); |
| 178 EventRouter::Get(browser_context)->BroadcastEvent(event.Pass()); | 174 EventRouter::Get(browser_context)->BroadcastEvent(event.Pass()); |
| 179 } | 175 } |
| 180 | 176 |
| 181 std::string ReadFileToString(const base::FilePath& path) { | 177 std::string ReadFileToString(const base::FilePath& path) { |
| 182 std::string data; | 178 std::string data; |
| 183 ignore_result(base::ReadFileToString(path, &data)); | 179 ignore_result(base::ReadFileToString(path, &data)); |
| 184 return data; | 180 return data; |
| 185 } | 181 } |
| 186 | 182 |
| 183 // Populates the common fields of an extension error. |
| 184 template <typename ErrorType> |
| 185 void PopulateErrorBase(const ExtensionError& error, |
| 186 ErrorType* out) { |
| 187 CHECK(out); |
| 188 out->type = error.type() == ExtensionError::MANIFEST_ERROR ? |
| 189 developer::ERROR_TYPE_MANIFEST : developer::ERROR_TYPE_RUNTIME; |
| 190 out->extension_id = error.extension_id(); |
| 191 out->from_incognito = error.from_incognito(); |
| 192 out->source = base::UTF16ToUTF8(error.source()); |
| 193 out->message = base::UTF16ToUTF8(error.message()); |
| 194 } |
| 195 |
| 196 // Given a ManifestError object, converts it into its developer_private |
| 197 // counterpart. |
| 198 linked_ptr<developer::ManifestError> ConstructManifestError( |
| 199 const ManifestError& error) { |
| 200 linked_ptr<developer::ManifestError> result(new developer::ManifestError()); |
| 201 PopulateErrorBase(error, result.get()); |
| 202 result->manifest_key = base::UTF16ToUTF8(error.manifest_key()); |
| 203 if (!error.manifest_specific().empty()) { |
| 204 result->manifest_specific.reset( |
| 205 new std::string(base::UTF16ToUTF8(error.manifest_specific()))); |
| 206 } |
| 207 return result; |
| 208 } |
| 209 |
| 210 // Given a RuntimeError object, converts it into its developer_private |
| 211 // counterpart. |
| 212 linked_ptr<developer::RuntimeError> ConstructRuntimeError( |
| 213 const RuntimeError& error) { |
| 214 linked_ptr<developer::RuntimeError> result(new developer::RuntimeError()); |
| 215 PopulateErrorBase(error, result.get()); |
| 216 switch (error.level()) { |
| 217 case logging::LOG_INFO: |
| 218 result->severity = developer::ERROR_SEVERITY_LOG; |
| 219 break; |
| 220 case logging::LOG_WARNING: |
| 221 result->severity = developer::ERROR_SEVERITY_WARN; |
| 222 break; |
| 223 case logging::LOG_ERROR: |
| 224 result->severity = developer::ERROR_SEVERITY_ERROR; |
| 225 break; |
| 226 default: |
| 227 NOTREACHED(); |
| 228 } |
| 229 result->occurrences = error.occurrences(); |
| 230 result->render_view_id = error.render_view_id(); |
| 231 result->render_process_id = error.render_process_id(); |
| 232 result->can_inspect = |
| 233 content::RenderViewHost::FromID(error.render_process_id(), |
| 234 error.render_view_id()) != nullptr; |
| 235 for (const StackFrame& f : error.stack_trace()) { |
| 236 linked_ptr<developer::StackFrame> frame(new developer::StackFrame()); |
| 237 frame->line_number = f.line_number; |
| 238 frame->column_number = f.column_number; |
| 239 frame->url = base::UTF16ToUTF8(f.source); |
| 240 frame->function_name = base::UTF16ToUTF8(f.function); |
| 241 result->stack_trace.push_back(frame); |
| 242 } |
| 243 return result; |
| 244 } |
| 245 |
| 246 // Given a Manifest::Type, converts it into its developer_private |
| 247 // counterpart. |
| 248 developer::ExtensionType GetExtensionType(Manifest::Type manifest_type) { |
| 249 developer::ExtensionType type = developer::EXTENSION_TYPE_EXTENSION; |
| 250 switch (manifest_type) { |
| 251 case Manifest::TYPE_EXTENSION: |
| 252 type = developer::EXTENSION_TYPE_EXTENSION; |
| 253 break; |
| 254 case Manifest::TYPE_THEME: |
| 255 type = developer::EXTENSION_TYPE_THEME; |
| 256 break; |
| 257 case Manifest::TYPE_HOSTED_APP: |
| 258 type = developer::EXTENSION_TYPE_HOSTED_APP; |
| 259 break; |
| 260 case Manifest::TYPE_LEGACY_PACKAGED_APP: |
| 261 type = developer::EXTENSION_TYPE_LEGACY_PACKAGED_APP; |
| 262 break; |
| 263 case Manifest::TYPE_PLATFORM_APP: |
| 264 type = developer::EXTENSION_TYPE_PLATFORM_APP; |
| 265 break; |
| 266 case Manifest::TYPE_SHARED_MODULE: |
| 267 type = developer::EXTENSION_TYPE_SHARED_MODULE; |
| 268 break; |
| 269 default: |
| 270 NOTREACHED(); |
| 271 } |
| 272 return type; |
| 273 } |
| 274 |
| 275 // Constructs information about a given |extension|. |
| 276 scoped_ptr<developer::ExtensionInfo> CreateExtensionInfo( |
| 277 const Extension& extension, |
| 278 developer::ExtensionState state, |
| 279 content::BrowserContext* browser_context) { |
| 280 scoped_ptr<developer::ExtensionInfo> info(new developer::ExtensionInfo()); |
| 281 |
| 282 ExtensionPrefs* prefs = ExtensionPrefs::Get(browser_context); |
| 283 // Don't consider the button hidden with the redesign, because "hidden" |
| 284 // buttons are now just hidden in the wrench menu. |
| 285 info->action_button_hidden = |
| 286 !ExtensionActionAPI::GetBrowserActionVisibility(prefs, extension.id()) && |
| 287 !FeatureSwitch::extension_action_redesign()->IsEnabled(); |
| 288 |
| 289 // Blacklist text. |
| 290 int blacklist_text = -1; |
| 291 switch (prefs->GetExtensionBlacklistState(extension.id())) { |
| 292 case BLACKLISTED_SECURITY_VULNERABILITY: |
| 293 blacklist_text = IDS_OPTIONS_BLACKLISTED_SECURITY_VULNERABILITY; |
| 294 break; |
| 295 case BLACKLISTED_CWS_POLICY_VIOLATION: |
| 296 blacklist_text = IDS_OPTIONS_BLACKLISTED_CWS_POLICY_VIOLATION; |
| 297 break; |
| 298 case BLACKLISTED_POTENTIALLY_UNWANTED: |
| 299 blacklist_text = IDS_OPTIONS_BLACKLISTED_POTENTIALLY_UNWANTED; |
| 300 break; |
| 301 default: |
| 302 break; |
| 303 } |
| 304 if (blacklist_text != -1) { |
| 305 info->blacklist_text.reset( |
| 306 new std::string(l10n_util::GetStringUTF8(blacklist_text))); |
| 307 } |
| 308 |
| 309 // Dependent extensions. |
| 310 if (extension.is_shared_module()) { |
| 311 scoped_ptr<ExtensionSet> dependent_extensions = |
| 312 ExtensionSystem::Get(browser_context)->extension_service()-> |
| 313 shared_module_service()->GetDependentExtensions(&extension); |
| 314 for (const scoped_refptr<const Extension>& dependent : |
| 315 *dependent_extensions) |
| 316 info->dependent_extensions.push_back(dependent->id()); |
| 317 } |
| 318 |
| 319 info->description = extension.description(); |
| 320 |
| 321 // Disable reasons. |
| 322 int disable_reasons = prefs->GetDisableReasons(extension.id()); |
| 323 info->disable_reasons.suspicious_install = |
| 324 (disable_reasons & Extension::DISABLE_NOT_VERIFIED) != 0; |
| 325 info->disable_reasons.corrupt_install = |
| 326 (disable_reasons & Extension::DISABLE_CORRUPTED) != 0; |
| 327 info->disable_reasons.update_required = |
| 328 (disable_reasons & Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY) != 0; |
| 329 |
| 330 // Error collection. |
| 331 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 332 ErrorConsole* error_console = ErrorConsole::Get(profile); |
| 333 bool error_console_enabled = |
| 334 error_console->IsEnabledForChromeExtensionsPage(); |
| 335 info->error_collection.is_enabled = error_console_enabled; |
| 336 info->error_collection.is_active = |
| 337 error_console_enabled && |
| 338 error_console->IsReportingEnabledForExtension(extension.id()); |
| 339 |
| 340 // File access. |
| 341 info->file_access.is_enabled = extension.wants_file_access(); |
| 342 info->file_access.is_active = |
| 343 util::AllowFileAccess(extension.id(), browser_context); |
| 344 |
| 345 // Home page. |
| 346 info->home_page.url = ManifestURL::GetHomepageURL(&extension).spec(); |
| 347 info->home_page.specified = ManifestURL::SpecifiedHomepageURL(&extension); |
| 348 |
| 349 bool is_enabled = state == developer::EXTENSION_STATE_ENABLED; |
| 350 |
| 351 // TODO(devlin): This won't work with apps (CORS). We should convert to data |
| 352 // urls. |
| 353 info->icon_url = |
| 354 ExtensionIconSource::GetIconURL(&extension, |
| 355 extension_misc::EXTENSION_ICON_MEDIUM, |
| 356 ExtensionIconSet::MATCH_BIGGER, |
| 357 !is_enabled, |
| 358 nullptr).spec(); |
| 359 |
| 360 info->id = extension.id(); |
| 361 |
| 362 // Incognito access. |
| 363 info->incognito_access.is_enabled = extension.can_be_incognito_enabled(); |
| 364 info->incognito_access.is_active = |
| 365 util::IsIncognitoEnabled(extension.id(), browser_context); |
| 366 |
| 367 info->installed_by_custodian = |
| 368 util::IsExtensionSupervised(&extension, profile); |
| 369 |
| 370 // Install warnings (only if unpacked and no error console). |
| 371 if (!error_console_enabled && |
| 372 Manifest::IsUnpackedLocation(extension.location())) { |
| 373 const std::vector<InstallWarning>& install_warnings = |
| 374 extension.install_warnings(); |
| 375 for (const InstallWarning& warning : install_warnings) |
| 376 info->install_warnings.push_back(warning.message); |
| 377 } |
| 378 |
| 379 // Launch url. |
| 380 if (extension.is_app()) { |
| 381 info->launch_url.reset( |
| 382 new std::string(AppLaunchInfo::GetFullLaunchURL(&extension).spec())); |
| 383 } |
| 384 |
| 385 // Location. |
| 386 if (extension.location() == Manifest::INTERNAL && |
| 387 ManifestURL::UpdatesFromGallery(&extension)) { |
| 388 info->location = developer::LOCATION_FROM_STORE; |
| 389 } else if (Manifest::IsUnpackedLocation(extension.location())) { |
| 390 info->location = developer::LOCATION_UNPACKED; |
| 391 } else { |
| 392 info->location = developer::LOCATION_UNKNOWN; |
| 393 } |
| 394 |
| 395 // Location text. |
| 396 int location_text = -1; |
| 397 if (info->location == developer::LOCATION_UNKNOWN) |
| 398 location_text = IDS_OPTIONS_INSTALL_LOCATION_UNKNOWN; |
| 399 else if (extension.location() == Manifest::EXTERNAL_REGISTRY) |
| 400 location_text = IDS_OPTIONS_INSTALL_LOCATION_3RD_PARTY; |
| 401 else if (extension.is_shared_module()) |
| 402 location_text = IDS_OPTIONS_INSTALL_LOCATION_SHARED_MODULE; |
| 403 if (location_text != -1) { |
| 404 info->location_text.reset( |
| 405 new std::string(l10n_util::GetStringUTF8(location_text))); |
| 406 } |
| 407 |
| 408 // Runtime/Manifest errors. |
| 409 if (error_console_enabled) { |
| 410 const ErrorList& errors = |
| 411 error_console->GetErrorsForExtension(extension.id()); |
| 412 for (const ExtensionError* error : errors) { |
| 413 switch (error->type()) { |
| 414 case ExtensionError::MANIFEST_ERROR: |
| 415 info->manifest_errors.push_back(ConstructManifestError( |
| 416 static_cast<const ManifestError&>(*error))); |
| 417 break; |
| 418 case ExtensionError::RUNTIME_ERROR: |
| 419 info->runtime_errors.push_back(ConstructRuntimeError( |
| 420 static_cast<const RuntimeError&>(*error))); |
| 421 break; |
| 422 case ExtensionError::NUM_ERROR_TYPES: |
| 423 NOTREACHED(); |
| 424 break; |
| 425 } |
| 426 } |
| 427 } |
| 428 |
| 429 ManagementPolicy* management_policy = |
| 430 ExtensionSystem::Get(browser_context)->management_policy(); |
| 431 info->must_remain_installed = |
| 432 management_policy->MustRemainInstalled(&extension, nullptr); |
| 433 |
| 434 info->name = extension.name(); |
| 435 info->offline_enabled = OfflineEnabledInfo::IsOfflineEnabled(&extension); |
| 436 |
| 437 // Options page. |
| 438 if (OptionsPageInfo::HasOptionsPage(&extension)) { |
| 439 info->options_page.reset(new developer::OptionsPage()); |
| 440 info->options_page->open_in_tab = |
| 441 OptionsPageInfo::ShouldOpenInTab(&extension); |
| 442 info->options_page->url = |
| 443 OptionsPageInfo::GetOptionsPage(&extension).spec(); |
| 444 } |
| 445 |
| 446 // Path. |
| 447 if (Manifest::IsUnpackedLocation(extension.location())) { |
| 448 info->path.reset(new std::string(extension.path().AsUTF8Unsafe())); |
| 449 info->prettified_path.reset(new std::string( |
| 450 extensions::path_util::PrettifyPath(extension.path()).AsUTF8Unsafe())); |
| 451 } |
| 452 |
| 453 if (Manifest::IsPolicyLocation(extension.location())) { |
| 454 info->policy_text.reset(new std::string( |
| 455 l10n_util::GetStringUTF8(IDS_OPTIONS_INSTALL_LOCATION_ENTERPRISE))); |
| 456 } |
| 457 |
| 458 // Runs on all urls. |
| 459 info->run_on_all_urls.is_enabled = |
| 460 (FeatureSwitch::scripts_require_action()->IsEnabled() && |
| 461 PermissionsData::ScriptsMayRequireActionForExtension( |
| 462 &extension, |
| 463 extension.permissions_data()->active_permissions().get())) || |
| 464 extension.permissions_data()->HasWithheldImpliedAllHosts() || |
| 465 util::HasSetAllowedScriptingOnAllUrls(extension.id(), browser_context); |
| 466 info->run_on_all_urls.is_active = |
| 467 util::AllowedScriptingOnAllUrls(extension.id(), browser_context); |
| 468 |
| 469 // Runtime warnings. |
| 470 WarningService* warning_service = WarningService::Get(profile); |
| 471 std::vector<std::string> warnings = |
| 472 warning_service->GetWarningMessagesForExtension(extension.id()); |
| 473 for (const std::string& warning : warnings) |
| 474 info->runtime_warnings.push_back(warning); |
| 475 |
| 476 info->state = state; |
| 477 |
| 478 info->type = GetExtensionType(extension.manifest()->type()); |
| 479 |
| 480 info->update_url = ManifestURL::GetUpdateURL(&extension).spec(); |
| 481 |
| 482 info->user_may_modify = |
| 483 management_policy->UserMayModifySettings(&extension, nullptr); |
| 484 |
| 485 info->version = extension.GetVersionForDisplay(); |
| 486 |
| 487 if (state != developer::EXTENSION_STATE_TERMINATED) { |
| 488 info->views = InspectableViewsFinder(profile, nullptr). |
| 489 GetViewsForExtension(extension, is_enabled); |
| 490 } |
| 491 return info.Pass(); |
| 492 } |
| 493 |
| 494 std::vector<linked_ptr<developer::ExtensionInfo>> GetExtensionsInfo( |
| 495 content::BrowserContext* context, |
| 496 bool include_disabled, |
| 497 bool include_terminated) { |
| 498 std::vector<linked_ptr<developer::ExtensionInfo>> list; |
| 499 auto add_to_list = [&list, context](const ExtensionSet& extensions, |
| 500 developer::ExtensionState state) { |
| 501 for (const scoped_refptr<const Extension>& extension : extensions) { |
| 502 if (ui_util::ShouldDisplayInExtensionSettings(extension.get(), context)) { |
| 503 scoped_ptr<developer::ExtensionInfo> info = |
| 504 CreateExtensionInfo(*extension, state, context); |
| 505 list.push_back(make_linked_ptr(info.release())); |
| 506 } |
| 507 } |
| 508 }; |
| 509 |
| 510 ExtensionRegistry* registry = ExtensionRegistry::Get(context); |
| 511 add_to_list(registry->enabled_extensions(), |
| 512 developer::EXTENSION_STATE_ENABLED); |
| 513 if (include_disabled) { |
| 514 add_to_list(registry->disabled_extensions(), |
| 515 developer::EXTENSION_STATE_DISABLED); |
| 516 } |
| 517 if (include_terminated) { |
| 518 add_to_list(registry->terminated_extensions(), |
| 519 developer::EXTENSION_STATE_TERMINATED); |
| 520 } |
| 521 |
| 522 return list; |
| 523 } |
| 524 |
| 187 } // namespace | 525 } // namespace |
| 188 | 526 |
| 189 namespace AllowFileAccess = api::developer_private::AllowFileAccess; | 527 namespace AllowFileAccess = api::developer_private::AllowFileAccess; |
| 190 namespace AllowIncognito = api::developer_private::AllowIncognito; | 528 namespace AllowIncognito = api::developer_private::AllowIncognito; |
| 191 namespace ChoosePath = api::developer_private::ChoosePath; | 529 namespace ChoosePath = api::developer_private::ChoosePath; |
| 192 namespace GetItemsInfo = api::developer_private::GetItemsInfo; | 530 namespace GetItemsInfo = api::developer_private::GetItemsInfo; |
| 193 namespace Inspect = api::developer_private::Inspect; | 531 namespace Inspect = api::developer_private::Inspect; |
| 194 namespace PackDirectory = api::developer_private::PackDirectory; | 532 namespace PackDirectory = api::developer_private::PackDirectory; |
| 195 namespace Reload = api::developer_private::Reload; | 533 namespace Reload = api::developer_private::Reload; |
| 196 | 534 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 const content::NotificationDetails& details) { | 587 const content::NotificationDetails& details) { |
| 250 Profile* profile = content::Source<Profile>(source).ptr(); | 588 Profile* profile = content::Source<Profile>(source).ptr(); |
| 251 CHECK(profile); | 589 CHECK(profile); |
| 252 CHECK(profile_->IsSameProfile(profile)); | 590 CHECK(profile_->IsSameProfile(profile)); |
| 253 developer::EventData event_data; | 591 developer::EventData event_data; |
| 254 | 592 |
| 255 switch (type) { | 593 switch (type) { |
| 256 case extensions::NOTIFICATION_EXTENSION_VIEW_UNREGISTERED: { | 594 case extensions::NOTIFICATION_EXTENSION_VIEW_UNREGISTERED: { |
| 257 event_data.event_type = developer::EVENT_TYPE_VIEW_UNREGISTERED; | 595 event_data.event_type = developer::EVENT_TYPE_VIEW_UNREGISTERED; |
| 258 event_data.item_id = GetExtensionID( | 596 event_data.item_id = GetExtensionID( |
| 259 content::Details<const RenderViewHost>(details).ptr()); | 597 content::Details<const content::RenderViewHost>(details).ptr()); |
| 260 break; | 598 break; |
| 261 } | 599 } |
| 262 case extensions::NOTIFICATION_EXTENSION_VIEW_REGISTERED: { | 600 case extensions::NOTIFICATION_EXTENSION_VIEW_REGISTERED: { |
| 263 event_data.event_type = developer::EVENT_TYPE_VIEW_REGISTERED; | 601 event_data.event_type = developer::EVENT_TYPE_VIEW_REGISTERED; |
| 264 event_data.item_id = GetExtensionID( | 602 event_data.item_id = GetExtensionID( |
| 265 content::Details<const RenderViewHost>(details).ptr()); | 603 content::Details<const content::RenderViewHost>(details).ptr()); |
| 266 break; | 604 break; |
| 267 } | 605 } |
| 268 default: | 606 default: |
| 269 NOTREACHED(); | 607 NOTREACHED(); |
| 270 return; | 608 return; |
| 271 } | 609 } |
| 272 | 610 |
| 273 BroadcastItemStateChanged(profile, event_data.event_type, event_data.item_id); | 611 BroadcastItemStateChanged(profile, event_data.event_type, event_data.item_id); |
| 274 } | 612 } |
| 275 | 613 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 bool DeveloperPrivateAutoUpdateFunction::RunSync() { | 706 bool DeveloperPrivateAutoUpdateFunction::RunSync() { |
| 369 ExtensionUpdater* updater = GetExtensionUpdater(GetProfile()); | 707 ExtensionUpdater* updater = GetExtensionUpdater(GetProfile()); |
| 370 if (updater) | 708 if (updater) |
| 371 updater->CheckNow(ExtensionUpdater::CheckParams()); | 709 updater->CheckNow(ExtensionUpdater::CheckParams()); |
| 372 SetResult(new base::FundamentalValue(true)); | 710 SetResult(new base::FundamentalValue(true)); |
| 373 return true; | 711 return true; |
| 374 } | 712 } |
| 375 | 713 |
| 376 DeveloperPrivateAutoUpdateFunction::~DeveloperPrivateAutoUpdateFunction() {} | 714 DeveloperPrivateAutoUpdateFunction::~DeveloperPrivateAutoUpdateFunction() {} |
| 377 | 715 |
| 378 scoped_ptr<developer::ItemInfo> | 716 DeveloperPrivateGetExtensionsInfoFunction:: |
| 379 DeveloperPrivateGetItemsInfoFunction::CreateItemInfo(const Extension& item, | 717 ~DeveloperPrivateGetExtensionsInfoFunction() { |
| 380 bool item_is_enabled) { | 718 } |
| 381 scoped_ptr<developer::ItemInfo> info(new developer::ItemInfo()); | |
| 382 | 719 |
| 383 ExtensionSystem* system = ExtensionSystem::Get(GetProfile()); | 720 ExtensionFunction::ResponseAction |
| 384 ExtensionService* service = system->extension_service(); | 721 DeveloperPrivateGetExtensionsInfoFunction::Run() { |
| 385 ExtensionRegistry* registry = ExtensionRegistry::Get(GetProfile()); | 722 scoped_ptr<developer::GetExtensionsInfo::Params> params( |
| 723 developer::GetExtensionsInfo::Params::Create(*args_)); |
| 724 EXTENSION_FUNCTION_VALIDATE(params); |
| 386 | 725 |
| 387 info->id = item.id(); | 726 bool include_disabled = true; |
| 388 info->name = item.name(); | 727 bool include_terminated = true; |
| 389 info->enabled = service->IsExtensionEnabled(info->id); | 728 if (params->options) { |
| 390 info->offline_enabled = OfflineEnabledInfo::IsOfflineEnabled(&item); | 729 if (params->options->include_disabled) |
| 391 info->version = item.VersionString(); | 730 include_disabled = *params->options->include_disabled; |
| 392 info->description = item.description(); | 731 if (params->options->include_terminated) |
| 393 | 732 include_terminated = *params->options->include_terminated; |
| 394 if (item.is_app()) { | |
| 395 if (item.is_legacy_packaged_app()) | |
| 396 info->type = developer::ITEM_TYPE_LEGACY_PACKAGED_APP; | |
| 397 else if (item.is_hosted_app()) | |
| 398 info->type = developer::ITEM_TYPE_HOSTED_APP; | |
| 399 else if (item.is_platform_app()) | |
| 400 info->type = developer::ITEM_TYPE_PACKAGED_APP; | |
| 401 else | |
| 402 NOTREACHED(); | |
| 403 } else if (item.is_theme()) { | |
| 404 info->type = developer::ITEM_TYPE_THEME; | |
| 405 } else if (item.is_extension()) { | |
| 406 info->type = developer::ITEM_TYPE_EXTENSION; | |
| 407 } else { | |
| 408 NOTREACHED(); | |
| 409 } | 733 } |
| 410 | 734 |
| 411 if (Manifest::IsUnpackedLocation(item.location())) { | 735 std::vector<linked_ptr<developer::ExtensionInfo>> list = |
| 412 info->path.reset( | 736 GetExtensionsInfo(browser_context(), |
| 413 new std::string(base::UTF16ToUTF8(item.path().LossyDisplayName()))); | 737 include_disabled, |
| 414 // If the ErrorConsole is enabled and the extension is unpacked, use the | 738 include_terminated); |
| 415 // more detailed errors from the ErrorConsole. Otherwise, use the install | 739 |
| 416 // warnings (using both is redundant). | 740 return RespondNow(ArgumentList( |
| 417 ErrorConsole* error_console = ErrorConsole::Get(GetProfile()); | 741 developer::GetExtensionsInfo::Results::Create(list))); |
| 418 if (error_console->IsEnabledForAppsDeveloperTools() && | 742 } |
| 419 item.location() == Manifest::UNPACKED) { | 743 |
| 420 const ErrorList& errors = error_console->GetErrorsForExtension(item.id()); | 744 DeveloperPrivateGetExtensionInfoFunction:: |
| 421 if (!errors.empty()) { | 745 ~DeveloperPrivateGetExtensionInfoFunction() { |
| 422 for (ErrorList::const_iterator iter = errors.begin(); | 746 } |
| 423 iter != errors.end(); | 747 |
| 424 ++iter) { | 748 ExtensionFunction::ResponseAction |
| 425 switch ((*iter)->type()) { | 749 DeveloperPrivateGetExtensionInfoFunction::Run() { |
| 426 case ExtensionError::MANIFEST_ERROR: | 750 scoped_ptr<developer::GetExtensionInfo::Params> params( |
| 427 info->manifest_errors.push_back( | 751 developer::GetExtensionInfo::Params::Create(*args_)); |
| 428 make_linked_ptr((*iter)->ToValue().release())); | 752 EXTENSION_FUNCTION_VALIDATE(params); |
| 429 break; | 753 |
| 430 case ExtensionError::RUNTIME_ERROR: { | 754 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context()); |
| 431 const RuntimeError* error = | 755 developer::ExtensionState state = developer::EXTENSION_STATE_ENABLED; |
| 432 static_cast<const RuntimeError*>(*iter); | 756 const Extension* extension = |
| 433 scoped_ptr<base::DictionaryValue> value = error->ToValue(); | 757 registry->enabled_extensions().GetByID(params->id); |
| 434 bool can_inspect = content::RenderViewHost::FromID( | 758 if (!extension && |
| 435 error->render_process_id(), | 759 (extension = registry->disabled_extensions().GetByID(params->id))) { |
| 436 error->render_view_id()) != NULL; | 760 state = developer::EXTENSION_STATE_DISABLED; |
| 437 value->SetBoolean("canInspect", can_inspect); | 761 } else if (!extension && |
| 438 info->runtime_errors.push_back(make_linked_ptr(value.release())); | 762 (extension = |
| 439 break; | 763 registry->terminated_extensions().GetByID(params->id))) { |
| 440 } | 764 state = developer::EXTENSION_STATE_TERMINATED; |
| 441 case ExtensionError::NUM_ERROR_TYPES: | 765 } else { |
| 442 NOTREACHED(); | 766 return RespondNow(Error(kNoSuchExtensionError)); |
| 443 break; | 767 } |
| 444 } | 768 |
| 445 } | 769 return RespondNow(OneArgument(CreateExtensionInfo( |
| 446 } | 770 *extension, state, browser_context())->ToValue().release())); |
| 447 } else { | 771 } |
| 448 for (std::vector<InstallWarning>::const_iterator it = | 772 |
| 449 item.install_warnings().begin(); | 773 DeveloperPrivateGetItemsInfoFunction::DeveloperPrivateGetItemsInfoFunction() {} |
| 450 it != item.install_warnings().end(); | 774 DeveloperPrivateGetItemsInfoFunction::~DeveloperPrivateGetItemsInfoFunction() {} |
| 451 ++it) { | 775 |
| 452 scoped_ptr<developer::InstallWarning> warning( | 776 ExtensionFunction::ResponseAction DeveloperPrivateGetItemsInfoFunction::Run() { |
| 453 new developer::InstallWarning); | 777 scoped_ptr<developer::GetItemsInfo::Params> params( |
| 454 warning->message = it->message; | 778 developer::GetItemsInfo::Params::Create(*args_)); |
| 455 info->install_warnings.push_back(make_linked_ptr(warning.release())); | 779 EXTENSION_FUNCTION_VALIDATE(params); |
| 456 } | 780 |
| 781 ExtensionSet items; |
| 782 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context()); |
| 783 items.InsertAll(registry->enabled_extensions()); |
| 784 |
| 785 if (params->include_disabled) |
| 786 items.InsertAll(registry->disabled_extensions()); |
| 787 if (params->include_terminated) |
| 788 items.InsertAll(registry->terminated_extensions()); |
| 789 |
| 790 std::map<std::string, ExtensionResource> resource_map; |
| 791 for (const scoped_refptr<const Extension>& item : items) { |
| 792 // Don't show component extensions and invisible apps. |
| 793 if (ui_util::ShouldDisplayInExtensionSettings(item.get(), |
| 794 browser_context())) { |
| 795 resource_map[item->id()] = |
| 796 IconsInfo::GetIconResource(item.get(), |
| 797 extension_misc::EXTENSION_ICON_MEDIUM, |
| 798 ExtensionIconSet::MATCH_BIGGER); |
| 457 } | 799 } |
| 458 } | 800 } |
| 459 | 801 |
| 460 info->incognito_enabled = util::IsIncognitoEnabled(item.id(), GetProfile()); | 802 std::vector<linked_ptr<developer::ExtensionInfo>> list = |
| 461 info->wants_file_access = item.wants_file_access(); | 803 GetExtensionsInfo(browser_context(), |
| 462 info->allow_file_access = util::AllowFileAccess(item.id(), GetProfile()); | 804 params->include_disabled, |
| 463 info->allow_reload = Manifest::IsUnpackedLocation(item.location()); | 805 params->include_terminated); |
| 464 info->is_unpacked = Manifest::IsUnpackedLocation(item.location()); | |
| 465 info->terminated = registry->terminated_extensions().Contains(item.id()); | |
| 466 info->allow_incognito = item.can_be_incognito_enabled(); | |
| 467 | 806 |
| 468 info->homepage_url.reset(new std::string( | 807 for (const linked_ptr<developer::ExtensionInfo>& info : list) |
| 469 ManifestURL::GetHomepageURL(&item).spec())); | 808 item_list_.push_back(developer_private_mangle::MangleExtensionInfo(*info)); |
| 470 if (!OptionsPageInfo::GetOptionsPage(&item).is_empty()) { | |
| 471 info->options_url.reset( | |
| 472 new std::string(OptionsPageInfo::GetOptionsPage(&item).spec())); | |
| 473 } | |
| 474 | 809 |
| 475 if (!ManifestURL::GetUpdateURL(&item).is_empty()) { | 810 content::BrowserThread::PostTask( |
| 476 info->update_url.reset( | 811 content::BrowserThread::FILE, |
| 477 new std::string(ManifestURL::GetUpdateURL(&item).spec())); | 812 FROM_HERE, |
| 478 } | 813 base::Bind(&DeveloperPrivateGetItemsInfoFunction::GetIconsOnFileThread, |
| 814 this, |
| 815 resource_map)); |
| 479 | 816 |
| 480 if (item.is_app()) { | 817 return RespondLater(); |
| 481 info->app_launch_url.reset( | |
| 482 new std::string(AppLaunchInfo::GetFullLaunchURL(&item).spec())); | |
| 483 } | |
| 484 | |
| 485 info->may_disable = system->management_policy()-> | |
| 486 UserMayModifySettings(&item, NULL); | |
| 487 info->is_app = item.is_app(); | |
| 488 info->views = GetInspectablePagesForExtension(&item, item_is_enabled); | |
| 489 | |
| 490 return info.Pass(); | |
| 491 } | 818 } |
| 492 | 819 |
| 493 void DeveloperPrivateGetItemsInfoFunction::GetIconsOnFileThread( | 820 void DeveloperPrivateGetItemsInfoFunction::GetIconsOnFileThread( |
| 494 ItemInfoList item_list, | 821 const std::map<std::string, ExtensionResource> resource_map) { |
| 495 const std::map<std::string, ExtensionResource> idToIcon) { | 822 for (const linked_ptr<developer::ItemInfo>& item : item_list_) { |
| 496 for (ItemInfoList::iterator iter = item_list.begin(); | 823 auto resource = resource_map.find(item->id); |
| 497 iter != item_list.end(); ++iter) { | 824 if (resource != resource_map.end()) { |
| 498 developer_private::ItemInfo* info = iter->get(); | 825 item->icon_url = ToDataURL(resource->second.GetFilePath(), |
| 499 std::map<std::string, ExtensionResource>::const_iterator resource_ptr | 826 item->type).spec(); |
| 500 = idToIcon.find(info->id); | |
| 501 if (resource_ptr != idToIcon.end()) { | |
| 502 info->icon_url = | |
| 503 ToDataURL(resource_ptr->second.GetFilePath(), info->type).spec(); | |
| 504 } | 827 } |
| 505 } | 828 } |
| 506 | 829 |
| 507 results_ = developer::GetItemsInfo::Results::Create(item_list); | 830 content::BrowserThread::PostTask( |
| 508 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 831 content::BrowserThread::UI, |
| 509 base::Bind(&DeveloperPrivateGetItemsInfoFunction::SendResponse, | 832 FROM_HERE, |
| 510 this, | 833 base::Bind(&DeveloperPrivateGetItemsInfoFunction::Finish, this)); |
| 511 true)); | |
| 512 } | 834 } |
| 513 | 835 |
| 514 void DeveloperPrivateGetItemsInfoFunction:: | 836 void DeveloperPrivateGetItemsInfoFunction::Finish() { |
| 515 GetInspectablePagesForExtensionProcess( | 837 Respond(ArgumentList(developer::GetItemsInfo::Results::Create(item_list_))); |
| 516 const Extension* extension, | |
| 517 const std::set<content::RenderViewHost*>& views, | |
| 518 ItemInspectViewList* result) { | |
| 519 bool has_generated_background_page = | |
| 520 BackgroundInfo::HasGeneratedBackgroundPage(extension); | |
| 521 for (std::set<content::RenderViewHost*>::const_iterator iter = views.begin(); | |
| 522 iter != views.end(); ++iter) { | |
| 523 content::RenderViewHost* host = *iter; | |
| 524 content::WebContents* web_contents = | |
| 525 content::WebContents::FromRenderViewHost(host); | |
| 526 ViewType host_type = GetViewType(web_contents); | |
| 527 if (VIEW_TYPE_EXTENSION_POPUP == host_type || | |
| 528 VIEW_TYPE_EXTENSION_DIALOG == host_type) | |
| 529 continue; | |
| 530 | |
| 531 content::RenderProcessHost* process = host->GetProcess(); | |
| 532 bool is_background_page = | |
| 533 (web_contents->GetURL() == BackgroundInfo::GetBackgroundURL(extension)); | |
| 534 result->push_back(constructInspectView( | |
| 535 web_contents->GetURL(), | |
| 536 process->GetID(), | |
| 537 host->GetRoutingID(), | |
| 538 process->GetBrowserContext()->IsOffTheRecord(), | |
| 539 is_background_page && has_generated_background_page)); | |
| 540 } | |
| 541 } | 838 } |
| 542 | 839 |
| 543 void DeveloperPrivateGetItemsInfoFunction::GetAppWindowPagesForExtensionProfile( | |
| 544 const Extension* extension, | |
| 545 ItemInspectViewList* result) { | |
| 546 AppWindowRegistry* registry = AppWindowRegistry::Get(GetProfile()); | |
| 547 if (!registry) return; | |
| 548 | |
| 549 const AppWindowRegistry::AppWindowList windows = | |
| 550 registry->GetAppWindowsForApp(extension->id()); | |
| 551 | |
| 552 bool has_generated_background_page = | |
| 553 BackgroundInfo::HasGeneratedBackgroundPage(extension); | |
| 554 for (AppWindowRegistry::const_iterator it = windows.begin(); | |
| 555 it != windows.end(); | |
| 556 ++it) { | |
| 557 content::WebContents* web_contents = (*it)->web_contents(); | |
| 558 RenderViewHost* host = web_contents->GetRenderViewHost(); | |
| 559 content::RenderProcessHost* process = host->GetProcess(); | |
| 560 bool is_background_page = | |
| 561 (web_contents->GetURL() == BackgroundInfo::GetBackgroundURL(extension)); | |
| 562 result->push_back(constructInspectView( | |
| 563 web_contents->GetURL(), | |
| 564 process->GetID(), | |
| 565 host->GetRoutingID(), | |
| 566 process->GetBrowserContext()->IsOffTheRecord(), | |
| 567 is_background_page && has_generated_background_page)); | |
| 568 } | |
| 569 } | |
| 570 | |
| 571 linked_ptr<developer::ItemInspectView> DeveloperPrivateGetItemsInfoFunction:: | |
| 572 constructInspectView( | |
| 573 const GURL& url, | |
| 574 int render_process_id, | |
| 575 int render_view_id, | |
| 576 bool incognito, | |
| 577 bool generated_background_page) { | |
| 578 linked_ptr<developer::ItemInspectView> view(new developer::ItemInspectView()); | |
| 579 | |
| 580 if (url.scheme() == kExtensionScheme) { | |
| 581 // No leading slash. | |
| 582 view->path = url.path().substr(1); | |
| 583 } else { | |
| 584 // For live pages, use the full URL. | |
| 585 view->path = url.spec(); | |
| 586 } | |
| 587 | |
| 588 view->render_process_id = render_process_id; | |
| 589 view->render_view_id = render_view_id; | |
| 590 view->incognito = incognito; | |
| 591 view->generated_background_page = generated_background_page; | |
| 592 return view; | |
| 593 } | |
| 594 | |
| 595 ItemInspectViewList DeveloperPrivateGetItemsInfoFunction:: | |
| 596 GetInspectablePagesForExtension( | |
| 597 const Extension* extension, | |
| 598 bool extension_is_enabled) { | |
| 599 ItemInspectViewList result; | |
| 600 // Get the extension process's active views. | |
| 601 ProcessManager* process_manager = ProcessManager::Get(GetProfile()); | |
| 602 GetInspectablePagesForExtensionProcess( | |
| 603 extension, | |
| 604 process_manager->GetRenderViewHostsForExtension(extension->id()), | |
| 605 &result); | |
| 606 | |
| 607 // Get app window views. | |
| 608 GetAppWindowPagesForExtensionProfile(extension, &result); | |
| 609 | |
| 610 // Include a link to start the lazy background page, if applicable. | |
| 611 if (BackgroundInfo::HasLazyBackgroundPage(extension) && | |
| 612 extension_is_enabled && | |
| 613 !process_manager->GetBackgroundHostForExtension(extension->id())) { | |
| 614 result.push_back(constructInspectView( | |
| 615 BackgroundInfo::GetBackgroundURL(extension), | |
| 616 -1, | |
| 617 -1, | |
| 618 false, | |
| 619 BackgroundInfo::HasGeneratedBackgroundPage(extension))); | |
| 620 } | |
| 621 | |
| 622 ExtensionService* service = GetExtensionService(GetProfile()); | |
| 623 // Repeat for the incognito process, if applicable. Don't try to get | |
| 624 // app windows for incognito process. | |
| 625 if (service->profile()->HasOffTheRecordProfile() && | |
| 626 IncognitoInfo::IsSplitMode(extension)) { | |
| 627 process_manager = | |
| 628 ProcessManager::Get(service->profile()->GetOffTheRecordProfile()); | |
| 629 GetInspectablePagesForExtensionProcess( | |
| 630 extension, | |
| 631 process_manager->GetRenderViewHostsForExtension(extension->id()), | |
| 632 &result); | |
| 633 | |
| 634 if (BackgroundInfo::HasLazyBackgroundPage(extension) && | |
| 635 extension_is_enabled && | |
| 636 !process_manager->GetBackgroundHostForExtension(extension->id())) { | |
| 637 result.push_back(constructInspectView( | |
| 638 BackgroundInfo::GetBackgroundURL(extension), | |
| 639 -1, | |
| 640 -1, | |
| 641 false, | |
| 642 BackgroundInfo::HasGeneratedBackgroundPage(extension))); | |
| 643 } | |
| 644 } | |
| 645 | |
| 646 return result; | |
| 647 } | |
| 648 | |
| 649 bool DeveloperPrivateGetItemsInfoFunction::RunAsync() { | |
| 650 scoped_ptr<developer::GetItemsInfo::Params> params( | |
| 651 developer::GetItemsInfo::Params::Create(*args_)); | |
| 652 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | |
| 653 | |
| 654 bool include_disabled = params->include_disabled; | |
| 655 bool include_terminated = params->include_terminated; | |
| 656 | |
| 657 ExtensionSet items; | |
| 658 | |
| 659 ExtensionRegistry* registry = ExtensionRegistry::Get(GetProfile()); | |
| 660 | |
| 661 items.InsertAll(registry->enabled_extensions()); | |
| 662 | |
| 663 if (include_disabled) { | |
| 664 items.InsertAll(registry->disabled_extensions()); | |
| 665 } | |
| 666 | |
| 667 if (include_terminated) { | |
| 668 items.InsertAll(registry->terminated_extensions()); | |
| 669 } | |
| 670 | |
| 671 ExtensionService* service = | |
| 672 ExtensionSystem::Get(GetProfile())->extension_service(); | |
| 673 std::map<std::string, ExtensionResource> id_to_icon; | |
| 674 ItemInfoList item_list; | |
| 675 | |
| 676 for (ExtensionSet::const_iterator iter = items.begin(); iter != items.end(); | |
| 677 ++iter) { | |
| 678 const Extension& item = *iter->get(); | |
| 679 | |
| 680 ExtensionResource item_resource = | |
| 681 IconsInfo::GetIconResource(&item, | |
| 682 extension_misc::EXTENSION_ICON_MEDIUM, | |
| 683 ExtensionIconSet::MATCH_BIGGER); | |
| 684 id_to_icon[item.id()] = item_resource; | |
| 685 | |
| 686 // Don't show component extensions and invisible apps. | |
| 687 if (ui_util::ShouldNotBeVisible(&item, GetProfile())) | |
| 688 continue; | |
| 689 | |
| 690 item_list.push_back(make_linked_ptr<developer::ItemInfo>( | |
| 691 CreateItemInfo( | |
| 692 item, service->IsExtensionEnabled(item.id())).release())); | |
| 693 } | |
| 694 | |
| 695 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, | |
| 696 base::Bind(&DeveloperPrivateGetItemsInfoFunction::GetIconsOnFileThread, | |
| 697 this, | |
| 698 item_list, | |
| 699 id_to_icon)); | |
| 700 | |
| 701 return true; | |
| 702 } | |
| 703 | |
| 704 DeveloperPrivateGetItemsInfoFunction::~DeveloperPrivateGetItemsInfoFunction() {} | |
| 705 | |
| 706 ExtensionFunction::ResponseAction | 840 ExtensionFunction::ResponseAction |
| 707 DeveloperPrivateAllowFileAccessFunction::Run() { | 841 DeveloperPrivateAllowFileAccessFunction::Run() { |
| 708 scoped_ptr<AllowFileAccess::Params> params( | 842 scoped_ptr<AllowFileAccess::Params> params( |
| 709 AllowFileAccess::Params::Create(*args_)); | 843 AllowFileAccess::Params::Create(*args_)); |
| 710 EXTENSION_FUNCTION_VALIDATE(params.get()); | 844 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 711 | 845 |
| 712 const Extension* extension = GetExtensionById(params->extension_id); | 846 const Extension* extension = GetExtensionById(params->extension_id); |
| 713 | 847 |
| 714 if (!extension) | 848 if (!extension) |
| 715 return RespondNow(Error(kNoSuchExtensionError)); | 849 return RespondNow(Error(kNoSuchExtensionError)); |
| (...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1477 | 1611 |
| 1478 TabStripModel* tab_strip = browser->tab_strip_model(); | 1612 TabStripModel* tab_strip = browser->tab_strip_model(); |
| 1479 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(web_contents), | 1613 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(web_contents), |
| 1480 false); // Not through direct user gesture. | 1614 false); // Not through direct user gesture. |
| 1481 return RespondNow(NoArguments()); | 1615 return RespondNow(NoArguments()); |
| 1482 } | 1616 } |
| 1483 | 1617 |
| 1484 } // namespace api | 1618 } // namespace api |
| 1485 | 1619 |
| 1486 } // namespace extensions | 1620 } // namespace extensions |
| OLD | NEW |