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

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

Issue 6321006: Add "sidebar" section to extension manifest:... (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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/common/extensions/extension_sidebar_utils.h"
6
7 #include "chrome/common/extensions/extension.h"
8 #include "chrome/common/extensions/extension_error_utils.h"
9 #include "chrome/common/url_constants.h"
10 #include "googleurl/src/gurl.h"
11
12 namespace {
13
14 // Errors.
15 const char kInvalidUrlError[] = "Invalid url: \"*\".";
16
17 bool CanUseHost(const Extension* extension,
18 const GURL& url,
19 std::string* error) {
20 if (extension->HasHostPermission(url))
Aaron Boodman 2011/01/20 00:36:11 This is overloading the meaning of host permission
Aleksey Shlyapnikov 2011/01/20 02:41:43 As chromium.org says, "Many extension capabilities
Aaron Boodman 2011/01/20 17:53:16 Yup. All of these are basically the same permissio
21 return true;
22
23 *error = ExtensionErrorUtils::FormatErrorMessage(
24 extension_manifest_errors::kCannotAccessPage, url.spec());
25 return false;
26 }
27
28 } // namespace
29
30 namespace extension_sidebar_utils {
31
32 std::string GetExtensionIdByContentId(const std::string& content_id) {
33 // At the moment, content_id == extension_id.
34 return content_id;
35 }
36
37 GURL ResolveAndVerifyUrl(const std::string& url_string,
38 const Extension* extension,
39 std::string* error) {
40 // Resolve possibly relative URL.
41 GURL url(url_string);
42 if (!url.is_valid())
43 url = extension->GetResourceURL(url_string);
44
45 if (!url.is_valid()) {
46 *error = ExtensionErrorUtils::FormatErrorMessage(kInvalidUrlError,
47 url_string);
48 return GURL();
49 }
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;
62 }
63
64 } // namespace extension_sidebar_utils
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698