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

Side by Side Diff: chrome/common/extensions/extension_sidebar_utils.cc

Issue 6378009: Only allow extension pages to be displayed in the sidebar to be consistent... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_sidebar_utils.h" 5 #include "chrome/common/extensions/extension_sidebar_utils.h"
6 6
7 #include "chrome/common/extensions/extension.h" 7 #include "chrome/common/extensions/extension.h"
8 #include "chrome/common/extensions/extension_error_utils.h" 8 #include "chrome/common/extensions/extension_error_utils.h"
9 #include "chrome/common/url_constants.h"
10 #include "googleurl/src/gurl.h" 9 #include "googleurl/src/gurl.h"
11 10
12 namespace { 11 namespace {
13 12
14 // Errors. 13 // Errors.
15 const char kInvalidUrlError[] = "Invalid url: \"*\"."; 14 const char kInvalidPathError[] = "Invalid path: \"*\".";
16
17 bool CanUseHost(const Extension* extension,
18 const GURL& url,
19 std::string* error) {
20 if (extension->HasHostPermission(url))
21 return true;
22
23 *error = ExtensionErrorUtils::FormatErrorMessage(
24 extension_manifest_errors::kCannotAccessPage, url.spec());
25 return false;
26 }
27 15
28 } // namespace 16 } // namespace
29 17
30 namespace extension_sidebar_utils { 18 namespace extension_sidebar_utils {
31 19
32 std::string GetExtensionIdByContentId(const std::string& content_id) { 20 std::string GetExtensionIdByContentId(const std::string& content_id) {
33 // At the moment, content_id == extension_id. 21 // At the moment, content_id == extension_id.
34 return content_id; 22 return content_id;
35 } 23 }
36 24
37 GURL ResolveAndVerifyUrl(const std::string& url_string, 25 GURL ResolveRelativePath(const std::string& relative_path,
38 const Extension* extension, 26 const Extension* extension,
39 std::string* error) { 27 std::string* error) {
40 // Resolve possibly relative URL. 28 GURL url(extension->GetResourceURL(relative_path));
41 GURL url(url_string);
42 if (!url.is_valid())
43 url = extension->GetResourceURL(url_string);
44
45 if (!url.is_valid()) { 29 if (!url.is_valid()) {
46 *error = ExtensionErrorUtils::FormatErrorMessage(kInvalidUrlError, 30 *error = ExtensionErrorUtils::FormatErrorMessage(kInvalidPathError,
47 url_string); 31 relative_path);
48 return GURL(); 32 return GURL();
49 } 33 }
50 if (!url.SchemeIs(chrome::kExtensionScheme) &&
51 !CanUseHost(extension, url, error)) {
52 return GURL();
53 }
54 // Disallow requests outside of the requesting extension view's extension.
55 if (url.SchemeIs(chrome::kExtensionScheme)) {
56 std::string extension_id(url.host());
57 if (extension_id != extension->id())
58 return GURL();
59 }
60
61 return url; 34 return url;
62 } 35 }
63 36
64 } // namespace extension_sidebar_utils 37 } // namespace extension_sidebar_utils
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_sidebar_utils.h ('k') | chrome/test/data/extensions/api_test/sidebar/test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698