Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Side by Side Diff: extensions/browser/api/runtime/runtime_api.cc

Issue 1283193003: Restrict chrome.runtime.setUninstallURL to http(s) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2454
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/browser/api/runtime/runtime_api.h" 5 #include "extensions/browser/api/runtime/runtime_api.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 const char kNoBackgroundPageError[] = "You do not have a background page."; 47 const char kNoBackgroundPageError[] = "You do not have a background page.";
48 const char kPageLoadError[] = "Background page failed to load."; 48 const char kPageLoadError[] = "Background page failed to load.";
49 const char kFailedToCreateOptionsPage[] = "Could not create an options page."; 49 const char kFailedToCreateOptionsPage[] = "Could not create an options page.";
50 const char kInstallId[] = "id"; 50 const char kInstallId[] = "id";
51 const char kInstallReason[] = "reason"; 51 const char kInstallReason[] = "reason";
52 const char kInstallReasonChromeUpdate[] = "chrome_update"; 52 const char kInstallReasonChromeUpdate[] = "chrome_update";
53 const char kInstallReasonUpdate[] = "update"; 53 const char kInstallReasonUpdate[] = "update";
54 const char kInstallReasonInstall[] = "install"; 54 const char kInstallReasonInstall[] = "install";
55 const char kInstallReasonSharedModuleUpdate[] = "shared_module_update"; 55 const char kInstallReasonSharedModuleUpdate[] = "shared_module_update";
56 const char kInstallPreviousVersion[] = "previousVersion"; 56 const char kInstallPreviousVersion[] = "previousVersion";
57 const char kInvalidUrlError[] = "Invalid URL."; 57 const char kInvalidUrlError[] = "Invalid URL: \"*\".";
58 const char kPlatformInfoUnavailable[] = "Platform information unavailable."; 58 const char kPlatformInfoUnavailable[] = "Platform information unavailable.";
59 59
60 const char kUpdatesDisabledError[] = "Autoupdate is not enabled."; 60 const char kUpdatesDisabledError[] = "Autoupdate is not enabled.";
61 61
62 // A preference key storing the url loaded when an extension is uninstalled. 62 // A preference key storing the url loaded when an extension is uninstalled.
63 const char kUninstallUrl[] = "uninstall_url"; 63 const char kUninstallUrl[] = "uninstall_url";
64 64
65 // The name of the directory to be returned by getPackageDirectoryEntry. This 65 // The name of the directory to be returned by getPackageDirectoryEntry. This
66 // particular value does not matter to user code, but is chosen for consistency 66 // particular value does not matter to user code, but is chosen for consistency
67 // with the equivalent Pepper API. 67 // with the equivalent Pepper API.
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 const std::string& extension_id, 394 const std::string& extension_id,
395 UninstallReason reason) { 395 UninstallReason reason) {
396 if (!(reason == UNINSTALL_REASON_USER_INITIATED || 396 if (!(reason == UNINSTALL_REASON_USER_INITIATED ||
397 reason == UNINSTALL_REASON_MANAGEMENT_API)) { 397 reason == UNINSTALL_REASON_MANAGEMENT_API)) {
398 return; 398 return;
399 } 399 }
400 400
401 GURL uninstall_url( 401 GURL uninstall_url(
402 GetUninstallURL(ExtensionPrefs::Get(context), extension_id)); 402 GetUninstallURL(ExtensionPrefs::Get(context), extension_id));
403 403
404 if (uninstall_url.is_empty()) 404 if (!uninstall_url.SchemeIsHTTPOrHTTPS()) {
405 // Previous versions of Chrome allowed non-http(s) URLs to be stored in the
406 // prefs. Now they're disallowed, but the old data may still exist.
405 return; 407 return;
408 }
406 409
407 RuntimeAPI::GetFactoryInstance()->Get(context)->OpenURL(uninstall_url); 410 RuntimeAPI::GetFactoryInstance()->Get(context)->OpenURL(uninstall_url);
408 } 411 }
409 412
410 ExtensionFunction::ResponseAction RuntimeGetBackgroundPageFunction::Run() { 413 ExtensionFunction::ResponseAction RuntimeGetBackgroundPageFunction::Run() {
411 ExtensionHost* host = ProcessManager::Get(browser_context()) 414 ExtensionHost* host = ProcessManager::Get(browser_context())
412 ->GetBackgroundHostForExtension(extension_id()); 415 ->GetBackgroundHostForExtension(extension_id());
413 if (LazyBackgroundTaskQueue::Get(browser_context()) 416 if (LazyBackgroundTaskQueue::Get(browser_context())
414 ->ShouldEnqueueTask(browser_context(), extension())) { 417 ->ShouldEnqueueTask(browser_context(), extension())) {
415 LazyBackgroundTaskQueue::Get(browser_context()) 418 LazyBackgroundTaskQueue::Get(browser_context())
(...skipping 21 matching lines...) Expand all
437 RuntimeAPI* api = RuntimeAPI::GetFactoryInstance()->Get(browser_context()); 440 RuntimeAPI* api = RuntimeAPI::GetFactoryInstance()->Get(browser_context());
438 return RespondNow(api->OpenOptionsPage(extension()) 441 return RespondNow(api->OpenOptionsPage(extension())
439 ? NoArguments() 442 ? NoArguments()
440 : Error(kFailedToCreateOptionsPage)); 443 : Error(kFailedToCreateOptionsPage));
441 } 444 }
442 445
443 ExtensionFunction::ResponseAction RuntimeSetUninstallURLFunction::Run() { 446 ExtensionFunction::ResponseAction RuntimeSetUninstallURLFunction::Run() {
444 std::string url_string; 447 std::string url_string;
445 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url_string)); 448 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url_string));
446 449
447 GURL url(url_string); 450 if (!url_string.empty() && !GURL(url_string).SchemeIsHTTPOrHTTPS()) {
448 if (!url.is_valid()) { 451 return RespondNow(Error(kInvalidUrlError, url_string));
449 return RespondNow(
450 Error(ErrorUtils::FormatErrorMessage(kInvalidUrlError, url_string)));
451 } 452 }
452 SetUninstallURL( 453 SetUninstallURL(
453 ExtensionPrefs::Get(browser_context()), extension_id(), url_string); 454 ExtensionPrefs::Get(browser_context()), extension_id(), url_string);
454 return RespondNow(NoArguments()); 455 return RespondNow(NoArguments());
455 } 456 }
456 457
457 ExtensionFunction::ResponseAction RuntimeReloadFunction::Run() { 458 ExtensionFunction::ResponseAction RuntimeReloadFunction::Run() {
458 RuntimeAPI::GetFactoryInstance()->Get(browser_context())->ReloadExtension( 459 RuntimeAPI::GetFactoryInstance()->Get(browser_context())->ReloadExtension(
459 extension_id()); 460 extension_id());
460 return RespondNow(NoArguments()); 461 return RespondNow(NoArguments());
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 content::ChildProcessSecurityPolicy* policy = 522 content::ChildProcessSecurityPolicy* policy =
522 content::ChildProcessSecurityPolicy::GetInstance(); 523 content::ChildProcessSecurityPolicy::GetInstance();
523 policy->GrantReadFileSystem(renderer_id, filesystem_id); 524 policy->GrantReadFileSystem(renderer_id, filesystem_id);
524 base::DictionaryValue* dict = new base::DictionaryValue(); 525 base::DictionaryValue* dict = new base::DictionaryValue();
525 dict->SetString("fileSystemId", filesystem_id); 526 dict->SetString("fileSystemId", filesystem_id);
526 dict->SetString("baseName", relative_path); 527 dict->SetString("baseName", relative_path);
527 return RespondNow(OneArgument(dict)); 528 return RespondNow(OneArgument(dict));
528 } 529 }
529 530
530 } // namespace extensions 531 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/test/data/extensions/api_test/runtime/uninstall_url/test.js ('k') | extensions/common/api/runtime.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698