OLD | NEW |
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/renderer/extensions/extension_renderer_info.h" | 5 #include "chrome/renderer/extensions/extension_renderer_info.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/common/render_messages_params.h" | |
9 #include "chrome/common/url_constants.h" | 8 #include "chrome/common/url_constants.h" |
10 | 9 |
11 // static | 10 ExtensionRendererInfo::ExtensionRendererInfo() { |
12 std::vector<ExtensionRendererInfo>* ExtensionRendererInfo::extensions_ = NULL; | |
13 | |
14 ExtensionRendererInfo::ExtensionRendererInfo() | |
15 : location_(Extension::INVALID), | |
16 allowed_to_execute_script_everywhere_(false) { | |
17 } | 11 } |
18 | 12 |
19 ExtensionRendererInfo::ExtensionRendererInfo( | 13 size_t ExtensionRendererInfo::size() const { |
20 const ExtensionRendererInfo& that) { | 14 return extensions_.size(); |
21 id_ = that.id_; | |
22 web_extent_ = that.web_extent_; | |
23 name_ = that.name_; | |
24 icon_url_ = that.icon_url_; | |
25 allowed_to_execute_script_everywhere_ = | |
26 that.allowed_to_execute_script_everywhere_; | |
27 host_permissions_ = that.host_permissions_; | |
28 location_ = that.location_; | |
29 } | 15 } |
30 | 16 |
31 ExtensionRendererInfo::~ExtensionRendererInfo() { | 17 void ExtensionRendererInfo::Update( |
| 18 const scoped_refptr<const Extension>& extension) { |
| 19 extensions_[extension->id()] = extension; |
32 } | 20 } |
33 | 21 |
34 void ExtensionRendererInfo::Update(const ViewMsg_ExtensionRendererInfo& info) { | 22 void ExtensionRendererInfo::Remove(const std::string& id) { |
35 id_ = info.id; | 23 extensions_.erase(id); |
36 web_extent_ = info.web_extent; | |
37 name_ = info.name; | |
38 location_ = info.location; | |
39 icon_url_ = info.icon_url; | |
40 allowed_to_execute_script_everywhere_ = | |
41 info.allowed_to_execute_script_everywhere; | |
42 host_permissions_ = info.host_permissions; | |
43 } | 24 } |
44 | 25 |
45 // static | 26 std::string ExtensionRendererInfo::GetIdByURL(const GURL& url) const { |
46 void ExtensionRendererInfo::UpdateExtensions( | |
47 const ViewMsg_ExtensionsUpdated_Params& params) { | |
48 size_t count = params.extensions.size(); | |
49 if (!extensions_) | |
50 extensions_ = new std::vector<ExtensionRendererInfo>(count); | |
51 else | |
52 extensions_->resize(count); | |
53 | |
54 for (size_t i = 0; i < count; ++i) | |
55 extensions_->at(i).Update(params.extensions[i]); | |
56 } | |
57 | |
58 // static | |
59 std::string ExtensionRendererInfo::GetIdByURL(const GURL& url) { | |
60 if (url.SchemeIs(chrome::kExtensionScheme)) | 27 if (url.SchemeIs(chrome::kExtensionScheme)) |
61 return url.host(); | 28 return url.host(); |
62 | 29 |
63 ExtensionRendererInfo* info = GetByURL(url); | 30 const Extension* extension = GetByURL(url); |
64 if (!info) | 31 if (!extension) |
65 return ""; | 32 return ""; |
66 | 33 |
67 return info->id(); | 34 return extension->id(); |
68 } | 35 } |
69 | 36 |
70 // static | 37 const Extension* ExtensionRendererInfo::GetByURL( |
71 ExtensionRendererInfo* ExtensionRendererInfo::GetByURL(const GURL& url) { | 38 const GURL& url) const { |
72 if (url.SchemeIs(chrome::kExtensionScheme)) | 39 if (url.SchemeIs(chrome::kExtensionScheme)) |
73 return GetByID(url.host()); | 40 return GetByID(url.host()); |
74 | 41 |
75 if (!extensions_) | 42 ExtensionMap::const_iterator i = extensions_.begin(); |
76 return NULL; | 43 for (; i != extensions_.end(); ++i) { |
77 | 44 if (i->second->web_extent().ContainsURL(url)) |
78 std::vector<ExtensionRendererInfo>::iterator i = extensions_->begin(); | 45 return i->second.get(); |
79 for (; i != extensions_->end(); ++i) { | |
80 if (i->web_extent_.ContainsURL(url)) | |
81 return &(*i); | |
82 } | 46 } |
83 | 47 |
84 return NULL; | 48 return NULL; |
85 } | 49 } |
86 | 50 |
87 // static | |
88 bool ExtensionRendererInfo::InSameExtent(const GURL& old_url, | 51 bool ExtensionRendererInfo::InSameExtent(const GURL& old_url, |
89 const GURL& new_url) { | 52 const GURL& new_url) const { |
90 return GetByURL(old_url) == GetByURL(new_url); | 53 return GetByURL(old_url) == GetByURL(new_url); |
91 } | 54 } |
92 | 55 |
93 // static | 56 const Extension* ExtensionRendererInfo::GetByID( |
94 ExtensionRendererInfo* ExtensionRendererInfo::GetByID( | 57 const std::string& id) const { |
95 const std::string& id) { | 58 ExtensionMap::const_iterator i = extensions_.find(id); |
96 | 59 if (i != extensions_.end()) |
97 if (!extensions_) { | 60 return i->second.get(); |
98 NOTREACHED(); | 61 else |
99 return NULL; | 62 return NULL; |
100 } | |
101 | |
102 std::vector<ExtensionRendererInfo>::iterator i = extensions_->begin(); | |
103 for (; i != extensions_->end(); ++i) { | |
104 if (i->id() == id) | |
105 return &(*i); | |
106 } | |
107 return NULL; | |
108 } | 63 } |
109 | 64 |
110 // static | 65 bool ExtensionRendererInfo::ExtensionBindingsAllowed(const GURL& url) const { |
111 bool ExtensionRendererInfo::ExtensionBindingsAllowed(const GURL& url) { | |
112 if (url.SchemeIs(chrome::kExtensionScheme)) | 66 if (url.SchemeIs(chrome::kExtensionScheme)) |
113 return true; | 67 return true; |
114 | 68 |
115 if (!extensions_) | 69 ExtensionMap::const_iterator i = extensions_.begin(); |
116 return false; | 70 for (; i != extensions_.end(); ++i) { |
117 | 71 if (i->second->location() == Extension::COMPONENT && |
118 std::vector<ExtensionRendererInfo>::iterator i = extensions_->begin(); | 72 i->second->web_extent().ContainsURL(url)) |
119 for (; i != extensions_->end(); ++i) { | |
120 if (i->location_ == Extension::COMPONENT && | |
121 i->web_extent_.ContainsURL(url)) | |
122 return true; | 73 return true; |
123 } | 74 } |
124 | 75 |
125 return false; | 76 return false; |
126 } | 77 } |
OLD | NEW |