| 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" | 8 #include "chrome/common/render_messages_params.h" |
| 9 #include "chrome/common/url_constants.h" | 9 #include "chrome/common/url_constants.h" |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 icon_url_ = that.icon_url_; | 22 icon_url_ = that.icon_url_; |
| 23 } | 23 } |
| 24 | 24 |
| 25 ExtensionRendererInfo::~ExtensionRendererInfo() { | 25 ExtensionRendererInfo::~ExtensionRendererInfo() { |
| 26 } | 26 } |
| 27 | 27 |
| 28 void ExtensionRendererInfo::Update(const ViewMsg_ExtensionRendererInfo& info) { | 28 void ExtensionRendererInfo::Update(const ViewMsg_ExtensionRendererInfo& info) { |
| 29 id_ = info.id; | 29 id_ = info.id; |
| 30 web_extent_ = info.web_extent; | 30 web_extent_ = info.web_extent; |
| 31 name_ = info.name; | 31 name_ = info.name; |
| 32 location_ = info.location; |
| 32 icon_url_ = info.icon_url; | 33 icon_url_ = info.icon_url; |
| 33 } | 34 } |
| 34 | 35 |
| 35 // static | 36 // static |
| 36 void ExtensionRendererInfo::UpdateExtensions( | 37 void ExtensionRendererInfo::UpdateExtensions( |
| 37 const ViewMsg_ExtensionsUpdated_Params& params) { | 38 const ViewMsg_ExtensionsUpdated_Params& params) { |
| 38 size_t count = params.extensions.size(); | 39 size_t count = params.extensions.size(); |
| 39 if (!extensions_) | 40 if (!extensions_) |
| 40 extensions_ = new std::vector<ExtensionRendererInfo>(count); | 41 extensions_ = new std::vector<ExtensionRendererInfo>(count); |
| 41 else | 42 else |
| 42 extensions_->resize(count); | 43 extensions_->resize(count); |
| 43 | 44 |
| 44 for (size_t i = 0; i < count; ++i) | 45 for (size_t i = 0; i < count; ++i) |
| 45 extensions_->at(i).Update(params.extensions[i]); | 46 extensions_->at(i).Update(params.extensions[i]); |
| 46 } | 47 } |
| 47 | 48 |
| 48 // static | 49 // static |
| 50 std::string ExtensionRendererInfo::GetIdByURL(const GURL& url) { |
| 51 if (url.SchemeIs(chrome::kExtensionScheme)) |
| 52 return url.host(); |
| 53 |
| 54 ExtensionRendererInfo* info = GetByURL(url); |
| 55 if (!info) |
| 56 return ""; |
| 57 |
| 58 return info->id(); |
| 59 } |
| 60 |
| 61 // static |
| 49 ExtensionRendererInfo* ExtensionRendererInfo::GetByURL(const GURL& url) { | 62 ExtensionRendererInfo* ExtensionRendererInfo::GetByURL(const GURL& url) { |
| 50 if (url.SchemeIs(chrome::kExtensionScheme)) | 63 if (url.SchemeIs(chrome::kExtensionScheme)) |
| 51 return GetByID(url.host()); | 64 return GetByID(url.host()); |
| 52 | 65 |
| 53 if (!extensions_) | 66 if (!extensions_) |
| 54 return NULL; | 67 return NULL; |
| 55 | 68 |
| 56 std::vector<ExtensionRendererInfo>::iterator i = extensions_->begin(); | 69 std::vector<ExtensionRendererInfo>::iterator i = extensions_->begin(); |
| 57 for (; i != extensions_->end(); ++i) { | 70 for (; i != extensions_->end(); ++i) { |
| 58 if (i->web_extent_.ContainsURL(url)) | 71 if (i->web_extent_.ContainsURL(url)) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 77 return NULL; | 90 return NULL; |
| 78 } | 91 } |
| 79 | 92 |
| 80 std::vector<ExtensionRendererInfo>::iterator i = extensions_->begin(); | 93 std::vector<ExtensionRendererInfo>::iterator i = extensions_->begin(); |
| 81 for (; i != extensions_->end(); ++i) { | 94 for (; i != extensions_->end(); ++i) { |
| 82 if (i->id() == id) | 95 if (i->id() == id) |
| 83 return &(*i); | 96 return &(*i); |
| 84 } | 97 } |
| 85 return NULL; | 98 return NULL; |
| 86 } | 99 } |
| 100 |
| 101 // static |
| 102 bool ExtensionRendererInfo::ExtensionBindingsAllowed(const GURL& url) { |
| 103 if (url.SchemeIs(chrome::kExtensionScheme)) |
| 104 return true; |
| 105 |
| 106 if (!extensions_) |
| 107 return false; |
| 108 |
| 109 std::vector<ExtensionRendererInfo>::iterator i = extensions_->begin(); |
| 110 for (; i != extensions_->end(); ++i) { |
| 111 if (i->location_ == Extension::COMPONENT && |
| 112 i->web_extent_.ContainsURL(url)) |
| 113 return true; |
| 114 } |
| 115 |
| 116 return false; |
| 117 } |
| OLD | NEW |