OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/common/extensions/extension.h" | 5 #include "chrome/common/extensions/extension.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 const int Extension::kSidebarIconMaxSize = 16; | 265 const int Extension::kSidebarIconMaxSize = 16; |
266 | 266 |
267 // Explicit permissions -- permission declaration required. | 267 // Explicit permissions -- permission declaration required. |
268 const char Extension::kBackgroundPermission[] = "background"; | 268 const char Extension::kBackgroundPermission[] = "background"; |
269 const char Extension::kBookmarkPermission[] = "bookmarks"; | 269 const char Extension::kBookmarkPermission[] = "bookmarks"; |
270 const char Extension::kClipboardReadPermission[] = "clipboardRead"; | 270 const char Extension::kClipboardReadPermission[] = "clipboardRead"; |
271 const char Extension::kClipboardWritePermission[] = "clipboardWrite"; | 271 const char Extension::kClipboardWritePermission[] = "clipboardWrite"; |
272 const char Extension::kContextMenusPermission[] = "contextMenus"; | 272 const char Extension::kContextMenusPermission[] = "contextMenus"; |
273 const char Extension::kContentSettingsPermission[] = "contentSettings"; | 273 const char Extension::kContentSettingsPermission[] = "contentSettings"; |
274 const char Extension::kCookiePermission[] = "cookies"; | 274 const char Extension::kCookiePermission[] = "cookies"; |
| 275 const char Extension::kChromeAuthPrivatePermission[] = "chromeAuthPrivate"; |
275 const char Extension::kChromePrivatePermission[] = "chromePrivate"; | 276 const char Extension::kChromePrivatePermission[] = "chromePrivate"; |
276 const char Extension::kChromeosInfoPrivatePermission[] = "chromeosInfoPrivate"; | 277 const char Extension::kChromeosInfoPrivatePermission[] = "chromeosInfoPrivate"; |
277 const char Extension::kDebuggerPermission[] = "debugger"; | 278 const char Extension::kDebuggerPermission[] = "debugger"; |
278 const char Extension::kExperimentalPermission[] = "experimental"; | 279 const char Extension::kExperimentalPermission[] = "experimental"; |
279 const char Extension::kFileBrowserHandlerPermission[] = "fileBrowserHandler"; | 280 const char Extension::kFileBrowserHandlerPermission[] = "fileBrowserHandler"; |
280 const char Extension::kFileBrowserPrivatePermission[] = "fileBrowserPrivate"; | 281 const char Extension::kFileBrowserPrivatePermission[] = "fileBrowserPrivate"; |
281 const char Extension::kGeolocationPermission[] = "geolocation"; | 282 const char Extension::kGeolocationPermission[] = "geolocation"; |
282 const char Extension::kHistoryPermission[] = "history"; | 283 const char Extension::kHistoryPermission[] = "history"; |
283 const char Extension::kIdlePermission[] = "idle"; | 284 const char Extension::kIdlePermission[] = "idle"; |
284 const char Extension::kManagementPermission[] = "management"; | 285 const char Extension::kManagementPermission[] = "management"; |
285 const char Extension::kMediaPlayerPrivatePermission[] = "mediaPlayerPrivate"; | 286 const char Extension::kMediaPlayerPrivatePermission[] = "mediaPlayerPrivate"; |
286 const char Extension::kNotificationPermission[] = "notifications"; | 287 const char Extension::kNotificationPermission[] = "notifications"; |
287 const char Extension::kProxyPermission[] = "proxy"; | 288 const char Extension::kProxyPermission[] = "proxy"; |
288 const char Extension::kTabPermission[] = "tabs"; | 289 const char Extension::kTabPermission[] = "tabs"; |
289 const char Extension::kUnlimitedStoragePermission[] = "unlimitedStorage"; | 290 const char Extension::kUnlimitedStoragePermission[] = "unlimitedStorage"; |
290 const char Extension::kWebstorePrivatePermission[] = "webstorePrivate"; | 291 const char Extension::kWebstorePrivatePermission[] = "webstorePrivate"; |
291 const char Extension::kWebSocketProxyPrivatePermission[] = | 292 const char Extension::kWebSocketProxyPrivatePermission[] = |
292 "webSocketProxyPrivate"; | 293 "webSocketProxyPrivate"; |
293 | 294 |
294 // In general, all permissions should have an install message. | 295 // In general, all permissions should have an install message. |
295 // See ExtensionsTest.PermissionMessages for an explanation of each | 296 // See ExtensionsTest.PermissionMessages for an explanation of each |
296 // exception. | 297 // exception. |
297 const Extension::Permission Extension::kPermissions[] = { | 298 const Extension::Permission Extension::kPermissions[] = { |
298 { kBackgroundPermission, PermissionMessage::ID_NONE }, | 299 { kBackgroundPermission, PermissionMessage::ID_NONE }, |
299 { kBookmarkPermission, PermissionMessage::ID_BOOKMARKS }, | 300 { kBookmarkPermission, PermissionMessage::ID_BOOKMARKS }, |
| 301 { kChromeAuthPrivatePermission, PermissionMessage::ID_NONE }, |
300 { kChromePrivatePermission, PermissionMessage::ID_NONE }, | 302 { kChromePrivatePermission, PermissionMessage::ID_NONE }, |
301 { kChromeosInfoPrivatePermission, PermissionMessage::ID_NONE }, | 303 { kChromeosInfoPrivatePermission, PermissionMessage::ID_NONE }, |
302 { kClipboardReadPermission, PermissionMessage::ID_CLIPBOARD }, | 304 { kClipboardReadPermission, PermissionMessage::ID_CLIPBOARD }, |
303 { kClipboardWritePermission, PermissionMessage::ID_NONE }, | 305 { kClipboardWritePermission, PermissionMessage::ID_NONE }, |
304 { kContentSettingsPermission, PermissionMessage::ID_NONE }, | 306 { kContentSettingsPermission, PermissionMessage::ID_NONE }, |
305 { kContextMenusPermission, PermissionMessage::ID_NONE }, | 307 { kContextMenusPermission, PermissionMessage::ID_NONE }, |
306 { kCookiePermission, PermissionMessage::ID_NONE }, | 308 { kCookiePermission, PermissionMessage::ID_NONE }, |
307 { kDebuggerPermission, PermissionMessage::ID_DEBUGGER }, | 309 { kDebuggerPermission, PermissionMessage::ID_DEBUGGER }, |
308 { kExperimentalPermission, PermissionMessage::ID_NONE }, | 310 { kExperimentalPermission, PermissionMessage::ID_NONE }, |
309 { kFileBrowserHandlerPermission, PermissionMessage::ID_NONE }, | 311 { kFileBrowserHandlerPermission, PermissionMessage::ID_NONE }, |
310 { kFileBrowserPrivatePermission, PermissionMessage::ID_NONE }, | 312 { kFileBrowserPrivatePermission, PermissionMessage::ID_NONE }, |
311 { kGeolocationPermission, PermissionMessage::ID_GEOLOCATION }, | 313 { kGeolocationPermission, PermissionMessage::ID_GEOLOCATION }, |
312 { kHistoryPermission, PermissionMessage::ID_BROWSING_HISTORY }, | 314 { kHistoryPermission, PermissionMessage::ID_BROWSING_HISTORY }, |
313 { kIdlePermission, PermissionMessage::ID_NONE }, | 315 { kIdlePermission, PermissionMessage::ID_NONE }, |
314 { kManagementPermission, PermissionMessage::ID_MANAGEMENT }, | 316 { kManagementPermission, PermissionMessage::ID_MANAGEMENT }, |
315 { kMediaPlayerPrivatePermission, PermissionMessage::ID_NONE }, | 317 { kMediaPlayerPrivatePermission, PermissionMessage::ID_NONE }, |
316 { kNotificationPermission, PermissionMessage::ID_NONE }, | 318 { kNotificationPermission, PermissionMessage::ID_NONE }, |
317 { kProxyPermission, PermissionMessage::ID_NONE }, | 319 { kProxyPermission, PermissionMessage::ID_NONE }, |
318 { kTabPermission, PermissionMessage::ID_TABS }, | 320 { kTabPermission, PermissionMessage::ID_TABS }, |
319 { kUnlimitedStoragePermission, PermissionMessage::ID_NONE }, | 321 { kUnlimitedStoragePermission, PermissionMessage::ID_NONE }, |
320 { kWebSocketProxyPrivatePermission, PermissionMessage::ID_NONE }, | 322 { kWebSocketProxyPrivatePermission, PermissionMessage::ID_NONE }, |
321 { kWebstorePrivatePermission, PermissionMessage::ID_NONE }, | 323 { kWebstorePrivatePermission, PermissionMessage::ID_NONE }, |
322 }; | 324 }; |
323 const size_t Extension::kNumPermissions = arraysize(Extension::kPermissions); | 325 const size_t Extension::kNumPermissions = arraysize(Extension::kPermissions); |
324 | 326 |
325 const char* const Extension::kHostedAppPermissionNames[] = { | 327 const char* const Extension::kHostedAppPermissionNames[] = { |
326 Extension::kBackgroundPermission, | 328 Extension::kBackgroundPermission, |
| 329 Extension::kChromeAuthPrivatePermission, |
327 Extension::kChromePrivatePermission, | 330 Extension::kChromePrivatePermission, |
328 Extension::kClipboardReadPermission, | 331 Extension::kClipboardReadPermission, |
329 Extension::kClipboardWritePermission, | 332 Extension::kClipboardWritePermission, |
330 Extension::kExperimentalPermission, | 333 Extension::kExperimentalPermission, |
331 Extension::kGeolocationPermission, | 334 Extension::kGeolocationPermission, |
332 Extension::kNotificationPermission, | 335 Extension::kNotificationPermission, |
333 Extension::kUnlimitedStoragePermission, | 336 Extension::kUnlimitedStoragePermission, |
334 Extension::kWebstorePrivatePermission, | 337 Extension::kWebstorePrivatePermission, |
335 }; | 338 }; |
336 const size_t Extension::kNumHostedAppPermissions = | 339 const size_t Extension::kNumHostedAppPermissions = |
337 arraysize(Extension::kHostedAppPermissionNames); | 340 arraysize(Extension::kHostedAppPermissionNames); |
338 | 341 |
339 const char* const Extension::kComponentPrivatePermissionNames[] = { | 342 const char* const Extension::kComponentPrivatePermissionNames[] = { |
| 343 Extension::kChromeAuthPrivatePermission, |
340 Extension::kFileBrowserPrivatePermission, | 344 Extension::kFileBrowserPrivatePermission, |
341 Extension::kWebstorePrivatePermission, | 345 Extension::kWebstorePrivatePermission, |
342 Extension::kMediaPlayerPrivatePermission, | 346 Extension::kMediaPlayerPrivatePermission, |
343 Extension::kChromeosInfoPrivatePermission, | 347 Extension::kChromeosInfoPrivatePermission, |
344 }; | 348 }; |
345 const size_t Extension::kNumComponentPrivatePermissions = | 349 const size_t Extension::kNumComponentPrivatePermissions = |
346 arraysize(Extension::kComponentPrivatePermissionNames); | 350 arraysize(Extension::kComponentPrivatePermissionNames); |
347 | 351 |
348 // We purposefully don't put this into kPermissionNames. | 352 // We purposefully don't put this into kPermissionNames. |
349 const char Extension::kOldUnlimitedStoragePermission[] = "unlimited_storage"; | 353 const char Extension::kOldUnlimitedStoragePermission[] = "unlimited_storage"; |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 std::set<std::string>::const_iterator i; | 534 std::set<std::string>::const_iterator i; |
531 for (i = api_permissions().begin(); i != api_permissions().end(); ++i) { | 535 for (i = api_permissions().begin(); i != api_permissions().end(); ++i) { |
532 PermissionMessage::MessageId message_id = GetPermissionMessageId(*i); | 536 PermissionMessage::MessageId message_id = GetPermissionMessageId(*i); |
533 DCHECK_GT(PermissionMessage::ID_NONE, PermissionMessage::ID_UNKNOWN); | 537 DCHECK_GT(PermissionMessage::ID_NONE, PermissionMessage::ID_UNKNOWN); |
534 if (message_id > PermissionMessage::ID_NONE) | 538 if (message_id > PermissionMessage::ID_NONE) |
535 messages.insert(PermissionMessage::CreateFromMessageId(message_id)); | 539 messages.insert(PermissionMessage::CreateFromMessageId(message_id)); |
536 } | 540 } |
537 return messages; | 541 return messages; |
538 } | 542 } |
539 | 543 |
| 544 void Extension::OverrideLaunchUrl(const GURL& override_url) { |
| 545 GURL new_url(override_url); |
| 546 if (!new_url.is_valid()) { |
| 547 LOG(WARNING) << "Invalid override url given for " << name(); |
| 548 } else { |
| 549 if (new_url.has_port()) { |
| 550 LOG(WARNING) << "Override URL passed for " << name() |
| 551 << " should not contain a port. Removing it."; |
| 552 |
| 553 GURL::Replacements remove_port; |
| 554 remove_port.ClearPort(); |
| 555 new_url = new_url.ReplaceComponents(remove_port); |
| 556 } |
| 557 |
| 558 launch_web_url_ = new_url.spec(); |
| 559 |
| 560 URLPattern pattern(kValidWebExtentSchemes); |
| 561 pattern.Parse(new_url.spec(), URLPattern::PARSE_STRICT); |
| 562 pattern.SetPath(pattern.path() + '*'); |
| 563 extent_.AddPattern(pattern); |
| 564 } |
| 565 } |
| 566 |
540 // static | 567 // static |
541 std::vector<std::string> Extension::GetDistinctHostsForDisplay( | 568 std::vector<std::string> Extension::GetDistinctHostsForDisplay( |
542 const URLPatternList& list) { | 569 const URLPatternList& list) { |
543 return GetDistinctHosts(list, true); | 570 return GetDistinctHosts(list, true); |
544 } | 571 } |
545 | 572 |
546 // static | 573 // static |
547 bool Extension::IsElevatedHostList( | 574 bool Extension::IsElevatedHostList( |
548 const URLPatternList& old_list, const URLPatternList& new_list) { | 575 const URLPatternList& old_list, const URLPatternList& new_list) { |
549 // TODO(jstritar): This is overly conservative with respect to subdomains. | 576 // TODO(jstritar): This is overly conservative with respect to subdomains. |
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1370 // In order for the --apps-gallery-url switch to work with the gallery | 1397 // In order for the --apps-gallery-url switch to work with the gallery |
1371 // process isolation, we must insert any provided value into the component | 1398 // process isolation, we must insert any provided value into the component |
1372 // app's launch url and web extent. | 1399 // app's launch url and web extent. |
1373 if (id() == extension_misc::kWebStoreAppId) { | 1400 if (id() == extension_misc::kWebStoreAppId) { |
1374 std::string gallery_url_str = CommandLine::ForCurrentProcess()-> | 1401 std::string gallery_url_str = CommandLine::ForCurrentProcess()-> |
1375 GetSwitchValueASCII(switches::kAppsGalleryURL); | 1402 GetSwitchValueASCII(switches::kAppsGalleryURL); |
1376 | 1403 |
1377 // Empty string means option was not used. | 1404 // Empty string means option was not used. |
1378 if (!gallery_url_str.empty()) { | 1405 if (!gallery_url_str.empty()) { |
1379 GURL gallery_url(gallery_url_str); | 1406 GURL gallery_url(gallery_url_str); |
1380 if (!gallery_url.is_valid()) { | 1407 OverrideLaunchUrl(gallery_url); |
1381 LOG(WARNING) << "Invalid url given in switch " | 1408 } |
1382 << switches::kAppsGalleryURL; | 1409 } else if (id() == extension_misc::kCloudPrintAppId) { |
1383 } else { | 1410 // In order for the --cloud-print-service switch to work, we must update |
1384 if (gallery_url.has_port()) { | 1411 // the launch URL and web extent. |
1385 LOG(WARNING) << "URLs passed to switch " << switches::kAppsGalleryURL | 1412 // TODO(sanjeevr): Ideally we want to use CloudPrintURL here but that is |
1386 << " should not contain a port. Removing it."; | 1413 // currently under chrome/browser. |
1387 | 1414 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
1388 GURL::Replacements remove_port; | 1415 GURL cloud_print_service_url = GURL(command_line.GetSwitchValueASCII( |
1389 remove_port.ClearPort(); | 1416 switches::kCloudPrintServiceURL)); |
1390 gallery_url = gallery_url.ReplaceComponents(remove_port); | 1417 if (!cloud_print_service_url.is_empty()) { |
1391 } | 1418 std::string path( |
1392 | 1419 cloud_print_service_url.path() + "/enable_chrome_connector"); |
1393 launch_web_url_ = gallery_url.spec(); | 1420 GURL::Replacements replacements; |
1394 | 1421 replacements.SetPathStr(path); |
1395 URLPattern pattern(kValidWebExtentSchemes); | 1422 GURL cloud_print_enable_connector_url = |
1396 pattern.Parse(gallery_url.spec(), URLPattern::PARSE_STRICT); | 1423 cloud_print_service_url.ReplaceComponents(replacements); |
1397 pattern.SetPath(pattern.path() + '*'); | 1424 OverrideLaunchUrl(cloud_print_enable_connector_url); |
1398 extent_.AddPattern(pattern); | |
1399 } | |
1400 } | 1425 } |
1401 } | 1426 } |
1402 | |
1403 return true; | 1427 return true; |
1404 } | 1428 } |
1405 | 1429 |
1406 bool Extension::LoadLaunchContainer(const DictionaryValue* manifest, | 1430 bool Extension::LoadLaunchContainer(const DictionaryValue* manifest, |
1407 std::string* error) { | 1431 std::string* error) { |
1408 Value* temp = NULL; | 1432 Value* temp = NULL; |
1409 if (!manifest->Get(keys::kLaunchContainer, &temp)) | 1433 if (!manifest->Get(keys::kLaunchContainer, &temp)) |
1410 return true; | 1434 return true; |
1411 | 1435 |
1412 std::string launch_container_string; | 1436 std::string launch_container_string; |
(...skipping 1748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3161 | 3185 |
3162 UninstalledExtensionInfo::~UninstalledExtensionInfo() {} | 3186 UninstalledExtensionInfo::~UninstalledExtensionInfo() {} |
3163 | 3187 |
3164 | 3188 |
3165 UnloadedExtensionInfo::UnloadedExtensionInfo( | 3189 UnloadedExtensionInfo::UnloadedExtensionInfo( |
3166 const Extension* extension, | 3190 const Extension* extension, |
3167 Reason reason) | 3191 Reason reason) |
3168 : reason(reason), | 3192 : reason(reason), |
3169 already_disabled(false), | 3193 already_disabled(false), |
3170 extension(extension) {} | 3194 extension(extension) {} |
OLD | NEW |