| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/extensions/extension_webrequest_api.h" | 5 #include "chrome/browser/extensions/extension_webrequest_api.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1189 case ExtensionWebRequestEventRouter::kOnBeforeSendHeaders: { | 1189 case ExtensionWebRequestEventRouter::kOnBeforeSendHeaders: { |
| 1190 net::HttpRequestHeaders* old_headers = blocked_request->request_headers; | 1190 net::HttpRequestHeaders* old_headers = blocked_request->request_headers; |
| 1191 net::HttpRequestHeaders* new_headers = response->request_headers.get(); | 1191 net::HttpRequestHeaders* new_headers = response->request_headers.get(); |
| 1192 return helpers::CalculateOnBeforeSendHeadersDelta( | 1192 return helpers::CalculateOnBeforeSendHeadersDelta( |
| 1193 response->extension_id, response->extension_install_time, | 1193 response->extension_id, response->extension_install_time, |
| 1194 response->cancel, old_headers, new_headers); | 1194 response->cancel, old_headers, new_headers); |
| 1195 } | 1195 } |
| 1196 case ExtensionWebRequestEventRouter::kOnHeadersReceived: { | 1196 case ExtensionWebRequestEventRouter::kOnHeadersReceived: { |
| 1197 net::HttpResponseHeaders* old_headers = | 1197 net::HttpResponseHeaders* old_headers = |
| 1198 blocked_request->original_response_headers.get(); | 1198 blocked_request->original_response_headers.get(); |
| 1199 helpers::ResponseHeaders* new_headers = |
| 1200 response->response_headers.get(); |
| 1199 return helpers::CalculateOnHeadersReceivedDelta( | 1201 return helpers::CalculateOnHeadersReceivedDelta( |
| 1200 response->extension_id, response->extension_install_time, | 1202 response->extension_id, response->extension_install_time, |
| 1201 response->cancel, old_headers->GetStatusLine(), | 1203 response->cancel, old_headers, new_headers); |
| 1202 response->response_headers_string); | |
| 1203 } | 1204 } |
| 1204 case ExtensionWebRequestEventRouter::kOnAuthRequired: | 1205 case ExtensionWebRequestEventRouter::kOnAuthRequired: |
| 1205 return helpers::CalculateOnAuthRequiredDelta( | 1206 return helpers::CalculateOnAuthRequiredDelta( |
| 1206 response->extension_id, response->extension_install_time, | 1207 response->extension_id, response->extension_install_time, |
| 1207 response->cancel, &response->auth_credentials); | 1208 response->cancel, &response->auth_credentials); |
| 1208 default: | 1209 default: |
| 1209 NOTREACHED(); | 1210 NOTREACHED(); |
| 1210 break; | 1211 break; |
| 1211 } | 1212 } |
| 1212 return NULL; | 1213 return NULL; |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1546 std::string value; | 1547 std::string value; |
| 1547 EXTENSION_FUNCTION_VALIDATE( | 1548 EXTENSION_FUNCTION_VALIDATE( |
| 1548 request_headers_value->GetDictionary(i, &header_value)); | 1549 request_headers_value->GetDictionary(i, &header_value)); |
| 1549 EXTENSION_FUNCTION_VALIDATE( | 1550 EXTENSION_FUNCTION_VALIDATE( |
| 1550 FromHeaderDictionary(header_value, &name, &value)); | 1551 FromHeaderDictionary(header_value, &name, &value)); |
| 1551 response->request_headers->SetHeader(name, value); | 1552 response->request_headers->SetHeader(name, value); |
| 1552 } | 1553 } |
| 1553 } | 1554 } |
| 1554 | 1555 |
| 1555 if (value->HasKey("responseHeaders")) { | 1556 if (value->HasKey("responseHeaders")) { |
| 1556 std::string response_headers_string; | 1557 helpers::ResponseHeaders* response_headers = |
| 1558 new helpers::ResponseHeaders(); |
| 1557 ListValue* response_headers_value = NULL; | 1559 ListValue* response_headers_value = NULL; |
| 1558 EXTENSION_FUNCTION_VALIDATE(value->GetList(keys::kResponseHeadersKey, | 1560 EXTENSION_FUNCTION_VALIDATE(value->GetList(keys::kResponseHeadersKey, |
| 1559 &response_headers_value)); | 1561 &response_headers_value)); |
| 1560 for (size_t i = 0; i < response_headers_value->GetSize(); ++i) { | 1562 for (size_t i = 0; i < response_headers_value->GetSize(); ++i) { |
| 1561 DictionaryValue* header_value = NULL; | 1563 DictionaryValue* header_value = NULL; |
| 1562 std::string name; | 1564 std::string name; |
| 1563 std::string value; | 1565 std::string value; |
| 1564 EXTENSION_FUNCTION_VALIDATE( | 1566 EXTENSION_FUNCTION_VALIDATE( |
| 1565 response_headers_value->GetDictionary(i, &header_value)); | 1567 response_headers_value->GetDictionary(i, &header_value)); |
| 1566 EXTENSION_FUNCTION_VALIDATE( | 1568 EXTENSION_FUNCTION_VALIDATE( |
| 1567 FromHeaderDictionary(header_value, &name, &value)); | 1569 FromHeaderDictionary(header_value, &name, &value)); |
| 1568 response_headers_string += name + ": " + value + '\n'; | 1570 response_headers->push_back(helpers::ResponseHeader(name, value)); |
| 1569 } | 1571 } |
| 1570 response_headers_string += '\n'; | 1572 response->response_headers.reset(response_headers); |
| 1571 response->response_headers_string.swap(response_headers_string); | |
| 1572 } | 1573 } |
| 1573 | 1574 |
| 1574 if (value->HasKey(keys::kAuthCredentialsKey)) { | 1575 if (value->HasKey(keys::kAuthCredentialsKey)) { |
| 1575 DictionaryValue* credentials_value = NULL; | 1576 DictionaryValue* credentials_value = NULL; |
| 1576 EXTENSION_FUNCTION_VALIDATE(value->GetDictionary( | 1577 EXTENSION_FUNCTION_VALIDATE(value->GetDictionary( |
| 1577 keys::kAuthCredentialsKey, | 1578 keys::kAuthCredentialsKey, |
| 1578 &credentials_value)); | 1579 &credentials_value)); |
| 1579 string16 username; | 1580 string16 username; |
| 1580 string16 password; | 1581 string16 password; |
| 1581 EXTENSION_FUNCTION_VALIDATE( | 1582 EXTENSION_FUNCTION_VALIDATE( |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1647 } else if ((*it)->name().find("AdBlock") != std::string::npos) { | 1648 } else if ((*it)->name().find("AdBlock") != std::string::npos) { |
| 1648 adblock = true; | 1649 adblock = true; |
| 1649 } else { | 1650 } else { |
| 1650 other = true; | 1651 other = true; |
| 1651 } | 1652 } |
| 1652 } | 1653 } |
| 1653 } | 1654 } |
| 1654 | 1655 |
| 1655 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); | 1656 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); |
| 1656 } | 1657 } |
| OLD | NEW |